test_db_status_detects_source_drift

Tests › tests/test_mcp_server.py

passed Passed in the packaged run.

What this test is for

Why it exists

#43: staleness used to be `stamped != CLEW_BUILD_VERSION` and nothing else, so a database built before any number of source edits still reported `stale: false` — and because build_or_refresh short-circuits on that flag, it REFUSED to rebuild. An agent then answered from a graph describing code that no longer existed, with `status` asserting the index was current. A version check cannot see source drift; only mtimes can.

Verifies REQ-DDB-MCP-003 REQ-DDB-QUERY-006 REQ-DDB-QUERY-008 REQ-DDB-QUERY-009

Given

  1. reg = st.TargetRegistry(tmp_path / "state")
  2. repo = tmp_path / "repo"
3 more
  1. repo.mkdir()
  2. target = reg.register(repo)
  3. Path(target.db_path).write_bytes(rich_db.read_bytes())
→

When

  1. st.db_status(target)
  2. conn = sqlite3.connect(target.db_path)
  3. rel = conn.execute("SELECT name FROM path WHERE type=1 LIMIT 1").fetchone()[0]
7 more
  1. conn.close()
  2. src = repo / rel
  3. src.parent.mkdir(parents=True, exist_ok=True)
  4. src.write_text("// edited after the build\n", encoding="utf-8")
  5. future = time.time() + 10
  6. os.utime(src, (future, future))
  7. status = st.db_status(target)
→

Then

  1. ✓ st.db_status(target)["stale"] is False
  2. ✓ st.db_status(target)["source_changed_files"] equals 0
  3. ✓ status["source_changed_files"] equals 1
  4. ✓ status["newest_changed_source"] equals rel
  5. ✓ status["stale"] is True

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.

thread `clew-first-build-` — `_first_build_worker` (clew/mcp_server/server.py) · 32 of 142 steps

… 32 earlier steps

thread startthread startthread startthread startclew/mcp_server/server.pyclew/mcp_server/server.pyclew/mcp_server/server.pyclew/mcp_server/server.pyclew/scope.pyclew/scope.pyclew/scope.pyclew/scope.pyclew/mcp_server/state.pyclew/mcp_server/state.pyclew/mcp_server/state.pyclew/mcp_server/state.pytry (line 1664)tryopt (line 1666)optopt (line 352)opt_first_build_worker33. _first_build_worker → target_for33target_for34. target_for → _safe_index_name34_safe_index_name35. target_for → state_home35state_home▶ test enters36. _first_build_worker → _run_build36_run_build37. _run_build → nested_tree_cache37nested_tree_cache

… 26 steps between

thread startthread startthread startthread startthread startclew/mcp_server/server.pyclew/mcp_server/server.pyclew/mcp_server/server.pyclew/mcp_server/server.pyclew/mcp_server/server.pyclew/scope.pyclew/scope.pyclew/scope.pyclew/scope.pyclew/scope.pyclew/mcp_server/state.pyclew/mcp_server/state.pyclew/mcp_server/state.pyclew/mcp_server/state.pyclew/mcp_server/state.pyclew/mcp_server/freshness.pyclew/mcp_server/freshness.pyclew/mcp_server/freshness.pyclew/mcp_server/freshness.pyclew/mcp_server/freshness.pyother filesother filesother filesother filesother filestry (line 3260)try_first_build_worker64. _os_lock → lock_path64lock_path65. _run_build_walked → db_status65db_status66. db_status → _options_meta66_options_meta▶ test enters67. _options_meta → _meta_section67_meta_section68. _meta_section → meta_section68meta_section69. db_status → stated_options69stated_options70. db_status → read_build_signature70read_build_signature71–79. db_status → _source_drift71_source_drift +8 more80. db_status → list80list81–84. db_status → _diagnostics_meta81_diagnostics_meta +3 more85. db_status → code_identity85code_identity86–88. code_identity → source_fingerprint86source_fingerprint +2 more89. db_status → notices89notices90–92. notices → code_identity90code_identity +2 more93–94. _cost_clause → _humanise_ms93_humanise_ms +1 more95–98. notices → _schema_notice95_schema_notice +3 more99. _run_build_walked → declared_scope_rejection99declared_scope_rejection100. declared_scope_rejection → _declared_index_scope100_declared_index_scope

… 42 later steps

5 more

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

What it checks (5)

  1. assert st.db_status(target)["stale"] is False observes db_status
  2. assert st.db_status(target)["source_changed_files"] == 0 observes db_status
  3. assert status["source_changed_files"] == 1 observes db_status via status
  4. assert status["newest_changed_source"] == rel observes db_status via status
  5. assert status["stale"] is True, "an edited source file must make the index stale" observes db_status via status

Where the product reaches it

  • index → _index_action → build_or_refresh → db_status (flow)

Call flow

test_db_status_detects_source_drift→db_status

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_db_status_detects_source_drift · 5 checksdb_statusREQ-DDB-CONFIG-006 · measureddb_statusREQ-DDB-CONFIG-007 · measureddb_status_coverage_metaREQ-DDB-INDEX-003 · measureddb_statusREQ-DDB-MCP-001 · measureddb_statusREQ-DDB-MCP-004 · measureddb_statusread_build_signatureREQ-DDB-PIPE-005 · measured

Requirements it verifies (4)

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

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