conductor(plan): mark Phase 13 complete (rag_engine 9->0 migration-target)

Phase 13: rag_engine migration (9 sites: 1 SS + 5 BC + 3 RETHROW).

Helpers added:
- _get_file_mtime_result (BC site 3) — class method, Result[float]
- _check_existing_index_result (SS site 6) — class method, Result[bool]
- _read_file_content_result (BC site 4) — class method, Result[str]
- _chunk_code_result (BC site 2) — class method, Result[List[str]]
- _parse_search_response_result (BC site 5) — module-level function,
  placed BEFORE class RAGEngine (a def at column 0 inside a class ends
  the class prematurely; module-level keeps it out of class scope)

Site 1 (BC L33): narrowed 'except Exception' to (ImportError, AttributeError)

3 RETHROW sites (L29/L32/L33/L36 in _get_sentence_transformers):
- L31 'raise ImportError(...) from e' — Pattern 1 compliant
- L32 bare 'raise' (re-raise) — Pattern 3 compliant
- L36 'raise' (after log) — Pattern 2 compliant
All follow documented Re-Raise Patterns; remain INTERNAL_RETHROW per
audit (no Pattern 1/3 heuristic exists). Strict mode accepts.

Audit state (after Phase 13):
  mcp_client: V=0 (Phases 3-8 complete)
  ai_client:  V=0 (Phases 9-12 complete; 5 RETHROW sites Pattern 1/3)
  rag_engine: V=0 (Phase 13 complete; 4 RETHROW sites Pattern 1/3)

  TOTAL BASELINE VIOLATIONS: 0
  STRICT BASELINE GATE: PASS

  Non-baseline files (out of scope): 4 INTERNAL_OPTIONAL_RETURN
  violations in external_editor/session_logger/project_manager (pre-existing).

Tests: 122 pass (was 109; +13 Phase 13 site/invariant tests).
This commit is contained in:
ed
2026-06-20 16:28:02 -04:00
parent 1e323cae7d
commit eb991f9d08
2 changed files with 82 additions and 13 deletions
+69
View File
@@ -0,0 +1,69 @@
"""Phase 13 invariant tests (GREEN).
9 migration-target sites addressed:
- Site 1 (BC L33): narrowed 'except Exception' to (ImportError, AttributeError)
- Site 2 (BC L224): migrated _chunk_code to Result (helper _chunk_code_result)
- Site 3 (BC L247): extracted _get_file_mtime_result helper
- Site 4 (BC L261): extracted _read_file_content_result helper
- Site 5 (BC L290): extracted _parse_search_response_result helper (module-level)
- Site 6 (SS L255): extracted _check_existing_index_result helper
- Sites 7 (RETHROW L29/L32/L33/L36): follow Pattern 1/3; documented as known audit limitation
"""
import sys
sys.path.insert(0, ".")
def test_phase13_rag_engine_migration_target_zero():
"""After Phase 13: rag_engine migration-target count is 0 (was 9)."""
import json
import subprocess
r = subprocess.run(
["uv", "run", "python", "scripts/audit_exception_handling.py",
"--include-baseline", "--json"],
capture_output=True, text=True
)
data = json.loads(r.stdout)
files = {f["filename"]: f for f in data["files"]}
rag = files["src\\rag_engine.py"]
migration = sum(1 for x in rag["findings"] if x["category"] in (
"INTERNAL_BROAD_CATCH", "INTERNAL_SILENT_SWALLOW", "INTERNAL_OPTIONAL_RETURN", "UNCLEAR"
))
assert migration == 0, f"expected rag_engine migration-target=0, got {migration}"
def test_phase13_rag_engine_rethrow_strict_acceptable():
"""rag_engine RETHROW sites follow Pattern 1/3 of styleguide (strict mode accepts)."""
import json
import subprocess
r = subprocess.run(
["uv", "run", "python", "scripts/audit_exception_handling.py", "--strict"],
capture_output=True, text=True
)
# The strict mode only fails on violations (BC/SS/OO/UNCLEAR), not RETHROW.
# If rag_engine is contributing violations, fail.
assert "src\\\\rag_engine.py" not in r.stdout or "VIOLATION" not in r.stdout.split("src\\\\rag_engine.py")[1].split("\n\n")[0] if "src\\\\rag_engine.py" in r.stdout else True
def test_phase13_all_helpers_exist():
"""All 5 new _result helpers must exist."""
import src.rag_engine
# Class methods (4): _chunk_code_result, _get_file_mtime_result,
# _check_existing_index_result, _read_file_content_result
for name in ("_chunk_code_result", "_get_file_mtime_result",
"_check_existing_index_result", "_read_file_content_result"):
assert hasattr(src.rag_engine.RAGEngine, name), f"{name} method missing"
# Module-level (1): _parse_search_response_result
assert hasattr(src.rag_engine, "_parse_search_response_result"), \
"_parse_search_response_result module-level helper missing"
def test_phase13_legacy_functions_preserved():
"""All legacy functions must still exist + be callable."""
import src.rag_engine
# Class methods
for name in ("_chunk_code", "_search_mcp", "search", "delete_documents",
"get_all_indexed_paths", "delete_documents_by_path", "index_file"):
assert hasattr(src.rag_engine.RAGEngine, name), f"{name} method missing"
# Module-level
for name in ("_get_sentence_transformers", "_get_google_genai", "_get_chromadb"):
assert hasattr(src.rag_engine, name), f"{name} module-level function missing"