Step 541: add Rust/Go constructive edit adapter
This commit is contained in:
@@ -3748,4 +3748,13 @@ target_link_libraries(step540_test PRIVATE
|
||||
tree_sitter_javascript tree_sitter_typescript
|
||||
tree_sitter_java tree_sitter_rust tree_sitter_go)
|
||||
|
||||
add_executable(step541_test tests/step541_test.cpp)
|
||||
target_include_directories(step541_test PRIVATE src)
|
||||
target_link_libraries(step541_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)
|
||||
|
||||
91
editor/src/RustGoConstructiveEditAdapter.h
Normal file
91
editor/src/RustGoConstructiveEditAdapter.h
Normal file
@@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
// Step 541: Rust/Go Constructive Edit Adapter
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct RustGoConstructiveEditRequest {
|
||||
std::string language; // rust/go
|
||||
std::string constructKind; // function/struct/impl/import/channel/borrow_region
|
||||
std::string operation;
|
||||
bool borrowOrLifetimeRisk = false;
|
||||
bool concurrencyRisk = false;
|
||||
};
|
||||
|
||||
struct RustGoConstructiveEditResult {
|
||||
bool supported = false;
|
||||
bool allowed = false;
|
||||
std::vector<std::string> legalOperations;
|
||||
std::vector<std::string> diagnostics;
|
||||
};
|
||||
|
||||
class RustGoConstructiveEditAdapter {
|
||||
public:
|
||||
static RustGoConstructiveEditResult evaluate(const RustGoConstructiveEditRequest& request) {
|
||||
RustGoConstructiveEditResult result;
|
||||
if (request.language != "rust" && request.language != "go") {
|
||||
result.diagnostics.push_back("unsupported_language");
|
||||
return result;
|
||||
}
|
||||
|
||||
result.supported = true;
|
||||
result.legalOperations = legalOps(request.constructKind);
|
||||
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 guard = safetyGuard(request);
|
||||
if (!guard.empty()) {
|
||||
result.diagnostics.push_back(guard);
|
||||
return result;
|
||||
}
|
||||
|
||||
result.allowed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
static std::vector<std::string> legalOps(const std::string& kind) {
|
||||
if (kind == "function") return {"rename", "update", "extract"};
|
||||
if (kind == "struct") return {"rename", "update"};
|
||||
if (kind == "impl") return {"update", "extract"};
|
||||
if (kind == "import") return {"insert", "delete", "reorder"};
|
||||
if (kind == "channel") return {"update", "extract"};
|
||||
if (kind == "borrow_region") return {"update", "extract"};
|
||||
return {};
|
||||
}
|
||||
|
||||
static std::string safetyGuard(const RustGoConstructiveEditRequest& request) {
|
||||
if (request.language == "rust" && request.borrowOrLifetimeRisk) {
|
||||
if (request.constructKind == "borrow_region" && request.operation == "extract") {
|
||||
return "rust_borrow_lifetime_extract_blocked";
|
||||
}
|
||||
if (request.constructKind == "struct" && request.operation == "rename") {
|
||||
return "rust_lifetime_sensitive_rename_blocked";
|
||||
}
|
||||
}
|
||||
|
||||
if (request.language == "go" && request.concurrencyRisk) {
|
||||
if (request.constructKind == "channel" && request.operation == "extract") {
|
||||
return "go_concurrency_extract_blocked";
|
||||
}
|
||||
if (request.constructKind == "function" && request.operation == "update") {
|
||||
return "go_concurrency_update_blocked";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static bool contains(const std::vector<std::string>& values,
|
||||
const std::string& value) {
|
||||
return std::set<std::string>(values.begin(), values.end()).count(value) != 0;
|
||||
}
|
||||
};
|
||||
127
editor/tests/step541_test.cpp
Normal file
127
editor/tests/step541_test.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
// Step 541: Rust/Go Constructive Edit Adapter (12 tests)
|
||||
|
||||
#include "RustGoConstructiveEditAdapter.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; } else {}
|
||||
|
||||
static bool hasDiag(const RustGoConstructiveEditResult& r, const std::string& d) {
|
||||
for (const auto& x : r.diagnostics) if (x == d) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void test_rust_function_rename_allowed() {
|
||||
TEST(rust_function_rename_allowed);
|
||||
auto r = RustGoConstructiveEditAdapter::evaluate({"rust", "function", "rename", false, false});
|
||||
CHECK(r.supported && r.allowed, "rust function rename should be allowed");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_rust_borrow_region_extract_blocked_on_risk() {
|
||||
TEST(rust_borrow_region_extract_blocked_on_risk);
|
||||
auto r = RustGoConstructiveEditAdapter::evaluate({"rust", "borrow_region", "extract", true, false});
|
||||
CHECK(!r.allowed, "rust borrow extract should be blocked on risk");
|
||||
CHECK(hasDiag(r, "rust_borrow_lifetime_extract_blocked"), "borrow/lifetime guard expected");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_rust_struct_rename_blocked_on_lifetime_risk() {
|
||||
TEST(rust_struct_rename_blocked_on_lifetime_risk);
|
||||
auto r = RustGoConstructiveEditAdapter::evaluate({"rust", "struct", "rename", true, false});
|
||||
CHECK(!r.allowed, "rust struct rename should be blocked on risk");
|
||||
CHECK(hasDiag(r, "rust_lifetime_sensitive_rename_blocked"), "lifetime guard expected");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_rust_impl_extract_allowed_without_risk() {
|
||||
TEST(rust_impl_extract_allowed_without_risk);
|
||||
auto r = RustGoConstructiveEditAdapter::evaluate({"rust", "impl", "extract", false, false});
|
||||
CHECK(r.allowed, "rust impl extract should be allowed without risk");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_go_channel_extract_blocked_on_concurrency_risk() {
|
||||
TEST(go_channel_extract_blocked_on_concurrency_risk);
|
||||
auto r = RustGoConstructiveEditAdapter::evaluate({"go", "channel", "extract", false, true});
|
||||
CHECK(!r.allowed, "go channel extract should be blocked on concurrency risk");
|
||||
CHECK(hasDiag(r, "go_concurrency_extract_blocked"), "go concurrency guard expected");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_go_function_update_blocked_on_concurrency_risk() {
|
||||
TEST(go_function_update_blocked_on_concurrency_risk);
|
||||
auto r = RustGoConstructiveEditAdapter::evaluate({"go", "function", "update", false, true});
|
||||
CHECK(!r.allowed, "go function update should be blocked on risk");
|
||||
CHECK(hasDiag(r, "go_concurrency_update_blocked"), "go update guard expected");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_go_function_update_allowed_without_risk() {
|
||||
TEST(go_function_update_allowed_without_risk);
|
||||
auto r = RustGoConstructiveEditAdapter::evaluate({"go", "function", "update", false, false});
|
||||
CHECK(r.allowed, "go function update should be allowed without risk");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_go_import_reorder_allowed() {
|
||||
TEST(go_import_reorder_allowed);
|
||||
auto r = RustGoConstructiveEditAdapter::evaluate({"go", "import", "reorder", false, false});
|
||||
CHECK(r.allowed, "go import reorder should be allowed");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_illegal_operation_for_construct_rejected() {
|
||||
TEST(illegal_operation_for_construct_rejected);
|
||||
auto r = RustGoConstructiveEditAdapter::evaluate({"rust", "struct", "extract", false, false});
|
||||
CHECK(!r.allowed, "illegal op should be rejected");
|
||||
CHECK(hasDiag(r, "operation_not_legal_for_construct"), "illegal op diag expected");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_unsupported_construct_rejected() {
|
||||
TEST(unsupported_construct_rejected);
|
||||
auto r = RustGoConstructiveEditAdapter::evaluate({"rust", "trait_object_magic", "update", false, false});
|
||||
CHECK(!r.supported, "unsupported construct should fail");
|
||||
CHECK(hasDiag(r, "unsupported_construct"), "unsupported construct diag expected");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_unsupported_language_rejected() {
|
||||
TEST(unsupported_language_rejected);
|
||||
auto r = RustGoConstructiveEditAdapter::evaluate({"python", "function", "rename", false, false});
|
||||
CHECK(!r.supported, "unsupported language should fail");
|
||||
CHECK(hasDiag(r, "unsupported_language"), "unsupported language diag expected");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_rust_import_insert_allowed() {
|
||||
TEST(rust_import_insert_allowed);
|
||||
auto r = RustGoConstructiveEditAdapter::evaluate({"rust", "import", "insert", false, false});
|
||||
CHECK(r.allowed, "rust import insert should be allowed");
|
||||
PASS();
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "Step 541: Rust/Go Constructive Edit Adapter\n";
|
||||
|
||||
test_rust_function_rename_allowed(); // 1
|
||||
test_rust_borrow_region_extract_blocked_on_risk(); // 2
|
||||
test_rust_struct_rename_blocked_on_lifetime_risk(); // 3
|
||||
test_rust_impl_extract_allowed_without_risk(); // 4
|
||||
test_go_channel_extract_blocked_on_concurrency_risk(); // 5
|
||||
test_go_function_update_blocked_on_concurrency_risk(); // 6
|
||||
test_go_function_update_allowed_without_risk(); // 7
|
||||
test_go_import_reorder_allowed(); // 8
|
||||
test_illegal_operation_for_construct_rejected(); // 9
|
||||
test_unsupported_construct_rejected(); // 10
|
||||
test_unsupported_language_rejected(); // 11
|
||||
test_rust_import_insert_allowed(); // 12
|
||||
|
||||
std::cout << "\nResults: " << passed << "/" << (passed + failed) << " passed\n";
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
34
progress.md
34
progress.md
@@ -9213,3 +9213,37 @@ legal operation mappings and module-level side-effect protection guards.
|
||||
- `editor/src/PythonTypeScriptConstructiveEditAdapter.h` within header-size limit (`84` <= `600`)
|
||||
- `editor/tests/step540_test.cpp` within test-file size guidance (`126` lines)
|
||||
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`
|
||||
|
||||
### Step 541: Rust/Go Constructive Edit Adapter
|
||||
**Status:** PASS (12/12 tests)
|
||||
|
||||
Implements Rust/Go constructive edit adaptation with ownership/lifetime and
|
||||
concurrency-sensitive guardrails for high-risk transform paths.
|
||||
|
||||
**Files added:**
|
||||
- `editor/src/RustGoConstructiveEditAdapter.h` - Rust/Go adapter module:
|
||||
- legal operation mappings for functions/structs/impl/import/channel/borrow regions
|
||||
- shared support for both `rust` and `go`
|
||||
- borrow/lifetime safety guards for Rust-sensitive operations
|
||||
- concurrency safety guards for Go-sensitive operations
|
||||
- structured diagnostics for unsupported constructs/languages and illegal ops
|
||||
- `editor/tests/step541_test.cpp` - 12 tests covering:
|
||||
- legal operation paths across Rust and Go constructs
|
||||
- ownership/lifetime guard behavior in Rust
|
||||
- concurrency guard behavior in Go
|
||||
- illegal operation rejections
|
||||
- unsupported construct/language behavior
|
||||
|
||||
**Files modified:**
|
||||
- `editor/CMakeLists.txt` - `step541_test` target
|
||||
|
||||
**Verification run:**
|
||||
- `cmake -S editor -B editor/build-native` - PASS
|
||||
- `cmake --build editor/build-native --target step541_test step540_test` - PASS
|
||||
- `./editor/build-native/step541_test` - PASS (12/12)
|
||||
- `./editor/build-native/step540_test` - PASS (12/12) regression coverage
|
||||
|
||||
**Architecture gate check:**
|
||||
- `editor/src/RustGoConstructiveEditAdapter.h` within header-size limit (`91` <= `600`)
|
||||
- `editor/tests/step541_test.cpp` within test-file size guidance (`127` lines)
|
||||
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`
|
||||
|
||||
Reference in New Issue
Block a user