Step 642: job dispatch table generator

This commit is contained in:
Bill
2026-02-17 21:45:40 -07:00
parent ec74db1275
commit 9f37be1550
4 changed files with 220 additions and 0 deletions

View File

@@ -4657,4 +4657,13 @@ target_link_libraries(step641_test PRIVATE
tree_sitter_javascript tree_sitter_typescript tree_sitter_javascript tree_sitter_typescript
tree_sitter_java tree_sitter_rust tree_sitter_go) 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) # Step 12: Dear ImGui shell scaffolding created (main.cpp exists but not built due to dependencies)

View File

@@ -0,0 +1,55 @@
#pragma once
// Step 642: Job dispatch table generator
#include <string>
#include <vector>
struct JobDispatchEntrySpec {
std::string jobType;
std::vector<std::string> requiredCaps;
std::string payloadType;
std::string executor;
};
struct JobDispatchTableOutput {
bool success = false;
std::string headerCode;
std::vector<std::string> errors;
};
class JobDispatchTableGenerator {
public:
static JobDispatchTableOutput generate(const std::vector<JobDispatchEntrySpec>& entries) {
JobDispatchTableOutput out;
if (entries.empty()) {
out.errors.push_back("entries_required");
return out;
}
out.success = true;
out.headerCode = "#pragma once\n"
"#include <string>\n"
"#include <unordered_map>\n"
"#include <functional>\n\n"
"using ExecutorFn = std::function<bool(const std::string&)>;\n"
"inline std::unordered_map<std::string, ExecutorFn> makeDispatchTable() {\n"
" std::unordered_map<std::string, ExecutorFn> 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<std::string>& 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;
}
};

View File

@@ -0,0 +1,125 @@
// Step 642: Job dispatch table generator (12 tests)
#include "JobDispatchTableGenerator.h"
#include <iostream>
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<JobDispatchEntrySpec> 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;
}

View File

@@ -13075,3 +13075,34 @@ statement generation anchors.
- `editor/src/SQLiteDataLayerGenerator.h` (`47` <= `600`) - `editor/src/SQLiteDataLayerGenerator.h` (`47` <= `600`)
- `editor/tests/step641_test.cpp` within test-file size guidance (`125` lines) - `editor/tests/step641_test.cpp` within test-file size guidance (`125` lines)
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md` - 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`