test_a_future_source_mtime_is_not_evidence_of_an_edit¶
Tests › tests/test_freshness.py
What this test is for
Why it exists
M7, 1.1.0 SECURITY AUDIT. `_source_drift` compares every indexed file's mtime against the database's, so a file stamped in the future — a checkout from a machine with a skewed clock, a tarball carrying bogus timestamps, or a repository that committed one on purpose — is NEWER than every database that will ever be built from it. The index is then permanently stale, and the 15 s `keep_current` loop rebuilds it forever: doxygen, cargo and the Kconfig parse, all repo-controlled stages, on a loop, for as long as the server lives.
Verifies REQ-DDB-MCP-004
Given
repo = tmp_path / "repo"(repo / "src").mkdir(parents=True)
10 more
(repo / "src" / "a.c").write_text("int a(void) { return 0; }\n", encoding="utf-8")(repo / "src" / "b.c").write_text("int b(void) { return 0; }\n", encoding="utf-8")db = tmp_path / "clew.db"conn = sqlite3.connect(str(db))conn.execute("CREATE TABLE path (name TEXT, type INTEGER)")conn.executemany("INSERT INTO path (name, type) VALUES (?, 1)", [("src/a.c",), ("src/b.c",)])conn.commit()conn.close()future = db.stat().st_mtime + 365 * 24 * 3600os.utime(repo / "src" / "a.c", (future, future))
When
changed, newest = st._source_drift(db, repo)recent = db.stat().st_mtime + 10os.utime(repo / "src" / "b.c", (recent, recent))changed, newest = st._source_drift(db, repo)
Then
- ✓ changed equals 0
- ✓ (changed, newest) equals (1, "src/b.c")
tests/test_freshness.py:938 · its file's page
What it checks (2)
assert changed == 0, f"a future mtime was counted as an edit ({newest})"not attributedassert (changed, newest) == (1, "src/b.c"), "a genuine edit must still raise drift"not attributed
Where the product reaches it
index→_index_action→build_or_refresh→db_status→_source_drift(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 (1)
| requirement | linked by | implementers exercised |
|---|---|---|
| REQ-DDB-MCP-004 | catalog | unknown |