test_declaration.py

tests/test_declaration.py

A target repo's `.clew.yaml` declaration (task #51).

test_a_declared_doxyfile_is_reachable_and_a_missing_one_refuses

None test_declaration.test_a_declared_doxyfile_is_reachable_and_a_missing_one_refuses(Path tmp_path)

A declared Doxyfile is used; a declared path that is not there REFUSES.

tests/test_declaration.py:378

Show on the map →

Called by none

Calls apply_options

Checks

  • assert SECTION_DOXYFILE in KNOWN_SECTIONS, "declarable, or the document-level gate refuses it"
  • assert applied == [SECTION_DOXYFILE]
  • assert Path(args.doxyfile) == doxydir / "mbedtls.doxyfile"
  • assert "typo.doxyfile" in str(refusal.value)
  • assert apply_options(ok, {"requirements": "nope.yaml"}, tmp_path) == ["requirements"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
Source · 48 lines
def test_a_declared_doxyfile_is_reachable_and_a_missing_one_refuses(tmp_path: Path) -> None:
    """gh#420. `discover_doxyfile` matches the NAME `Doxyfile` in the repo root, `docs/` and
    `doc/` and refuses to guess further, because it was once caught selecting a test FIXTURE's
    Doxyfile to index a whole project. Mbed-TLS ships `doxygen/mbedtls.doxyfile` — wrong
    directory AND wrong filename — so it was unreachable from discovery, and until this section
    existed there was no way to state it either. `--doxyfile` could name it on one command line,
    which is the shape the mandate calls not-a-declaration: unrecorded, unreplayed, and
    unreachable from the MCP surface.

    BOTH HALVES, and the second is the fail-closed one. A stated path that is not a file must
    refuse rather than fall through to whole-repo synthesis, because synthesis is a LEGITIMATE
    build — so the result would be a well-formed index of a different thing, reporting success.
    That is why `doxyfile` is in `PATH_OPTIONS_MUST_EXIST` while `requirements` is not: a missing
    catalog degrades to empty metadata over the same rows, a missing Doxyfile changes which
    source is compiled in.
    """
    from types import SimpleNamespace

    from clew.buildoptions import BuildOptionError, apply_options
    from clew.declaration import SECTION_DOXYFILE

    assert SECTION_DOXYFILE in KNOWN_SECTIONS, "declarable, or the document-level gate refuses it"

    doxydir = tmp_path / "doxygen"
    doxydir.mkdir()
    (doxydir / "mbedtls.doxyfile").write_text(
        "INPUT = ../include\nFILE_PATTERNS = *.h\n", encoding="utf-8"
    )

    ## RESOLVED AGAINST THE REPO ROOT, not the process's cwd — an MCP server's cwd is not the
    ## target repo, and the declaration states the path an author would write in-tree.
    args = SimpleNamespace()
    applied = apply_options(args, {SECTION_DOXYFILE: "doxygen/mbedtls.doxyfile"}, tmp_path)
    assert applied == [SECTION_DOXYFILE]
    assert Path(args.doxyfile) == doxydir / "mbedtls.doxyfile"

    ## AND THE REFUSAL NAMES THE PATH. A typo'd declaration silently indexing the whole repo is
    ## the "wrong answer beats no answer" failure this whole section is shaped around.
    with pytest.raises(BuildOptionError) as refusal:
        apply_options(SimpleNamespace(), {SECTION_DOXYFILE: "doxygen/typo.doxyfile"}, tmp_path)
    assert "typo.doxyfile" in str(refusal.value)

    ## THE CONTRAST THAT JUSTIFIES THE SET: a missing `requirements` catalog is NOT refused here,
    ## because each loader reports its own absent document with the context to say what it was for.
    ok = SimpleNamespace()
    assert apply_options(ok, {"requirements": "nope.yaml"}, tmp_path) == ["requirements"]

Activity · 16 steps
lines 394–394from types import SimpleNamespacelines 396–396from clew.buildoptions import BuildOptionError, apply_optionslines 397–397from clew.declaration import SECTION_DOXYFILElines 399–399assert SECTION_DOXYFILE in KNOWN_SECTIONS, "declarable, or the document-level gate refuses it"lines 401–401doxydir = tmp_path / "doxygen"lines 402–402doxydir.mkdir()lines 403–405(doxydir / "mbedtls.doxyfile").write_text( "INPUT = ../include\nFILE_PATTERNS = *.h\n", encoding="utf-8" )lines 409–409args = SimpleNamespace()lines 410–410applied = apply_options(args, {SECTION_DOXYFILE: "doxygen/mbedtls.doxyfile"}, tmp_path)lines 411–411assert applied == [SECTION_DOXYFILE]lines 412–412assert Path(args.doxyfile) == doxydir / "mbedtls.doxyfile"lines 416–416with pytest.raises(BuildOptionError) as refusallines 417–417apply_options(SimpleNamespace(), {SECTION_DOXYFILE: "doxygen/typo.doxyfile"}, tmp_path)lines 418–418assert "typo.doxyfile" in str(refusal.value)lines 422–422ok = SimpleNamespace()lines 423–423assert apply_options(ok, {"requirements": "nope.yaml"}, tmp_path) == ["requirements"]

test_a_declared_event_tag_vocabulary_is_read_and_normalised

None test_declaration.test_a_declared_event_tag_vocabulary_is_read_and_normalised(Path tmp_path)

The accessor's happy path, and the reason the section exists: a repo whose bus is documented `@broadcasts`/`@reacts` had no way to say so, because `import_event_edges` took the vocabulary as a parameter no caller passed.

tests/test_declaration.py:225

Checks

  • assert declared_event_tags(decl) == {"broadcasts": PRODUCER, "reacts": CONSUMER}
  • assert declared_event_tags({}) is None
  • assert declared_event_tags({"event_tags": {}}) is None
  • assert declared_event_tags({"event_tags": []}) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_declared_event_tag_vocabulary_is_read_and_normalised → declared_event_tags
Source · 17 lines
def test_a_declared_event_tag_vocabulary_is_read_and_normalised(tmp_path: Path) -> None:
    """The accessor's happy path, and the reason the section exists: a repo whose
    bus is documented `@broadcasts`/`@reacts` had no way to say so, because
    `import_event_edges` took the vocabulary as a parameter no caller passed."""
    from clew.declaration import declared_event_tags
    from clew.event_edges import CONSUMER, PRODUCER

    decl = {"event_tags": {"Broadcasts": "Producer", "reacts": "consumer"}}
    assert declared_event_tags(decl) == {"broadcasts": PRODUCER, "reacts": CONSUMER}

    # Undeclared is None, NOT {} — the importer's parameter distinguishes them, and
    # only None means "keep the built-in verbs".
    assert declared_event_tags({}) is None
    assert declared_event_tags({"event_tags": {}}) is None
    assert declared_event_tags({"event_tags": []}) is None

Activity · 7 steps
lines 229–229from clew.declaration import declared_event_tagslines 230–230from clew.event_edges import CONSUMER, PRODUCERlines 232–232decl = {"event_tags": {"Broadcasts": "Producer", "reacts": "consumer"}}lines 233–233assert declared_event_tags(decl) == {"broadcasts": PRODUCER, "reacts": CONSUMER}lines 237–237assert declared_event_tags({}) is Nonelines 238–238assert declared_event_tags({"event_tags": {}}) is Nonelines 239–239assert declared_event_tags({"event_tags": []}) is None

test_absent_declaration_is_not_an_error

None test_declaration.test_absent_declaration_is_not_an_error(Path tmp_path)

Most repos declare nothing and run entirely on built-in defaults, so an absent file is the norm rather than a failure.

tests/test_declaration.py:35

Checks

  • assert load_declaration(tmp_path) == {}
  • assert load_declaration(None) == {}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_absent_declaration_is_not_an_error → load_declaration
REQ-DDB-GUARD-012inferredtest_absent_declaration_is_not_an_error → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_absent_declaration_is_not_an_error → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 7 lines
def test_absent_declaration_is_not_an_error(tmp_path: Path) -> None:
    """Most repos declare nothing and run entirely on built-in defaults, so an
    absent file is the norm rather than a failure."""
    assert load_declaration(tmp_path) == {}
    assert load_declaration(None) == {}

Activity · 2 steps
lines 38–38assert load_declaration(tmp_path) == {}lines 39–39assert load_declaration(None) == {}

test_an_experimental_section_is_tolerated_and_ignored

test_declaration.TestForwardCompatibility.test_an_experimental_section_is_tolerated_and_ignored(self, tmp_path)

An `x-` section neither refuses nor reaches the build.

tests/test_declaration.py:455

Checks

  • assert "thread_patterns" in data, "the known sections must still be read"
  • assert not [key for key in data if key.startswith("x-")], (f"an experimental section reached the build, which is worse than refusing it: {data}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_experimental_section_is_tolerated_and_ignored → load_declaration
REQ-DDB-GUARD-012inferredtest_an_experimental_section_is_tolerated_and_ignored → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_an_experimental_section_is_tolerated_and_ignored → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 15 lines
    def test_an_experimental_section_is_tolerated_and_ignored(self, tmp_path):
        """@brief An `x-` section neither refuses nor reaches the build. @version 2"""
        ## FIXTURE CHANGED (2.0.0, R5-CFG F1): `thread_patterns: [worker]` was a list, which no
        ## reader ever read and the loader now refuses; the property is the `x-` tolerance.
        (tmp_path / ".clew.yaml").write_text(
            "x-future-thing:\n  whatever: 1\nthread_patterns:\n  spawns:\n    - {name: worker}\n"
        )

        data = load_declaration(tmp_path)

        assert "thread_patterns" in data, "the known sections must still be read"
        assert not [key for key in data if key.startswith("x-")], (
            f"an experimental section reached the build, which is worse than refusing it: {data}"
        )
Activity · 4 steps
lines 459–461(tmp_path / ".clew.yaml").write_text( "x-future-thing:\n whatever: 1\nthread_patterns:\n spawns:\n - {name: worker}\n" )lines 463–463data = load_declaration(tmp_path)lines 465–465assert "thread_patterns" in data, "the known sections must still be read"lines 466–468assert not [key for key in data if key.startswith("x-")], ( f"an experimental section reached the build, which is worse than refusing it: {data}" )

test_an_unknown_event_role_is_refused

None test_declaration.test_an_unknown_event_role_is_refused(Path tmp_path)

FAIL CLOSED, one level below the section allow-list. Degrading a misspelled `producers:` to a default would file an emitter as a handler, and a REVERSED edge is worse than a missing one: these rows carry `declared=1` and `confidence='high'` because an author asserted them, so `chain_trace` would report causality flowing the wrong way with the strongest grading the pipeline can give.

tests/test_declaration.py:242

Checks

  • assert "broadcasts" in message, "the refusal must name the offending tag"
  • assert "producer" in message and "consumer" in message, "and the allowed roles"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_unknown_event_role_is_refused → declared_event_tags
Source · 18 lines
def test_an_unknown_event_role_is_refused(tmp_path: Path) -> None:
    """FAIL CLOSED, one level below the section allow-list. Degrading a misspelled
    `producers:` to a default would file an emitter as a handler, and a REVERSED
    edge is worse than a missing one: these rows carry `declared=1` and
    `confidence='high'` because an author asserted them, so `chain_trace` would
    report causality flowing the wrong way with the strongest grading the pipeline
    can give."""
    from clew.declaration import declared_event_tags
    from clew.vocabulary import DeclarationError

    with pytest.raises(DeclarationError) as exc:
        declared_event_tags({"event_tags": {"broadcasts": "producers"}})

    message = str(exc.value)
    assert "broadcasts" in message, "the refusal must name the offending tag"
    assert "producer" in message and "consumer" in message, "and the allowed roles"

Activity · 7 steps
lines 249–249from clew.declaration import declared_event_tagslines 250–250from clew.vocabulary import DeclarationErrorlines 252–252with pytest.raises(DeclarationError) as exclines 253–253declared_event_tags({"event_tags": {"broadcasts": "producers"}})lines 255–255message = str(exc.value)lines 256–256assert "broadcasts" in message, "the refusal must name the offending tag"lines 257–257assert "producer" in message and "consumer" in message, "and the allowed roles"

test_an_unknown_section_beside_the_guard_section_is_still_refused

None test_declaration.test_an_unknown_section_beside_the_guard_section_is_still_refused(Path tmp_path)

Sharing the file must not loosen the allow-list: a misspelled section next to a valid `guard:` parses, nothing reads it, and the build would report the declaration honoured.

tests/test_declaration.py:290

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_unknown_section_beside_the_guard_section_is_still_refused → load_declaration
REQ-DDB-GUARD-012inferredtest_an_unknown_section_beside_the_guard_section_is_still_refused → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_an_unknown_section_beside_the_guard_section_is_still_refused → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 12 lines
def test_an_unknown_section_beside_the_guard_section_is_still_refused(tmp_path: Path) -> None:
    """Sharing the file must not loosen the allow-list: a misspelled section next to a valid
    `guard:` parses, nothing reads it, and the build would report the declaration honoured."""
    (tmp_path / ".clew.yaml").write_text(
        "guard:\n  output_dir: o/\nthread_pattern:\n  spawns: []\n", encoding="utf-8"
    )
    from clew.vocabulary import DeclarationError

    with pytest.raises(DeclarationError, match="unknown section"):
        load_declaration(tmp_path)

Activity · 4 steps
lines 293–295(tmp_path / ".clew.yaml").write_text( "guard:\n output_dir: o/\nthread_pattern:\n spawns: []\n", encoding="utf-8" )lines 296–296from clew.vocabulary import DeclarationErrorlines 298–298with pytest.raises(DeclarationError, match="unknown section")lines 299–299load_declaration(tmp_path)

test_an_unknown_section_is_refused

None test_declaration.test_an_unknown_section_is_refused(Path tmp_path)

The no-hardcoding mandate's worst case, closed at document level.

tests/test_declaration.py:174

Checks

  • assert "shared_key_pattern" in message and "thread_pattern" in message
  • assert "shared_key_patterns" in message, "the refusal must name the ALLOWED spellings"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_unknown_section_is_refused → load_declaration
REQ-DDB-GUARD-012inferredtest_an_unknown_section_is_refused → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_an_unknown_section_is_refused → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 28 lines
def test_an_unknown_section_is_refused(tmp_path: Path) -> None:
    """The no-hardcoding mandate's worst case, closed at document level.

    A singular/plural slip parses to valid YAML that NO consumer reads, so the
    build ran entirely on built-in defaults — while `load_declaration` logged
    "declares shared_key_pattern" and told the owner the file was honoured.
    Substituting our assumptions for a declaration the author did write, and
    reporting success, is precisely what the mandate forbids.

    `dispatch.py::_reject_unknown` closed this one level down; this lifts it to the
    document, which is where the quietest slips live."""
    import pytest

    from clew.declaration import load_declaration
    from clew.vocabulary import DeclarationError

    (tmp_path / ".clew.yaml").write_text(
        "shared_key_pattern:\n  - prefix: Store_Set\nthread_pattern:\n  - name: spawn\n",
        encoding="utf-8",
    )
    with pytest.raises(DeclarationError) as exc:
        load_declaration(tmp_path)

    message = str(exc.value)
    assert "shared_key_pattern" in message and "thread_pattern" in message
    assert "shared_key_patterns" in message, "the refusal must name the ALLOWED spellings"

Activity · 9 steps
lines 185–185import pytestlines 187–187from clew.declaration import load_declarationlines 188–188from clew.vocabulary import DeclarationErrorlines 190–193(tmp_path / ".clew.yaml").write_text( "shared_key_pattern:\n - prefix: Store_Set\nthread_pattern:\n - name: spawn\n", encoding="utf-8", )lines 194–194with pytest.raises(DeclarationError) as exclines 195–195load_declaration(tmp_path)lines 197–197message = str(exc.value)lines 198–198assert "shared_key_pattern" in message and "thread_pattern" in messagelines 199–199assert "shared_key_patterns" in message, "the refusal must name the ALLOWED spellings"

test_an_x_prefix_does_not_excuse_a_misspelling

test_declaration.TestForwardCompatibility.test_an_x_prefix_does_not_excuse_a_misspelling(self, tmp_path, caplog)

A tolerated section is logged, not silent.

tests/test_declaration.py:470

Checks

  • assert data == {}
  • assert any("x-thread_patterns" in record.getMessage() for record in caplog.records), ("a tolerated section must still be named, or a typo with an `x-` prefix is silent" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_x_prefix_does_not_excuse_a_misspelling → load_declaration
REQ-DDB-GUARD-012inferredtest_an_x_prefix_does_not_excuse_a_misspelling → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_an_x_prefix_does_not_excuse_a_misspelling → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 17 lines
    def test_an_x_prefix_does_not_excuse_a_misspelling(self, tmp_path, caplog):
        """THE LIMIT. `x-thread_patterns` is not a tolerated experiment, it is a typo with a prefix —
        but there is no way to tell those apart, and tolerating it silently is exactly the
        failure mode the refusal exists to prevent. This asserts the rule stays narrow: the
        prefix buys tolerance, and tolerance means the section is reported as ignored.

        @brief A tolerated section is logged, not silent. @version 1
        """
        (tmp_path / ".clew.yaml").write_text("x-thread_patterns:\n  - worker\n")

        with caplog.at_level(logging.WARNING, logger="clew.declaration"):
            data = load_declaration(tmp_path)

        assert data == {}
        assert any("x-thread_patterns" in record.getMessage() for record in caplog.records), (
            "a tolerated section must still be named, or a typo with an `x-` prefix is silent"
        )

1 more lines, not shown

Activity · 5 steps
lines 478–478(tmp_path / ".clew.yaml").write_text("x-thread_patterns:\n - worker\n")lines 480–480with caplog.at_level(logging.WARNING, logger="clew.declaration")lines 481–481data = load_declaration(tmp_path)lines 483–483assert data == {}lines 484–486assert any("x-thread_patterns" in record.getMessage() for record in caplog.records), ( "a tolerated section must still be named, or a typo with an `x-` prefix is silent" )

test_build_meta_records_the_stated_declaration

None test_declaration.test_build_meta_records_the_stated_declaration(Path tmp_path)

The build records which document was stated, and records nothing when none was.

tests/test_declaration.py:347

Checks

  • assert held["declaration.stated_sha256"] == "ab" * 32
  • assert held["declaration.stated_sections"] == "locks"
  • assert not [k for k in held2 if k.startswith("declaration.")], ("a build with no stated document must write NO declaration row — the harness gate reads " "absence as 'not stated', so a placeholder row would certify a policy nobody stated" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
REQ-DDB-CONFIG-006measuredtest_build_meta_records_the_stated_declaration → write_build_signature
REQ-DDB-CONFIG-007measuredtest_build_meta_records_the_stated_declaration → write_build_signature
REQ-DDB-PIPE-005measuredtest_build_meta_records_the_stated_declaration → write_build_signature
Source · 28 lines
def test_build_meta_records_the_stated_declaration(tmp_path: Path) -> None:
    """Both halves. A recorded document is what makes the harness gate possible; an ABSENT
    section is what makes "no document was stated" honestly readable, rather than presenting as
    a statement that was made and was blank.
    """
    import sqlite3

    from clew.signature import write_build_signature

    db = tmp_path / "clew.db"
    write_build_signature(db, declaration={"stated_sha256": "ab" * 32, "stated_sections": "locks"})
    conn = sqlite3.connect(str(db))
    held = dict(conn.execute("SELECT key, value FROM build_meta"))
    conn.close()
    assert held["declaration.stated_sha256"] == "ab" * 32
    assert held["declaration.stated_sections"] == "locks"

    db2 = tmp_path / "plain.db"
    write_build_signature(db2)
    conn = sqlite3.connect(str(db2))
    held2 = dict(conn.execute("SELECT key, value FROM build_meta"))
    conn.close()
    assert not [k for k in held2 if k.startswith("declaration.")], (
        "a build with no stated document must write NO declaration row — the harness gate reads "
        "absence as 'not stated', so a placeholder row would certify a policy nobody stated"
    )

Activity · 15 steps
lines 352–352import sqlite3lines 354–354from clew.signature import write_build_signaturelines 356–356db = tmp_path / "clew.db"lines 357–357write_build_signature(db, declaration={"stated_sha256": "ab" * 32, "stated_sections": "locks"})lines 358–358conn = sqlite3.connect(str(db))lines 359–359held = dict(conn.execute("SELECT key, value FROM build_meta"))lines 360–360conn.close()lines 361–361assert held["declaration.stated_sha256"] == "ab" * 32lines 362–362assert held["declaration.stated_sections"] == "locks"lines 364–364db2 = tmp_path / "plain.db"lines 365–365write_build_signature(db2)lines 366–366conn = sqlite3.connect(str(db2))lines 367–367held2 = dict(conn.execute("SELECT key, value FROM build_meta"))lines 368–368conn.close()lines 369–372assert not [k for k in held2 if k.startswith("declaration.")], ( "a build with no stated document must write NO declaration row — the harness gate reads " "absence as 'not stated', so a placeholder row would certify a policy nobody stated" )

test_declared_path_section_resolves_relative_to_the_repo

None test_declaration.test_declared_path_section_resolves_relative_to_the_repo(Path tmp_path)

Formats that are not YAML (the ingot data-model TOML) are NAMED by the section rather than inlined; the path stays repo-relative so the declaration is portable.

tests/test_declaration.py:81

Checks

  • assert declared_path(decl, SECTION_DATA_MODEL, tmp_path) == (tmp_path / "model.toml").resolve()
  • assert declared_path({SECTION_DATA_MODEL: "gone.toml"}, SECTION_DATA_MODEL, tmp_path) is None
  • assert declared_path({}, SECTION_DATA_MODEL, tmp_path) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_declared_path_section_resolves_relative_to_the_repo → declared_path
Source · 13 lines
def test_declared_path_section_resolves_relative_to_the_repo(tmp_path: Path) -> None:
    """Formats that are not YAML (the ingot data-model TOML) are NAMED by the
    section rather than inlined; the path stays repo-relative so the
    declaration is portable."""
    (tmp_path / "model.toml").write_text("", encoding="utf-8")
    decl = {SECTION_DATA_MODEL: "model.toml"}
    assert declared_path(decl, SECTION_DATA_MODEL, tmp_path) == (tmp_path / "model.toml").resolve()

    # Declared but missing warns and yields None rather than failing the build.
    assert declared_path({SECTION_DATA_MODEL: "gone.toml"}, SECTION_DATA_MODEL, tmp_path) is None
    assert declared_path({}, SECTION_DATA_MODEL, tmp_path) is None

Activity · 5 steps
lines 85–85(tmp_path / "model.toml").write_text("", encoding="utf-8")lines 86–86decl = {SECTION_DATA_MODEL: "model.toml"}lines 87–87assert declared_path(decl, SECTION_DATA_MODEL, tmp_path) == (tmp_path / "model.toml").resolve()lines 90–90assert declared_path({SECTION_DATA_MODEL: "gone.toml"}, SECTION_DATA_MODEL, tmp_path) is Nonelines 91–91assert declared_path({}, SECTION_DATA_MODEL, tmp_path) is None

test_entry_patterns_declaration_replaces_the_guesses_not_the_facts

None test_declaration.test_entry_patterns_declaration_replaces_the_guesses_not_the_facts()

tests/test_declaration.py:119

Show on the map →

Called by none

Calls _entry_patterns, list

Checks

  • assert set(ENTRY_PATTERN_FACTS) <= set(declared.values), "facts must survive"
  • assert "%trampoline%" in declared.values and "dispatch_%" in declared.values
  • assert "%init%" not in declared.values, "a declaration replaces the guesses"
  • assert list(_entry_patterns(args, {}).values) == DEFAULT_ENTRY_PATTERNS
  • assert list(_entry_patterns(explicit, decl).values) == [*ENTRY_PATTERN_FACTS, "only_this"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_entry_patterns_declaration_replaces_the_guesses_not_the_facts → _entry_patterns → string_list
REQ-DDB-CONFIG-006measuredtest_entry_patterns_declaration_replaces_the_guesses_not_the_facts → _entry_patterns → resolve_layered
Source · 40 lines
def test_entry_patterns_declaration_replaces_the_guesses_not_the_facts() -> None:
    """#34: a repo whose handlers are reached only through indirect dispatch has
    no static caller for them, so liveness marks them orphan. Naming that
    convention reclaims them — measured on a C++ codebase, declaring its dispatch naming
    takes orphans from 61 to 17, and the survivors (now_ms, parse_bool,
    read_file, slurp) are genuine utility leaves.

    REWRITTEN FOR gh#319, and the old contract is what the rewrite is about. This
    test used to assert that a declaration EXTENDS the whole default set while an
    explicit flag REPLACES it — two different meanings of "supersede" for one
    setting, so moving a value from `.clew.yaml` onto the command line
    silently dropped `main`, `app_main` and every guess with them. Its final line
    (`_entry_patterns(explicit, decl) == ["only_this"]`) PINNED that collapse as
    intended behaviour.

    Both stated tiers now displace only the tier-5 name-shape guesses, and the
    tier-3 language/platform entry points accumulate beneath whatever is stated.
    The full rule is exercised in tests/test_tiers.py; this keeps the
    declaration-shaped case where the declaration format is tested."""
    import argparse

    from clew.cli import _entry_patterns
    from clew.reachability import DEFAULT_ENTRY_PATTERNS, ENTRY_PATTERN_FACTS

    args = argparse.Namespace(entry_patterns=None)
    decl = {SECTION_ENTRY_PATTERNS: ["%trampoline%", "dispatch_%"]}

    declared = _entry_patterns(args, decl)
    assert set(ENTRY_PATTERN_FACTS) <= set(declared.values), "facts must survive"
    assert "%trampoline%" in declared.values and "dispatch_%" in declared.values
    assert "%init%" not in declared.values, "a declaration replaces the guesses"

    # No declaration: exactly the defaults, unchanged.
    assert list(_entry_patterns(args, {}).values) == DEFAULT_ENTRY_PATTERNS

    # An explicit flag beats the declaration — and still cannot drop a fact.
    explicit = argparse.Namespace(entry_patterns=["only_this"])
    assert list(_entry_patterns(explicit, decl).values) == [*ENTRY_PATTERN_FACTS, "only_this"]

Activity · 12 steps
lines 138–138import argparselines 140–140from clew.cli import _entry_patternslines 141–141from clew.reachability import DEFAULT_ENTRY_PATTERNS, ENTRY_PATTERN_FACTSlines 143–143args = argparse.Namespace(entry_patterns=None)lines 144–144decl = {SECTION_ENTRY_PATTERNS: ["%trampoline%", "dispatch_%"]}lines 146–146declared = _entry_patterns(args, decl)lines 147–147assert set(ENTRY_PATTERN_FACTS) <= set(declared.values), "facts must survive"lines 148–148assert "%trampoline%" in declared.values and "dispatch_%" in declared.valueslines 149–149assert "%init%" not in declared.values, "a declaration replaces the guesses"lines 152–152assert list(_entry_patterns(args, {}).values) == DEFAULT_ENTRY_PATTERNSlines 155–155explicit = argparse.Namespace(entry_patterns=["only_this"])lines 156–156assert list(_entry_patterns(explicit, decl).values) == [*ENTRY_PATTERN_FACTS, "only_this"]

test_every_known_section_is_accepted

None test_declaration.test_every_known_section_is_accepted(Path tmp_path)

The negative control. Without it the refusal above would pass just as happily against a loader that rejected everything, and a declaration format nobody can use is worse than one that mis-reads a typo.

tests/test_declaration.py:202

Checks

  • assert set(load_declaration(tmp_path)) == set(KNOWN_SECTIONS)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_every_known_section_is_accepted → load_declaration
REQ-DDB-GUARD-012measuredtest_every_known_section_is_accepted → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_every_known_section_is_accepted → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 23 lines
def test_every_known_section_is_accepted(tmp_path: Path) -> None:
    """The negative control. Without it the refusal above would pass just as
    happily against a loader that rejected everything, and a declaration format
    nobody can use is worse than one that mis-reads a typo."""
    from clew.declaration import KNOWN_SECTIONS, LIST_SECTIONS, PATH_SECTIONS, load_declaration

    ## FIXTURE CHANGED (2.0.0, R5-CFG F1): every section used to be written `[]`, a value the loader
    ## now refuses for a mapping or path section (a wrong SHAPE is refused, not dropped). The
    ## property under test — every known NAME is accepted — is unchanged, so each section gets an
    ## empty value of its own shape.
    def empty(section: str) -> str:
        return "[]" if section in LIST_SECTIONS else ("x" if section in PATH_SECTIONS else "{}")

    body = "".join(f"{section}: {empty(section)}\n" for section in sorted(KNOWN_SECTIONS))
    (tmp_path / ".clew.yaml").write_text(body + "guard: {}\n", encoding="utf-8")

    # `guard:` is accepted and then dropped: it is the gate's section, not a declaration.
    assert set(load_declaration(tmp_path)) == set(KNOWN_SECTIONS)


# ─── event_tags: a mis-typed ROLE is refused, not defaulted ──────────────────

Activity · 5 steps
lines 206–206from clew.declaration import KNOWN_SECTIONS, LIST_SECTIONS, PATH_SECTIONS, load_declarationlines 212–213def empty(section: str) -> str: return "[]" if section in LIST_SECTIONS else ("x" if section in PATH_SECTIONS else "{}")lines 215–215body = "".join(f"{section}: {empty(section)}\n" for section in sorted(KNOWN_SECTIONS))lines 216–216(tmp_path / ".clew.yaml").write_text(body + "guard: {}\n", encoding="utf-8")lines 219–219assert set(load_declaration(tmp_path)) == set(KNOWN_SECTIONS)

test_explicit_flag_wins_over_the_declaration

None test_declaration.test_explicit_flag_wins_over_the_declaration(Path tmp_path)

The file is the repo's standing statement; a flag is a deliberate one-off override, so the flag takes precedence.

tests/test_declaration.py:105

Show on the map →

Called by none

Calls _declared_or_flag

Checks

  • assert _declared_or_flag(str(explicit), decl, SECTION_SHARED_KEY) == explicit.resolve()
  • assert _declared_or_flag(None, decl, SECTION_SHARED_KEY) == decl[SECTION_SHARED_KEY]
  • assert _declared_or_flag(None, {}, SECTION_SHARED_KEY) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
Source · 14 lines
def test_explicit_flag_wins_over_the_declaration(tmp_path: Path) -> None:
    """The file is the repo's standing statement; a flag is a deliberate
    one-off override, so the flag takes precedence."""
    from clew.cli import _declared_or_flag

    decl = {SECTION_SHARED_KEY: {"writers": [{"name_prefix": "FROM_DECL_"}]}}
    explicit = tmp_path / "patterns.yaml"
    explicit.write_text("writers: []\n", encoding="utf-8")

    assert _declared_or_flag(str(explicit), decl, SECTION_SHARED_KEY) == explicit.resolve()
    assert _declared_or_flag(None, decl, SECTION_SHARED_KEY) == decl[SECTION_SHARED_KEY]
    assert _declared_or_flag(None, {}, SECTION_SHARED_KEY) is None

Activity · 7 steps
lines 108–108from clew.cli import _declared_or_flaglines 110–110decl = {SECTION_SHARED_KEY: {"writers": [{"name_prefix": "FROM_DECL_"}]}}lines 111–111explicit = tmp_path / "patterns.yaml"lines 112–112explicit.write_text("writers: []\n", encoding="utf-8")lines 114–114assert _declared_or_flag(str(explicit), decl, SECTION_SHARED_KEY) == explicit.resolve()lines 115–115assert _declared_or_flag(None, decl, SECTION_SHARED_KEY) == decl[SECTION_SHARED_KEY]lines 116–116assert _declared_or_flag(None, {}, SECTION_SHARED_KEY) is None

test_inline_manifest_still_busts_the_stage_cache

None test_declaration.test_inline_manifest_still_busts_the_stage_cache(Path tmp_path)

manifest_key folds a manifest's CONTENT into the affected stage's cache key. A declaration delivered as a mapping must hash the same way a file does, or editing `.clew.yaml` would silently reuse stale extractions.

tests/test_declaration.py:94

Checks

  • assert manifest_key(a) == manifest_key(dict(a)), "hash must be content-stable"
  • assert manifest_key(a) != manifest_key(b), "a changed declaration must invalidate"
  • assert manifest_key(None) == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
REQ-DDB-INDEX-002inferredtest_inline_manifest_still_busts_the_stage_cache → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_inline_manifest_still_busts_the_stage_cache → manifest_key
Source · 11 lines
def test_inline_manifest_still_busts_the_stage_cache(tmp_path: Path) -> None:
    """manifest_key folds a manifest's CONTENT into the affected stage's cache
    key. A declaration delivered as a mapping must hash the same way a file
    does, or editing `.clew.yaml` would silently reuse stale extractions."""
    a = {"writers": [{"name_prefix": "A_"}]}
    b = {"writers": [{"name_prefix": "B_"}]}
    assert manifest_key(a) == manifest_key(dict(a)), "hash must be content-stable"
    assert manifest_key(a) != manifest_key(b), "a changed declaration must invalidate"
    assert manifest_key(None) == ""

Activity · 5 steps
lines 98–98a = {"writers": [{"name_prefix": "A_"}]}lines 99–99b = {"writers": [{"name_prefix": "B_"}]}lines 100–100assert manifest_key(a) == manifest_key(dict(a)), "hash must be content-stable"lines 101–101assert manifest_key(a) != manifest_key(b), "a changed declaration must invalidate"lines 102–102assert manifest_key(None) == ""

test_malformed_declaration_degrades_to_defaults

None test_declaration.test_malformed_declaration_degrades_to_defaults(Path tmp_path)

A typo must not fail a build that would otherwise succeed — it warns and falls back, rather than taking the repo's index down with it.

tests/test_declaration.py:42

Checks

  • assert load_declaration(tmp_path) == {}
  • assert load_declaration(tmp_path) == {}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_malformed_declaration_degrades_to_defaults → load_declaration
REQ-DDB-GUARD-012inferredtest_malformed_declaration_degrades_to_defaults → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_malformed_declaration_degrades_to_defaults → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 10 lines
def test_malformed_declaration_degrades_to_defaults(tmp_path: Path) -> None:
    """A typo must not fail a build that would otherwise succeed — it warns and
    falls back, rather than taking the repo's index down with it."""
    (tmp_path / ".clew.yaml").write_text("shared_key_patterns: [oops\n", encoding="utf-8")
    assert load_declaration(tmp_path) == {}

    (tmp_path / ".clew.yaml").write_text("- not\n- a\n- mapping\n", encoding="utf-8")
    assert load_declaration(tmp_path) == {}

Activity · 4 steps
lines 45–45(tmp_path / ".clew.yaml").write_text("shared_key_patterns: [oops\n", encoding="utf-8")lines 46–46assert load_declaration(tmp_path) == {}lines 48–48(tmp_path / ".clew.yaml").write_text("- not\n- a\n- mapping\n", encoding="utf-8")lines 49–49assert load_declaration(tmp_path) == {}

test_sections_mirror_the_standalone_manifest_formats

None test_declaration.test_sections_mirror_the_standalone_manifest_formats(Path tmp_path)

A section holds EXACTLY what the corresponding standalone file holds, so a repo can move an existing manifest's contents in verbatim and the same parser handles both delivery routes.

tests/test_declaration.py:52

Checks

  • assert len(writers) == 1
  • assert len(readers) == 1
  • assert "osThreadNew_wrapper" in names
  • assert {p.name for p in DEFAULT_SPAWN_PATTERNS} <= names

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_sections_mirror_the_standalone_manifest_formats → load_declaration
REQ-DDB-GUARD-012inferredtest_sections_mirror_the_standalone_manifest_formats → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-SCHEMA-001measuredtest_sections_mirror_the_standalone_manifest_formats → load_thread_patterns
REQ-DDB-SCHEMA-005measuredtest_sections_mirror_the_standalone_manifest_formats → load_shared_key_patterns
REQ-DDB-SCHEMA-012measuredtest_sections_mirror_the_standalone_manifest_formats → load_shared_key_patterns → declaration_origin
REQ-DDB-WIKI-054inferredtest_sections_mirror_the_standalone_manifest_formats → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 29 lines
def test_sections_mirror_the_standalone_manifest_formats(tmp_path: Path) -> None:
    """A section holds EXACTLY what the corresponding standalone file holds, so
    a repo can move an existing manifest's contents in verbatim and the same
    parser handles both delivery routes."""
    (tmp_path / ".clew.yaml").write_text(
        "shared_key_patterns:\n"
        "  writers:\n"
        '    - name_prefix: "Store_Set_"\n'
        "  readers:\n"
        '    - name_prefix: "Store_Get_"\n'
        "thread_patterns:\n"
        "  spawns:\n"
        '    - name: "osThreadNew_wrapper"\n'
        "      entry_arg_index: 1\n",
        encoding="utf-8",
    )
    decl = load_declaration(tmp_path)

    writers, readers = load_shared_key_patterns(section(decl, SECTION_SHARED_KEY))
    assert len(writers) == 1
    assert len(readers) == 1

    spawns = load_thread_patterns(section(decl, SECTION_THREADS))
    names = {p.name for p in spawns}
    # The declared wrapper is MERGED over the defaults, never replacing them.
    assert "osThreadNew_wrapper" in names
    assert {p.name for p in DEFAULT_SPAWN_PATTERNS} <= names

Activity · 9 steps
lines 56–67(tmp_path / ".clew.yaml").write_text( "shared_key_patterns:\n" " writers:\n" ' - name_prefix: "Store_Set_"\n' " readers:\n" ' - name_prefix: "Store_Get_"\n' "thread_patterns:\n" " spawns:\n" ' - name: "osThreadNew_wrapper"\n' " entry_arg_index: 1\n", encoding="utf-8", )lines 68–68decl = load_declaration(tmp_path)lines 70–70writers, readers = load_shared_key_patterns(section(decl, SECTION_SHARED_KEY))lines 71–71assert len(writers) == 1lines 72–72assert len(readers) == 1lines 74–74spawns = load_thread_patterns(section(decl, SECTION_THREADS))lines 75–75names = {p.name for p in spawns}lines 77–77assert "osThreadNew_wrapper" in nameslines 78–78assert {p.name for p in DEFAULT_SPAWN_PATTERNS} <= names

test_stated_document_meta_identifies_the_document_by_content

None test_declaration.test_stated_document_meta_identifies_the_document_by_content(Path tmp_path)

A stated declaration document identifies itself in build_meta by content.

tests/test_declaration.py:314

Checks

  • assert meta["stated_sections"] == "locks, vendored", "sections must be SORTED, not file order"
  • assert len(meta["stated_sha256"]) == 64
  • assert other["stated_sha256"] != meta["stated_sha256"]
  • assert other["stated_sections"] == meta["stated_sections"], ("the SECTION LIST is unchanged by a whitespace edit, which is why the sha is the " "load-bearing half rather than the section names" )
  • assert not any("/" in value for value in meta.values()), f"a path leaked into {meta}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_stated_document_meta_identifies_the_document_by_content → stated_document_meta
Source · 30 lines
def test_stated_document_meta_identifies_the_document_by_content(tmp_path: Path) -> None:
    """WHY THIS EXISTS AT ALL, because the obvious alternative was tried and shipped broken.
    `options.*` records which TIER won per option, and it CANNOT answer "was this document
    applied". Measured on mbedtls 2026-08-14: one document declaring `locks`, `vendored` and
    `preprocessor` produced an index reading `options.locks.tier=explicit` (replayed from an
    older build), `options.predefined.tier=heuristic`, and no vendored row at all. Every reader
    reported health and a graded run was invalid.
    """
    from clew.declaration import stated_document_meta

    raw = b"vendored:\n  - 3rdparty\nlocks:\n  locks: []\n"
    meta = stated_document_meta(raw, {"vendored": ["3rdparty"], "locks": {}})
    assert meta["stated_sections"] == "locks, vendored", "sections must be SORTED, not file order"
    assert len(meta["stated_sha256"]) == 64

    ## CONTENT-ADDRESSED: one byte's difference must produce a different identity, or a document
    ## edited after the build that stated it would still certify as applied — which is the
    ## quieter half of the defect above.
    other = stated_document_meta(raw + b"\n", {"vendored": ["3rdparty"], "locks": {}})
    assert other["stated_sha256"] != meta["stated_sha256"]
    assert other["stated_sections"] == meta["stated_sections"], (
        "the SECTION LIST is unchanged by a whitespace edit, which is why the sha is the "
        "load-bearing half rather than the section names"
    )

    ## NO PATH ANYWHERE IN IT. A stated document lives in the consumer's tree, so a path here
    ## publishes the builder's machine layout through every MCP reply.
    assert not any("/" in value for value in meta.values()), f"a path leaked into {meta}"

Activity · 9 steps
lines 322–322from clew.declaration import stated_document_metalines 324–324raw = b"vendored:\n - 3rdparty\nlocks:\n locks: []\n"lines 325–325meta = stated_document_meta(raw, {"vendored": ["3rdparty"], "locks": {}})lines 326–326assert meta["stated_sections"] == "locks, vendored", "sections must be SORTED, not file order"lines 327–327assert len(meta["stated_sha256"]) == 64lines 332–332other = stated_document_meta(raw + b"\n", {"vendored": ["3rdparty"], "locks": {}})lines 333–333assert other["stated_sha256"] != meta["stated_sha256"]lines 334–337assert other["stated_sections"] == meta["stated_sections"], ( "the SECTION LIST is unchanged by a whitespace edit, which is why the sha is the " "load-bearing half rather than the section names" )lines 341–341assert not any("/" in value for value in meta.values()), f"a path leaked into {meta}"

test_string_list_section_ignores_a_malformed_value

None test_declaration.test_string_list_section_ignores_a_malformed_value(Path tmp_path)

A non-list value degrades to 'declared nothing' with a warning rather than being coerced — seeding something unintended into reachability would mark genuinely dead code live, which is worse than a false orphan.

tests/test_declaration.py:159

Show on the map →

Called by none

Calls string_list

Checks

  • assert string_list({SECTION_ENTRY_PATTERNS: ["a", "b"]}, SECTION_ENTRY_PATTERNS) == ["a", "b"]
  • assert string_list({SECTION_ENTRY_PATTERNS: "not a list"}, SECTION_ENTRY_PATTERNS) == []
  • assert string_list({SECTION_ENTRY_PATTERNS: {"k": "v"}}, SECTION_ENTRY_PATTERNS) == []
  • assert string_list({}, SECTION_ENTRY_PATTERNS) == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_string_list_section_ignores_a_malformed_value → string_list
Source · 15 lines
def test_string_list_section_ignores_a_malformed_value(tmp_path: Path) -> None:
    """A non-list value degrades to 'declared nothing' with a warning rather
    than being coerced — seeding something unintended into reachability would
    mark genuinely dead code live, which is worse than a false orphan."""
    from clew.declaration import string_list

    assert string_list({SECTION_ENTRY_PATTERNS: ["a", "b"]}, SECTION_ENTRY_PATTERNS) == ["a", "b"]
    assert string_list({SECTION_ENTRY_PATTERNS: "not a list"}, SECTION_ENTRY_PATTERNS) == []
    assert string_list({SECTION_ENTRY_PATTERNS: {"k": "v"}}, SECTION_ENTRY_PATTERNS) == []
    assert string_list({}, SECTION_ENTRY_PATTERNS) == []


# ─── a misspelled section is refused, not silently defaulted ─────────────────

Activity · 5 steps
lines 163–163from clew.declaration import string_listlines 165–165assert string_list({SECTION_ENTRY_PATTERNS: ["a", "b"]}, SECTION_ENTRY_PATTERNS) == ["a", "b"]lines 166–166assert string_list({SECTION_ENTRY_PATTERNS: "not a list"}, SECTION_ENTRY_PATTERNS) == []lines 167–167assert string_list({SECTION_ENTRY_PATTERNS: {"k": "v"}}, SECTION_ENTRY_PATTERNS) == []lines 168–168assert string_list({}, SECTION_ENTRY_PATTERNS) == []

test_the_declaration_and_the_gate_config_share_one_file

None test_declaration.test_the_declaration_and_the_gate_config_share_one_file(Path tmp_path)

Tristan's call: one `.clew.yaml` standard rather than a second file for the gate. The gate reads its `guard:` section; the index reads the rest, and never sees `guard:`.

tests/test_declaration.py:274

Checks

  • assert load_declaration(tmp_path) == {"index_scope": {"include": ["^src/"]}}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_declaration_and_the_gate_config_share_one_file → load_declaration
REQ-DDB-GUARD-012inferredtest_the_declaration_and_the_gate_config_share_one_file → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_the_declaration_and_the_gate_config_share_one_file → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 16 lines
def test_the_declaration_and_the_gate_config_share_one_file(tmp_path: Path) -> None:
    """Tristan's call: one `.clew.yaml` standard rather than a second file for the gate. The
    gate reads its `guard:` section; the index reads the rest, and never sees `guard:`."""
    (tmp_path / ".clew.yaml").write_text(
        "guard:\n"
        "  validate:\n"
        "    tags:\n"
        "      req:\n"
        "        pattern: '^REQ-X-[A-Z]+-[0-9]{3}$'\n"
        "index_scope:\n"
        "  include: ['^src/']\n",
        encoding="utf-8",
    )
    assert load_declaration(tmp_path) == {"index_scope": {"include": ["^src/"]}}

Activity · 2 steps
lines 277–286(tmp_path / ".clew.yaml").write_text( "guard:\n" " validate:\n" " tags:\n" " req:\n" " pattern: '^REQ-X-[A-Z]+-[0-9]{3}$'\n" "index_scope:\n" " include: ['^src/']\n", encoding="utf-8", )lines 287–287assert load_declaration(tmp_path) == {"index_scope": {"include": ["^src/"]}}

test_the_index_scope_spelling_cannot_drift

None test_declaration.test_the_index_scope_spelling_cannot_drift()

`index_scope` is owned by `scope.py` but repeated as a literal in `declaration.py`'s allow-list, because neither module imports the other.

tests/test_declaration.py:260

Show on the map →

Called by none

Calls none

Checks

  • assert INDEX_SCOPE_SECTION in KNOWN_SECTIONS

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
Source · 14 lines
def test_the_index_scope_spelling_cannot_drift() -> None:
    """`index_scope` is owned by `scope.py` but repeated as a literal in
    `declaration.py`'s allow-list, because neither module imports the other.

    Duplicated spellings drift silently — that is the whole lesson of
    `vocabulary.py`, which centralised 26 restated CHECK constraints. This pins the
    two together so a rename in one place fails here instead of making every
    `index_scope:` declaration a refused unknown section."""
    from clew.declaration import KNOWN_SECTIONS
    from clew.scope import INDEX_SCOPE_SECTION

    assert INDEX_SCOPE_SECTION in KNOWN_SECTIONS

Activity · 3 steps
lines 268–268from clew.declaration import KNOWN_SECTIONSlines 269–269from clew.scope import INDEX_SCOPE_SECTIONlines 271–271assert INDEX_SCOPE_SECTION in KNOWN_SECTIONS

test_the_old_guard_config_passthrough_is_not_read

None test_declaration.test_the_old_guard_config_passthrough_is_not_read(Path tmp_path)

HARD BREAK: `.doxygen-guard.yaml` and its `x-clew` passthrough are gone. A repo that has not moved its declaration gets the built-in defaults, not a silent fallback.

tests/test_declaration.py:302

Checks

  • assert load_declaration(tmp_path) == {}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_old_guard_config_passthrough_is_not_read → load_declaration
REQ-DDB-GUARD-012inferredtest_the_old_guard_config_passthrough_is_not_read → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_the_old_guard_config_passthrough_is_not_read → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 9 lines
def test_the_old_guard_config_passthrough_is_not_read(tmp_path: Path) -> None:
    """HARD BREAK: `.doxygen-guard.yaml` and its `x-clew` passthrough are gone. A repo that
    has not moved its declaration gets the built-in defaults, not a silent fallback."""
    (tmp_path / ".doxygen-guard.yaml").write_text(
        "x-clew:\n  index_scope:\n    include: ['^from-guard/']\n", encoding="utf-8"
    )
    assert load_declaration(tmp_path) == {}

Activity · 2 steps
lines 305–307(tmp_path / ".doxygen-guard.yaml").write_text( "x-clew:\n index_scope:\n include: ['^from-guard/']\n", encoding="utf-8" )lines 308–308assert load_declaration(tmp_path) == {}

test_the_refusal_names_the_probable_cause

test_declaration.TestForwardCompatibility.test_the_refusal_names_the_probable_cause(self, tmp_path)

An unknown section points at an upgrade.

tests/test_declaration.py:440

Checks

  • assert "clew-trace" in message, (f"the refusal never mentions upgrading, which is the usual cause: {message}" )
  • assert "guardd" in message and "allowed" in message, "the mechanical fix must survive"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_refusal_names_the_probable_cause → load_declaration
REQ-DDB-GUARD-012inferredtest_the_refusal_names_the_probable_cause → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_the_refusal_names_the_probable_cause → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 15 lines
    def test_the_refusal_names_the_probable_cause(self, tmp_path):
        """@brief An unknown section points at an upgrade. @version 1"""
        (tmp_path / ".clew.yaml").write_text("guardd:\n  version_gate: strict\n")

        from clew.vocabulary import DeclarationError

        with pytest.raises(DeclarationError) as excinfo:
            load_declaration(tmp_path)

        message = str(excinfo.value)
        assert "clew-trace" in message, (
            f"the refusal never mentions upgrading, which is the usual cause: {message}"
        )
        assert "guardd" in message and "allowed" in message, "the mechanical fix must survive"
Activity · 7 steps
lines 442–442(tmp_path / ".clew.yaml").write_text("guardd:\n version_gate: strict\n")lines 444–444from clew.vocabulary import DeclarationErrorlines 446–446with pytest.raises(DeclarationError) as excinfolines 447–447load_declaration(tmp_path)lines 449–449message = str(excinfo.value)lines 450–452assert "clew-trace" in message, ( f"the refusal never mentions upgrading, which is the usual cause: {message}" )lines 453–453assert "guardd" in message and "allowed" in message, "the mechanical fix must survive"