test_propose.py

tests/test_propose.py

Auto-detected starter `.clew.yaml` (issue #54) — the proposer's contract.

test_a_declared_hand_section_is_reported_as_already_declared

None test_propose.test_a_declared_hand_section_is_reported_as_already_declared(Path tmp_path)

A hand-declared section reports as declared, not as undetected.

tests/test_propose.py:743

Show on the map →

Called by none

Calls _repo, _section, propose

Checks

  • assert _section(proposal, SECTION_LOCKS).status is SectionStatus.ALREADY_DECLARED
  • assert _section(proposal, SECTION_MQTT).status is SectionStatus.NOT_ANALYSED

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_declared_hand_section_is_reported_as_already_declared → propose
REQ-DDB-GUARD-012inferredtest_a_declared_hand_section_is_reported_as_already_declared → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-005inferredtest_a_declared_hand_section_is_reported_as_already_declared → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-011measuredtest_a_declared_hand_section_is_reported_as_already_declared → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_declared_hand_section_is_reported_as_already_declared → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-WIKI-054inferredtest_a_declared_hand_section_is_reported_as_already_declared → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 15 lines
def test_a_declared_hand_section_is_reported_as_already_declared(tmp_path: Path) -> None:
    """`locks:` has no detector by design. When the repo declares one anyway, the
    draft must confirm clew SEES it — otherwise the same "not analysed" text
    appears whether or not the owner has already done the work."""
    root = _repo(tmp_path / "declared", _PLAIN_SOURCE)
    ## FIXTURE CHANGED (2.0.0, R5-CFG F1): `locks:` written as a bare list was never read — the
    ## section is the manifest document, `{locks: [...]}` — and the loader now refuses it.
    (root / DECLARATION_NAME).write_text(
        "locks:\n  locks:\n    - {name: AcmeGuard, form: raii}\n", encoding="utf-8"
    )
    proposal = propose(root, None)
    assert _section(proposal, SECTION_LOCKS).status is SectionStatus.ALREADY_DECLARED
    assert _section(proposal, SECTION_MQTT).status is SectionStatus.NOT_ANALYSED

Activity · 5 steps
lines 747–747root = _repo(tmp_path / "declared", _PLAIN_SOURCE)lines 750–752(root / DECLARATION_NAME).write_text( "locks:\n locks:\n - {name: AcmeGuard, form: raii}\n", encoding="utf-8" )lines 753–753proposal = propose(root, None)lines 754–754assert _section(proposal, SECTION_LOCKS).status is SectionStatus.ALREADY_DECLAREDlines 755–755assert _section(proposal, SECTION_MQTT).status is SectionStatus.NOT_ANALYSED

test_a_draft_with_no_candidates_states_nothing

None test_propose.test_a_draft_with_no_candidates_states_nothing(Path tmp_path)

A draft that proposes nothing yields an empty statement, not an error.

tests/test_propose.py:570

Checks

  • assert marked_lines(proposal.yaml_text) == []
  • assert statement_from_draft(proposal.yaml_text) == {}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_draft_with_no_candidates_states_nothing → propose
REQ-DDB-CONFIG-008measuredtest_a_draft_with_no_candidates_states_nothing → statement_from_draft
REQ-DDB-GUARD-012inferredtest_a_draft_with_no_candidates_states_nothing → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-005inferredtest_a_draft_with_no_candidates_states_nothing → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-011measuredtest_a_draft_with_no_candidates_states_nothing → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_draft_with_no_candidates_states_nothing → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-WIKI-054inferredtest_a_draft_with_no_candidates_states_nothing → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 21 lines
def test_a_draft_with_no_candidates_states_nothing(tmp_path: Path) -> None:
    """`{}` is a RESULT — no candidate survived the dry run — and it must not read as a
    failure, because a repository that needs no declaration is the correct negative this
    whole feature has to preserve. An exception here would make "nothing to declare"
    indistinguishable from "the proposer broke".

    @brief An empty draft yields an empty statement.
    @version 1
    """
    from clew.propose import statement_from_draft

    root = tmp_path / "bare"
    (root / "src").mkdir(parents=True)
    (root / "src" / "main.c").write_text("int main(void) { return 0; }\n", encoding="utf-8")

    proposal = propose(root, None)

    assert marked_lines(proposal.yaml_text) == []
    assert statement_from_draft(proposal.yaml_text) == {}

Activity · 7 steps
lines 579–579from clew.propose import statement_from_draftlines 581–581root = tmp_path / "bare"lines 582–582(root / "src").mkdir(parents=True)lines 583–583(root / "src" / "main.c").write_text("int main(void) { return 0; }\n", encoding="utf-8")lines 585–585proposal = propose(root, None)lines 587–587assert marked_lines(proposal.yaml_text) == []lines 588–588assert statement_from_draft(proposal.yaml_text) == {}

test_a_late_resolving_second_arm_revises_the_kind_instead_of_being_dropped

None test_propose.test_a_late_resolving_second_arm_revises_the_kind_instead_of_being_dropped()

A wrapper's two #if arms are folded even when one resolves later.

tests/test_propose.py:424

Show on the map →

Called by none

Calls _call, _fdef, resolve_fixpoint

Checks

  • assert spawn.entry_arg_index == 0, "the arms agree on the entry argument"
  • assert spawn.kind == "unknown", f"the arms disagree on kind; got {spawn.kind!r}"
  • assert "kind" in spawn.conflicts
  • assert "name_arg_index" in spawn.conflicts, "only the RTOS arm names its task"
  • assert downstream.kind == "unknown", (f"the withheld kind must propagate; got {downstream.kind!r}" )
  • assert "kind" in downstream.conflicts, ("a kind withheld upstream must still be EXPLAINED downstream — an " 'unexplained kind: "unknown" is exactly as unauditable as a wrong one' )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_late_resolving_second_arm_revises_the_kind_instead_of_being_dropped → resolve_fixpoint
Source · 76 lines
def test_a_late_resolving_second_arm_revises_the_kind_instead_of_being_dropped() -> None:
    """Measured on a C/POSIX library: `SYSTEM_TASKCREATE` has an ESP-IDF arm
    reaching `xTaskCreate` in ONE hop and a POSIX arm reaching `pthread_create` in
    THREE. The fast arm resolved in round 1; by round 3 the fixpoint could see
    both and would have folded them to `kind: "unknown"` — but the round-1 answer
    was frozen, so the draft proposed `kind: "task"` on a repo that only ever
    compiles the POSIX arm. That is this feature's headline failure: a plausible,
    committed, wrong declaration asserting the wrong OS.

    The disagreement is a property of the DEFINITIONS, not of the order they
    happen to resolve in, so a later round must be allowed to revise an earlier
    answer.

    @brief A slower `#if` arm still reaches the fold.
    @version 1
    """
    known, _refused = resolve_fixpoint(
        {
            # The two macro arms. Arm A is one hop from a seed, arm B is three.
            "ACME_SPAWN": [
                _fdef(
                    "ACME_SPAWN",
                    ("fn", "name", "handle"),
                    (_call("xTaskCreate", ((0, 0), (1, 1))),),
                ),
                _fdef(
                    "ACME_SPAWN",
                    ("fn", "name", "handle"),
                    (_call("acme_posix_spawn", ((0, 0), (1, 1), (2, 2))),),
                ),
            ],
            "acme_posix_spawn": [
                _fdef(
                    "acme_posix_spawn",
                    ("fn", "name", "handle"),
                    (_call("acme_thread_create", ((0, 2), (1, 0), (2, 1))),),
                )
            ],
            "acme_thread_create": [
                _fdef(
                    "acme_thread_create",
                    ("handle", "fn", "name"),
                    (_call("pthread_create", ((0, 0), (2, 1))),),
                )
            ],
            # One hop further out: it must inherit the WITHHELD kind, not the
            # stale one, or the revision stops at the wrapper it was found on.
            "acme_start_worker": [
                _fdef(
                    "acme_start_worker",
                    ("entry", "label"),
                    (_call("ACME_SPAWN", ((0, 0), (1, 1))),),
                )
            ],
        }
    )

    spawn = known["ACME_SPAWN"]
    assert spawn.entry_arg_index == 0, "the arms agree on the entry argument"
    assert spawn.kind == "unknown", f"the arms disagree on kind; got {spawn.kind!r}"
    assert "kind" in spawn.conflicts
    assert "name_arg_index" in spawn.conflicts, "only the RTOS arm names its task"

    downstream = known["acme_start_worker"]
    assert downstream.kind == "unknown", (
        f"the withheld kind must propagate; got {downstream.kind!r}"
    )
    assert "kind" in downstream.conflicts, (
        "a kind withheld upstream must still be EXPLAINED downstream — an "
        'unexplained kind: "unknown" is exactly as unauditable as a wrong one'
    )


# ─── the load-bearing test: the draft parses back to what it claims ─────────

Activity · 9 steps
lines 440–479known, _refused = resolve_fixpoint( { # The two macro arms. Arm A is one hop from a seed, arm B is three. "ACME_SPAWN": [ _fdef( "ACME_SPAWN", ("fn", "name", "handle"), (_call("xTaskCreate", ((0, 0), (1, 1))),), ), _fdef( "ACME_SPAWN", ("fn", "name", "handle"), (_call("acme_posix_spawn", ((0, 0), (1, 1), (2, 2))),), ), ], "acme_posix_spawn": [ _fdef( "acme_posix_spawn", ("fn", "name", "handle"), (_call("acme_thread_create", ((0, 2), (1, 0), (2, 1))),), ) ], "acme_thread_create": [ _fdef( "acme_thread_create", ("handle", "fn", "name"), (_call("pthread_create", ((0, 0), (2, 1))),), ) ], # One hop further out: it must inherit the WITHHELD kind, not the # stale one, or the revision stops at the wrapper it was found on. "acme_start_worker": [ _fdef( "acme_start_worker", ("entry", "label"), (_call("ACME_SPAWN", ((0, 0), (1, 1))),), ) ], } )lines 481–481spawn = known["ACME_SPAWN"]lines 482–482assert spawn.entry_arg_index == 0, "the arms agree on the entry argument"lines 483–483assert spawn.kind == "unknown", f"the arms disagree on kind; got {spawn.kind!r}"lines 484–484assert "kind" in spawn.conflictslines 485–485assert "name_arg_index" in spawn.conflicts, "only the RTOS arm names its task"lines 487–487downstream = known["acme_start_worker"]lines 488–490assert downstream.kind == "unknown", ( f"the withheld kind must propagate; got {downstream.kind!r}" )lines 491–494assert "kind" in downstream.conflicts, ( "a kind withheld upstream must still be EXPLAINED downstream — an " 'unexplained kind: "unknown" is exactly as unauditable as a wrong one' )

test_a_non_c_indexed_scope_is_not_applicable_not_no_candidates

None test_propose.test_a_non_c_indexed_scope_is_not_applicable_not_no_candidates(Path tmp_path)

A non-C/C++ indexed scope reports NOT_APPLICABLE, not a measured absence.

tests/test_propose.py:760

Show on the map →

Called by none

Calls _section, propose

Checks

  • assert proposal.scope["files_in_scope"] >= 1, "the Python file must be IN scope"
  • assert proposal.scope["ast_readable_in_scope"] == 0
  • assert section.status is SectionStatus.NOT_APPLICABLE, f"{name}: {section.reason}"
  • assert "not a measurement of the repo" in section.reason

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_non_c_indexed_scope_is_not_applicable_not_no_candidates → propose
REQ-DDB-GUARD-012inferredtest_a_non_c_indexed_scope_is_not_applicable_not_no_candidates → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-005inferredtest_a_non_c_indexed_scope_is_not_applicable_not_no_candidates → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-011measuredtest_a_non_c_indexed_scope_is_not_applicable_not_no_candidates → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_non_c_indexed_scope_is_not_applicable_not_no_candidates → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-WIKI-054inferredtest_a_non_c_indexed_scope_is_not_applicable_not_no_candidates → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 26 lines
def test_a_non_c_indexed_scope_is_not_applicable_not_no_candidates(tmp_path: Path) -> None:
    """The parser router covers Python as well as C/C++, so a Python file PARSES —
    and then contributes nothing, because a Python `function_definition` has no
    `declarator` chain and its calls are `call`, not `call_expression`. Counting
    parses would report a Python codebase as a MEASURED empty C repo: a claim about
    the repo, where the truth is a claim about the detector. clew's own indexed
    scope is exactly this case, so it is not hypothetical.

    @brief The blocking check is language-aware, not parse-count-aware.
    @version 1
    """
    root = tmp_path / "pyrepo"
    (root / "src").mkdir(parents=True)
    (root / ".clew.yaml").write_text("index_scope:\n  roots: [src]\n", encoding="utf-8")
    (root / "src" / "app.py").write_text("def main():\n    return 0\n", encoding="utf-8")

    proposal = propose(root, None)

    assert proposal.scope["files_in_scope"] >= 1, "the Python file must be IN scope"
    assert proposal.scope["ast_readable_in_scope"] == 0
    for name in (SECTION_SHARED_KEY, SECTION_THREADS):
        section = _section(proposal, name)
        assert section.status is SectionStatus.NOT_APPLICABLE, f"{name}: {section.reason}"
        assert "not a measurement of the repo" in section.reason

Activity · 11 steps
lines 771–771root = tmp_path / "pyrepo"lines 772–772(root / "src").mkdir(parents=True)lines 773–773(root / ".clew.yaml").write_text("index_scope:\n roots: [src]\n", encoding="utf-8")lines 774–774(root / "src" / "app.py").write_text("def main():\n return 0\n", encoding="utf-8")lines 776–776proposal = propose(root, None)lines 778–778assert proposal.scope["files_in_scope"] >= 1, "the Python file must be IN scope"lines 779–779assert proposal.scope["ast_readable_in_scope"] == 0lines 780–780◇ for name in (SECTION_SHARED_KEY, SECTION_THREADS)lines 781–781section = _section(proposal, name)lines 782–782assert section.status is SectionStatus.NOT_APPLICABLE, f"{name}: {section.reason}"lines 783–783assert "not a measurement of the repo" in section.reason

test_a_zero_byte_docs_db_is_rejected_rather_than_crashed_on

None test_propose.test_a_zero_byte_docs_db_is_rejected_rather_than_crashed_on(Path tmp_path)

A file that is not a clew index is rejected, not crashed on.

tests/test_propose.py:718

Show on the map →

Called by none

Calls _repo, _section, index_defect, propose

Checks

  • assert index_defect(empty)
  • assert proposal.db_status["exists"] is True
  • assert proposal.db_status["usable"] is False
  • assert _section(proposal, SECTION_SHARED_KEY).status is SectionStatus.NOT_ANALYSED
  • assert "REJECTED" in proposal.yaml_text
  • assert "memberdef" in proposal.yaml_text

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_zero_byte_docs_db_is_rejected_rather_than_crashed_on → index_defect
REQ-DDB-CONFIG-006measured
REQ-DDB-GUARD-012inferredtest_a_zero_byte_docs_db_is_rejected_rather_than_crashed_on → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-005measuredtest_a_zero_byte_docs_db_is_rejected_rather_than_crashed_on → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-011measuredtest_a_zero_byte_docs_db_is_rejected_rather_than_crashed_on → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_zero_byte_docs_db_is_rejected_rather_than_crashed_on → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-005measured
REQ-DDB-WIKI-054inferredtest_a_zero_byte_docs_db_is_rejected_rather_than_crashed_on → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 23 lines
def test_a_zero_byte_docs_db_is_rejected_rather_than_crashed_on(tmp_path: Path) -> None:
    """`<repo>/clew.db` is part of the discovery order, and a zero-byte leftover
    of that name really does sit in this repo's own sample tree. The dry run calls
    pipeline importers that select straight from `memberdef`, so an index that is
    not one used to reach an `OperationalError` mid-analysis.

    @brief An unusable index degrades to "no index", with the defect named.
    @version 1
    """
    root = _repo(tmp_path / "bogus", _ACME_SOURCE)
    empty = root / "clew.db"
    empty.write_bytes(b"")
    assert index_defect(empty)

    proposal = propose(root, empty)

    assert proposal.db_status["exists"] is True
    assert proposal.db_status["usable"] is False
    assert _section(proposal, SECTION_SHARED_KEY).status is SectionStatus.NOT_ANALYSED
    assert "REJECTED" in proposal.yaml_text
    assert "memberdef" in proposal.yaml_text

Activity · 10 steps
lines 727–727root = _repo(tmp_path / "bogus", _ACME_SOURCE)lines 728–728empty = root / "clew.db"lines 729–729empty.write_bytes(b"")lines 730–730assert index_defect(empty)lines 732–732proposal = propose(root, empty)lines 734–734assert proposal.db_status["exists"] is Truelines 735–735assert proposal.db_status["usable"] is Falselines 736–736assert _section(proposal, SECTION_SHARED_KEY).status is SectionStatus.NOT_ANALYSEDlines 737–737assert "REJECTED" in proposal.yaml_textlines 738–738assert "memberdef" in proposal.yaml_text

test_an_undeclared_scope_blocks_detection_rather_than_guessing

None test_propose.test_an_undeclared_scope_blocks_detection_rather_than_guessing(Path tmp_path)

An undeclared index scope blocks detection instead of proposing vendor code.

tests/test_propose.py:788

Show on the map →

Called by none

Calls _section, propose

Checks

  • assert section.status is SectionStatus.NOT_ANALYSED
  • assert "NOT DERIVED" in proposal.yaml_text
  • assert "first-party" in section.reason.lower() or "FIRST-PARTY" in section.reason

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_undeclared_scope_blocks_detection_rather_than_guessing → propose
REQ-DDB-GUARD-012inferredtest_an_undeclared_scope_blocks_detection_rather_than_guessing → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-005inferredtest_an_undeclared_scope_blocks_detection_rather_than_guessing → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-011measuredtest_an_undeclared_scope_blocks_detection_rather_than_guessing → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_an_undeclared_scope_blocks_detection_rather_than_guessing → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-WIKI-054inferredtest_an_undeclared_scope_blocks_detection_rather_than_guessing → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 17 lines
def test_an_undeclared_scope_blocks_detection_rather_than_guessing(tmp_path: Path) -> None:
    """Without a derived scope clew has no notion of first-party, and the first
    thing a detector proposes is a vendored library's own helper. The gate must
    report that as un-analysed rather than as an empty measurement."""
    root = tmp_path / "unscoped"
    (root / "src").mkdir(parents=True)
    (root / "src" / "app.c").write_text(_ACME_SOURCE, encoding="utf-8")
    proposal = propose(root, None)
    section = _section(proposal, SECTION_SHARED_KEY)
    assert section.status is SectionStatus.NOT_ANALYSED
    assert "NOT DERIVED" in proposal.yaml_text
    assert "first-party" in section.reason.lower() or "FIRST-PARTY" in section.reason


# ─── the MCP surface ────────────────────────────────────────────────────────

Activity · 8 steps
lines 792–792root = tmp_path / "unscoped"lines 793–793(root / "src").mkdir(parents=True)lines 794–794(root / "src" / "app.c").write_text(_ACME_SOURCE, encoding="utf-8")lines 795–795proposal = propose(root, None)lines 796–796section = _section(proposal, SECTION_SHARED_KEY)lines 797–797assert section.status is SectionStatus.NOT_ANALYSEDlines 798–798assert "NOT DERIVED" in proposal.yaml_textlines 799–799assert "first-party" in section.reason.lower() or "FIRST-PARTY" in section.reason

test_demobot_recovers_the_ingot_convention_from_call_sites

None test_propose.test_demobot_recovers_the_ingot_convention_from_call_sites(Path repo_root, Path rich_db)

demobot's generated accessor family is recovered and correctly refused.

tests/test_propose.py:260

Show on the map →

Called by none

Calls _section, list, propose

Checks

  • assert section.status is SectionStatus.NO_CANDIDATES
  • assert name_keyed is not None, f"the generated family was dropped in silence: {list(by_name)}"
  • assert "DataModel_Get_*" in name_keyed.name
  • assert "below the floor" in name_keyed.reason
  • assert "1 key(s) are both written and read" in name_keyed.reason
  • assert by_key is not None, list(by_name)
  • assert "arity varies" in by_key.reason
  • assert "VARIABLE" in by_key.reason

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_demobot_recovers_the_ingot_convention_from_call_sites → propose
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-GUARD-012measuredtest_demobot_recovers_the_ingot_convention_from_call_sites → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-005measuredtest_demobot_recovers_the_ingot_convention_from_call_sites → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measuredtest_demobot_recovers_the_ingot_convention_from_call_sites → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_demobot_recovers_the_ingot_convention_from_call_sites → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_demobot_recovers_the_ingot_convention_from_call_sites → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 40 lines
def test_demobot_recovers_the_ingot_convention_from_call_sites(
    repo_root: Path, rich_db: Path
) -> None:
    """The fixture's data model is `DataModel_Set_<KEY>` / `Get_<KEY>`, and the
    detector must recover that family FROM CALL SITES — the whole reason it does
    not reuse the build-time diagnostic, which reads `memberdef` and is
    structurally blind to a macro-shaped accessor.

    It must ALSO refuse it, and say why. The fixture deliberately has exactly ONE
    key that is both written and read (its punchline is the missing path between a
    writer and a reader of `DEMOBOT_UX_SOUND_EVENT`), so the pair sits below the
    shared-key evidence floor. One coincidence is not a data model. The name-keyed
    family and the argument-keyed `...ByKey` dispatchers must stay SEPARATE
    families — merging them at the common `DataModel_Set` would take the arity gate
    down with both.

    Measured identical on the retired `sample/` build and on `csample`: the same 1
    shared key over the same 3 attributed call sites, the same two rejections.

    @brief The generated family is recovered, refused, and the refusal explained.
    @version 2
    """
    section = _section(propose(repo_root, rich_db), SECTION_SHARED_KEY)
    assert section.status is SectionStatus.NO_CANDIDATES
    by_name = {r.name: r for r in section.rejections}

    name_keyed = next((r for name, r in by_name.items() if "DataModel_Set_*" in name), None)
    assert name_keyed is not None, f"the generated family was dropped in silence: {list(by_name)}"
    assert "DataModel_Get_*" in name_keyed.name
    assert "below the floor" in name_keyed.reason
    assert "1 key(s) are both written and read" in name_keyed.reason

    # The ByKey dispatchers are a DIFFERENT family, refused for a different
    # reason: their key is an argument, not part of the name.
    by_key = next((r for name, r in by_name.items() if name == "DataModel_Set*"), None)
    assert by_key is not None, list(by_name)
    assert "arity varies" in by_key.reason
    assert "VARIABLE" in by_key.reason

Activity · 12 steps
lines 282–282section = _section(propose(repo_root, rich_db), SECTION_SHARED_KEY)lines 283–283assert section.status is SectionStatus.NO_CANDIDATESlines 284–284by_name = {r.name: r for r in section.rejections}lines 286–286name_keyed = next((r for name, r in by_name.items() if "DataModel_Set_*" in name), None)lines 287–287assert name_keyed is not None, f"the generated family was dropped in silence: {list(by_name)}"lines 288–288assert "DataModel_Get_*" in name_keyed.namelines 289–289assert "below the floor" in name_keyed.reasonlines 290–290assert "1 key(s) are both written and read" in name_keyed.reasonlines 294–294by_key = next((r for name, r in by_name.items() if name == "DataModel_Set*"), None)lines 295–295assert by_key is not None, list(by_name)lines 296–296assert "arity varies" in by_key.reasonlines 297–297assert "VARIABLE" in by_key.reason

test_draft_becomes_a_statable_option_without_a_file

None test_propose.test_draft_becomes_a_statable_option_without_a_file(Path tmp_path)

The same draft round-trips into a build OPTION, not only into a file.

tests/test_propose.py:534

Show on the map →

Called by none

Calls _acme, _section, apply_options, load_declaration, propose, statement_from_draft, uncomment

Checks

  • assert _section(proposal, SECTION_SHARED_KEY).status is SectionStatus.PROPOSED
  • assert statement == load_declaration(active), "one proposal, two spellings of it"
  • assert apply_options(args, statement, root) == sorted(statement)
  • assert getattr(args, SECTION_SHARED_KEY)["writers"] == [{"name_prefix": "ACME_SET_"}]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_draft_becomes_a_statable_option_without_a_file → load_declaration
REQ-DDB-CONFIG-006measuredtest_draft_becomes_a_statable_option_without_a_file → _acme → _index → write_build_signature
REQ-DDB-CONFIG-007measuredtest_draft_becomes_a_statable_option_without_a_file → _acme → _index → write_build_signature
REQ-DDB-CONFIG-008measuredtest_draft_becomes_a_statable_option_without_a_file → statement_from_draft
REQ-DDB-GUARD-012inferredtest_draft_becomes_a_statable_option_without_a_file → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-005measuredtest_draft_becomes_a_statable_option_without_a_file → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measuredtest_draft_becomes_a_statable_option_without_a_file → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_draft_becomes_a_statable_option_without_a_file → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_draft_becomes_a_statable_option_without_a_file → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 34 lines
def test_draft_becomes_a_statable_option_without_a_file(tmp_path: Path) -> None:
    """gh#360. The test above proves the draft parses when an owner ACTIVATES IT IN A FILE;
    this proves the other route exists at all. An agent has nowhere to write that file — a
    third-party repo must stay byte-identical, and anywhere else is untracked or `git
    clean`ed — so before this, `propose_declaration` returned prose and `options` took a
    structure, with no path between them.

    ASSERTED AGAINST THE DECLARATION LOADER'S OWN RESULT, so the two vocabularies are pinned
    to each other rather than each to its own idea of the shape. Then driven through the real
    `apply_options`, which is the only check that the proposal survives validation as strict
    as a parsed file's — a statement the validator would refuse is not a route.

    @brief A draft's statement is exactly what a build option accepts.
    @version 1
    """
    from clew.buildoptions import apply_options
    from clew.propose import statement_from_draft

    root, db = _acme(tmp_path)
    proposal = propose(root, db)
    assert _section(proposal, SECTION_SHARED_KEY).status is SectionStatus.PROPOSED

    active = tmp_path / "activated"
    active.mkdir()
    (active / DECLARATION_NAME).write_text(uncomment(proposal.yaml_text), encoding="utf-8")
    statement = statement_from_draft(proposal.yaml_text)

    assert statement == load_declaration(active), "one proposal, two spellings of it"

    args = SimpleNamespace(**dict.fromkeys(statement))
    assert apply_options(args, statement, root) == sorted(statement)
    assert getattr(args, SECTION_SHARED_KEY)["writers"] == [{"name_prefix": "ACME_SET_"}]

Activity · 13 steps
lines 549–549from clew.buildoptions import apply_optionslines 550–550from clew.propose import statement_from_draftlines 552–552root, db = _acme(tmp_path)lines 553–553proposal = propose(root, db)lines 554–554assert _section(proposal, SECTION_SHARED_KEY).status is SectionStatus.PROPOSEDlines 556–556active = tmp_path / "activated"lines 557–557active.mkdir()lines 558–558(active / DECLARATION_NAME).write_text(uncomment(proposal.yaml_text), encoding="utf-8")lines 559–559statement = statement_from_draft(proposal.yaml_text)lines 561–561assert statement == load_declaration(active), "one proposal, two spellings of it"lines 563–563args = SimpleNamespace(**dict.fromkeys(statement))lines 564–564assert apply_options(args, statement, root) == sorted(statement)lines 565–565assert getattr(args, SECTION_SHARED_KEY)["writers"] == [{"name_prefix": "ACME_SET_"}]

test_every_declaration_section_is_reported_on

None test_propose.test_every_declaration_section_is_reported_on()

Every declaration section is reported on, not just the detected ones.

tests/test_propose.py:209

Checks

  • assert set(section_names()) == set(KNOWN_SECTIONS)
  • assert {

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_every_declaration_section_is_reported_on → section_names
Source · 38 lines
def test_every_declaration_section_is_reported_on() -> None:
    """A draft that simply omits `locks:` leaves an owner unable to tell "we
    looked and found nothing" from "we never looked" — opposite actions. So the
    registry must cover the declaration module's whole surface, and this test is
    what makes a newly-added section impossible to leave out silently.

    IT DID NOT DO THAT. The assertion was a hand-written literal set, so it moved
    only when someone edited it — and `preprocessor` (gh#17) and `kconfig` (gh#18)
    were both added to `KNOWN_SECTIONS` and never to the registry, staying missing
    from every rendered draft while this test passed and its own docstring claimed
    the omission was impossible. A guard that fires on some of the real cases is
    worse than none: it converts "unchecked" into "checked and fine".

    So it now compares against `KNOWN_SECTIONS` itself, which is the set the
    loader ACCEPTS. That cannot be satisfied by editing one list, and a section
    reachable in a repo's YAML but absent from the proposer is the definition of
    the gap this test names.

    @brief The registry enumerates every `.clew.yaml` section.
    @version 2
    """
    from clew.declaration import KNOWN_SECTIONS

    assert set(section_names()) == set(KNOWN_SECTIONS)
    # The literals stay named, so a RENAME still has to touch this file rather than
    # silently satisfying the set comparison on both sides.
    assert {
        SECTION_SHARED_KEY,
        SECTION_THREADS,
        SECTION_MQTT,
        SECTION_DATA_MODEL,
        SECTION_LOCKS,
        SECTION_ENTRY_PATTERNS,
        SECTION_DISPATCH,
        INDEX_SCOPE_SECTION,
    } <= set(section_names())

Activity · 3 steps
lines 230–230from clew.declaration import KNOWN_SECTIONSlines 232–232assert set(section_names()) == set(KNOWN_SECTIONS)lines 235–244assert { SECTION_SHARED_KEY, SECTION_THREADS, SECTION_MQTT, SECTION_DATA_MODEL, SECTION_LOCKS, SECTION_ENTRY_PATTERNS, SECTION_DISPATCH, INDEX_SCOPE_SECTION, } <= set(section_names())

test_existing_declaration_is_not_overwritten_without_force

None test_propose.test_existing_declaration_is_not_overwritten_without_force(Path tmp_path)

An existing .clew.yaml is never overwritten without force.

tests/test_propose.py:654

Checks

  • assert propose_main(argv) == 2
  • assert declaration.read_text(encoding="utf-8") == original, "the declaration was clobbered"
  • assert propose_main([*argv, "--force"]) == 0
  • assert declaration.read_text(encoding="utf-8") != original
  • assert load_declaration(root) == {}, "the written draft must be inert"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_existing_declaration_is_not_overwritten_without_force → load_declaration
REQ-DDB-CONFIG-006measuredtest_existing_declaration_is_not_overwritten_without_force → _acme → _index → write_build_signature
REQ-DDB-CONFIG-007measuredtest_existing_declaration_is_not_overwritten_without_force → _acme → _index → write_build_signature
REQ-DDB-GUARD-010measuredtest_existing_declaration_is_not_overwritten_without_force → propose_main → _resolve_db → find_index
REQ-DDB-GUARD-012inferredtest_existing_declaration_is_not_overwritten_without_force → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-005measuredtest_existing_declaration_is_not_overwritten_without_force → _acme → _index → write_build_signature
REQ-DDB-PIPE-011measuredtest_existing_declaration_is_not_overwritten_without_force → propose_main → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_existing_declaration_is_not_overwritten_without_force → propose_main → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-WIKI-054inferredtest_existing_declaration_is_not_overwritten_without_force → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 23 lines
def test_existing_declaration_is_not_overwritten_without_force(tmp_path: Path) -> None:
    """The one file this command is about is the one file it must not clobber:
    replacing a hand-tuned declaration with an all-comments draft DISABLES every
    convention it declared while the build keeps succeeding — a silently different
    answer, which is worse than a crash.

    @brief The output path is refused when it exists, unless --force.
    @version 1
    """
    root, db = _acme(tmp_path)
    declaration = root / DECLARATION_NAME
    original = "shared_key_patterns:\n  writers:\n    - name_prefix: 'HAND_SET_'\n"
    declaration.write_text(original, encoding="utf-8")
    argv = ["--repo-root", str(root), "--db", str(db), "-o", str(declaration)]

    assert propose_main(argv) == 2
    assert declaration.read_text(encoding="utf-8") == original, "the declaration was clobbered"

    assert propose_main([*argv, "--force"]) == 0
    assert declaration.read_text(encoding="utf-8") != original
    assert load_declaration(root) == {}, "the written draft must be inert"

Activity · 10 steps
lines 663–663root, db = _acme(tmp_path)lines 664–664declaration = root / DECLARATION_NAMElines 665–665original = "shared_key_patterns:\n writers:\n - name_prefix: 'HAND_SET_'\n"lines 666–666declaration.write_text(original, encoding="utf-8")lines 667–667argv = ["--repo-root", str(root), "--db", str(db), "-o", str(declaration)]lines 669–669assert propose_main(argv) == 2lines 670–670assert declaration.read_text(encoding="utf-8") == original, "the declaration was clobbered"lines 672–672assert propose_main([*argv, "--force"]) == 0lines 673–673assert declaration.read_text(encoding="utf-8") != originallines 674–674assert load_declaration(root) == {}, "the written draft must be inert"

test_ignore_declaration_re_proposes_a_declared_convention

None test_propose.test_ignore_declaration_re_proposes_a_declared_convention(Path tmp_path)

--ignore-declaration re-proposes what the repo already declares.

tests/test_propose.py:694

Show on the map →

Called by none

Calls _acme, _section, propose

Checks

  • assert _section(propose(root, db), SECTION_SHARED_KEY).status is SectionStatus.NO_CANDIDATES
  • assert audited.status is SectionStatus.PROPOSED
  • assert audited.entries[0].measured["new_edges"] > 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_ignore_declaration_re_proposes_a_declared_convention → propose
REQ-DDB-CONFIG-006measuredtest_ignore_declaration_re_proposes_a_declared_convention → _acme → _index → write_build_signature
REQ-DDB-CONFIG-007measuredtest_ignore_declaration_re_proposes_a_declared_convention → _acme → _index → write_build_signature
REQ-DDB-GUARD-012inferredtest_ignore_declaration_re_proposes_a_declared_convention → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-005measuredtest_ignore_declaration_re_proposes_a_declared_convention → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measuredtest_ignore_declaration_re_proposes_a_declared_convention → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_ignore_declaration_re_proposes_a_declared_convention → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_ignore_declaration_re_proposes_a_declared_convention → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 22 lines
def test_ignore_declaration_re_proposes_a_declared_convention(tmp_path: Path) -> None:
    """An owner auditing a hand-written declaration needs to see whether the
    evidence supports it. With the declaration read, its own entry is (correctly)
    refused as already covered; ignoring it turns the same entry back into a
    measured proposal — which is the audit."""
    root, db = _acme(tmp_path)
    (root / DECLARATION_NAME).write_text(
        "index_scope:\n  roots: [src]\n"
        "shared_key_patterns:\n"
        "  writers:\n    - name_prefix: 'ACME_SET_'\n"
        "  readers:\n    - name_prefix: 'ACME_GET_'\n",
        encoding="utf-8",
    )
    assert _section(propose(root, db), SECTION_SHARED_KEY).status is SectionStatus.NO_CANDIDATES
    audited = _section(propose(root, db, use_declaration=False), SECTION_SHARED_KEY)
    assert audited.status is SectionStatus.PROPOSED
    assert audited.entries[0].measured["new_edges"] > 0


# ─── refusing a database that is not one ────────────────────────────────────

Activity · 6 steps
lines 699–699root, db = _acme(tmp_path)lines 700–706(root / DECLARATION_NAME).write_text( "index_scope:\n roots: [src]\n" "shared_key_patterns:\n" " writers:\n - name_prefix: 'ACME_SET_'\n" " readers:\n - name_prefix: 'ACME_GET_'\n", encoding="utf-8", )lines 707–707assert _section(propose(root, db), SECTION_SHARED_KEY).status is SectionStatus.NO_CANDIDATESlines 708–708audited = _section(propose(root, db, use_declaration=False), SECTION_SHARED_KEY)lines 709–709assert audited.status is SectionStatus.PROPOSEDlines 710–710assert audited.entries[0].measured["new_edges"] > 0

test_index_scope_is_report_only

None test_propose.test_index_scope_is_report_only(Path tmp_path)

index_scope is report-only and never emits YAML.

tests/test_propose.py:853

Show on the map →

Called by none

Calls _acme, _section, propose

Checks

  • assert section.status is SectionStatus.REPORT_ONLY
  • assert section.yaml_header == ()
  • assert section.entries == ()
  • assert any("REPLACES the scope" in note for note in section.notes)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_index_scope_is_report_only → propose
REQ-DDB-CONFIG-006measuredtest_index_scope_is_report_only → _acme → _index → write_build_signature
REQ-DDB-CONFIG-007measuredtest_index_scope_is_report_only → _acme → _index → write_build_signature
REQ-DDB-GUARD-012inferredtest_index_scope_is_report_only → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-005measuredtest_index_scope_is_report_only → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measuredtest_index_scope_is_report_only → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_index_scope_is_report_only → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_index_scope_is_report_only → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 15 lines
def test_index_scope_is_report_only(tmp_path: Path) -> None:
    """`index_scope.roots` REPLACES the scope rather than extending it, so an owner
    who activates a proposed root narrows the index to exactly that root and DELETES
    everything the other tiers covered — and the build logs that as a success. There
    is no safe emission.

    @brief The index_scope section reports and never emits YAML.
    @version 2
    """
    root, db = _acme(tmp_path)
    section = _section(propose(root, db), INDEX_SCOPE_SECTION)
    assert section.status is SectionStatus.REPORT_ONLY
    assert section.yaml_header == ()
    assert section.entries == ()
    assert any("REPLACES the scope" in note for note in section.notes)

1 more lines, not shown

Activity · 6 steps
lines 862–862root, db = _acme(tmp_path)lines 863–863section = _section(propose(root, db), INDEX_SCOPE_SECTION)lines 864–864assert section.status is SectionStatus.REPORT_ONLYlines 865–865assert section.yaml_header == ()lines 866–866assert section.entries == ()lines 867–867assert any("REPLACES the scope" in note for note in section.notes)

test_mcp_propose_returns_a_draft_and_keeps_stdout_clean

None test_propose.test_mcp_propose_returns_a_draft_and_keeps_stdout_clean(Path tmp_path)

The MCP tool returns a draft without ever writing to stdout.

tests/test_propose.py:807

Show on the map →

Called by none

Calls _acme, _captured_stdout

Checks

  • assert result["ok"] is True, result
  • assert result["measured_against"] == str(db)
  • assert result["draft"].lstrip().startswith("#")
  • assert SECTION_SHARED_KEY in result["draft"]
  • assert leaked.getvalue() == "", "the proposer must never write to this stdout"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-006measuredtest_mcp_propose_returns_a_draft_and_keeps_stdout_clean → _acme → _index → write_build_signature
REQ-DDB-CONFIG-007measuredtest_mcp_propose_returns_a_draft_and_keeps_stdout_clean → _acme → _index → write_build_signature
REQ-DDB-CONFIG-008measured
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-005measuredtest_mcp_propose_returns_a_draft_and_keeps_stdout_clean → _acme → _index → write_build_signature
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measured
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-012measured
Source · 33 lines
def test_mcp_propose_returns_a_draft_and_keeps_stdout_clean(tmp_path: Path) -> None:
    """On the MCP server `sys.stdout` IS the protocol transport, and every dry run
    re-runs a pipeline importer that renders a rich progress bar. Spliced into the
    JSON-RPC stream those bars corrupt the framing, so the proposer runs with its
    output bound to a buffer instead.

    Written against the OUTCOME rather than the mechanism: the draft comes back, and
    nothing reached this process's stdout. That holds however the silencing is done,
    which is what makes it a regression guard rather than a restatement.

    @brief The tier-0 propose tool is transport-safe.
    @version 2
    """
    pytest.importorskip(
        "mcp",
        reason="the MCP SDK is a REQUIRED dependency, so this skipping means a BROKEN install, not an unselected extra",
    )
    from clew.mcp_server.server import DocsDbServer
    from clew.mcp_server.state import Target

    root, db = _acme(tmp_path)
    target = Target(repo_path=str(root), slug="acme-test", db_path=str(db))

    with _captured_stdout() as leaked:
        result = DocsDbServer.__new__(DocsDbServer)._run_propose(target, False)

    assert result["ok"] is True, result
    assert result["measured_against"] == str(db)
    assert result["draft"].lstrip().startswith("#")
    assert SECTION_SHARED_KEY in result["draft"]
    assert leaked.getvalue() == "", "the proposer must never write to this stdout"

Activity · 12 steps
lines 820–823pytest.importorskip( "mcp", reason="the MCP SDK is a REQUIRED dependency, so this skipping means a BROKEN install, not an unselected extra", )lines 824–824from clew.mcp_server.server import DocsDbServerlines 825–825from clew.mcp_server.state import Targetlines 827–827root, db = _acme(tmp_path)lines 828–828target = Target(repo_path=str(root), slug="acme-test", db_path=str(db))lines 830–830with _captured_stdout() as leakedlines 831–831result = DocsDbServer.__new__(DocsDbServer)._run_propose(target, False)lines 833–833assert result["ok"] is True, resultlines 834–834assert result["measured_against"] == str(db)lines 835–835assert result["draft"].lstrip().startswith("#")lines 836–836assert SECTION_SHARED_KEY in result["draft"]lines 837–837assert leaked.getvalue() == "", "the proposer must never write to this stdout"

test_no_convention_yields_an_empty_but_valid_draft_that_says_so

None test_propose.test_no_convention_yields_an_empty_but_valid_draft_that_says_so(Path tmp_path)

A repo with no detectable convention yields an empty but valid draft.

tests/test_propose.py:325

Show on the map →

Called by none

Calls _index, _repo, _section, marked_lines, propose, section_names, uncomment

Checks

  • assert shared.status is SectionStatus.NO_CANDIDATES, shared.reason
  • assert shared.checked["families"] == 0
  • assert _section(proposal, SECTION_THREADS).status is SectionStatus.NO_CANDIDATES
  • assert not any(s.entries for s in proposal.sections)
  • assert marked_lines(proposal.yaml_text) == [], "an empty draft must carry no YAML"
  • assert uncomment(proposal.yaml_text).strip() == ""
  • assert proposal.yaml_text.count("STATUS:") == len(section_names())

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_no_convention_yields_an_empty_but_valid_draft_that_says_so → propose
REQ-DDB-CONFIG-006measuredtest_no_convention_yields_an_empty_but_valid_draft_that_says_so → _index → write_build_signature
REQ-DDB-CONFIG-007measuredtest_no_convention_yields_an_empty_but_valid_draft_that_says_so → _index → write_build_signature
REQ-DDB-GUARD-012inferredtest_no_convention_yields_an_empty_but_valid_draft_that_says_so → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-005measuredtest_no_convention_yields_an_empty_but_valid_draft_that_says_so → _index → write_build_signature
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measuredtest_no_convention_yields_an_empty_but_valid_draft_that_says_so → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_no_convention_yields_an_empty_but_valid_draft_that_says_so → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_no_convention_yields_an_empty_but_valid_draft_that_says_so → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 25 lines
def test_no_convention_yields_an_empty_but_valid_draft_that_says_so(tmp_path: Path) -> None:
    """The failure to avoid is a draft that fills the silence with something
    plausible. With a real index to measure against and nothing to find, every
    section must report a MEASURED absence — `no_candidates`, with the counts that
    make it legible — and the document must contain no activatable YAML at all.

    @brief Nothing detectable produces a measured empty draft, not an invention.
    @version 1
    """
    root = _repo(tmp_path / "plain", _PLAIN_SOURCE)
    db = _index(tmp_path / "plain.db", "src/app.c", [(1, "helper", 1, 5), (2, "main_loop", 7, 10)])

    proposal = propose(root, db)

    shared = _section(proposal, SECTION_SHARED_KEY)
    assert shared.status is SectionStatus.NO_CANDIDATES, shared.reason
    assert shared.checked["families"] == 0
    assert _section(proposal, SECTION_THREADS).status is SectionStatus.NO_CANDIDATES
    assert not any(s.entries for s in proposal.sections)
    assert marked_lines(proposal.yaml_text) == [], "an empty draft must carry no YAML"
    assert uncomment(proposal.yaml_text).strip() == ""
    # ... and it has to SAY so, per section, rather than omitting them.
    assert proposal.yaml_text.count("STATUS:") == len(section_names())

Activity · 11 steps
lines 334–334root = _repo(tmp_path / "plain", _PLAIN_SOURCE)lines 335–335db = _index(tmp_path / "plain.db", "src/app.c", [(1, "helper", 1, 5), (2, "main_loop", 7, 10)])lines 337–337proposal = propose(root, db)lines 339–339shared = _section(proposal, SECTION_SHARED_KEY)lines 340–340assert shared.status is SectionStatus.NO_CANDIDATES, shared.reasonlines 341–341assert shared.checked["families"] == 0lines 342–342assert _section(proposal, SECTION_THREADS).status is SectionStatus.NO_CANDIDATESlines 343–343assert not any(s.entries for s in proposal.sections)lines 344–344assert marked_lines(proposal.yaml_text) == [], "an empty draft must carry no YAML"lines 345–345assert uncomment(proposal.yaml_text).strip() == ""lines 347–347assert proposal.yaml_text.count("STATUS:") == len(section_names())

test_no_dry_run_is_fail_closed

None test_propose.test_no_dry_run_is_fail_closed(Path tmp_path)

--no-dry-run is fail-closed, not "trust the structure".

tests/test_propose.py:371

Show on the map →

Called by none

Calls _acme, _section, propose

Checks

  • assert _section(propose(root, db), SECTION_SHARED_KEY).status is SectionStatus.PROPOSED
  • assert section.status is SectionStatus.NOT_ANALYSED
  • assert section.entries == ()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_no_dry_run_is_fail_closed → propose
REQ-DDB-CONFIG-006measuredtest_no_dry_run_is_fail_closed → _acme → _index → write_build_signature
REQ-DDB-CONFIG-007measuredtest_no_dry_run_is_fail_closed → _acme → _index → write_build_signature
REQ-DDB-GUARD-012inferredtest_no_dry_run_is_fail_closed → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-005measuredtest_no_dry_run_is_fail_closed → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measuredtest_no_dry_run_is_fail_closed → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_no_dry_run_is_fail_closed → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_no_dry_run_is_fail_closed → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 12 lines
def test_no_dry_run_is_fail_closed(tmp_path: Path) -> None:
    """Disabling measurement must remove the proposal, not the gate."""
    root, db = _acme(tmp_path)
    assert _section(propose(root, db), SECTION_SHARED_KEY).status is SectionStatus.PROPOSED
    section = _section(propose(root, db, dry_run=False), SECTION_SHARED_KEY)
    assert section.status is SectionStatus.NOT_ANALYSED
    assert section.entries == ()


# ─── a late-resolving `#if` arm must revise the answer, not be discarded ────

Activity · 5 steps
lines 373–373root, db = _acme(tmp_path)lines 374–374assert _section(propose(root, db), SECTION_SHARED_KEY).status is SectionStatus.PROPOSEDlines 375–375section = _section(propose(root, db, dry_run=False), SECTION_SHARED_KEY)lines 376–376assert section.status is SectionStatus.NOT_ANALYSEDlines 377–377assert section.entries == ()

test_rejections_appear_in_the_rendered_draft_with_reasons

None test_propose.test_rejections_appear_in_the_rendered_draft_with_reasons(Path repo_root, Path rich_db)

Rejections reach the rendered draft with their reasons.

tests/test_propose.py:302

Show on the map →

Called by none

Calls _section, propose

Checks

  • assert "REJECTED" in text
  • assert "DataModel_Set_" in text
  • assert "floor" in text
  • assert section.rejections
  • assert rejection.reason, f"{rejection.name} was refused with no reason"
  • assert rejection.name in text, f"{rejection.name} never reached the draft"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_rejections_appear_in_the_rendered_draft_with_reasons → propose
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-GUARD-012measuredtest_rejections_appear_in_the_rendered_draft_with_reasons → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-005measuredtest_rejections_appear_in_the_rendered_draft_with_reasons → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measuredtest_rejections_appear_in_the_rendered_draft_with_reasons → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_rejections_appear_in_the_rendered_draft_with_reasons → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_rejections_appear_in_the_rendered_draft_with_reasons → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 21 lines
def test_rejections_appear_in_the_rendered_draft_with_reasons(
    repo_root: Path, rich_db: Path
) -> None:
    """A refused candidate is part of the deliverable. The candidate an owner
    EXPECTED is exactly the one they go looking for, and without the reason the
    only available conclusion is that clew missed it."""
    proposal = propose(repo_root, rich_db)
    text = proposal.yaml_text
    assert "REJECTED" in text
    assert "DataModel_Set_" in text
    assert "floor" in text
    section = _section(proposal, SECTION_SHARED_KEY)
    assert section.rejections
    for rejection in section.rejections:
        assert rejection.reason, f"{rejection.name} was refused with no reason"
        assert rejection.name in text, f"{rejection.name} never reached the draft"


# ─── a repo with no convention says so, and invents nothing ─────────────────

Activity · 10 steps
lines 308–308proposal = propose(repo_root, rich_db)lines 309–309text = proposal.yaml_textlines 310–310assert "REJECTED" in textlines 311–311assert "DataModel_Set_" in textlines 312–312assert "floor" in textlines 313–313section = _section(proposal, SECTION_SHARED_KEY)lines 314–314assert section.rejectionslines 315–315◇ for rejection in section.rejectionslines 316–316assert rejection.reason, f"{rejection.name} was refused with no reason"lines 317–317assert rejection.name in text, f"{rejection.name} never reached the draft"

test_rendered_draft_round_trips_through_load_declaration

None test_propose.test_rendered_draft_round_trips_through_load_declaration(Path tmp_path)

The rendered draft round-trips through the real declaration loader.

tests/test_propose.py:502

Show on the map →

Called by none

Calls _acme, _section, load_declaration, propose, uncomment

Checks

  • assert shared.status is SectionStatus.PROPOSED, shared.reason
  • assert load_declaration(target) == {}
  • assert set(declared) == {SECTION_SHARED_KEY}
  • assert declared[SECTION_SHARED_KEY]["writers"] == [{"name_prefix": "ACME_SET_"}]
  • assert declared[SECTION_SHARED_KEY]["readers"] == [{"name_prefix": "ACME_GET_"}]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_rendered_draft_round_trips_through_load_declaration → load_declaration
REQ-DDB-CONFIG-006measuredtest_rendered_draft_round_trips_through_load_declaration → _acme → _index → write_build_signature
REQ-DDB-CONFIG-007measuredtest_rendered_draft_round_trips_through_load_declaration → _acme → _index → write_build_signature
REQ-DDB-GUARD-012inferredtest_rendered_draft_round_trips_through_load_declaration → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-005measuredtest_rendered_draft_round_trips_through_load_declaration → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measuredtest_rendered_draft_round_trips_through_load_declaration → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_rendered_draft_round_trips_through_load_declaration → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_rendered_draft_round_trips_through_load_declaration → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 30 lines
def test_rendered_draft_round_trips_through_load_declaration(tmp_path: Path) -> None:
    """A draft that does not parse is useless, and every emitted line is a
    comment — so the only way to prove the proposal is real is to perform the
    activation an owner would perform and load the result through the SAME code
    path a build uses.

    @brief Activating the draft yields the declaration it claims to propose.
    @version 1
    """
    root, db = _acme(tmp_path)
    proposal = propose(root, db)
    shared = _section(proposal, SECTION_SHARED_KEY)
    assert shared.status is SectionStatus.PROPOSED, shared.reason

    # As written, the draft is inert: the loader sees no sections at all.
    target = tmp_path / "inert"
    target.mkdir()
    (target / DECLARATION_NAME).write_text(proposal.yaml_text, encoding="utf-8")
    assert load_declaration(target) == {}

    # Activated, it parses to exactly the proposed section.
    active = tmp_path / "active"
    active.mkdir()
    (active / DECLARATION_NAME).write_text(uncomment(proposal.yaml_text), encoding="utf-8")
    declared = load_declaration(active)
    assert set(declared) == {SECTION_SHARED_KEY}
    assert declared[SECTION_SHARED_KEY]["writers"] == [{"name_prefix": "ACME_SET_"}]
    assert declared[SECTION_SHARED_KEY]["readers"] == [{"name_prefix": "ACME_GET_"}]

Activity · 15 steps
lines 511–511root, db = _acme(tmp_path)lines 512–512proposal = propose(root, db)lines 513–513shared = _section(proposal, SECTION_SHARED_KEY)lines 514–514assert shared.status is SectionStatus.PROPOSED, shared.reasonlines 517–517target = tmp_path / "inert"lines 518–518target.mkdir()lines 519–519(target / DECLARATION_NAME).write_text(proposal.yaml_text, encoding="utf-8")lines 520–520assert load_declaration(target) == {}lines 523–523active = tmp_path / "active"lines 524–524active.mkdir()lines 525–525(active / DECLARATION_NAME).write_text(uncomment(proposal.yaml_text), encoding="utf-8")lines 526–526declared = load_declaration(active)lines 527–527assert set(declared) == {SECTION_SHARED_KEY}lines 528–528assert declared[SECTION_SHARED_KEY]["writers"] == [{"name_prefix": "ACME_SET_"}]lines 529–529assert declared[SECTION_SHARED_KEY]["readers"] == [{"name_prefix": "ACME_GET_"}]

test_stdout_is_the_default_destination

None test_propose.test_stdout_is_the_default_destination(Path tmp_path, pytest.CaptureFixture capsys)

The draft goes to stdout when no output path is given.

tests/test_propose.py:679

Show on the map →

Called by none

Calls _acme, propose_main

Checks

  • assert propose_main(["--repo-root", str(root), "--db", str(db)]) == 0
  • assert out.lstrip().startswith("#")
  • assert (root / DECLARATION_NAME).read_text(encoding="utf-8") == before, ("the declaration the repo already carries must come back byte-identical" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_stdout_is_the_default_destination → propose_main
REQ-DDB-CONFIG-006measuredtest_stdout_is_the_default_destination → _acme → _index → write_build_signature
REQ-DDB-CONFIG-007measuredtest_stdout_is_the_default_destination → _acme → _index → write_build_signature
REQ-DDB-GUARD-010measuredtest_stdout_is_the_default_destination → propose_main → _resolve_db → find_index
REQ-DDB-GUARD-012inferredtest_stdout_is_the_default_destination → propose_main → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-005measuredtest_stdout_is_the_default_destination → _acme → _index → write_build_signature
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measuredtest_stdout_is_the_default_destination → propose_main → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_stdout_is_the_default_destination → propose_main → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_stdout_is_the_default_destination → propose_main → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 13 lines
def test_stdout_is_the_default_destination(tmp_path: Path, capsys: pytest.CaptureFixture) -> None:
    """A command that writes into the tree by default turns "show me what you
    would suggest" into an edit."""
    root, db = _acme(tmp_path)
    before = (root / DECLARATION_NAME).read_text(encoding="utf-8")
    assert propose_main(["--repo-root", str(root), "--db", str(db)]) == 0
    out = capsys.readouterr().out
    assert out.lstrip().startswith("#")
    assert (root / DECLARATION_NAME).read_text(encoding="utf-8") == before, (
        "the declaration the repo already carries must come back byte-identical"
    )

Activity · 6 steps
lines 682–682root, db = _acme(tmp_path)lines 683–683before = (root / DECLARATION_NAME).read_text(encoding="utf-8")lines 684–684assert propose_main(["--repo-root", str(root), "--db", str(db)]) == 0lines 685–685out = capsys.readouterr().outlines 686–686assert out.lstrip().startswith("#")lines 687–689assert (root / DECLARATION_NAME).read_text(encoding="utf-8") == before, ( "the declaration the repo already carries must come back byte-identical" )

test_uncomment_recovers_only_the_marked_lines

None test_propose.test_uncomment_recovers_only_the_marked_lines()

uncomment recovers only the marked lines.

tests/test_propose.py:632

Show on the map →

Called by none

Calls uncomment

Checks

  • assert yaml.safe_load(uncomment(text)) == {

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_uncomment_recovers_only_the_marked_lines → uncomment
Source · 20 lines
def test_uncomment_recovers_only_the_marked_lines() -> None:
    """The marker exists so prose ABOUT a proposal can never be mistaken for the
    proposal. Anything else in the file is dropped."""
    text = "\n".join(
        [
            "# prose that mentions shared_key_patterns: and must not be parsed",
            YAML_MARKER + "shared_key_patterns:",
            YAML_MARKER + "  writers:",
            YAML_MARKER + '    - name_prefix: "Z_SET_"',
            "#  ── NOTES ──",
        ]
    )
    assert yaml.safe_load(uncomment(text)) == {
        SECTION_SHARED_KEY: {"writers": [{"name_prefix": "Z_SET_"}]}
    }


# ─── the CLI must not clobber a repo's own declaration ─────────────────────

Activity · 2 steps
lines 635–643text = "\n".join( [ "# prose that mentions shared_key_patterns: and must not be parsed", YAML_MARKER + "shared_key_patterns:", YAML_MARKER + " writers:", YAML_MARKER + ' - name_prefix: "Z_SET_"', "# ── NOTES ──", ] )lines 644–646assert yaml.safe_load(uncomment(text)) == { SECTION_SHARED_KEY: {"writers": [{"name_prefix": "Z_SET_"}]} }

test_without_an_index_the_shared_key_section_refuses_to_propose

None test_propose.test_without_an_index_the_shared_key_section_refuses_to_propose(Path tmp_path)

Without a usable index the gated section refuses instead of guessing.

tests/test_propose.py:352

Show on the map →

Called by none

Calls _acme, _section, propose

Checks

  • assert section.status is SectionStatus.NOT_ANALYSED
  • assert section.entries == ()
  • assert section.checked["arity_consistent_pairs"] >= 1, ("the structural filters must still have FOUND the pair — the refusal is " "the measurement gate, not a detection failure" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_without_an_index_the_shared_key_section_refuses_to_propose → propose
REQ-DDB-CONFIG-006measuredtest_without_an_index_the_shared_key_section_refuses_to_propose → _acme → _index → write_build_signature
REQ-DDB-CONFIG-007measuredtest_without_an_index_the_shared_key_section_refuses_to_propose → _acme → _index → write_build_signature
REQ-DDB-GUARD-012inferredtest_without_an_index_the_shared_key_section_refuses_to_propose → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-005measuredtest_without_an_index_the_shared_key_section_refuses_to_propose → propose → db_status_summary → read_build_signature
REQ-DDB-PIPE-011measuredtest_without_an_index_the_shared_key_section_refuses_to_propose → propose → build_context → scan_repo → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_without_an_index_the_shared_key_section_refuses_to_propose → propose → build_context → repo_source_files → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-005measured
REQ-DDB-WIKI-054inferredtest_without_an_index_the_shared_key_section_refuses_to_propose → propose → build_context → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 17 lines
def test_without_an_index_the_shared_key_section_refuses_to_propose(tmp_path: Path) -> None:
    """An unmeasured shared-key declaration can mint a bipartite blob of
    fabricated causal edges, so the structural filters passing is NOT enough.
    With no index the section must report `not_analysed` — never a guess derived
    from the (perfectly real) call-site evidence it did collect."""
    root, _db = _acme(tmp_path)

    section = _section(propose(root, None), SECTION_SHARED_KEY)

    assert section.status is SectionStatus.NOT_ANALYSED
    assert section.entries == ()
    assert section.checked["arity_consistent_pairs"] >= 1, (
        "the structural filters must still have FOUND the pair — the refusal is "
        "the measurement gate, not a detection failure"
    )

Activity · 5 steps
lines 357–357root, _db = _acme(tmp_path)lines 359–359section = _section(propose(root, None), SECTION_SHARED_KEY)lines 361–361assert section.status is SectionStatus.NOT_ANALYSEDlines 362–362assert section.entries == ()lines 363–366assert section.checked["arity_consistent_pairs"] >= 1, ( "the structural filters must still have FOUND the pair — the refusal is " "the measurement gate, not a detection failure" )