test_lock_roster_separates_the_mutex_count_from_the_row_count¶
Tests › tests/test_mcp_server.py
What this test is for
Why it exists
THE TRAP THE OBVIOUS SHAPE WOULD HAVE SET. `locks` is keyed UNIQUE(name, scope, kind), so one `std::shared_mutex` taken with both a `lock_guard` and a `shared_lock` occupies TWO rows. A roster returning only rows invites "the codebase has len(rows) mutexes", and an acceptance rubric grades refusing exactly that conflation — so a convenience tool that returned rows alone would have made its own graded error easier to commit rather than harder.
Verifies REQ-DDB-MCP-001 REQ-DDB-MCP-003 REQ-DDB-QUERY-006 REQ-DDB-QUERY-008 REQ-DDB-QUERY-009
Given
db = tmp_path / "clew.db"conn = sqlite3.connect(str(db))
7 more
conn.executescript( """ CREATE TABLE path (name TEXT); CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, name TEXT); CREATE TABLE locks ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, scope TEXT NOT NULL, kind TEXT NOT NULL, decl_path_rowid INTEGER, decl_line INTEGER, identity_confidence TEXT NOT NULL, source TEXT NOT NULL, UNIQUE(name, scope, kind) ); CREATE TABLE lock_acquisitions ( id INTEGER PRIMARY KEY, lock_id INTEGER, holder_rowid INTEGER, path_rowid INTEGER, form TEXT, role TEXT, mode TEXT, start_line INTEGER, end_line INTEGER, pattern_name TEXT, declared INTEGER, confidence TEXT ); """ )conn.execute("INSERT INTO path (rowid, name) VALUES (1, 'src/engine.cpp')")conn.execute("INSERT INTO memberdef (rowid, name) VALUES (1, 'poll')")conn.executemany( "INSERT INTO locks (id, name, scope, kind, decl_path_rowid, decl_line, " "identity_confidence, source) VALUES (?, ?, ?, ?, 1, ?, 'high', 'ast')", [ (1, "mutex_", "class:Registry", "shared_mutex", 10), (2, "mutex_", "class:Registry", "mutex", 10), ## A DIFFERENT mutex that shares the bare member name, so a collapse on ## `name` alone would wrongly merge it into the pair above. (3, "mutex_", "class:Cache", "mutex", 44), ], )conn.executemany( "INSERT INTO lock_acquisitions (lock_id, holder_rowid, path_rowid, form, role, " "mode, start_line, pattern_name, declared, confidence) " "VALUES (?, 1, 1, 'raii', 'scoped', 'exclusive', ?, 'lock_guard', 0, 'high')", [(1, 11), (1, 12), (3, 45)], )conn.commit()conn.close()
When
inv = q.lock_roster(db)
Then
- ✓ inv.rows equals 3
- ✓ inv.distinct_mutexes equals 2
- ✓ inv.row_meaning contains "3 row(s) over 2 distinct lock identity(ies)"
- ✓ inv.row_meaning contains "distinct_mutexes"
- ✓ inv.locks[0].acquisitions equals 2
- ✓ sorted(e.acquisitions for e in inv.locks) equals [0, 1, 2]
What it exercises
The parts of the system's flows this test ran, measured by per-test coverage: lit steps ran in this test, dimmed ones did not, and ▶ marks where the test called in. Each title opens the whole flow with these steps lit.
clew — `main` (clew/cli.py) · 14 of 400 steps
… 215 earlier steps
… 125 steps between
… 38 later steps
2 more
- `main` (scripts/export_parity.py) · 14 of 203 steps
- Look up one name: everything the index holds about it · 1 of 226 steps
tests/test_mcp_server.py:3104 · its file's page
What it checks (6)
assert inv.rows == 3, "three identities"observeslock_rosterviainvassert inv.distinct_mutexes == 2, "but two physical mutexes — the collapse must fire"observeslock_rosterviainvassert "3 row(s) over 2 distinct lock identity(ies)" in inv.row_meaningobserveslock_rosterviainvassert "distinct_mutexes" in inv.row_meaning, "the field must still be explained by name"observeslock_rosterviainvassert inv.locks[0].acquisitions == 2observeslock_rosterviainvassert sorted(e.acquisitions for e in inv.locks) == [0, 1, 2]observeslock_rosterviainv
Where the product reaches it
main→query_main→_payload→export_search→corpus_payload→lock_roster(flow)
Call flow
What it reaches
Each row runs from this test, through the calls it makes, to the code a requirement names. If that code breaks, the test's checks are what should catch it. Reaching is not proving: a check only proves what it observes. No mutation records were given, so these rows say what the test REACHES.
Requirements it verifies (5)
| requirement | linked by | implementers exercised |
|---|---|---|
| REQ-DDB-MCP-001 | catalog | unknown |
| REQ-DDB-MCP-003 | catalog | unknown |
| REQ-DDB-QUERY-006 | catalog | unknown |
| REQ-DDB-QUERY-008 | catalog | unknown |
| REQ-DDB-QUERY-009 | catalog | unknown |
Also reaches 4 requirements
Its run touches their code; that is reach, not proof.
- REQ-DDB-QUERY-001 measured
- REQ-DDB-QUERY-003 measured
- REQ-DDB-QUERY-011 measured
- REQ-DDB-SCHEMA-011 measured