Skip to content

The agent that grows with you

test(install-e2e): record SQLite sidecars again; only a mid-walk vanish is tolerated

teknium1ff6e6849496e
diff --git a/tests/install/e2e-assets/verify-user-state.py b/tests/install/e2e-assets/verify-user-state.py
index 36e091ff287..7a598f6b3fa 100644
--- a/tests/install/e2e-assets/verify-user-state.py
+++ b/tests/install/e2e-assets/verify-user-state.py
@@ -276,6 +276,17 @@ def _env_line_summary(path: str) -> dict:
return {"lines": len(lines), "comments": comments, "blanks": blanks, "key_order": order}
+def _entry_record_unless_vanished(rel: str, abs_path: str) -> dict | None:
+ """A SQLite sidecar can vanish between listdir and its digest (a live gateway closes
+ the connection): record what exists, never crash on that race. Anything else raises."""
+ try:
+ return _entry_record(abs_path)
+ except FileNotFoundError:
+ if _volatile_sidecar(rel):
+ return None
+ raise
+
+
def _entry_record(abs_path: str) -> dict:
if _is_link(abs_path):
record: dict = {"kind": "symlink", "target": os.readlink(abs_path)}
@@ -332,10 +343,6 @@ def _walk_root(home: str, root_rel: str, *, profiles: bool, judged: bool):
rel = os.path.relpath(abs_path, home).replace(os.sep, "/")
if _owns_plugins(rel, profiles=profiles):
continue
- # Never judged, and a live gateway (it serves every profile) can close the
- # connection between listdir and the digest open: skip, don't race it.
- if _volatile_sidecar(rel):
- continue
# The judged skills/.archive tree is walked as its own root, so the
# advisory walk of skills/ must not claim it.
if not judged and (rel.split("/")[-1] == SKILL_ARCHIVE or "/" + SKILL_ARCHIVE + "/" in rel):
@@ -366,7 +373,9 @@ def snapshot_home(home: str, profiles_dir: str | None = None) -> dict:
for rel_root, profiles, judged in targets:
for rel, abs_path, entry_judged in _walk_root(home, rel_root, profiles=profiles, judged=judged):
- (entries if entry_judged else advisory)[rel] = _entry_record(abs_path)
+ record = _entry_record_unless_vanished(rel, abs_path)
+ if record is not None:
+ (entries if entry_judged else advisory)[rel] = record
# Profiles may live somewhere else entirely (a test harness override).
if profiles_dir and os.path.abspath(profiles_dir) != os.path.join(home, PROFILES_DIR):
@@ -382,7 +391,9 @@ def snapshot_home(home: str, profiles_dir: str | None = None) -> dict:
override_abs, name, profiles=True, judged=True):
if sub_rel == name:
continue
- (entries if sub_judged else advisory)[f"{PROFILES_DIR}/{sub_rel}"] = _entry_record(sub_abs)
+ record = _entry_record_unless_vanished(sub_rel, sub_abs)
+ if record is not None:
+ (entries if sub_judged else advisory)[f"{PROFILES_DIR}/{sub_rel}"] = record
return {
"schema": SCHEMA_VERSION,
diff --git a/tests/scripts/test_verify_user_state.py b/tests/scripts/test_verify_user_state.py
index 5f090c6e74c..c116ec98b90 100644
--- a/tests/scripts/test_verify_user_state.py
+++ b/tests/scripts/test_verify_user_state.py
@@ -389,6 +389,46 @@ def test_sqlite_sidecars_may_vanish_but_the_database_may_not(tmp_path):
assert report["ok"] is False
+def test_a_sidecar_vanishing_mid_walk_is_not_a_scan_crash(tmp_path, monkeypatch):
+ """listdir sees a -journal, the gateway closes its connection, the digest open fails.
+
+ Only a volatile sidecar may vanish that way; any other file vanishing still raises.
+ """
+ home = tmp_path / "home"
+ (home / "cron").mkdir(parents=True)
+ for name in ("executions.db-journal", "jobs.json"):
+ (home / "cron" / name).write_text("x\n", encoding="utf-8")
+ real = vus._entry_record
+ gone = {"executions.db-journal"}
+
+ def racing(abs_path):
+ if os.path.basename(abs_path) in gone:
+ raise FileNotFoundError(abs_path)
+ return real(abs_path)
+
+ monkeypatch.setattr(vus, "_entry_record", racing)
+ snap = vus.snapshot_home(str(home))
+ assert "cron/jobs.json" in snap["entries"]
+ assert "cron/executions.db-journal" not in snap["entries"]
+
+ gone.add("jobs.json")
+ with pytest.raises(FileNotFoundError):
+ vus.snapshot_home(str(home))
+
+
+def test_the_running_gateways_state_record_may_change_but_not_vanish(tmp_path):
+ """The update restarts the gateway, so gateway_state.json's pid/start_time must move."""
+ home = tmp_path / "home"
+ home.mkdir()
+ (home / "gateway_state.json").write_text('{"pid": 1}', encoding="utf-8")
+ snap = vus.snapshot_home(str(home))
+ (home / "gateway_state.json").write_text('{"pid": 2}', encoding="utf-8")
+ assert vus.verify_home(str(home), snap)["ok"] is True
+ os.remove(home / "gateway_state.json")
+ report = vus.verify_home(str(home), snap)
+ assert report["deleted"] == ["gateway_state.json"] and report["ok"] is False
+
+
def test_any_sqlite_database_is_judged_by_rows_not_bytes(tmp_path):
"""Live SQLite files churn bytes constantly; their contract is the rows.