Complete step454 phase21a integration tests

This commit is contained in:
Bill
2026-02-16 19:45:10 -07:00
parent fdc602a2db
commit 0047b984c1
3 changed files with 154 additions and 0 deletions

View File

@@ -2965,4 +2965,13 @@ target_link_libraries(step453_test PRIVATE
tree_sitter_javascript tree_sitter_typescript
tree_sitter_java tree_sitter_rust tree_sitter_go)
add_executable(step454_test tests/step454_test.cpp)
target_include_directories(step454_test PRIVATE src)
target_link_libraries(step454_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)

View File

@@ -0,0 +1,119 @@
// Step 454: Phase 21a Integration Tests (8 tests)
#include "AlgorithmEquivalence.h"
#include "ConcurrencyTranslator.h"
#include "IntentTranslator.h"
#include "MemoryModelTranslator.h"
#include "TypeSystemTranslator.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 {}
void test_intent_driven_sort_python_to_rust() {
TEST(intent_driven_sort_python_to_rust);
std::vector<FunctionIntent> funcs = {{"sort_items", "sort list ascending", "items.sort()"}};
auto intent = IntentTranslator::translate(funcs, "python", "rust");
CHECK(intent.hasTranslationFor("sort_items"), "expected translated function");
auto t = intent.getTranslation("sort_items");
CHECK(t.isIdiomatic, "expected idiomatic translation");
CHECK(t.confidence >= 0.90f, "expected high confidence");
PASS();
}
void test_algorithm_recognition_sort_to_stdlib() {
TEST(algorithm_recognition_sort_to_stdlib);
std::string src = "for(i=0;i<n;i++) for(j=0;j<n-1;j++) if(a[j]>a[j+1]) swap(a[j],a[j+1]);";
auto algo = AlgorithmRecognizer::analyze(src, "c", "rust");
CHECK(algo.hasPattern("bubble_sort"), "expected bubble sort detection");
auto eq = algo.equivalentFor("bubble_sort");
CHECK(eq.usesStdLib, "expected stdlib use");
CHECK(eq.targetCode.find("sort") != std::string::npos, "expected rust sort mapping");
PASS();
}
void test_type_translation_generics_preserved_java_to_rust() {
TEST(type_translation_generics_preserved_java_to_rust);
auto tr = TypeSystemTranslator::translate({"List<T>", "Map<K,V>"}, "java", "rust");
CHECK(tr.getTranslation("List<T>").targetType == "Vec<T>", "expected Vec<T>");
CHECK(tr.getTranslation("Map<K,V>").targetType == "HashMap<K,V>", "expected HashMap");
CHECK(tr.countLossy() == 0, "expected no lossy mappings");
PASS();
}
void test_type_translation_to_c_is_lossy_when_needed() {
TEST(type_translation_to_c_is_lossy_when_needed);
auto tr = TypeSystemTranslator::translate({"Optional<T>", "List<T>"}, "java", "c");
CHECK(tr.countLossy() >= 2, "expected lossy mappings for C target");
CHECK(tr.getTranslation("List<T>").annotation == "@Risk(high)", "expected risk annotation");
PASS();
}
void test_concurrency_async_python_to_rust_requires_review() {
TEST(concurrency_async_python_to_rust_requires_review);
auto conc = ConcurrencyTranslator::analyze("async def fetch(): await io()", "python", "rust");
CHECK(conc.hasPattern("async/await"), "expected async detection");
CHECK(conc.countNeedsReview() >= 1, "expected runtime review requirement");
PASS();
}
void test_memory_manual_c_to_rust_gains_safety() {
TEST(memory_manual_c_to_rust_gains_safety);
auto mem = MemoryModelTranslator::analyze("p = malloc(8); free(p);", "c", "rust");
CHECK(mem.hasPattern("@Owner(Manual)"), "expected manual ownership pattern");
CHECK(mem.countSafetyGained() >= 1, "expected safety gain");
CHECK(mem.countSafetyLost() == 0, "expected no safety loss");
PASS();
}
void test_no_intent_falls_back_to_structural_and_review() {
TEST(no_intent_falls_back_to_structural_and_review);
std::vector<FunctionIntent> funcs = {{"mystery", "", "x = a + b * c"}};
auto intent = IntentTranslator::translate(funcs, "python", "rust");
auto t = intent.getTranslation("mystery");
CHECK(!t.isIdiomatic, "no intent should not be idiomatic");
CHECK(t.needsReview, "no intent should trigger review");
PASS();
}
void test_phase_21a_combined_pipeline_signals() {
TEST(phase_21a_combined_pipeline_signals);
std::vector<FunctionIntent> funcs = {{
"rank_users",
"sort list ascending",
"for(i=0;i<n;i++) for(j=0;j<n-1;j++) if(a[j]>a[j+1]) swap(a[j],a[j+1]);"
}};
auto intent = IntentTranslator::translate(funcs, "python", "rust");
auto algo = AlgorithmRecognizer::analyze(funcs[0].source, "python", "rust");
auto types = TypeSystemTranslator::translate({"List<T>"}, "python", "rust");
auto conc = ConcurrencyTranslator::analyze("async def rank_users(): await fetch()", "python", "rust");
auto mem = MemoryModelTranslator::analyze("buf = malloc(64); free(buf);", "c", "rust");
CHECK(intent.countIdiomatic() == 1, "expected idiomatic intent mapping");
CHECK(algo.hasPattern("bubble_sort"), "expected algorithm pattern");
CHECK(types.getTranslation("List<T>").targetType == "Vec<T>", "expected rust vector mapping");
CHECK(conc.hasPattern("async/await"), "expected concurrency pattern");
CHECK(mem.countSafetyGained() >= 1, "expected safety gain in memory translation");
PASS();
}
int main() {
std::cout << "Step 454: Phase 21a Integration Tests\n";
test_intent_driven_sort_python_to_rust(); // 1
test_algorithm_recognition_sort_to_stdlib(); // 2
test_type_translation_generics_preserved_java_to_rust();// 3
test_type_translation_to_c_is_lossy_when_needed(); // 4
test_concurrency_async_python_to_rust_requires_review();// 5
test_memory_manual_c_to_rust_gains_safety(); // 6
test_no_intent_falls_back_to_structural_and_review(); // 7
test_phase_21a_combined_pipeline_signals(); // 8
std::cout << "\nResults: " << passed << "/" << (passed + failed)
<< " passed\n";
return failed == 0 ? 0 : 1;
}

View File

@@ -5822,3 +5822,29 @@ borrow-checked models with explicit safety-delta tracking.
**Architecture gate check:**
- `editor/src/MemoryModelTranslator.h` within header-size limit (`249` <= `600`)
- `editor/tests/step453_test.cpp` within test-file size guidance (`142` lines)
### Step 454: Phase 21a Integration
**Status:** PASS (8/8 tests)
Adds Phase 21a end-to-end integration coverage across intent, algorithm,
types, concurrency, and memory translation components.
**Files added:**
- `editor/tests/step454_test.cpp` — 8 integration tests covering:
- intent-driven idiomatic translation (Python→Rust sort intent)
- algorithm recognizer stdlib mapping validation
- type-system preservation vs lossy-risk behavior
- async runtime review requirements in concurrency translation
- manual-memory safety gains during C→Rust migration
- no-intent structural fallback/review behavior
- combined pipeline signal checks across all phase components
- `editor/CMakeLists.txt``step454_test` target
**Verification run:**
- `cmake --build editor/build-native --target step454_test` — PASS
- `./editor/build-native/step454_test` — PASS (8/8)
- `./editor/build-native/step453_test` — PASS (12/12) regression coverage
**Architecture gate check:**
- `editor/tests/step454_test.cpp` within test-file size guidance (`119` lines)
- No new production header introduced in this integration step