test_ast_fold_cache.py¶
tests/test_ast_fold_cache.py
gh#34 — the AST call-edge stage re-resolves every file on every refresh.
test_a_new_function_invalidates_every_cached_fold
None test_ast_fold_cache.test_a_new_function_invalidates_every_cached_fold(Path tmp_path, monkeypatch)
A changed resolution input re-folds everything, not just the changed file.
tests/test_ast_fold_cache.py:212
Checks
assert second == 2, (f"a changed name->rowid map invalidates every file's fold, not just the edited " f"one — folded {second}" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | |
| REQ-DDB-PIPE-003 | measured | test_a_new_function_invalidates_every_cached_fold → _run_stage → import_ast_call_edges → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_a_new_function_invalidates_every_cached_fold → _run_stage → import_ast_call_edges → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_a_new_function_invalidates_every_cached_fold → _run_stage → import_ast_call_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-WIKI-054 | inferred | test_a_new_function_invalidates_every_cached_fold → _run_stage → import_ast_call_edges → _fold_all_files → _fold_call_payload → _ast_record_call_edge → _narrow_by_receiver → _one_class → all |
Source · 33 lines
def test_a_new_function_invalidates_every_cached_fold(tmp_path: Path, monkeypatch) -> None:
"""THE GUARD THAT MATTERS MOST, and the reason the payload sha alone is not the key. A
new function joins `name_to_rowids`, so a call site in an UNCHANGED file may now resolve
to a different rowid — or resolve at all where it did not. Serving that file's old edges
would be a stale edge presented as a measurement, which is this project's most expensive
recorded defect class.
@brief A changed resolution input re-folds everything, not just the changed file.
@return None.
@version 1
"""
repo = tmp_path / "repo"
db = _two_file_db(repo, {"a.py": _A, "b.py": _B})
cache = tmp_path / "clew.db.idxcache"
_run_stage(db, repo, cache, monkeypatch)
## A NEW index, with an extra function — the resolution inputs have moved.
widened = _two_file_db(
repo,
{
"a.py": _A,
"b.py": _B + '\n\ndef third(z):\n """@brief Third."""\n return other(z)\n',
},
db_name="widened.db",
)
second, _rows = _run_stage(widened, repo, cache, monkeypatch)
assert second == 2, (
f"a changed name->rowid map invalidates every file's fold, not just the edited "
f"one — folded {second}"
)
Activity · 7 steps
test_an_unchanged_file_is_not_refolded_on_a_second_run
None test_ast_fold_cache.test_an_unchanged_file_is_not_refolded_on_a_second_run(Path tmp_path, monkeypatch)
A second run over an unchanged tree folds nothing.
tests/test_ast_fold_cache.py:171
Checks
assert first == 2, f"the cold run must fold both files, folded {first}"assert second == 0, f"an unchanged tree needs no folding, folded {second}"assert second_rows == first_rows, "the cached run must write exactly the same edges"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | |
| REQ-DDB-PIPE-003 | measured | test_an_unchanged_file_is_not_refolded_on_a_second_run → _run_stage → import_ast_call_edges → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_an_unchanged_file_is_not_refolded_on_a_second_run → _run_stage → import_ast_call_edges → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_an_unchanged_file_is_not_refolded_on_a_second_run → _run_stage → import_ast_call_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-WIKI-054 | inferred | test_an_unchanged_file_is_not_refolded_on_a_second_run → _run_stage → import_ast_call_edges → _fold_all_files → _fold_call_payload → _ast_record_call_edge → _narrow_by_receiver → _one_class → all |
Source · 20 lines
def test_an_unchanged_file_is_not_refolded_on_a_second_run(tmp_path: Path, monkeypatch) -> None:
"""THE 59%. Nothing about the tree or the index moved between the two runs, so the second
run has nothing to resolve — and resolved it all again anyway.
@brief A second run over an unchanged tree folds nothing.
@return None.
@version 1
"""
repo = tmp_path / "repo"
db = _two_file_db(repo, {"a.py": _A, "b.py": _B})
cache = tmp_path / "clew.db.idxcache"
first, first_rows = _run_stage(db, repo, cache, monkeypatch)
second, second_rows = _run_stage(db, repo, cache, monkeypatch)
assert first == 2, f"the cold run must fold both files, folded {first}"
assert second == 0, f"an unchanged tree needs no folding, folded {second}"
assert second_rows == first_rows, "the cached run must write exactly the same edges"
Activity · 8 steps
test_only_the_edited_file_is_refolded
None test_ast_fold_cache.test_only_the_edited_file_is_refolded(Path tmp_path, monkeypatch)
Editing one body re-folds one file.
tests/test_ast_fold_cache.py:191
Checks
assert second == 1, f"only the edited file needed folding, folded {second}"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | |
| REQ-DDB-PIPE-003 | measured | test_only_the_edited_file_is_refolded → _run_stage → import_ast_call_edges → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_only_the_edited_file_is_refolded → _run_stage → import_ast_call_edges → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_only_the_edited_file_is_refolded → _run_stage → import_ast_call_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-WIKI-054 | inferred | test_only_the_edited_file_is_refolded → _run_stage → import_ast_call_edges → _fold_all_files → _fold_call_payload → _ast_record_call_edge → _narrow_by_receiver → _one_class → all |
Source · 21 lines
def test_only_the_edited_file_is_refolded(tmp_path: Path, monkeypatch) -> None:
"""THE COMMON INCREMENTAL EDIT: a body changes, no signature does, so the resolution
inputs are identical and every other file's fold is still valid. This is the case the
field report was made of — seven edited files out of 913.
@brief Editing one body re-folds one file.
@return None.
@version 1
"""
repo = tmp_path / "repo"
db = _two_file_db(repo, {"a.py": _A, "b.py": _B})
cache = tmp_path / "clew.db.idxcache"
_run_stage(db, repo, cache, monkeypatch)
## A body edit only: same functions, same lines, different statement.
(repo / "b.py").write_text(_B.replace("return y * 2", "return y * 3"), encoding="utf-8")
second, _rows = _run_stage(db, repo, cache, monkeypatch)
assert second == 1, f"only the edited file needed folding, folded {second}"
Activity · 7 steps
test_the_cached_run_writes_exactly_what_a_cold_run_writes
None test_ast_fold_cache.test_the_cached_run_writes_exactly_what_a_cold_run_writes(Path tmp_path, monkeypatch)
A cache-served run and a cache-free run write identical rows.
tests/test_ast_fold_cache.py:245
Checks
assert folded_warm == 0 and folded_cold == 2, "the two runs must differ in HOW they got there"assert warm_rows == cold_rows, "...and not in what they wrote"assert warm_rows, "the fixture must produce edges at all, or this asserts nothing"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | |
| REQ-DDB-PIPE-003 | measured | test_the_cached_run_writes_exactly_what_a_cold_run_writes → _run_stage → import_ast_call_edges → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_the_cached_run_writes_exactly_what_a_cold_run_writes → _run_stage → import_ast_call_edges → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_the_cached_run_writes_exactly_what_a_cold_run_writes → _run_stage → import_ast_call_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-WIKI-054 | inferred | test_the_cached_run_writes_exactly_what_a_cold_run_writes → _run_stage → import_ast_call_edges → _fold_all_files → _fold_call_payload → _ast_record_call_edge → _narrow_by_receiver → _one_class → all |
Source · 21 lines
def test_the_cached_run_writes_exactly_what_a_cold_run_writes(tmp_path: Path, monkeypatch) -> None:
"""PARITY, asserted rather than argued. A cache that produces almost the right edges is
worse than no cache: the rows it gets wrong are indistinguishable from measurements.
@brief A cache-served run and a cache-free run write identical rows.
@return None.
@version 1
"""
repo = tmp_path / "repo"
db = _two_file_db(repo, {"a.py": _A, "b.py": _B})
warm_cache = tmp_path / "warm.idxcache"
_run_stage(db, repo, warm_cache, monkeypatch)
folded_warm, warm_rows = _run_stage(db, repo, warm_cache, monkeypatch)
cold_cache = tmp_path / "cold.idxcache"
folded_cold, cold_rows = _run_stage(db, repo, cold_cache, monkeypatch)
assert folded_warm == 0 and folded_cold == 2, "the two runs must differ in HOW they got there"
assert warm_rows == cold_rows, "...and not in what they wrote"
assert warm_rows, "the fixture must produce edges at all, or this asserts nothing"1 more lines, not shown