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

Show on the map →

Called by none

Calls _doxygen_has, _indexed_path, _scope_stamp, _write_target

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

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-001measured
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 · 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
lines 529–529root = tmp_path / "scoped"lines 530–530doxyfile = _write_target(root)lines 531–531(root / "extra").mkdir()lines 532–537(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", )lines 538–538db = tmp_path / "scoped.db"lines 543–543build_index(output=db, repo_root=root, doxyfile=doxyfile)lines 544–547assert _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" )lines 550–555build_index( output=db, repo_root=root, doxyfile=doxyfile, options={"index_scope": {"roots": ["src"]}}, )lines 556–560assert 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" )lines 561–561assert _doxygen_has(db, WRITER), "the narrowed scope must still index what it named"lines 581–581build_index(output=db, repo_root=root, doxyfile=doxyfile, options={"index_scope": {}})lines 582–585assert _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)" )lines 586–589assert _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" )lines 590–593assert _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" )

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

Show on the map →

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_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" )
  • assert _shared_key_rows(db) == baseline
  • 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) == ()
  • assert _shared_key_rows(db) == baseline
  • assert stated_options(_options_meta(db)) == ()

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-006measuredtest_a_stated_manifest_survives_a_rebuild_and_a_withdrawal_undoes_it → _options_meta
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_manifest_survives_a_rebuild_and_a_withdrawal_undoes_it → _options_meta → _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 · 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
lines 157–157root = tmp_path / "target"lines 158–158doxyfile = _write_target(root)lines 159–159db = tmp_path / "clew.db"lines 161–161build_index(output=db, repo_root=root, doxyfile=doxyfile)lines 162–162baseline = _shared_key_rows(db)lines 163–163assert stated_options(_options_meta(db)) == (), "nothing was stated, so nothing is stamped"lines 165–167build_index( output=db, repo_root=root, doxyfile=doxyfile, options={SECTION_SHARED_KEY: MANIFEST} )lines 168–168stated = _shared_key_rows(db)lines 169–172assert 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" )lines 173–173assert stated_options(_options_meta(db)) == (SECTION_SHARED_KEY,)lines 176–176build_index(output=db, repo_root=root, doxyfile=doxyfile)lines 177–180assert _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" )lines 181–181replayed = _options_meta(db)lines 182–182assert replayed[f"{SECTION_SHARED_KEY}.{TIER_KEY}"] == TIER_EXPLICITlines 183–183assert recorded_document(replayed, SECTION_SHARED_KEY) == MANIFESTlines 184–187assert 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" )lines 191–191build_index(output=db, repo_root=root, doxyfile=doxyfile, options={SECTION_SHARED_KEY: {}})lines 192–192assert _shared_key_rows(db) == baselinelines 193–193withdrawn = _options_meta(db)lines 194–194assert withdrawn[f"{SECTION_SHARED_KEY}.{TIER_KEY}"] == TIER_HEURISTIClines 195–198assert 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" )lines 199–199assert recorded_document(withdrawn, SECTION_SHARED_KEY) is Nonelines 200–200assert stated_options(withdrawn) == ()lines 204–204build_index(output=db, repo_root=root, doxyfile=doxyfile)lines 205–205assert _shared_key_rows(db) == baselinelines 206–206assert stated_options(_options_meta(db)) == ()

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

Show on the map →

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_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"
  • assert stated_options(_options_meta(db)) == ()
  • assert _resolved_macro_count(db) == 0
  • assert _doxygen_functions(db) == baseline

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-006measuredtest_a_stated_predefined_survives_a_rebuild_and_a_withdrawal_undoes_it → _options_meta
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_predefined_survives_a_rebuild_and_a_withdrawal_undoes_it → _options_meta → _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 · 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
lines 305–305root = tmp_path / "gated"lines 306–306(root / "src").mkdir(parents=True)lines 307–307(root / "src" / "gated.c").write_text(_GATED_SOURCE, encoding="utf-8")lines 308–308doxyfile = root / "Doxyfile"lines 309–309doxyfile.write_text(DOXYFILE, encoding="utf-8")lines 310–310db = tmp_path / "gated.db"lines 312–312build_index(output=db, repo_root=root, doxyfile=doxyfile)lines 313–313baseline = _doxygen_functions(db)lines 314–314assert stated_options(_options_meta(db)) == ()lines 316–318build_index( output=db, repo_root=root, doxyfile=doxyfile, options={"predefined": ["DEMO_FEATURE_ON"]} )lines 319–319stated = _doxygen_functions(db)lines 320–323assert 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" )lines 324–324assert "predefined" in stated_options(_options_meta(db))lines 338–338build_index(output=db, repo_root=root, doxyfile=doxyfile)lines 339–342assert _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" )lines 343–343replayed = _options_meta(db)lines 344–347assert 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" )lines 348–351assert "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" )lines 352–354assert _resolved_macro_count(db) == 1, ( "the replayed macro must reach the stage, not just the stamp" )lines 369–369build_index(output=db, repo_root=root, doxyfile=doxyfile, options={"predefined": []})lines 370–374assert _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)" )lines 375–375withdrawn = _options_meta(db)lines 376–376assert withdrawn[f"predefined.{TIER_KEY}"] == TIER_HEURISTIClines 377–380assert 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" )lines 381–381assert _resolved_macro_count(db) == 0, "the withdrawal must reach the preprocessor stage"lines 384–384build_index(output=db, repo_root=root, doxyfile=doxyfile)lines 385–385assert stated_options(_options_meta(db)) == ()lines 386–386assert _resolved_macro_count(db) == 0lines 387–387assert _doxygen_functions(db) == baseline

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

Show on the map →

Called by none

Calls _resolved_macro_count

Checks

  • assert _resolved_macro_count(db) == 0
  • 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" )
  • assert _resolved_macro_count(db) == 0

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-001measured
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 · 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

Activity · 12 steps
lines 407–407root = tmp_path / "sectioned"lines 408–408(root / "src").mkdir(parents=True)lines 409–409(root / "src" / "gated.c").write_text(_GATED_SOURCE, encoding="utf-8")lines 410–410doxyfile = root / "Doxyfile"lines 411–411doxyfile.write_text(DOXYFILE, encoding="utf-8")lines 412–412db = tmp_path / "sectioned.db"lines 414–414build_index(output=db, repo_root=root, doxyfile=doxyfile)lines 415–415assert _resolved_macro_count(db) == 0lines 418–423build_index( output=db, repo_root=root, doxyfile=doxyfile, options={"preprocessor": {"predefined": ["DEMO_FEATURE_ON"]}}, )lines 424–427assert _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" )lines 430–430build_index(output=db, repo_root=root, doxyfile=doxyfile, options={"preprocessor": {}})lines 431–431assert _resolved_macro_count(db) == 0