test_a_future_source_mtime_is_not_evidence_of_an_edit

Tests › tests/test_freshness.py

passed Passed in the packaged run.

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

  1. repo = tmp_path / "repo"
  2. (repo / "src").mkdir(parents=True)
10 more
  1. (repo / "src" / "a.c").write_text("int a(void) { return 0; }\n", encoding="utf-8")
  2. (repo / "src" / "b.c").write_text("int b(void) { return 0; }\n", encoding="utf-8")
  3. db = tmp_path / "clew.db"
  4. conn = sqlite3.connect(str(db))
  5. conn.execute("CREATE TABLE path (name TEXT, type INTEGER)")
  6. conn.executemany("INSERT INTO path (name, type) VALUES (?, 1)", [("src/a.c",), ("src/b.c",)])
  7. conn.commit()
  8. conn.close()
  9. future = db.stat().st_mtime + 365 * 24 * 3600
  10. os.utime(repo / "src" / "a.c", (future, future))
→

When

  1. changed, newest = st._source_drift(db, repo)
  2. recent = db.stat().st_mtime + 10
  3. os.utime(repo / "src" / "b.c", (recent, recent))
  4. changed, newest = st._source_drift(db, repo)
→

Then

  1. ✓ changed equals 0
  2. ✓ (changed, newest) equals (1, "src/b.c")

tests/test_freshness.py:938 · its file's page

What it checks (2)

  1. assert changed == 0, f"a future mtime was counted as an edit ({newest})" not attributed
  2. assert (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

test_a_future_source_mtime_is_not_evidence_of_an_edit→_source_drift

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)

requirementlinked byimplementers exercised
REQ-DDB-MCP-004catalogunknown