test_scope_replay.py¶
tests/test_scope_replay.py
A stated `index_scope` survives the next build that states nothing.
test_a_stated_index_scope_survives_a_plain_rebuild
None test_scope_replay.test_a_stated_index_scope_survives_a_plain_rebuild(Path tmp_path)
The second, unstated build indexes what the first build was told to index.
Checks
assert meta_section(out, "scope")["roots"] == "kept", "premise: the statement narrowed it"assert scope["roots"] == "kept", (f"a plain rebuild widened a stated index_scope to {scope['roots']!r} " f"({scope.get('reason')!r}) instead of replaying it" )assert meta_section(out, "options")["index_scope.tier"] == "explicit", ("the replayed statement must still be recorded as a statement, so the next build " "replays it too" )
Result: passed
Verifies
Source · 30 lines
def test_a_stated_index_scope_survives_a_plain_rebuild(tmp_path: Path) -> None:
"""THE PLAIN REBUILD IS THE AUTOMATIC ONE. `_auto_refresh` and the background loop both call
`_run_build` with `options=None`, so what this second `build_index` call does is what every
unattended refresh of a narrowed index does.
@brief A recorded index_scope is replayed rather than widened to the whole repository.
@version 1
"""
from clew.cli import build_index
root = _two_tree_repo(tmp_path / "repo")
out = tmp_path / "clew.db"
build_index(output=out, repo_root=root, options={"index_scope": {"roots": ["kept"]}})
assert meta_section(out, "scope")["roots"] == "kept", "premise: the statement narrowed it"
(root / "kept" / "kept_fn.c").write_text(
"/** @brief kept_fn. */\nint kept_fn(void) { return 1; }\n", encoding="utf-8"
)
build_index(output=out, repo_root=root)
scope = meta_section(out, "scope")
assert scope["roots"] == "kept", (
f"a plain rebuild widened a stated index_scope to {scope['roots']!r} "
f"({scope.get('reason')!r}) instead of replaying it"
)
assert meta_section(out, "options")["index_scope.tier"] == "explicit", (
"the replayed statement must still be recorded as a statement, so the next build "
"replays it too"
)1 more lines, not shown