test_subject_surface.py

tests/test_subject_surface.py

The subject-agnostic dossier, the corpus-agnostic search, and the `index` lifecycle.

test_a_file_row_in_compounddef_does_not_classify_as_a_class

None test_subject_surface.test_a_file_row_in_compounddef_does_not_classify_as_a_class(Path tmp_path)

A `kind='file'` compound row is not a class subject.

tests/test_subject_surface.py:140

Checks

  • assert "class" not in q.resolve_subject(db, "threading.c")
  • assert q.resolve_subject(db, "real_struct_t") == ("class",)
  • assert q.dossier(db, "real_struct_t") is not None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_a_file_row_in_compounddef_does_not_classify_as_a_class → dossier → _chain_for → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_a_file_row_in_compounddef_does_not_classify_as_a_class → resolve_subject → connect
REQ-DDB-QUERY-002inferredtest_a_file_row_in_compounddef_does_not_classify_as_a_class → dossier → _chain_for → chain_trace
REQ-DDB-QUERY-003measuredtest_a_file_row_in_compounddef_does_not_classify_as_a_class → dossier → identity_rowids
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-005inferredtest_a_file_row_in_compounddef_does_not_classify_as_a_class → dossier → _chain_for → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_a_file_row_in_compounddef_does_not_classify_as_a_class → dossier → identity_rowids
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-013measuredtest_a_file_row_in_compounddef_does_not_classify_as_a_class → dossier → _qualified_reread → _split_qualified → bare_tail
REQ-DDB-WIKI-054inferredtest_a_file_row_in_compounddef_does_not_classify_as_a_class → dossier → _rank_enum_over_mirror → _class_side_is_only_enum_mirrors → all
Source · 48 lines
def test_a_file_row_in_compounddef_does_not_classify_as_a_class(tmp_path: Path) -> None:
    """MEASURED ON MBEDTLS: `resolve_subject("threading.c")` returned `('class',)` while
    `dossier` returned nothing at all. doxygen puts more than classes in
    `compounddef` — it registers a row per FILE with `kind='file'` — and `_is_compound` did
    not filter on `CLASS_KINDS` while `lookup_class` did. So the probe said "class" and the
    builder found none.

    A WRONG KIND IS WORSE THAN A MISS, and the disagreement is the specific harm: the caller
    is told the kind exists and handed an empty section, with nothing in the reply saying
    the two halves disagreed. Same shape as the config probe/builder split fixed one commit
    earlier, which is why this is asserted rather than left to the type filter.

    HAND-BUILT, because `rich_db`'s `compounddef` is hand-made and carries NO `kind='file'`
    rows — the fixture does not reproduce this doxygen behaviour, so a test derived from it
    would have passed vacuously while the defect shipped. That is this suite's documented
    second tier: an invariant the whole-graph fixture cannot contain gets its own database.

    @brief A `kind='file'` compound row is not a class subject.
    @return None.
    @version 1
    """
    db = tmp_path / "clew.db"
    conn = sqlite3.connect(str(db))
    conn.execute("CREATE TABLE path (rowid INTEGER PRIMARY KEY, name TEXT, type INTEGER)")
    conn.execute("INSERT INTO path(rowid, name, type) VALUES(1, 'library/threading.c', 1)")
    conn.execute(
        "CREATE TABLE compounddef (rowid INTEGER PRIMARY KEY, name TEXT, kind TEXT, "
        "file_id INTEGER, line INTEGER, briefdescription TEXT, prot INTEGER)"
    )
    ## Doxygen's own shape: the FILE row and a real STRUCT row side by side, so the test
    ## proves the filter discriminates rather than merely refusing everything.
    conn.executemany(
        "INSERT INTO compounddef(name, kind, file_id, line, briefdescription, prot) "
        "VALUES(?, ?, 1, 10, '', 0)",
        [("threading.c", "file"), ("real_struct_t", "struct")],
    )
    conn.commit()
    conn.close()

    assert "class" not in q.resolve_subject(db, "threading.c")
    assert q.resolve_subject(db, "real_struct_t") == ("class",)
    ## THE TWO HALVES AGREE on the row that IS a class.
    assert q.dossier(db, "real_struct_t") is not None


# ─── the variable subject: the defect that motivated the whole collapse ──────

Activity · 11 steps
lines 161–161db = tmp_path / "clew.db"lines 162–162conn = sqlite3.connect(str(db))lines 163–163conn.execute("CREATE TABLE path (rowid INTEGER PRIMARY KEY, name TEXT, type INTEGER)")lines 164–164conn.execute("INSERT INTO path(rowid, name, type) VALUES(1, 'library/threading.c', 1)")lines 165–168conn.execute( "CREATE TABLE compounddef (rowid INTEGER PRIMARY KEY, name TEXT, kind TEXT, " "file_id INTEGER, line INTEGER, briefdescription TEXT, prot INTEGER)" )lines 171–175conn.executemany( "INSERT INTO compounddef(name, kind, file_id, line, briefdescription, prot) " "VALUES(?, ?, 1, 10, '', 0)", [("threading.c", "file"), ("real_struct_t", "struct")], )lines 176–176conn.commit()lines 177–177conn.close()lines 179–179assert "class" not in q.resolve_subject(db, "threading.c")lines 180–180assert q.resolve_subject(db, "real_struct_t") == ("class",)lines 182–182assert q.dossier(db, "real_struct_t") is not None

test_a_kind_filter_never_relabels_another_kind

None test_subject_surface.test_a_kind_filter_never_relabels_another_kind(QueryTools tools)

`kind=` narrows resolution and misses rather than substituting.

tests/test_subject_surface.py:261

Show on the map →

Called by none

Calls none

Checks

  • assert tools.dossier("app_run")["subject_kind"] == "function"
  • assert tools.dossier("app_run", kind="variable")["found"] is False
  • assert tools.dossier("app_run", kind="function")["subject_kind"] == "function"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-MCP-003measured
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-011measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-002measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-009measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-013measured
REQ-DDB-QUERY-014measured
REQ-DDB-SCHEMA-011measured
Source · 14 lines
def test_a_kind_filter_never_relabels_another_kind(tools: QueryTools) -> None:
    """AN EXPLICIT KIND IS A FILTER, NOT AN OVERRIDE. A caller that ruled a kind out must
    not be handed the thing it ruled out under the label it asked for — that is the
    silent-substitution failure a dispatching argument invites.

    @brief `kind=` narrows resolution and misses rather than substituting.
    @return None.
    @version 1
    """
    assert tools.dossier("app_run")["subject_kind"] == "function"
    assert tools.dossier("app_run", kind="variable")["found"] is False
    assert tools.dossier("app_run", kind="function")["subject_kind"] == "function"

Activity · 3 steps
lines 270–270assert tools.dossier("app_run")["subject_kind"] == "function"lines 271–271assert tools.dossier("app_run", kind="variable")["found"] is Falselines 272–272assert tools.dossier("app_run", kind="function")["subject_kind"] == "function"

test_a_kind_with_no_subject_refuses_by_naming_the_route

None test_subject_surface.test_a_kind_with_no_subject_refuses_by_naming_the_route(QueryTools tools)

Every kind that left the list is now a filter, not a refusal.

tests/test_subject_surface.py:345

Show on the map →

Called by none

Calls none

Checks

  • assert tools.dossier("app_run", kind="typedef")["found"] is False
  • assert tools.dossier("app_run", kind="file")["found"] is False

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-003measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-013measured
REQ-DDB-QUERY-014measured
Source · 34 lines
def test_a_kind_with_no_subject_refuses_by_naming_the_route(tools: QueryTools) -> None:
    """ONE KIND CANNOT BE ALIASED and pretending otherwise would be worse than refusing: there is
    no typedef subject to build. What made the original refusal expensive was not that it refused
    — it was that it stopped there, so the caller had to guess where to go next and guessed
    `grep`.

    So the refusal names the route. Asserted on the ROUTE, not just on the exception, because a
    bare "unknown kind" is what already existed.

    THIS TEST SAID "THREE KINDS" AND NOW SAYS ONE, and both corrections are the same correction
    made twice. `enumeration` left this list in gh#6 when its subject was built. `file` left it
    in C1 of the 1.1.0 acceptance review, where its refusal was not merely stale but measured:
    48 of 237 unanswered `dossier` subjects were file paths, and the route this list named —
    `search(corpus='prose')` — is a token conjunction over every corpus at once.

    AND NOW SAYS NONE: `typedef` left it in 1.3.0, as this docstring said it one day would —
    TypeScript type aliases are typedef rows, and the refusal's claim that a search row carried
    all the index holds was false for every one of them. The list and its refusal path stay: the
    partition test above still demands that a kind search emits either follows or explains itself.

    @brief Every kind that left the list is now a filter, not a refusal.
    @return None.
    @version 3
    """
    ## `kind='typedef'` on a function name is a filter that finds nothing, not a raise.
    assert tools.dossier("app_run", kind="typedef")["found"] is False
    ## The one that LEFT the list, asserted here so the correction cannot be silently undone:
    ## `kind='file'` must be a filter now, which on a function name means None rather than a raise.
    assert tools.dossier("app_run", kind="file")["found"] is False


# ─── depth: chain_trace, folded in and bounded ───────────────────────────────

Activity · 2 steps
lines 370–370assert tools.dossier("app_run", kind="typedef")["found"] is Falselines 373–373assert tools.dossier("app_run", kind="file")["found"] is False

test_a_macro_is_not_reported_as_an_unsupported_kind

None test_subject_surface.test_a_macro_is_not_reported_as_an_unsupported_kind(Path tmp_path)

macro definition is the memberdef spelling of a SUPPORTED kind and must not be flagged.

tests/test_subject_surface.py:737

Checks

  • assert q.unresolved_kinds(db, "WRAP") == (), ("`macro definition` is how memberdef spells the supported `macro` subject kind" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_a_macro_is_not_reported_as_an_unsupported_kind → unresolved_kinds → connect
REQ-DDB-QUERY-003measuredtest_a_macro_is_not_reported_as_an_unsupported_kind → unresolved_kinds → table_exists
Source · 22 lines
def test_a_macro_is_not_reported_as_an_unsupported_kind(tmp_path: Path) -> None:
    """THE FALSE-POSITIVE HALF, and it is a real trap rather than a hypothetical: `SUBJECT_KINDS`
    spells it `macro` and `memberdef.kind` spells it `macro definition`, so a naive set difference
    reports every macro in the index as a kind `dossier` cannot describe — while `dossier` resolves
    macros perfectly well. That clause would send a reader chasing a phantom limitation.

    @brief A macro definition row is not reported as unsupported.
    @return None.
    @version 1
    """
    db = tmp_path / "m.db"
    conn = sqlite3.connect(str(db))
    conn.execute("CREATE TABLE memberdef (rowid_ INTEGER, name TEXT, kind TEXT)")
    conn.execute("INSERT INTO memberdef(name, kind) VALUES('WRAP', 'macro definition')")
    conn.commit()
    conn.close()

    assert q.unresolved_kinds(db, "WRAP") == (), (
        "`macro definition` is how memberdef spells the supported `macro` subject kind"
    )

Activity · 7 steps
lines 747–747db = tmp_path / "m.db"lines 748–748conn = sqlite3.connect(str(db))lines 749–749conn.execute("CREATE TABLE memberdef (rowid_ INTEGER, name TEXT, kind TEXT)")lines 750–750conn.execute("INSERT INTO memberdef(name, kind) VALUES('WRAP', 'macro definition')")lines 751–751conn.commit()lines 752–752conn.close()lines 754–756assert q.unresolved_kinds(db, "WRAP") == (), ( "`macro definition` is how memberdef spells the supported `macro` subject kind" )

test_a_miss_on_an_indexed_kind_says_it_is_a_kind_gap_not_an_absence

None test_subject_surface.test_a_miss_on_an_indexed_kind_says_it_is_a_kind_gap_not_an_absence(Path tmp_path)

A name indexed under an unsupported kind must not be called a definitive negative.

tests/test_subject_surface.py:682

Checks

  • assert q.unresolved_kinds(db, "MY_ALIAS") == ("friend",), ("a kind the index holds and no subject describes must be reported as an unsupported KIND" )
  • assert q.unresolved_kinds(db, "MY_ENUM") == (), ("an enumeration is a SUPPORTED kind since gh#6's subject landed, so reporting it as a " "gap would send a reader looking for a limitation that has been closed" )
  • assert q.unresolved_kinds(db, "a_fn") == (), ("a function is a supported kind and must not be reported as unresolvable" )
  • assert q.unresolved_kinds(db, "nothing_at_all") == (), ("a genuinely absent name has no unsupported kinds either — this is the control that " "stops the clause firing on every miss and training a reader to ignore it" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_a_miss_on_an_indexed_kind_says_it_is_a_kind_gap_not_an_absence → unresolved_kinds → connect
REQ-DDB-QUERY-003measuredtest_a_miss_on_an_indexed_kind_says_it_is_a_kind_gap_not_an_absence → unresolved_kinds → table_exists
Source · 51 lines
def test_a_miss_on_an_indexed_kind_says_it_is_a_kind_gap_not_an_absence(tmp_path: Path) -> None:
    """gh#6. `SUBJECT_KINDS` had no `enumeration` while `SEARCHED_MEMBERDEF_KINDS` did, so
    `search` found a C enum and `dossier` answered "Not indexed in this repository. A definitive
    negative from the database" for the same name. A reporter asked about four enum symbols they
    knew existed and got that on all four; on a codebase whose architecture rule is "pure C at all
    `.so` boundaries", the authoritative definitions were invisible while the generated Python
    mirror was not.

    THE CONFIDENCE WAS THE DAMAGE. Their words: it "reads as 'this tool is wrong about my repo'
    rather than 'this kind isn't indexed yet'".

    NOW ASSERTED ON `typedef`, BECAUSE THE ENUM CASE IS FIXED. `enumeration` became a subject
    kind, so it correctly stops being reported as a gap — and this test would have passed
    unchanged only by pinning the defect. What it exists to guard is the SHAPE, not the one kind
    that motivated it: a surface describing some memberdef kinds and not others always has a
    gap, and the gap must read as a gap rather than as an absence.

    NOW ASSERTED ON `friend`, BECAUSE THE TYPEDEF CASE IS FIXED TOO (1.3.0): `typedef` became a
    subject kind for the same reason `enumeration` did. `friend` is a doxygen memberdef kind no
    subject describes — the gap this test's shape is about.

    @brief An unresolvable-but-indexed kind is reported as a coverage limitation.
    @return None.
    @version 3
    """
    db = tmp_path / "e.db"
    conn = sqlite3.connect(str(db))
    conn.execute("CREATE TABLE memberdef (rowid_ INTEGER, name TEXT, kind TEXT)")
    conn.executemany(
        "INSERT INTO memberdef(name, kind) VALUES(?, ?)",
        [("MY_ALIAS", "friend"), ("MY_ENUM", "enumeration"), ("a_fn", "function")],
    )
    conn.commit()
    conn.close()

    assert q.unresolved_kinds(db, "MY_ALIAS") == ("friend",), (
        "a kind the index holds and no subject describes must be reported as an unsupported KIND"
    )
    assert q.unresolved_kinds(db, "MY_ENUM") == (), (
        "an enumeration is a SUPPORTED kind since gh#6's subject landed, so reporting it as a "
        "gap would send a reader looking for a limitation that has been closed"
    )
    assert q.unresolved_kinds(db, "a_fn") == (), (
        "a function is a supported kind and must not be reported as unresolvable"
    )
    assert q.unresolved_kinds(db, "nothing_at_all") == (), (
        "a genuinely absent name has no unsupported kinds either — this is the control that "
        "stops the clause firing on every miss and training a reader to ignore it"
    )

Activity · 10 steps
lines 707–707db = tmp_path / "e.db"lines 708–708conn = sqlite3.connect(str(db))lines 709–709conn.execute("CREATE TABLE memberdef (rowid_ INTEGER, name TEXT, kind TEXT)")lines 710–713conn.executemany( "INSERT INTO memberdef(name, kind) VALUES(?, ?)", [("MY_ALIAS", "friend"), ("MY_ENUM", "enumeration"), ("a_fn", "function")], )lines 714–714conn.commit()lines 715–715conn.close()lines 717–719assert q.unresolved_kinds(db, "MY_ALIAS") == ("friend",), ( "a kind the index holds and no subject describes must be reported as an unsupported KIND" )lines 720–723assert q.unresolved_kinds(db, "MY_ENUM") == (), ( "an enumeration is a SUPPORTED kind since gh#6's subject landed, so reporting it as a " "gap would send a reader looking for a limitation that has been closed" )lines 724–726assert q.unresolved_kinds(db, "a_fn") == (), ( "a function is a supported kind and must not be reported as unresolvable" )lines 727–730assert q.unresolved_kinds(db, "nothing_at_all") == (), ( "a genuinely absent name has no unsupported kinds either — this is the control that " "stops the clause firing on every miss and training a reader to ignore it" )

test_a_name_that_is_two_subjects_reports_both

None test_subject_surface.test_a_name_that_is_two_subjects_reports_both(Path rich_db)

A doubly-classified name lists every kind it resolves to.

tests/test_subject_surface.py:108

Checks

  • assert set(kinds) >= {"lock", "variable"}, kinds
  • assert kinds[0] == "lock"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_a_name_that_is_two_subjects_reports_both → resolve_subject → connect
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
Source · 21 lines
def test_a_name_that_is_two_subjects_reports_both(rich_db: Path) -> None:
    """AN ARBITRARY PICK REPORTED AS THE ANSWER is this repo's own recorded failure, one
    level up: three unrelated `_classify` functions collapsed into one node and the
    dossier listed the union of their neighbours at `confidence: exact`. The classifier
    refuses to repeat it — a name that is several things says so.

    `dm_mutex` really is two subjects: a `static pthread_mutex_t` object and a row in the
    lock layer. Both are true and the resolver publishes both.

    @brief A doubly-classified name lists every kind it resolves to.
    @return None.
    @version 1
    """
    kinds = q.resolve_subject(rich_db, DM_MUTEX)
    assert set(kinds) >= {"lock", "variable"}, kinds
    ## PROBE ORDER IS THE DEFAULT, and the richness layer outranks the generic row: a
    ## question about `dm_mutex` is a question about a lock, and the lock subject is the
    ## one that carries the critical sections.
    assert kinds[0] == "lock"

Activity · 3 steps
lines 121–121kinds = q.resolve_subject(rich_db, DM_MUTEX)lines 122–122assert set(kinds) >= {"lock", "variable"}, kindslines 126–126assert kinds[0] == "lock"

test_a_subject_with_no_traversal_seed_discloses_it

None test_subject_surface.test_a_subject_with_no_traversal_seed_discloses_it(QueryTools tools)

A depth request on a seedless subject returns `depth_note`.

tests/test_subject_surface.py:416

Show on the map →

Called by none

Calls none

Checks

  • assert reply["subject_kind"] == "lock"
  • assert "chain" not in reply
  • assert "only a function is an endpoint" in reply["depth_note"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-003measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-011measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-014measured
REQ-DDB-SCHEMA-011measured
Source · 19 lines
def test_a_subject_with_no_traversal_seed_discloses_it(tools: QueryTools) -> None:
    """A SILENT NO-OP IS WORSE THAN A REFUSAL. Only a function is an endpoint of the call
    and shared-key edges a chain follows, so a lock or a requirement has nothing to walk
    from — and a `depth` argument that quietly did nothing would leave a caller believing
    it had seen three hops of context.

    @brief A depth request on a seedless subject returns `depth_note`.
    @return None.
    @version 1
    """
    reply = tools.dossier(DM_MUTEX, kind="lock", depth=3)
    assert reply["subject_kind"] == "lock"
    assert "chain" not in reply
    assert "only a function is an endpoint" in reply["depth_note"]


# ─── corpora ─────────────────────────────────────────────────────────────────

Activity · 4 steps
lines 426–426reply = tools.dossier(DM_MUTEX, kind="lock", depth=3)lines 427–427assert reply["subject_kind"] == "lock"lines 428–428assert "chain" not in replylines 429–429assert "only a function is an endpoint" in reply["depth_note"]

test_a_variable_subject_reports_every_declaration_site_and_its_source

None test_subject_surface.test_a_variable_subject_reports_every_declaration_site_and_its_source(QueryTools tools)

A variable subject carries its sites and the source line each is declared on.

tests/test_subject_surface.py:188

Show on the map →

Called by none

Calls none

Checks

  • assert reply["subject_kind"] == "variable"
  • assert reply["sites"], "a variable subject must name where it is declared"
  • assert site["file"].endswith("dm.c")
  • assert site["static"] is True
  • assert "PTHREAD_MUTEX_INITIALIZER" in text, ("the declaration excerpt must carry the initializer, which is the only place the " "binding is recorded" )
  • assert field not in reply, f"a variable payload must not carry {field!r}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-MCP-003measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-014measured
Source · 41 lines
def test_a_variable_subject_reports_every_declaration_site_and_its_source(
    tools: QueryTools,
) -> None:
    """THE HEADLINE FIX, and the reason there are four tools instead of nineteen.
    `dossier` resolved through `function_candidates`, which filters `kind='function'`, so
    every non-function subject was unreachable from the tool a model is told to call
    FIRST — and it answered `found: false`, which reads as "not indexed" rather than as
    "this tool cannot describe that".

    Measured live on the public mbedtls index, where it matters most: the whole locking
    API is `mbedtls_mutex_lock` and three siblings, all of them function POINTERS, i.e.
    variables. `dossier('mbedtls_mutex_lock')` returned `found: false` for the symbol
    every locking question in that repository runs through.

    THE DECLARATION LINE IS THE POINT, not the row. doxygen records no `initializer` for
    those pointers, so the binding lives only in the source text at `memberdef.line` —
    which `body_excerpt` could never reach, because a variable has no `bodystart`.

    @brief A variable subject carries its sites and the source line each is declared on.
    @return None.
    @version 1
    """
    reply = tools.dossier(DM_MUTEX, kind="variable")
    assert reply["subject_kind"] == "variable"
    assert reply["sites"], "a variable subject must name where it is declared"
    site = reply["sites"][0]
    assert site["file"].endswith("dm.c")
    assert site["static"] is True
    text = " ".join(site["declaration"]["lines"])
    assert "PTHREAD_MUTEX_INITIALIZER" in text, (
        "the declaration excerpt must carry the initializer, which is the only place the "
        "binding is recorded"
    )

    ## ABSENCE, NOT EMPTINESS. A variable has no body, no callers and no callees, and the
    ## payload says so by not having the fields — an empty `callers: []` here would be a
    ## measurement of something that was never measurable.
    for field in ("callers", "callees", "body", "liveness", "threads"):
        assert field not in reply, f"a variable payload must not carry {field!r}"

Activity · 10 steps
lines 210–210reply = tools.dossier(DM_MUTEX, kind="variable")lines 211–211assert reply["subject_kind"] == "variable"lines 212–212assert reply["sites"], "a variable subject must name where it is declared"lines 213–213site = reply["sites"][0]lines 214–214assert site["file"].endswith("dm.c")lines 215–215assert site["static"] is Truelines 216–216text = " ".join(site["declaration"]["lines"])lines 217–220assert "PTHREAD_MUTEX_INITIALIZER" in text, ( "the declaration excerpt must carry the initializer, which is the only place the " "binding is recorded" )lines 225–225◇ for field in ("callers", "callees", "body", "liveness", "threads")lines 226–226assert field not in reply, f"a variable payload must not carry {field!r}"

test_an_inventory_corpus_keeps_its_envelope_rather_than_becoming_rows

None test_subject_surface.test_an_inventory_corpus_keeps_its_envelope_rather_than_becoming_rows(QueryTools tools)

The lock corpus answers with the inventory envelope, not a row list.

tests/test_subject_surface.py:449

Show on the map →

Called by none

Calls none

Checks

  • assert key in reply, f"the lock inventory lost {key!r} on the way through search"
  • assert "results" not in reply, "an inventory is not a row list"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-003measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-011measured
Source · 22 lines
def test_an_inventory_corpus_keeps_its_envelope_rather_than_becoming_rows(
    tools: QueryTools,
) -> None:
    """THE TWO CORPUS SHAPES ARE NOT NORMALISED, deliberately. Flattening an inventory
    into `_many` rows would drop `distinct_mutexes`, `row_meaning` and `origin` — the
    exact fields that stop a row count being reported as a mutex count, which an
    acceptance rubric grades. A tidier uniform shape would have made the graded error
    easier to commit.

    @brief The lock corpus answers with the inventory envelope, not a row list.
    @return None.
    @version 1
    """
    reply = tools.search(corpus="locks")
    for key in ("locks", "rows", "distinct_mutexes", "row_meaning", "origin", "nestings"):
        assert key in reply, f"the lock inventory lost {key!r} on the way through search"
    assert "results" not in reply, "an inventory is not a row list"


# ─── the `index` lifecycle tool ──────────────────────────────────────────────

Activity · 4 steps
lines 462–462reply = tools.search(corpus="locks")lines 463–463◇ for key in ("locks", "rows", "distinct_mutexes", "row_meaning", "origin", "nestings")lines 464–464assert key in reply, f"the lock inventory lost {key!r} on the way through search"lines 465–465assert "results" not in reply, "an inventory is not a row list"

test_an_unindexed_name_resolves_to_nothing

None test_subject_surface.test_an_unindexed_name_resolves_to_nothing(Path rich_db)

An unknown name classifies as no kind at all.

tests/test_subject_surface.py:129

Checks

  • assert q.resolve_subject(rich_db, "no_such_symbol_anywhere_xyz") == ()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_an_unindexed_name_resolves_to_nothing → resolve_subject → connect
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
Source · 11 lines
def test_an_unindexed_name_resolves_to_nothing(rich_db: Path) -> None:
    """The negative half. A classifier that returned a kind for every string would make
    `dossier` answer confidently about names the index has never seen.

    @brief An unknown name classifies as no kind at all.
    @return None.
    @version 1
    """
    assert q.resolve_subject(rich_db, "no_such_symbol_anywhere_xyz") == ()

Activity · 1 steps
lines 137–137assert q.resolve_subject(rich_db, "no_such_symbol_anywhere_xyz") == ()

test_an_unknown_index_action_is_refused_by_name

None test_subject_surface.test_an_unknown_index_action_is_refused_by_name(Path tmp_path)

An unknown `action` raises and names the known ones.

tests/test_subject_surface.py:523

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_an_unknown_index_action_is_refused_by_name → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_an_unknown_index_action_is_refused_by_name → build_server → _refusal_as_tool_error
REQ-DDB-WIKI-034measuredtest_an_unknown_index_action_is_refused_by_name → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 18 lines
async def test_an_unknown_index_action_is_refused_by_name(tmp_path: Path) -> None:
    """Fail closed, list the allowed set, and say where a CODE question goes instead —
    `index` is the tool a model reaches for when it has confused administering the index
    with querying it.

    @brief An unknown `action` raises and names the known ones.
    @return None.
    @version 1
    """
    from clew.mcp_server import state as st
    from clew.mcp_server.server import build_server

    _mcp, state = build_server(st.TargetRegistry(tmp_path / "state"))
    with pytest.raises(ValueError, match="Unknown index action"):
        await state.index(None, action="statuses")


@pytest.mark.anyio

test_an_unknown_subject_kind_is_refused_by_name

None test_subject_surface.test_an_unknown_subject_kind_is_refused_by_name(QueryTools tools)

An unknown `kind` raises and names the known ones.

tests/test_subject_surface.py:275

Show on the map →

Called by none

Calls none

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-003measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-014measured
Source · 13 lines
def test_an_unknown_subject_kind_is_refused_by_name(tools: QueryTools) -> None:
    """Fail closed and list the allowed set, the same contract the declaration loader has.
    A misspelled kind that fell through to the default would answer about a function under
    a heading the caller never asked for.

    @brief An unknown `kind` raises and names the known ones.
    @return None.
    @version 1
    """
    with pytest.raises(ValueError, match="Unknown subject kind"):
        tools.dossier("app_run", kind="functions")

Activity · 2 steps
lines 284–284with pytest.raises(ValueError, match="Unknown subject kind")lines 285–285tools.dossier("app_run", kind="functions")

test_depth_above_the_bound_is_refused_not_clamped

None test_subject_surface.test_depth_above_the_bound_is_refused_not_clamped(QueryTools tools)

A depth over `MAX_SUBJECT_DEPTH` raises and states the bound.

tests/test_subject_surface.py:400

Show on the map →

Called by none

Calls none

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-003measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-014measured
Source · 16 lines
def test_depth_above_the_bound_is_refused_not_clamped(tools: QueryTools) -> None:
    """REFUSED, for the reason every cap on this surface refuses: a clamped depth answers
    three hops to a request for eight and reports no difference, which is the
    silent-degradation failure the `_limited` disclosures exist to convert into a
    measurement.

    @brief A depth over `MAX_SUBJECT_DEPTH` raises and states the bound.
    @return None.
    @version 1
    """
    with pytest.raises(ValueError, match="depth must be between"):
        tools.dossier("app_run", depth=q.MAX_SUBJECT_DEPTH + 1)
    with pytest.raises(ValueError, match="depth must be between"):
        tools.dossier("app_run", depth=0)

Activity · 4 steps
lines 410–410with pytest.raises(ValueError, match="depth must be between")lines 411–411tools.dossier("app_run", depth=q.MAX_SUBJECT_DEPTH + 1)lines 412–412with pytest.raises(ValueError, match="depth must be between")lines 413–413tools.dossier("app_run", depth=0)

test_depth_one_carries_no_chain_and_deeper_does

None test_subject_surface.test_depth_one_carries_no_chain_and_deeper_does(QueryTools tools)

Depth 1 is adjacency; depth > 1 adds the bounded chain.

tests/test_subject_surface.py:379

Show on the map →

Called by none

Calls chain_trace, one

Checks

  • assert "chain" not in tools.dossier("app_run")
  • assert deep["chain"]["nodes"], "a depth > 1 request must actually traverse"
  • assert deep["chain"] == wire.one(q.chain_trace(tools.db(), "app_run", max_depth=3))

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_depth_one_carries_no_chain_and_deeper_does → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-MCP-003measured
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-011measured
REQ-DDB-QUERY-001measuredtest_depth_one_carries_no_chain_and_deeper_does → one
REQ-DDB-QUERY-002measuredtest_depth_one_carries_no_chain_and_deeper_does → chain_trace
REQ-DDB-QUERY-003measuredtest_depth_one_carries_no_chain_and_deeper_does → chain_trace → function_candidates
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-005measuredtest_depth_one_carries_no_chain_and_deeper_does → chain_trace → _make_node
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-009measured
REQ-DDB-QUERY-010measuredtest_depth_one_carries_no_chain_and_deeper_does → chain_trace → function_candidates
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-014measured
REQ-DDB-SCHEMA-011measured
Source · 21 lines
def test_depth_one_carries_no_chain_and_deeper_does(tools: QueryTools) -> None:
    """`chain_trace` was a separate tool and is now a depth. Depth 1 must stay exactly
    what it was — adjacency, no traversal, no extra bytes — or every existing call pays
    for a walk it did not ask for.

    @brief Depth 1 is adjacency; depth > 1 adds the bounded chain.
    @return None.
    @version 1
    """
    from clew import wire

    assert "chain" not in tools.dossier("app_run")
    deep = tools.dossier("app_run", depth=3)
    assert deep["chain"]["nodes"], "a depth > 1 request must actually traverse"
    ## Compared against `chain_trace` ITSELF, not merely checked for shape: the fold's
    ## whole claim is that it reuses that walk — its fan-out taper, its cycle handling and
    ## its non-fuzzy-edges-only rule — rather than being a second traversal with a second
    ## set of bounds to get wrong.
    assert deep["chain"] == wire.one(q.chain_trace(tools.db(), "app_run", max_depth=3))

Activity · 5 steps
lines 388–388from clew import wirelines 390–390assert "chain" not in tools.dossier("app_run")lines 391–391deep = tools.dossier("app_run", depth=3)lines 392–392assert deep["chain"]["nodes"], "a depth > 1 request must actually traverse"lines 397–397assert deep["chain"] == wire.one(q.chain_trace(tools.db(), "app_run", max_depth=3))

test_every_builders_section_is_reachable_through_the_envelope

None test_subject_surface.test_every_builders_section_is_reachable_through_the_envelope()

Every `_BUILDERS` section key round-trips through `SubjectDossier.section`.

tests/test_subject_surface.py:74

Show on the map →

Called by none

Calls none

Checks

  • assert "enumeration" in sections, "the section this test was written for"
  • assert built.section is sentinel, f"section {name!r} is populated but unreachable"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measured
Source · 34 lines
def test_every_builders_section_is_reachable_through_the_envelope() -> None:
    """THE THIRD PARITY, and its absence was a SHIPPED defect. `SubjectDossier.section` is
    what `_flatten_subject` reads to build the MCP payload, and it returned None for the
    whole `enumeration` kind — so `dossier("ent_decision_t")` over MCP answered
    `found: false` on a symbol carrying a brief, a body span and its enumerators, which is
    gh#6's fix being inert on the very surface gh#6 was filed against. Worse than the
    original: `unresolved_kinds` no longer names `enumeration` (it IS a subject kind now),
    so the reply lost its coverage-limitation clause and became a BARE definitive negative.

    `section`'s own docstring already promised this could not happen — "a section added to
    this dataclass is found without a second edit somewhere else" — while the code it
    documented was a hand-written tuple that the eighth section was simply left out of. A
    claim in a docstring is not a mechanism.

    IT ASSERTS THE KEY, NOT THE COUNT. A count passes the day someone adds a section and
    removes another, and this is exactly the edit that gets forgotten.

    @brief Every `_BUILDERS` section key round-trips through `SubjectDossier.section`.
    @return None.
    @version 1
    """
    from dataclasses import fields

    from clew.query.models import SubjectDossier

    envelope = {"subject", "kind", "also", "chain"}
    sections = [f.name for f in fields(SubjectDossier) if f.name not in envelope]
    assert "enumeration" in sections, "the section this test was written for"
    for name in sections:
        sentinel = object()
        built = SubjectDossier(subject="x", kind="x", **{name: sentinel})
        assert built.section is sentinel, f"section {name!r} is populated but unreachable"

Activity · 9 steps
lines 95–95from dataclasses import fieldslines 97–97from clew.query.models import SubjectDossierlines 99–99envelope = {"subject", "kind", "also", "chain"}lines 100–100sections = [f.name for f in fields(SubjectDossier) if f.name not in envelope]lines 101–101assert "enumeration" in sections, "the section this test was written for"lines 102–102◇ for name in sectionslines 103–103sentinel = object()lines 104–104built = SubjectDossier(subject="x", kind="x", **{name: sentinel})lines 105–105assert built.section is sentinel, f"section {name!r} is populated but unreachable"

test_every_declared_corpus_answers

None test_subject_surface.test_every_declared_corpus_answers(QueryTools tools)

Every entry in `CORPORA` returns an attributed envelope.

tests/test_subject_surface.py:435

Show on the map →

Called by none

Calls none

Checks

  • assert isinstance(reply, dict), corpus
  • assert "target" in reply, f"{corpus} must name the repository it answered from"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-MCP-003measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-002measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-011measured
REQ-DDB-QUERY-014measured
REQ-DDB-SCHEMA-011measured
Source · 14 lines
def test_every_declared_corpus_answers(tools: QueryTools) -> None:
    """Same table-parity argument as the subject kinds, one tool over: a corpus named in
    the dispatch that raises is a documented argument nothing can use.

    @brief Every entry in `CORPORA` returns an attributed envelope.
    @return None.
    @version 1
    """
    for corpus in CORPORA:
        reply = tools.search("dm", corpus=corpus)
        assert isinstance(reply, dict), corpus
        assert "target" in reply, f"{corpus} must name the repository it answered from"

Activity · 4 steps
lines 443–443◇ for corpus in CORPORAlines 444–444reply = tools.search("dm", corpus=corpus)lines 445–445assert isinstance(reply, dict), corpuslines 446–446assert "target" in reply, f"{corpus} must name the repository it answered from"

test_index_stamps_the_action_that_produced_the_reply

None test_subject_surface.test_index_stamps_the_action_that_produced_the_reply(Path tmp_path)

Every `index` reply carries the `action` that produced it.

tests/test_subject_surface.py:496

Checks

  • assert listed["action"] == "targets"
  • assert listed["results"] == [], "an empty registry lists nothing, in the wrapped shape"
  • assert reported["action"] == "status", "the mapping-shaped result must survive the stamp"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_index_stamps_the_action_that_produced_the_reply → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_index_stamps_the_action_that_produced_the_reply → build_server → _refusal_as_tool_error
REQ-DDB-WIKI-034measuredtest_index_stamps_the_action_that_produced_the_reply → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 27 lines
async def test_index_stamps_the_action_that_produced_the_reply(tmp_path: Path) -> None:
    """A DISPATCHING TOOL WHOSE RESULT DOES NOT SAY WHICH BRANCH RAN is a payload a caller
    has to identify by shape, and two of these five return a bare mapping. The stamp is
    added in ONE place for exactly that reason — five returns each remembering to do it is
    how one branch ships unstamped.

    `list_targets` returns a LIST, so the wrapping is asymmetric; both shapes are asserted
    because the asymmetry is where a stamp goes missing.

    @brief Every `index` reply carries the `action` that produced it.
    @return None.
    @version 1
    """
    from clew.mcp_server import state as st
    from clew.mcp_server.server import build_server

    _mcp, state = build_server(st.TargetRegistry(tmp_path / "state"))
    listed = await state.index(None, action="targets")
    assert listed["action"] == "targets"
    assert listed["results"] == [], "an empty registry lists nothing, in the wrapped shape"

    ## 2.0.0: `cull` retired; `status` is the remaining mapping-shaped result.
    reported = await state.index(None, action="status")
    assert reported["action"] == "status", "the mapping-shaped result must survive the stamp"


@pytest.mark.anyio

test_no_index_action_answers_about_a_repository_it_was_not_asked_about

None test_subject_surface.test_no_index_action_answers_about_a_repository_it_was_not_asked_about(Path tmp_path)

No index action may silently answer about a target other than the one asked for.

tests/test_subject_surface.py:541

Checks

  • assert asked_about in str(exc), (f"{action!r} refused, but did not name the target it could not honour" )
  • assert asked_about in str(reply), (f"index(action={action!r}, target=...) answered without naming the target it " f"was asked about — so it silently answered about {adopted} instead" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-008measured
REQ-DDB-MCP-001measuredtest_no_index_action_answers_about_a_repository_it_was_not_asked_about → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_no_index_action_answers_about_a_repository_it_was_not_asked_about → build_server → _refusal_as_tool_error
REQ-DDB-WIKI-034measuredtest_no_index_action_answers_about_a_repository_it_was_not_asked_about → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 59 lines
async def test_no_index_action_answers_about_a_repository_it_was_not_asked_about(
    tmp_path: Path,
) -> None:
    """THE GUARD THAT WOULD HAVE CAUGHT THE SILENT DROP, and it is structural on purpose.
    `target` was in scope on the `status`, `targets` and `cull` branches of `_index_action`
    and simply never passed on, so `unknown_target_error` was UNREACHABLE from all three —
    there was no error path because nothing on those branches ever resolved the string.

    Measured before the fix: asking `status` about a second repository returned the FIRST
    one's `repo_path`, build version, coverage and staleness, with no error and no mention
    that the target had been dropped. That is the class of defect that voided a 36-cell
    acceptance grid, where every validity term checked that the agent called database tools
    and none checked that the database held the right repository.

    THE ASSERTION IS A DISJUNCTION BECAUSE TWO ANSWERS ARE CORRECT and one is not: an action
    may honour the target, or refuse it by name. What it may not do is answer about something
    else. Written this way the test survives a later decision to thread `target` into
    `status` properly, and it covers any action added to `INDEX_ACTIONS` afterwards without
    being edited — which is what the suite's existing completeness sweep cannot do, because
    `test_mcp_routing` asserts over `TIER1_TOOLS` and `index` is tier 0.

    Its negative half is built in rather than written separately: `refresh` already REPORTS a
    refusal naming the target and `stats` already RAISES one, so two of the five branches must
    pass unchanged. A version of this test that everything failed would not distinguish "the
    three droppers are broken" from "my probe is wrong".

    @brief No index action may silently answer about a target other than the one asked for.
    @return None.
    @version 1
    """
    from clew.mcp_server import state as st
    from clew.mcp_server.server import INDEX_ACTIONS, build_server
    from clew.mcp_server.state import TARGET_SOURCE_FLAG

    _mcp, state = build_server(st.TargetRegistry(tmp_path / "state"))
    ## An ADOPTED target is what makes this reproduce the measured defect rather than a
    ## no-target marker: the wrong answer is another repository's status, not an absence.
    adopted = tmp_path / "repo_a"
    adopted.mkdir()
    state.adopt(str(adopted), TARGET_SOURCE_FLAG)

    ## Deliberately never created, so no branch can start a doxygen run over it.
    asked_about = str(tmp_path / "repo_b_never_existed")

    for action in INDEX_ACTIONS:
        try:
            reply = await state.index(_FakeCtx(), action=action, target=asked_about)
        except (ValueError, RuntimeError) as exc:
            assert asked_about in str(exc), (
                f"{action!r} refused, but did not name the target it could not honour"
            )
            continue
        assert asked_about in str(reply), (
            f"index(action={action!r}, target=...) answered without naming the target it "
            f"was asked about — so it silently answered about {adopted} instead"
        )


@pytest.mark.anyio

test_the_declaration_excerpt_stops_at_the_statement_terminator

None test_subject_surface.test_the_declaration_excerpt_stops_at_the_statement_terminator(Path rich_db, Path repo_root)

The declaration excerpt covers one statement and reports its own bound.

tests/test_subject_surface.py:229

Checks

  • assert excerpt is not None
  • assert excerpt.total_lines == 1, "a one-line declaration must not drag in its neighbours"
  • assert excerpt.truncated is False
  • assert excerpt.lines[0].rstrip().endswith(";")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_the_declaration_excerpt_stops_at_the_statement_terminator → declaration_excerpt
REQ-DDB-QUERY-003measuredtest_the_declaration_excerpt_stops_at_the_statement_terminator → declaration_excerpt → _recorded_end → table_exists
Source · 32 lines
def test_the_declaration_excerpt_stops_at_the_statement_terminator(
    rich_db: Path, repo_root: Path
) -> None:
    """The excerpt is a bounded window cut at the first `;`, and `truncated` says when the
    bound was reached first. Pinned because it is a HEURISTIC: a `;` inside a string
    literal ends it early, and the cost of that has to stay "a short excerpt", never a
    wrong file or a wrong line.

    @brief The declaration excerpt covers one statement and reports its own bound.
    @return None.
    @version 1
    """
    import sqlite3

    conn = sqlite3.connect(str(rich_db))
    try:
        rowid = conn.execute(
            "SELECT rowid FROM memberdef WHERE name=? AND kind='variable'", (DM_MUTEX,)
        ).fetchone()[0]
        excerpt = q.declaration_excerpt(conn, rowid, repo_root)
    finally:
        conn.close()

    assert excerpt is not None
    assert excerpt.total_lines == 1, "a one-line declaration must not drag in its neighbours"
    assert excerpt.truncated is False
    assert excerpt.lines[0].rstrip().endswith(";")


# ─── `kind` filters, and never relabels ──────────────────────────────────────

Activity · 9 steps
lines 241–241import sqlite3lines 243–243conn = sqlite3.connect(str(rich_db))lines 244–244trylines 245–247rowid = conn.execute( "SELECT rowid FROM memberdef WHERE name=? AND kind='variable'", (DM_MUTEX,) ).fetchone()[0]lines 248–248excerpt = q.declaration_excerpt(conn, rowid, repo_root)lines 252–252assert excerpt is not Nonelines 253–253assert excerpt.total_lines == 1, "a one-line declaration must not drag in its neighbours"lines 254–254assert excerpt.truncated is Falselines 255–255assert excerpt.lines[0].rstrip().endswith(";")

test_the_exported_dossier_answers_about_a_non_function_subject

None test_subject_surface.test_the_exported_dossier_answers_about_a_non_function_subject(Path rich_db)

The exported dossier must be the any-kind form, and function_dossier the narrow one.

tests/test_subject_surface.py:650

Checks

  • assert req is not None, "precondition: the fixture must hold at least one requirement edge"
  • assert wide is not None and wide.kind == "requirement", (f"the exported `dossier` returned {wide!r} for requirement {req.req_id!r}; it must be " f"the any-kind form, matching the MCP tool that shares its name" )
  • assert q.function_dossier(rich_db, req.req_id) is None, ("`function_dossier` must stay the narrow form — if it answers about a requirement too, " "the two exported names describe one behaviour and the distinction is undocumented" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier → connect
REQ-DDB-QUERY-002inferredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_the_exported_dossier_answers_about_a_non_function_subject → all_req_edges → table_exists
REQ-DDB-QUERY-004measuredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier
REQ-DDB-QUERY-005inferredtest_the_exported_dossier_answers_about_a_non_function_subject → dossier → _chain_for → chain_trace → _make_node
REQ-DDB-QUERY-006inferredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier
REQ-DDB-QUERY-010measuredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier
REQ-DDB-QUERY-012measuredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013measuredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-011inferredtest_the_exported_dossier_answers_about_a_non_function_subject → function_dossier → _dossier_conn → locks_held_for_rowids
REQ-DDB-SCHEMA-015measured
REQ-DDB-WIKI-054inferredtest_the_exported_dossier_answers_about_a_non_function_subject → dossier → _rank_enum_over_mirror → _class_side_is_only_enum_mirrors → all
Source · 28 lines
def test_the_exported_dossier_answers_about_a_non_function_subject(rich_db: Path) -> None:
    """`clew.query.dossier` was the FUNCTION-ONLY form while the MCP tool of the same name
    described any indexed kind, so the documented `from clew.query import dossier` returned
    `None` for a requirement, lock, thread, class or variable — and `None` is also what "not
    indexed" looks like, so the weaker function was indistinguishable from an empty index.

    Both directions are asserted. Checking only that `dossier` handles a requirement would
    still pass if `function_dossier` were quietly widened to the same thing, leaving two names
    for one behaviour and nothing recording which the tool layer is a view over.

    @brief `dossier` takes any subject kind; `function_dossier` takes functions.
    @return None.
    @version 1
    """
    req = next(iter(q.all_req_edges(rich_db)), None)
    assert req is not None, "precondition: the fixture must hold at least one requirement edge"

    wide = q.dossier(rich_db, req.req_id)
    assert wide is not None and wide.kind == "requirement", (
        f"the exported `dossier` returned {wide!r} for requirement {req.req_id!r}; it must be "
        f"the any-kind form, matching the MCP tool that shares its name"
    )
    assert q.function_dossier(rich_db, req.req_id) is None, (
        "`function_dossier` must stay the narrow form — if it answers about a requirement too, "
        "the two exported names describe one behaviour and the distinction is undocumented"
    )

Activity · 5 steps
lines 664–664req = next(iter(q.all_req_edges(rich_db)), None)lines 665–665assert req is not None, "precondition: the fixture must hold at least one requirement edge"lines 667–667wide = q.dossier(rich_db, req.req_id)lines 668–671assert wide is not None and wide.kind == "requirement", ( f"the exported `dossier` returned {wide!r} for requirement {req.req_id!r}; it must be " f"the any-kind form, matching the MCP tool that shares its name" )lines 672–675assert q.function_dossier(rich_db, req.req_id) is None, ( "`function_dossier` must stay the narrow form — if it answers about a requirement too, " "the two exported names describe one behaviour and the distinction is undocumented" )

test_the_registry_wide_actions_refuse_a_target_and_still_answer_without_one

None test_subject_surface.test_the_registry_wide_actions_refuse_a_target_and_still_answer_without_one(Path tmp_path)

The registry-wide actions refuse a target by name, and still work without one.

tests/test_subject_surface.py:600

Checks

  • assert str(real) in message, "the refusal must name the target it will not honour"
  • assert action in message, "and which action refused it"
  • assert listed["results"] == [], "an empty registry still lists, in the wrapped shape"
  • assert "error" in reported or reported.get("active") is True, ("status still reports on the derived target, or says plainly there is none" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_the_registry_wide_actions_refuse_a_target_and_still_answer_without_one → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_the_registry_wide_actions_refuse_a_target_and_still_answer_without_one → build_server → _refusal_as_tool_error
REQ-DDB-WIKI-034measuredtest_the_registry_wide_actions_refuse_a_target_and_still_answer_without_one → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 46 lines
async def test_the_registry_wide_actions_refuse_a_target_and_still_answer_without_one(
    tmp_path: Path,
) -> None:
    """The chosen resolution, pinned: `status`, `targets` and `cull` REFUSE a supplied target
    rather than honouring it. That is not a stopgap — two of the three have no per-target
    meaning to honour. `cull` is a registry-wide sweep, and `targets` IS the registry
    listing; a target argument on either is a category error, not an unimplemented feature.

    `status` could be threaded properly and deliberately is not yet: doing so needs a
    `target_source` value meaning "named on this call", a decision about what `active` and
    `tier1_registered` report for a routed reply, and a slug→path inverse that does not exist
    (`target_for` is path→slug only). Refusing closes the silent wrong answer without any of
    that.

    THE SECOND HALF IS THE LOAD-BEARING ONE. A refusal that also broke the ordinary
    no-target call would trade a wrong answer for no answer, and a test asserting only the
    raise would call that a fix.

    @brief The registry-wide actions refuse a target by name, and still work without one.
    @return None.
    @version 1
    """
    from clew.mcp_server import state as st
    from clew.mcp_server.server import build_server

    _mcp, state = build_server(st.TargetRegistry(tmp_path / "state"))
    ## A REAL directory, so the refusal cannot be the unknown-target path in disguise.
    real = tmp_path / "an_actual_directory"
    real.mkdir()

    for action in ("status", "targets"):  # 2.0.0: `cull` retired to the CLI
        with pytest.raises(ValueError) as exc:
            await state.index(_FakeCtx(), action=action, target=str(real))
        message = str(exc.value)
        assert str(real) in message, "the refusal must name the target it will not honour"
        assert action in message, "and which action refused it"

    ## The other half: omitted, every one of them still answers.
    listed = await state.index(_FakeCtx(), action="targets")
    assert listed["results"] == [], "an empty registry still lists, in the wrapped shape"
    reported = await state.index(_FakeCtx(), action="status")
    assert "error" in reported or reported.get("active") is True, (
        "status still reports on the derived target, or says plainly there is none"
    )

Activity · 15 steps
lines 622–622from clew.mcp_server import state as stlines 623–623from clew.mcp_server.server import build_serverlines 625–625_mcp, state = build_server(st.TargetRegistry(tmp_path / "state"))lines 627–627real = tmp_path / "an_actual_directory"lines 628–628real.mkdir()lines 630–630◇ for action in ("status", "targets"): # 2.0.0: `cull` retired to the CLIlines 631–631with pytest.raises(ValueError) as exclines 632–632await state.index(_FakeCtx(), action=action, target=str(real))lines 633–633message = str(exc.value)lines 634–634assert str(real) in message, "the refusal must name the target it will not honour"lines 635–635assert action in message, "and which action refused it"lines 638–638listed = await state.index(_FakeCtx(), action="targets")lines 639–639assert listed["results"] == [], "an empty registry still lists, in the wrapped shape"lines 640–640reported = await state.index(_FakeCtx(), action="status")lines 641–643assert "error" in reported or reported.get("active") is True, ( "status still reports on the derived target, or says plainly there is none" )