From 9f37be1550072692510dd6901bc6d1109d49f52f Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 17 Feb 2026 21:45:40 -0700 Subject: [PATCH] Step 642: job dispatch table generator --- editor/CMakeLists.txt | 9 ++ editor/src/JobDispatchTableGenerator.h | 55 +++++++++++ editor/tests/step642_test.cpp | 125 +++++++++++++++++++++++++ progress.md | 31 ++++++ 4 files changed, 220 insertions(+) create mode 100644 editor/src/JobDispatchTableGenerator.h create mode 100644 editor/tests/step642_test.cpp diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index 4219dda..5425b24 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -4657,4 +4657,13 @@ target_link_libraries(step641_test PRIVATE tree_sitter_javascript tree_sitter_typescript tree_sitter_java tree_sitter_rust tree_sitter_go) +add_executable(step642_test tests/step642_test.cpp) +target_include_directories(step642_test PRIVATE src) +target_link_libraries(step642_test PRIVATE + nlohmann_json::nlohmann_json + unofficial::tree-sitter::tree-sitter + tree_sitter_python tree_sitter_cpp tree_sitter_elisp + tree_sitter_javascript tree_sitter_typescript + tree_sitter_java tree_sitter_rust tree_sitter_go) + # Step 12: Dear ImGui shell scaffolding created (main.cpp exists but not built due to dependencies) diff --git a/editor/src/JobDispatchTableGenerator.h b/editor/src/JobDispatchTableGenerator.h new file mode 100644 index 0000000..18c8115 --- /dev/null +++ b/editor/src/JobDispatchTableGenerator.h @@ -0,0 +1,55 @@ +#pragma once +// Step 642: Job dispatch table generator + +#include +#include + +struct JobDispatchEntrySpec { + std::string jobType; + std::vector requiredCaps; + std::string payloadType; + std::string executor; +}; + +struct JobDispatchTableOutput { + bool success = false; + std::string headerCode; + std::vector errors; +}; + +class JobDispatchTableGenerator { +public: + static JobDispatchTableOutput generate(const std::vector& entries) { + JobDispatchTableOutput out; + if (entries.empty()) { + out.errors.push_back("entries_required"); + return out; + } + + out.success = true; + out.headerCode = "#pragma once\n" + "#include \n" + "#include \n" + "#include \n\n" + "using ExecutorFn = std::function;\n" + "inline std::unordered_map makeDispatchTable() {\n" + " std::unordered_map table;\n"; + for (const auto& e : entries) { + out.headerCode += " table[\"" + e.jobType + "\"] = " + e.executor + ";\n"; + out.headerCode += " // payload=" + e.payloadType + " caps=" + joinCaps(e.requiredCaps) + "\n"; + } + out.headerCode += " return table;\n}\n"; + return out; + } + +private: + static std::string joinCaps(const std::vector& caps) { + if (caps.empty()) return "none"; + std::string out; + for (std::size_t i = 0; i < caps.size(); ++i) { + if (i) out += ","; + out += caps[i]; + } + return out; + } +}; diff --git a/editor/tests/step642_test.cpp b/editor/tests/step642_test.cpp new file mode 100644 index 0000000..7d698e2 --- /dev/null +++ b/editor/tests/step642_test.cpp @@ -0,0 +1,125 @@ +// Step 642: Job dispatch table generator (12 tests) + +#include "JobDispatchTableGenerator.h" + +#include + +static int passed = 0, failed = 0; +#define TEST(name) { std::cout << " " << #name << "... "; } +#define PASS() { std::cout << "PASS\n"; ++passed; } +#define FAIL(msg) { std::cout << "FAIL: " << msg << "\n"; ++failed; } +#define CHECK(cond, msg) if (!(cond)) { FAIL(msg); return; } + +static std::vector sampleEntries() { + return { + {"compile", {"cpp", "build"}, "CompilePayload", "runCompile"}, + {"test", {"cpp", "test"}, "TestPayload", "runTests"} + }; +} + +void test_generate_rejects_empty_entries() { + TEST(generate_rejects_empty_entries); + auto out = JobDispatchTableGenerator::generate({}); + CHECK(!out.success, "empty entries should fail"); + PASS(); +} + +void test_generate_succeeds_with_entries() { + TEST(generate_succeeds_with_entries); + auto out = JobDispatchTableGenerator::generate(sampleEntries()); + CHECK(out.success, "generation should succeed"); + PASS(); +} + +void test_header_contains_executor_alias() { + TEST(header_contains_executor_alias); + auto out = JobDispatchTableGenerator::generate(sampleEntries()); + CHECK(out.headerCode.find("using ExecutorFn") != std::string::npos, "ExecutorFn alias missing"); + PASS(); +} + +void test_header_contains_dispatch_table_factory() { + TEST(header_contains_dispatch_table_factory); + auto out = JobDispatchTableGenerator::generate(sampleEntries()); + CHECK(out.headerCode.find("makeDispatchTable") != std::string::npos, "factory missing"); + PASS(); +} + +void test_header_contains_compile_job_entry() { + TEST(header_contains_compile_job_entry); + auto out = JobDispatchTableGenerator::generate(sampleEntries()); + CHECK(out.headerCode.find("table[\"compile\"] = runCompile") != std::string::npos, "compile entry missing"); + PASS(); +} + +void test_header_contains_test_job_entry() { + TEST(header_contains_test_job_entry); + auto out = JobDispatchTableGenerator::generate(sampleEntries()); + CHECK(out.headerCode.find("table[\"test\"] = runTests") != std::string::npos, "test entry missing"); + PASS(); +} + +void test_header_contains_payload_marker_for_compile() { + TEST(header_contains_payload_marker_for_compile); + auto out = JobDispatchTableGenerator::generate(sampleEntries()); + CHECK(out.headerCode.find("payload=CompilePayload") != std::string::npos, "compile payload marker missing"); + PASS(); +} + +void test_header_contains_caps_marker_for_compile() { + TEST(header_contains_caps_marker_for_compile); + auto out = JobDispatchTableGenerator::generate(sampleEntries()); + CHECK(out.headerCode.find("caps=cpp,build") != std::string::npos, "compile caps marker missing"); + PASS(); +} + +void test_header_contains_caps_marker_for_test() { + TEST(header_contains_caps_marker_for_test); + auto out = JobDispatchTableGenerator::generate(sampleEntries()); + CHECK(out.headerCode.find("caps=cpp,test") != std::string::npos, "test caps marker missing"); + PASS(); +} + +void test_header_is_header_only() { + TEST(header_is_header_only); + auto out = JobDispatchTableGenerator::generate(sampleEntries()); + CHECK(out.headerCode.find("#pragma once") != std::string::npos, "pragma missing"); + PASS(); +} + +void test_generate_handles_entry_with_no_caps() { + TEST(generate_handles_entry_with_no_caps); + auto out = JobDispatchTableGenerator::generate({{"lint", {}, "LintPayload", "runLint"}}); + CHECK(out.headerCode.find("caps=none") != std::string::npos, "none caps marker missing"); + PASS(); +} + +void test_entry_order_is_preserved() { + TEST(entry_order_is_preserved); + auto out = JobDispatchTableGenerator::generate(sampleEntries()); + std::size_t compilePos = out.headerCode.find("table[\"compile\"]"); + std::size_t testPos = out.headerCode.find("table[\"test\"]"); + CHECK(compilePos != std::string::npos && testPos != std::string::npos && compilePos < testPos, + "entry order mismatch"); + PASS(); +} + +int main() { + std::cout << "Step 642: Job dispatch table generator\n"; + + test_generate_rejects_empty_entries(); + test_generate_succeeds_with_entries(); + test_header_contains_executor_alias(); + test_header_contains_dispatch_table_factory(); + test_header_contains_compile_job_entry(); + test_header_contains_test_job_entry(); + test_header_contains_payload_marker_for_compile(); + test_header_contains_caps_marker_for_compile(); + test_header_contains_caps_marker_for_test(); + test_header_is_header_only(); + test_generate_handles_entry_with_no_caps(); + test_entry_order_is_preserved(); + + std::cout << "\nResults: " << passed << "/" << (passed + failed) << " passed\n"; + return failed == 0 ? 0 : 1; +} diff --git a/progress.md b/progress.md index 94b8d84..988f99b 100644 --- a/progress.md +++ b/progress.md @@ -13075,3 +13075,34 @@ statement generation anchors. - `editor/src/SQLiteDataLayerGenerator.h` (`47` <= `600`) - `editor/tests/step641_test.cpp` within test-file size guidance (`125` lines) - Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md` + +### Step 642: Job dispatch table generator +**Status:** PASS (12/12 tests) + +Adds dispatch-table generation from job-type registry definitions with executor +binding, payload/capability markers, and header-only factory emission for +drone-side typed dispatch wiring. + +**Files added:** +- `editor/src/JobDispatchTableGenerator.h` - dispatch generator: + - validates dispatch entry input + - emits `ExecutorFn` alias and `makeDispatchTable()` factory + - embeds payload/capability metadata comments per job type +- `editor/tests/step642_test.cpp` - 12 tests covering: + - empty-input rejection and valid generation + - dispatch table and executor binding emission + - payload/capability marker correctness and ordering + +**Files modified:** +- `editor/CMakeLists.txt` - `step642_test` target + +**Verification run:** +- `cmake -S editor -B editor/build-native` - PASS +- `cmake --build editor/build-native --target step642_test step641_test` - PASS +- `./editor/build-native/step642_test` - PASS (12/12) +- `./editor/build-native/step641_test` - PASS (12/12) regression coverage + +**Architecture gate check:** +- `editor/src/JobDispatchTableGenerator.h` (`55` <= `600`) +- `editor/tests/step642_test.cpp` within test-file size guidance (`125` lines) +- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`