From 1f3ee28cfbdd693c8a6e76f8c3fc7e8345c3379d Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 17 Feb 2026 09:38:11 -0700 Subject: [PATCH] Step 539: add C/C++ constructive edit adapter --- editor/CMakeLists.txt | 9 ++ editor/src/CppConstructiveEditAdapter.h | 90 +++++++++++++++++ editor/tests/step539_test.cpp | 126 ++++++++++++++++++++++++ progress.md | 32 ++++++ 4 files changed, 257 insertions(+) create mode 100644 editor/src/CppConstructiveEditAdapter.h create mode 100644 editor/tests/step539_test.cpp diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index da5b5fc..22f3ab0 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -3730,4 +3730,13 @@ target_link_libraries(step538_test PRIVATE tree_sitter_javascript tree_sitter_typescript tree_sitter_java tree_sitter_rust tree_sitter_go) +add_executable(step539_test tests/step539_test.cpp) +target_include_directories(step539_test PRIVATE src) +target_link_libraries(step539_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/CppConstructiveEditAdapter.h b/editor/src/CppConstructiveEditAdapter.h new file mode 100644 index 0000000..c52f369 --- /dev/null +++ b/editor/src/CppConstructiveEditAdapter.h @@ -0,0 +1,90 @@ +#pragma once +// Step 539: C/C++ Constructive Edit Adapter + +#include +#include +#include + +struct CppConstructiveEditRequest { + std::string language; // c or cpp + std::string constructKind; // declaration/definition/include/macro/class/member + std::string fileType; // header/source + std::string operation; +}; + +struct CppConstructiveEditResult { + bool supported = false; + bool allowed = false; + std::vector legalOperations; + std::vector diagnostics; +}; + +class CppConstructiveEditAdapter { +public: + static CppConstructiveEditResult evaluate(const CppConstructiveEditRequest& request) { + CppConstructiveEditResult result; + if (request.language != "c" && request.language != "cpp") { + result.diagnostics.push_back("unsupported_language"); + return result; + } + + result.supported = true; + result.legalOperations = legalOps(request.constructKind, request.fileType); + if (result.legalOperations.empty()) { + result.supported = false; + result.diagnostics.push_back("unsupported_construct"); + return result; + } + + if (!contains(result.legalOperations, request.operation)) { + result.diagnostics.push_back("operation_not_legal_for_construct"); + return result; + } + + auto boundary = boundaryGuard(request); + if (!boundary.empty()) { + result.diagnostics.push_back(boundary); + return result; + } + + result.allowed = true; + return result; + } + +private: + static std::vector legalOps(const std::string& kind, + const std::string& fileType) { + if (kind == "declaration") return {"rename", "update", "delete", "extract"}; + if (kind == "definition") return {"rename", "update", "extract", "inline"}; + if (kind == "include") return {"insert", "delete", "reorder"}; + if (kind == "macro") return {"rename", "update", "delete"}; + if (kind == "class") return {"rename", "update", "extract"}; + if (kind == "member") { + if (fileType == "header") return {"rename", "update", "extract"}; + return {"rename", "update"}; + } + return {}; + } + + static std::string boundaryGuard(const CppConstructiveEditRequest& request) { + // Header/source safety: definitions and include edits should stay in safe domains. + if (request.constructKind == "definition" && request.fileType == "header" && + request.operation == "inline") { + return "header_source_boundary_violation"; + } + if (request.constructKind == "include" && request.fileType == "source" && + request.operation == "reorder") { + return "source_include_reorder_blocked"; + } + if (request.constructKind == "macro" && request.fileType == "source" && + request.operation == "delete") { + return "macro_delete_requires_header_review"; + } + return ""; + } + + static bool contains(const std::vector& values, + const std::string& value) { + return std::set(values.begin(), values.end()).count(value) != 0; + } +}; diff --git a/editor/tests/step539_test.cpp b/editor/tests/step539_test.cpp new file mode 100644 index 0000000..afb7a20 --- /dev/null +++ b/editor/tests/step539_test.cpp @@ -0,0 +1,126 @@ +// Step 539: C/C++ Constructive Edit Adapter (12 tests) + +#include "CppConstructiveEditAdapter.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; } else {} + +static bool hasDiag(const CppConstructiveEditResult& r, const std::string& d) { + for (const auto& x : r.diagnostics) if (x == d) return true; + return false; +} + +void test_cpp_declaration_rename_allowed() { + TEST(cpp_declaration_rename_allowed); + auto r = CppConstructiveEditAdapter::evaluate({"cpp", "declaration", "header", "rename"}); + CHECK(r.supported && r.allowed, "declaration rename should be allowed"); + PASS(); +} + +void test_cpp_definition_extract_allowed_in_source() { + TEST(cpp_definition_extract_allowed_in_source); + auto r = CppConstructiveEditAdapter::evaluate({"cpp", "definition", "source", "extract"}); + CHECK(r.allowed, "source definition extract should be allowed"); + PASS(); +} + +void test_include_insert_allowed() { + TEST(include_insert_allowed); + auto r = CppConstructiveEditAdapter::evaluate({"cpp", "include", "header", "insert"}); + CHECK(r.allowed, "include insert should be allowed"); + PASS(); +} + +void test_include_reorder_blocked_in_source() { + TEST(include_reorder_blocked_in_source); + auto r = CppConstructiveEditAdapter::evaluate({"cpp", "include", "source", "reorder"}); + CHECK(!r.allowed, "source include reorder should be blocked"); + CHECK(hasDiag(r, "source_include_reorder_blocked"), "boundary diagnostic expected"); + PASS(); +} + +void test_macro_update_allowed() { + TEST(macro_update_allowed); + auto r = CppConstructiveEditAdapter::evaluate({"cpp", "macro", "header", "update"}); + CHECK(r.allowed, "macro update should be allowed"); + PASS(); +} + +void test_macro_delete_blocked_in_source() { + TEST(macro_delete_blocked_in_source); + auto r = CppConstructiveEditAdapter::evaluate({"cpp", "macro", "source", "delete"}); + CHECK(!r.allowed, "macro delete in source should be blocked"); + CHECK(hasDiag(r, "macro_delete_requires_header_review"), "macro boundary diagnostic expected"); + PASS(); +} + +void test_member_extract_allowed_in_header() { + TEST(member_extract_allowed_in_header); + auto r = CppConstructiveEditAdapter::evaluate({"cpp", "member", "header", "extract"}); + CHECK(r.allowed, "header member extract should be allowed"); + PASS(); +} + +void test_member_extract_blocked_in_source() { + TEST(member_extract_blocked_in_source); + auto r = CppConstructiveEditAdapter::evaluate({"cpp", "member", "source", "extract"}); + CHECK(!r.allowed, "source member extract should be illegal"); + CHECK(hasDiag(r, "operation_not_legal_for_construct"), "illegal-op diagnostic expected"); + PASS(); +} + +void test_definition_inline_blocked_in_header() { + TEST(definition_inline_blocked_in_header); + auto r = CppConstructiveEditAdapter::evaluate({"cpp", "definition", "header", "inline"}); + CHECK(!r.allowed, "header definition inline should be blocked"); + CHECK(hasDiag(r, "header_source_boundary_violation"), "boundary diagnostic expected"); + PASS(); +} + +void test_unsupported_construct_rejected() { + TEST(unsupported_construct_rejected); + auto r = CppConstructiveEditAdapter::evaluate({"cpp", "template_magic", "header", "rename"}); + CHECK(!r.supported, "unsupported construct should not be supported"); + CHECK(hasDiag(r, "unsupported_construct"), "unsupported construct diagnostic expected"); + PASS(); +} + +void test_unsupported_language_rejected() { + TEST(unsupported_language_rejected); + auto r = CppConstructiveEditAdapter::evaluate({"typescript", "definition", "source", "update"}); + CHECK(!r.supported, "unsupported language should not be supported"); + CHECK(hasDiag(r, "unsupported_language"), "unsupported language diagnostic expected"); + PASS(); +} + +void test_c_language_paths_supported() { + TEST(c_language_paths_supported); + auto r = CppConstructiveEditAdapter::evaluate({"c", "definition", "source", "update"}); + CHECK(r.supported && r.allowed, "c definition update should be supported"); + PASS(); +} + +int main() { + std::cout << "Step 539: C/C++ Constructive Edit Adapter\n"; + + test_cpp_declaration_rename_allowed(); // 1 + test_cpp_definition_extract_allowed_in_source();// 2 + test_include_insert_allowed(); // 3 + test_include_reorder_blocked_in_source(); // 4 + test_macro_update_allowed(); // 5 + test_macro_delete_blocked_in_source(); // 6 + test_member_extract_allowed_in_header(); // 7 + test_member_extract_blocked_in_source(); // 8 + test_definition_inline_blocked_in_header(); // 9 + test_unsupported_construct_rejected(); // 10 + test_unsupported_language_rejected(); // 11 + test_c_language_paths_supported(); // 12 + + std::cout << "\nResults: " << passed << "/" << (passed + failed) << " passed\n"; + return failed == 0 ? 0 : 1; +} diff --git a/progress.md b/progress.md index d18d042..a340d48 100644 --- a/progress.md +++ b/progress.md @@ -9149,3 +9149,35 @@ telemetry into a single constrained execution surface for agent-facing editing. - **Steps completed:** 5 - **New tests in phase plan:** 56/56 passing - **Legal-choice API + validation + telemetry integration:** PASS + +### Step 539: C/C++ Constructive Edit Adapter +**Status:** PASS (12/12 tests) + +Implements a C/C++ constructive edit adapter with construct-aware legal +operation mapping and header/source boundary safety checks. + +**Files added:** +- `editor/src/CppConstructiveEditAdapter.h` - C/C++ adapter module: + - legal operation mappings for declarations/definitions/includes/macros/classes/members + - language support for both `c` and `cpp` + - header/source boundary guards for sensitive operations + - structured diagnostics for unsupported constructs/languages and blocked ops +- `editor/tests/step539_test.cpp` - 12 tests covering: + - legal operation paths across declarations, definitions, includes, macros, members + - boundary-safe rejections (header/source violations) + - unsupported construct/language behavior + - C language compatibility path + +**Files modified:** +- `editor/CMakeLists.txt` - `step539_test` target + +**Verification run:** +- `cmake -S editor -B editor/build-native` - PASS +- `cmake --build editor/build-native --target step539_test step538_test` - PASS +- `./editor/build-native/step539_test` - PASS (12/12) +- `./editor/build-native/step538_test` - PASS (8/8) regression coverage + +**Architecture gate check:** +- `editor/src/CppConstructiveEditAdapter.h` within header-size limit (`90` <= `600`) +- `editor/tests/step539_test.cpp` within test-file size guidance (`126` lines) +- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`