src/html-generator/test-embedding-list-generator.lua

81 lines

1#!/usr/bin/env lua
2
3-- Test Embedding List Generator System
4-- Validates similarity and diversity list generation
5
6package.path = package.path .. ';./?.lua;./libs/?.lua'
7
8local utils = require("libs.utils")
9local embedding_generator = require("src.html-generator.embedding-list-generator")
10
11local M = {}
12local DIR = "/mnt/mtwo/programming/ai-stuff/neocities-modernization"
13
14-- {{{ function M.test_embedding_list_generation
15function M.test_embedding_list_generation()
16 utils.log_info("Testing embedding list generation...")
17
18 local embeddings_dir = DIR .. "/assets/embeddings"
19 local model_name = "embeddinggemma_latest"
20
21 -- Test generation
22 local success = embedding_generator.generate_all_embedding_lists(embeddings_dir, model_name, {
23 chain_length = 10 -- Shorter for testing
24 })
25
26 if success then
27 utils.log_info("✅ Embedding list generation: PASSED")
28
29 -- Validate output files exist
30 local most_similar_dir = embeddings_dir .. "/" .. model_name .. "/similarity_lists/most_similar"
31 local diversity_dir = embeddings_dir .. "/" .. model_name .. "/similarity_lists/diversity_chains"
32
33 -- Check sample files
34 local sample_files = {
35 most_similar_dir .. "/poem-001-most-similar.json",
36 diversity_dir .. "/poem-001-diversity-chain.json"
37 }
38
39 local files_valid = 0
40 for _, file_path in ipairs(sample_files) do
41 if utils.file_exists(file_path) then
42 local data = utils.read_json_file(file_path)
43 if data then
44 files_valid = files_valid + 1
45 utils.log_info(string.format("✅ Sample file valid: %s", file_path))
46 end
47 end
48 end
49
50 utils.log_info(string.format("Sample validation: %d/%d files valid", files_valid, #sample_files))
51 return files_valid >= 1
52 else
53 utils.log_error("❌ Embedding list generation: FAILED")
54 return false
55 end
56end
57-- }}}
58
59-- {{{ function M.run_all_tests
60function M.run_all_tests()
61 utils.log_info("Running embedding list generator test suite...")
62
63 local generation_test = M.test_embedding_list_generation()
64
65 if generation_test then
66 utils.log_info("🎉 ALL EMBEDDING LIST GENERATOR TESTS PASSED")
67 else
68 utils.log_error("❌ Some embedding list generator tests FAILED")
69 end
70
71 return generation_test
72end
73-- }}}
74
75-- Run tests if called directly
76if arg and arg[0] and arg[0]:match("test%-embedding%-list%-generator%.lua$") then
77 local success = M.run_all_tests()
78 os.exit(success and 0 or 1)
79end
80
81return M