test_db_status_detects_source_drift¶
Tests › tests/test_mcp_server.py
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
reg = st.TargetRegistry(tmp_path / "state")repo = tmp_path / "repo"
3 more
repo.mkdir()target = reg.register(repo)Path(target.db_path).write_bytes(rich_db.read_bytes())
When
st.db_status(target)conn = sqlite3.connect(target.db_path)rel = conn.execute("SELECT name FROM path WHERE type=1 LIMIT 1").fetchone()[0]
7 more
conn.close()src = repo / relsrc.parent.mkdir(parents=True, exist_ok=True)src.write_text("// edited after the build\n", encoding="utf-8")future = time.time() + 10os.utime(src, (future, future))status = st.db_status(target)
Then
- ✓ st.db_status(target)["stale"] is False
- ✓ st.db_status(target)["source_changed_files"] equals 0
- ✓ status["source_changed_files"] equals 1
- ✓ status["newest_changed_source"] equals rel
- ✓ 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
… 26 steps between
… 42 later steps
5 more
- Build, refresh and check the index · 32 of 153 steps
- `main` (scripts/stage_probe.py) · 31 of 37 steps
- clew — `main` (clew/cli.py) · 1 of 400 steps
- clew-mcp — `main` (clew/mcp_server/server.py) · 1 of 17 steps
- `main` (scripts/incremental_probe.py) · 1 of 3 steps
tests/test_mcp_server.py:2303 · its file's page
What it checks (5)
assert st.db_status(target)["stale"] is Falseobservesdb_statusassert st.db_status(target)["source_changed_files"] == 0observesdb_statusassert status["source_changed_files"] == 1observesdb_statusviastatusassert status["newest_changed_source"] == relobservesdb_statusviastatusassert status["stale"] is True, "an edited source file must make the index stale"observesdb_statusviastatus
Where the product reaches it
index→_index_action→build_or_refresh→db_status(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 (4)
| requirement | linked by | implementers exercised |
|---|---|---|
| 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 6 requirements
Its run touches their code; that is reach, not proof.
- REQ-DDB-CONFIG-006 measured
- REQ-DDB-CONFIG-007 measured
- REQ-DDB-INDEX-003 measured
- REQ-DDB-MCP-001 measured
- REQ-DDB-MCP-004 measured
- REQ-DDB-PIPE-005 measured