9646f7cf7b
Phase 5 (1 of 9 cruft sites obliterated): OBLITERATED: RAGEngine._chunk_code wrapper. It delegated to _chunk_code_result and provided a fallback to _chunk_text on AST failure. Migration: index_file() now calls _chunk_code_result directly with .ok check + chunk-size threshold check + fallback to _chunk_text inline. The structured ErrorInfo is propagated if needed (no caller currently consumes it). Sub-track 5 tests updated: - tests/tier2/phase13_invariant_test.py: _chunk_code moved to obliterated list - tests/tier2/phase13_site2_test.py: _legacy_no_broad_except -> _legacy_obliterated - tests/test_cruft_removal.py: 2 new tests (wrapper-obliterated invariant + caller-uses-result invariant) PITFALL encountered: the edit_file tool removed a leading space on the next class method's 'def' line, causing an IndentationError. Fixed by binary-write replacement preserving CRLF + leading-space styleguide convention (project uses 1-space indentation; class body methods start at column 1). Test result: 124/124 pass. Audit gate: src/rag_engine.py --strict exits 0 (no new violations). Wrapper count: 3 -> 2 (Phase 6 remaining: gui_2 2).
76 lines
3.5 KiB
Python
76 lines
3.5 KiB
Python
"""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 (some OBLITERATED by cruft-removal)."""
|
|
import src.rag_engine
|
|
# Class methods (some OBLITERATED)
|
|
preserved = ("_search_mcp", "search", "delete_documents",
|
|
"get_all_indexed_paths", "delete_documents_by_path", "index_file")
|
|
obliterated = ("_chunk_code",)
|
|
for name in preserved:
|
|
assert hasattr(src.rag_engine.RAGEngine, name), f"{name} method missing"
|
|
for name in obliterated:
|
|
assert not hasattr(src.rag_engine.RAGEngine, name), (
|
|
f"{name} wrapper must be OBLITERATED (cruft-removal Phase 5); "
|
|
f"callers must use {name}_result directly"
|
|
)
|
|
# 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" |