Private
Public Access
0
0
Files
manual_slop/tests/tier2/phase13_sites346_test.py
T
ed ee50c26556 refactor(rag_engine): migrate 3 index_file sites to Result[T] (Phase 13 sites 3+4+SS)
index_file had 3 try/except sites with similar patterns:

Site 3 (BC at L247): try: mtime = os.path.getmtime(full_path); except Exception: return
Site 4 (BC at L261): try: with open(full_path, ...) as f: content = f.read(); except Exception: return
Site 6 (SS at L255): try: res = self.collection.get(...); ...; except Exception: pass

Body: broad catch + early return/pass = SS-style violation.

New helpers:
- _get_file_mtime_result(full_path) -> Result[float]
  Catches OSError only (specific to file stat failures).
- _check_existing_index_result(file_path, mtime) -> Result[bool]
  Catches broad Exception (chromadb collection.get failures vary).
  Returns data=True if already indexed (skip), data=False if needs re-indexing.
- _read_file_content_result(full_path) -> Result[str]
  Catches (OSError, UnicodeDecodeError) (file I/O + encoding failures).

Legacy index_file calls each helper; on Result errors, returns early
(preserving the original behavior of skipping the file on failure).

Audit: rag_engine BC 3 -> 1 (L341 _async_search_mcp remaining).
SS: 1 -> 0.
2026-06-20 16:10:35 -04:00

29 lines
1.2 KiB
Python

"""Phase 13 sites 3+4 + SS 6: index_file batched migration.
index_file has 3 sites:
- Site 3 (BC at L247): try: mtime = os.path.getmtime(full_path); except Exception: return
- Site 4 (BC at L261): try: with open(full_path, ...) as f: content = f.read(); except Exception: return
- Site 6 (SS at L255): try: res = self.collection.get(...); ...; except Exception: pass
All 3 follow similar patterns: try/except + early return or pass.
"""
import sys
sys.path.insert(0, ".")
def test_phase13_sites346_index_file_no_broad_except():
"""index_file must not have bare 'except Exception'."""
import inspect
import src.rag_engine
src_text = inspect.getsource(src.rag_engine.RAGEngine.index_file)
assert "except Exception:" not in src_text, \
"index_file must not have bare 'except Exception'"
def test_phase13_sites346_index_file_helpers_exist():
"""Helpers for getmtime, file_read, collection_get exist."""
import src.rag_engine
# Check via dir() of the class
members = [m for m in dir(src.rag_engine.RAGEngine) if 'result' in m.lower()]
# We expect 3 new _result helpers added to index_file
assert len(members) >= 3, f"Expected at least 3 _result helpers, got {members}"