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.

tests/test_scope_replay.py:50

Show on the map →

Called by none

Calls _two_tree_repo, meta_section

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

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-009measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measured
REQ-DDB-INDEX-005measured
REQ-DDB-INDEX-006measured
REQ-DDB-INDEX-007measured
REQ-DDB-INDEX-008measured
REQ-DDB-INDEX-009measured
REQ-DDB-INDEX-010measured
REQ-DDB-INDEX-011measured
REQ-DDB-MCP-001measuredtest_a_stated_index_scope_survives_a_plain_rebuild → meta_section
REQ-DDB-MCP-004measured
REQ-DDB-PIPE-001measured
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-004measured
REQ-DDB-PIPE-005measured
REQ-DDB-PIPE-006measured
REQ-DDB-PIPE-007measured
REQ-DDB-PIPE-008measured
REQ-DDB-PIPE-009measured
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measured
REQ-DDB-PIPE-012measured
REQ-DDB-PIPE-013measured
REQ-DDB-PIPE-014measured
REQ-DDB-PIPE-015measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measured
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-003measured
REQ-DDB-SCHEMA-004measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-009measured
REQ-DDB-SCHEMA-011measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measured
REQ-DDB-SCHEMA-014measured
REQ-DDB-SCHEMA-015measured
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

Activity · 10 steps
lines 58–58from clew.cli import build_indexlines 60–60root = _two_tree_repo(tmp_path / "repo")lines 61–61out = tmp_path / "clew.db"lines 63–63build_index(output=out, repo_root=root, options={"index_scope": {"roots": ["kept"]}})lines 64–64assert meta_section(out, "scope")["roots"] == "kept", "premise: the statement narrowed it"lines 66–68(root / "kept" / "kept_fn.c").write_text( "/** @brief kept_fn. */\nint kept_fn(void) { return 1; }\n", encoding="utf-8" )lines 69–69build_index(output=out, repo_root=root)lines 71–71scope = meta_section(out, "scope")lines 72–75assert 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" )lines 76–79assert 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" )