test_lock_roster_separates_the_mutex_count_from_the_row_count

Tests › tests/test_mcp_server.py

passed Passed in the packaged run.

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

  1. db = tmp_path / "clew.db"
  2. conn = sqlite3.connect(str(db))
7 more
  1. 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 ); """ )
  2. conn.execute("INSERT INTO path (rowid, name) VALUES (1, 'src/engine.cpp')")
  3. conn.execute("INSERT INTO memberdef (rowid, name) VALUES (1, 'poll')")
  4. 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), ], )
  5. 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)], )
  6. conn.commit()
  7. conn.close()
→

When

  1. inv = q.lock_roster(db)
→

Then

  1. ✓ inv.rows equals 3
  2. ✓ inv.distinct_mutexes equals 2
  3. ✓ inv.row_meaning contains "3 row(s) over 2 distinct lock identity(ies)"
  4. ✓ inv.row_meaning contains "distinct_mutexes"
  5. ✓ inv.locks[0].acquisitions equals 2
  6. ✓ 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

command-line usercommand-line usercommand-line usercommand-line userclew/query/symbols.pyclew/query/symbols.pyclew/query/symbols.pyclew/query/symbols.pyclew/query/_common.pyclew/query/_common.pyclew/query/_common.pyclew/query/_common.pyloop (line 1576)loopmain216. _memberdef_corpora → _expansion_sql216_expansion_sql217. _expansion_sql → has_columns217has_columns218. has_columns → table_exists218table_exists219. _memberdef_corpora → _memberdef_candidates219_memberdef_candidates220. _memberdef_candidates → table_exists220table_exists

… 125 steps between

command-line usercommand-line usercommand-line usercommand-line userclew/query/_common.pyclew/query/_common.pyclew/query/_common.pyclew/query/_common.pyother filesother filesother filesother filesloop ×2 (line 555)loop ×2main346. _files_corpus → files_miss346files_miss347. corpus_payload → lock_roster347lock_roster348. lock_roster → connect348connect▶ test enters349. lock_roster → table_exists349table_exists350–351. lock_roster → _entries350_entries +1 more352. _roster_sql → has_columns352has_columns353–354. lock_roster → nestings_on353nestings_on +1 more355. _layer_present → table_exists355table_exists356. nestings_on → table_exists356table_exists357–360. lock_roster → _nesting_pairs357_nesting_pairs +3 more361–362. corpus_payload → one361one ×2

… 38 later steps

2 more

tests/test_mcp_server.py:3104 · its file's page

What it checks (6)

  1. assert inv.rows == 3, "three identities" observes lock_roster via inv
  2. assert inv.distinct_mutexes == 2, "but two physical mutexes — the collapse must fire" observes lock_roster via inv
  3. assert "3 row(s) over 2 distinct lock identity(ies)" in inv.row_meaning observes lock_roster via inv
  4. assert "distinct_mutexes" in inv.row_meaning, "the field must still be explained by name" observes lock_roster via inv
  5. assert inv.locks[0].acquisitions == 2 observes lock_roster via inv
  6. assert sorted(e.acquisitions for e in inv.locks) == [0, 1, 2] observes lock_roster via inv

Where the product reaches it

  • main → query_main → _payload → export_search → corpus_payload → lock_roster (flow)

Call flow

test_lock_roster_separates_the_mutex_count_from_the_row_count→lock_roster

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.

test_lock_roster_separates_the_mutex_count_from_the_row_count · 6 checkslock_rosterREQ-DDB-QUERY-001 · measuredlock_rostertable_existsREQ-DDB-QUERY-003 · measuredlock_rosterREQ-DDB-QUERY-011 · measuredlock_rosternestings_onREQ-DDB-SCHEMA-011 · measured

Requirements it verifies (5)

requirementlinked byimplementers exercised
REQ-DDB-MCP-001catalogunknown
REQ-DDB-MCP-003catalogunknown
REQ-DDB-QUERY-006catalogunknown
REQ-DDB-QUERY-008catalogunknown
REQ-DDB-QUERY-009catalogunknown
Also reaches 4 requirements

Its run touches their code; that is reach, not proof.