test_manifest_replay_integration.py¶
tests/integration/test_manifest_replay_integration.py
A tier-1 manifest statement survives a real rebuild — measured in EDGE ROWS (gh#364).
test_a_stated_index_scope_narrows_the_index_and_a_withdrawal_widens_it
None test_manifest_replay_integration.test_a_stated_index_scope_narrows_the_index_and_a_withdrawal_widens_it(Path tmp_path)
ASSERTED ON ROWS AGAIN, WHICH IS THE #399 CONTROL.
tests/integration/test_manifest_replay_integration.py:511
Checks
assert _doxygen_has(db, "aside_fn"), ("the whole-repo baseline did not reach extra/ — without that this fixture cannot " "distinguish a narrowed scope from a scope statement that was silently dropped" )assert not _doxygen_has(db, "aside_fn"), ("a stated `index_scope:` never reached derive_scope — the option was accepted and " "then dropped, which builds a DIFFERENT boundary than the caller stated and reports " "success" )assert _doxygen_has(db, WRITER), "the narrowed scope must still index what it named"assert _indexed_path(db, "extra/aside.c"), ("the withdrawal widened the scope on paper and the index did not follow — the " "doxygen output cache served the narrow build's output back to the wide key (#399)" )assert _doxygen_has(db, "aside_fn"), ("extra/ is back in the file inventory but its function is not, so the served output " "is not the one this configuration produced" )assert _scope_stamp(db) == (SOURCE_WHOLE_REPO, "."), ("the withdrawal did not widen the scope back — three-state semantics are what make " "every other option's absent/empty/non-empty rule uniform" )
Result: passed
Verifies
Source · 85 lines
def test_a_stated_index_scope_narrows_the_index_and_a_withdrawal_widens_it(
tmp_path: Path,
) -> None:
"""gh#382's LAST KEY, and the one that could not use the injection point. `index_scope`
is resolved by `derive_scope_logged` BEFORE the declaration the stages read is loaded, so
the stated document is threaded down into `scope._declared_index_scope` and built through
the SAME construction a written declaration takes.
MEASURED ON WHAT GOT INDEXED, never on the stamp. A scope statement that is recorded and
then ignored satisfies every metadata assertion while indexing the whole tree — which is
the failure the other controls in this module were written against, one section over.
THE FIXTURE NEEDS TWO ROOTS. With one, "narrowed to src" and "the whole repo" index the
same files and the control proves nothing; `extra/` exists purely so its function's
ABSENCE is the measurement.
@brief A stated index_scope reaches the scope stage.
"""
root = tmp_path / "scoped"
doxyfile = _write_target(root)
(root / "extra").mkdir()
(root / "extra" / "aside.c").write_text(
"/** @file\n * @brief Out-of-scope fixture.\n */\n\n"
"/** @brief A function only a WIDE scope reaches.\n * @version 1\n */\n"
"void aside_fn(void) {}\n",
encoding="utf-8",
)
db = tmp_path / "scoped.db"
## 1. State nothing: the whole-repo tier, which must reach BOTH directories. The
## Doxyfile says `INPUT = src`, and from-guard REPLACES that (gh#333) — so this
## assertion also pins that a repo is not punished for documenting itself.
build_index(output=db, repo_root=root, doxyfile=doxyfile)
assert _doxygen_has(db, "aside_fn"), (
"the whole-repo baseline did not reach extra/ — without that this fixture cannot "
"distinguish a narrowed scope from a scope statement that was silently dropped"
)
## 2. STATE THE SECTION. `extra/` must fall out of the index entirely.
build_index(
output=db,
repo_root=root,
doxyfile=doxyfile,
options={"index_scope": {"roots": ["src"]}},
)
assert not _doxygen_has(db, "aside_fn"), (
"a stated `index_scope:` never reached derive_scope — the option was accepted and "
"then dropped, which builds a DIFFERENT boundary than the caller stated and reports "
"success"
)
assert _doxygen_has(db, WRITER), "the narrowed scope must still index what it named"
## 3. WITHDRAW IT. `{}` restores the target's own answer, here the whole repo. A
## statement that cannot be taken back is a one-way door on a surface whose whole
## point is that the target's tree is never modified.
##
## ASSERTED ON ROWS AGAIN, WHICH IS THE #399 CONTROL. This step used to check only
## `_scope_stamp`, because the doxygen output cache mapped many KEYS to ONE output
## file that every build overwrote: `doxygen_get` hit on "a row for this key exists
## AND the path exists", which is true of every key as soon as ANY of them has run.
## So the withdrawal reached `derive_scope` — `scope.source` read `whole-repo`, roots
## `.` — while step 2's NARROW output was served back to this WIDE key and `path` still
## held only `src/store.c`. That is why the defect is not "the newer output wins" but
## "whichever output was written last wins, whatever its key said": the `predefined`
## withdrawal above was served a WIDER earlier output and this one a NARROWER one.
##
## `doxygen_get` now compares the recorded digest of the output against the file's
## current one, so this key MISSES against step 2's overwrite and doxygen re-runs.
## The two lines below are the control: with that verification removed they fail and
## only the stamp survives, which is exactly the state this comment used to describe.
build_index(output=db, repo_root=root, doxyfile=doxyfile, options={"index_scope": {}})
assert _indexed_path(db, "extra/aside.c"), (
"the withdrawal widened the scope on paper and the index did not follow — the "
"doxygen output cache served the narrow build's output back to the wide key (#399)"
)
assert _doxygen_has(db, "aside_fn"), (
"extra/ is back in the file inventory but its function is not, so the served output "
"is not the one this configuration produced"
)
assert _scope_stamp(db) == (SOURCE_WHOLE_REPO, "."), (
"the withdrawal did not widen the scope back — three-state semantics are what make "
"every other option's absent/empty/non-empty rule uniform"
)
Activity · 14 steps
test_a_stated_manifest_survives_a_rebuild_and_a_withdrawal_undoes_it
None test_manifest_replay_integration.test_a_stated_manifest_survives_a_rebuild_and_a_withdrawal_undoes_it(Path tmp_path)
FOUR REAL BUILDS, ONE OUTPUT PATH, counted in edge rows.
tests/integration/test_manifest_replay_integration.py:136
Called by none
Calls _options_meta, _shared_key_rows, _write_target, recorded_document, stated_options
Checks
assert stated_options(_options_meta(db)) == (), "nothing was stated, so nothing is stamped"assert stated > baseline, (f"the stated manifest produced no edges ({stated} vs baseline {baseline}) — the " f"control cannot distinguish a lost statement from a fixture that never worked" )assert stated_options(_options_meta(db)) == (SECTION_SHARED_KEY,)assert _shared_key_rows(db) == stated, ("the rebuild lost the stated layer — this is gh#364 exactly: the build reports " "success and the causal layer silently reverts to the undeclared policy" )assert replayed[f"{SECTION_SHARED_KEY}.{TIER_KEY}"] == TIER_EXPLICITassert recorded_document(replayed, SECTION_SHARED_KEY) == MANIFESTassert stated_options(replayed) == (SECTION_SHARED_KEY,), ("a replayed statement makes this index carry a policy the repository does not " "declare — allowed only because it is visible" )assert _shared_key_rows(db) == baselineassert withdrawn[f"{SECTION_SHARED_KEY}.{TIER_KEY}"] == TIER_HEURISTICassert f"{SECTION_SHARED_KEY}.{EXPLICIT_KEY}" not in withdrawn, ("the record must be GONE, not ignored: a withdrawal that silently fails to " "withdraw is the key_arg_idx-for-key_arg_index class of defect" )assert recorded_document(withdrawn, SECTION_SHARED_KEY) is Noneassert stated_options(withdrawn) == ()assert _shared_key_rows(db) == baselineassert stated_options(_options_meta(db)) == ()
Result: passed
Verifies
Source · 73 lines
def test_a_stated_manifest_survives_a_rebuild_and_a_withdrawal_undoes_it(
tmp_path: Path,
) -> None:
"""FOUR REAL BUILDS, ONE OUTPUT PATH, counted in edge rows.
1. state nothing -> the undeclared baseline (expected 0 here)
2. state the manifest -> the layer appears
3. state nothing AGAIN -> the layer SURVIVES (this is the fix)
4. withdraw with `{}` -> the layer returns to the baseline, record gone
Build 3 is the whole point and it is the one that used to fail: nothing recorded
the statement, so the rebuild re-resolved the manifest from the target's own
declaration — which this fixture does not have — and the layer went back to zero
with the build reporting success. It is also the normal case rather than a corner:
`status` reports staleness and the guidance says refresh, so an agent that brings
the index up then rebuilds would lose its own bringup work and never be told.
ONE OUTPUT PATH throughout, deliberately. The record lives in the database being
replaced, so a fresh path per build would test nothing — and the replay reads the
live path BEFORE the atomic swap for exactly that reason.
"""
root = tmp_path / "target"
doxyfile = _write_target(root)
db = tmp_path / "clew.db"
build_index(output=db, repo_root=root, doxyfile=doxyfile)
baseline = _shared_key_rows(db)
assert stated_options(_options_meta(db)) == (), "nothing was stated, so nothing is stamped"
build_index(
output=db, repo_root=root, doxyfile=doxyfile, options={SECTION_SHARED_KEY: MANIFEST}
)
stated = _shared_key_rows(db)
assert stated > baseline, (
f"the stated manifest produced no edges ({stated} vs baseline {baseline}) — the "
f"control cannot distinguish a lost statement from a fixture that never worked"
)
assert stated_options(_options_meta(db)) == (SECTION_SHARED_KEY,)
## THE FIX. No options at all, which is what an MCP refresh passes.
build_index(output=db, repo_root=root, doxyfile=doxyfile)
assert _shared_key_rows(db) == stated, (
"the rebuild lost the stated layer — this is gh#364 exactly: the build reports "
"success and the causal layer silently reverts to the undeclared policy"
)
replayed = _options_meta(db)
assert replayed[f"{SECTION_SHARED_KEY}.{TIER_KEY}"] == TIER_EXPLICIT
assert recorded_document(replayed, SECTION_SHARED_KEY) == MANIFEST
assert stated_options(replayed) == (SECTION_SHARED_KEY,), (
"a replayed statement makes this index carry a policy the repository does not "
"declare — allowed only because it is visible"
)
## THE WITHDRAWAL, proven by the row count returning to the baseline and by the
## record being ABSENT rather than merely ignored on this run.
build_index(output=db, repo_root=root, doxyfile=doxyfile, options={SECTION_SHARED_KEY: {}})
assert _shared_key_rows(db) == baseline
withdrawn = _options_meta(db)
assert withdrawn[f"{SECTION_SHARED_KEY}.{TIER_KEY}"] == TIER_HEURISTIC
assert f"{SECTION_SHARED_KEY}.{EXPLICIT_KEY}" not in withdrawn, (
"the record must be GONE, not ignored: a withdrawal that silently fails to "
"withdraw is the key_arg_idx-for-key_arg_index class of defect"
)
assert recorded_document(withdrawn, SECTION_SHARED_KEY) is None
assert stated_options(withdrawn) == ()
## And a build AFTER the withdrawal stays at the baseline — the withdrawal is not
## itself replayed as a statement on the next pass.
build_index(output=db, repo_root=root, doxyfile=doxyfile)
assert _shared_key_rows(db) == baseline
assert stated_options(_options_meta(db)) == ()
Activity · 26 steps
test_a_stated_predefined_survives_a_rebuild_and_a_withdrawal_undoes_it
None test_manifest_replay_integration.test_a_stated_predefined_survives_a_rebuild_and_a_withdrawal_undoes_it(Path tmp_path)
THE STAMP WAS ONCE THE ONLY LOAD-BEARING ASSERTION HERE, and mutation is how that was established rather than assumed: with the replay deleted, the row-count line below still PASSED — because the doxygen cache served the previous build's output under the reverted key (#399) — and only the tier assertion failed.
tests/integration/test_manifest_replay_integration.py:284
Called by none
Calls _doxygen_functions, _options_meta, _resolved_macro_count, stated_options
Checks
assert stated_options(_options_meta(db)) == ()assert stated > baseline, (f"the stated macro produced no new doxygen rows ({stated} vs baseline {baseline}) — " f"the control cannot tell a lost statement from a fixture that never worked" )assert "predefined" in stated_options(_options_meta(db))assert _doxygen_functions(db) == stated, ("the rebuild lost the stated preprocessor configuration — the build reports success " "and the index silently describes a DIFFERENT variant of the repository" )assert replayed[f"predefined.{TIER_KEY}"] == TIER_EXPLICIT, ("the record is what makes the replay possible, and it is the assertion mutation " "shows to be load-bearing" )assert "predefined" in stated_options(replayed), ("a replayed statement makes this index carry a policy the repository does not " "declare — allowed only because it is visible" )assert _resolved_macro_count(db) == 1, ("the replayed macro must reach the stage, not just the stamp" )assert _doxygen_functions(db) == baseline, ("the withdrawal returned the stamp and the macro count to the baseline while the " "index kept the gated function — the doxygen cache served the stated build's output " "back to the withdrawn key (#399)" )assert withdrawn[f"predefined.{TIER_KEY}"] == TIER_HEURISTICassert f"predefined.{EXPLICIT_KEY}" not in withdrawn, ("the record must be GONE, not ignored: a withdrawal that silently fails is the " "key_arg_idx-for-key_arg_index class of defect" )assert _resolved_macro_count(db) == 0, "the withdrawal must reach the preprocessor stage"assert stated_options(_options_meta(db)) == ()assert _resolved_macro_count(db) == 0assert _doxygen_functions(db) == baseline
Result: passed
Verifies
Source · 106 lines
def test_a_stated_predefined_survives_a_rebuild_and_a_withdrawal_undoes_it(
tmp_path: Path,
) -> None:
"""gh#366 — THE SAME HOLE gh#364 CLOSED FOR MANIFESTS, and it loses more than a policy.
A stated `predefined` decides which preprocessor branches doxygen parses at all, so
losing it changes WHICH CODE IS IN THE INDEX rather than merely how it is annotated.
FOUR REAL BUILDS, ONE OUTPUT PATH, counted in DOXYGEN-EMITTED rows:
1. state nothing -> the gated function is absent from doxygen's rows
2. state the macro -> doxygen parses the branch and emits it
3. state nothing AGAIN -> it SURVIVES (this is the fix; it used to vanish)
4. withdraw with `[]` -> back to the baseline, and the RECORD is gone
Build 3 was the failure and it is the normal case, not a corner: `status` reports
staleness and the guidance says refresh, so an agent that brings an index up with a
stated configuration and then refreshes discards its own bringup work silently.
THE COUNT IS PROVENANCE-FILTERED because AST recovery masks the loss — see
`_doxygen_functions`. An unfiltered count cannot tell a lost statement from a working one.
"""
root = tmp_path / "gated"
(root / "src").mkdir(parents=True)
(root / "src" / "gated.c").write_text(_GATED_SOURCE, encoding="utf-8")
doxyfile = root / "Doxyfile"
doxyfile.write_text(DOXYFILE, encoding="utf-8")
db = tmp_path / "gated.db"
build_index(output=db, repo_root=root, doxyfile=doxyfile)
baseline = _doxygen_functions(db)
assert stated_options(_options_meta(db)) == ()
build_index(
output=db, repo_root=root, doxyfile=doxyfile, options={"predefined": ["DEMO_FEATURE_ON"]}
)
stated = _doxygen_functions(db)
assert stated > baseline, (
f"the stated macro produced no new doxygen rows ({stated} vs baseline {baseline}) — "
f"the control cannot tell a lost statement from a fixture that never worked"
)
assert "predefined" in stated_options(_options_meta(db))
## THE FIX. No options at all, which is exactly what an MCP refresh passes.
##
## THE STAMP WAS ONCE THE ONLY LOAD-BEARING ASSERTION HERE, and mutation is how that was
## established rather than assumed: with the replay deleted, the row-count line below
## still PASSED — because the doxygen cache served the previous build's output under the
## reverted key (#399) — and only the tier assertion failed. A reader who trusted the row
## count would have thought this test guarded more than it did.
##
## #399 IS FIXED, so the row count is load-bearing too and this note is kept as the record
## of why a passing row count is not self-evidently a working test. `doxygen_get` now
## verifies that the file it serves still holds the digest THIS key produced, so a
## reverted key misses instead of inheriting its neighbour's output.
build_index(output=db, repo_root=root, doxyfile=doxyfile)
assert _doxygen_functions(db) == stated, (
"the rebuild lost the stated preprocessor configuration — the build reports success "
"and the index silently describes a DIFFERENT variant of the repository"
)
replayed = _options_meta(db)
assert replayed[f"predefined.{TIER_KEY}"] == TIER_EXPLICIT, (
"the record is what makes the replay possible, and it is the assertion mutation "
"shows to be load-bearing"
)
assert "predefined" in stated_options(replayed), (
"a replayed statement makes this index carry a policy the repository does not "
"declare — allowed only because it is visible"
)
assert _resolved_macro_count(db) == 1, (
"the replayed macro must reach the stage, not just the stamp"
)
## THE WITHDRAWAL. `[]` is the list spelling of `{}`, and the record must be GONE.
##
## ASSERTED ON ROWS AGAIN AS WELL AS ON WHAT THE PIPELINE RESOLVED. This step used to
## check only `_resolved_macro_count`, and said so: the withdrawal reached the pipeline
## correctly — the `preprocessor.*` rows disappeared and the stamp returned to
## `heuristic` — while `memberdef` STILL HELD the gated function, because the doxygen
## cache mapped many keys to ONE output path that every build overwrote (#399). A
## row-count assertion therefore failed on a defect that was not this one.
##
## That cache is fixed, so the row count is asserted here too. It is the counterpart of
## the `index_scope` control below and it points the OTHER WAY, which is what identified
## the defect as aliasing rather than staleness: this key was served a WIDER earlier
## output, that one a NARROWER earlier output. Neither is "the newer output wins".
build_index(output=db, repo_root=root, doxyfile=doxyfile, options={"predefined": []})
assert _doxygen_functions(db) == baseline, (
"the withdrawal returned the stamp and the macro count to the baseline while the "
"index kept the gated function — the doxygen cache served the stated build's output "
"back to the withdrawn key (#399)"
)
withdrawn = _options_meta(db)
assert withdrawn[f"predefined.{TIER_KEY}"] == TIER_HEURISTIC
assert f"predefined.{EXPLICIT_KEY}" not in withdrawn, (
"the record must be GONE, not ignored: a withdrawal that silently fails is the "
"key_arg_idx-for-key_arg_index class of defect"
)
assert _resolved_macro_count(db) == 0, "the withdrawal must reach the preprocessor stage"
## And the withdrawal is not itself replayed as a statement on the next pass.
build_index(output=db, repo_root=root, doxyfile=doxyfile)
assert stated_options(_options_meta(db)) == ()
assert _resolved_macro_count(db) == 0
assert _doxygen_functions(db) == baseline
Activity · 29 steps
test_a_stated_preprocessor_section_reaches_the_stage_through_the_declaration
None test_manifest_replay_integration.test_a_stated_preprocessor_section_reaches_the_stage_through_the_declaration(Path tmp_path)
gh#382 — `preprocessor:` and `kconfig:` were TIER-2 ONLY: readable from a checked-in `.clew.yaml` and unreachable from the MCP surface, because neither has an argparse dest. That is CLAUDE.md's rule read the other way round — "a declaration reachable only from argv is not a declaration" — and it bites hardest on the case the declaration model exists for: a third-party repo carrying no config file for a tool it has never heard of.
tests/integration/test_manifest_replay_integration.py:390
Checks
assert _resolved_macro_count(db) == 0assert _resolved_macro_count(db) == 1, ("a stated `preprocessor:` section never reached resolve_preprocessor — the option " "was accepted and then dropped, which is worse than refusing it" )assert _resolved_macro_count(db) == 0
Result: passed
Verifies
Source · 44 lines
def test_a_stated_preprocessor_section_reaches_the_stage_through_the_declaration(
tmp_path: Path,
) -> None:
"""gh#382 — `preprocessor:` and `kconfig:` were TIER-2 ONLY: readable from a checked-in
`.clew.yaml` and unreachable from the MCP surface, because neither has an argparse
dest. That is CLAUDE.md's rule read the other way round — "a declaration reachable only
from argv is not a declaration" — and it bites hardest on the case the declaration model
exists for: a third-party repo carrying no config file for a tool it has never heard of.
THE SECTION NAME IS THE OPTION NAME, which is the 1:1 ruling made literal, and the whole
section document is stated. Verified through the STAGE rather than the stamp: a section
that is recorded but never read would satisfy any metadata assertion.
`predefined` remains as a convenience alias for `preprocessor.predefined`, so this test
also pins that stating the SECTION works where only the alias did before — the alias
cannot express `config_header:` at all.
"""
root = tmp_path / "sectioned"
(root / "src").mkdir(parents=True)
(root / "src" / "gated.c").write_text(_GATED_SOURCE, encoding="utf-8")
doxyfile = root / "Doxyfile"
doxyfile.write_text(DOXYFILE, encoding="utf-8")
db = tmp_path / "sectioned.db"
build_index(output=db, repo_root=root, doxyfile=doxyfile)
assert _resolved_macro_count(db) == 0
## THE SECTION, not the alias. This is the route that did not exist.
build_index(
output=db,
repo_root=root,
doxyfile=doxyfile,
options={"preprocessor": {"predefined": ["DEMO_FEATURE_ON"]}},
)
assert _resolved_macro_count(db) == 1, (
"a stated `preprocessor:` section never reached resolve_preprocessor — the option "
"was accepted and then dropped, which is worse than refusing it"
)
## AND WITHDRAWING IT restores the target's own declaration (here: none).
build_index(output=db, repo_root=root, doxyfile=doxyfile, options={"preprocessor": {}})
assert _resolved_macro_count(db) == 0