test(issue-20): session guard for new entries in the recorded control planes' .mam/jobs and .mam/delegate_job_logs
Watches this checkout's .mam and the ones the recorded binding named. A new entry is a leak when it is an audit log without a registry record, or when its agent_session is missing or not a registered session; live delegations write the record first and target a registered session. Reports, never deletes. The #19 guard's docstring pointed at a #15 session guard that never existed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sdga4A8i1iSc8DaaW9iKU2
This commit is contained in:
1 parent
7bd695c209
commit
c5844a8e12
3 files changed
+282
-1
No files matched your search
+22
-1
@@ -126,6 +126,10 @@ def _pid_alive(pid):
|
||||
# one) reports new entries in the recorded control planes.
|
||||
# ==============================================================================
|
||||
_REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
_TESTS_DIR = str(Path(__file__).resolve().parent)
|
||||
if _TESTS_DIR not in sys.path:
|
||||
sys.path.insert(0, _TESTS_DIR)
|
||||
import _mam_state_guard # noqa: E402
|
||||
|
||||
_BINDING_VARS = ("WORKSPACE_ROOT", "AGENT_SESSIONS_YAML", "MAM_JOBS_DIR", "DELEGATE_JOB_LOGS_DIR")
|
||||
_RECORDED_BINDING = {}
|
||||
@@ -1440,10 +1444,27 @@ def _drop_ambient_mam_version():
|
||||
os.environ["MAM_VERSION"] = previous
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def mam_state_leak_guard(_ambient_control_plane):
|
||||
"""Issue #20: no test may leave a record in a real `.mam/jobs` or an audit
|
||||
log in a real `.mam/delegate_job_logs` - this checkout's, or the control
|
||||
plane the ambient binding named before pytest_configure dropped it.
|
||||
Delegations the live system runs meanwhile are told apart by
|
||||
_mam_state_guard.leaks (record first, registered session). The per-test
|
||||
defaults are the fix, this is the regression alarm; it reports and never
|
||||
deletes - these are real control planes. The session registry yaml/db is
|
||||
not hashed: reconcile and create write it during a run."""
|
||||
roots = _mam_state_guard.watch_roots(_REPO_ROOT, _ambient_control_plane)
|
||||
before = _mam_state_guard.snapshot(roots, _ambient_control_plane)
|
||||
yield
|
||||
found = _mam_state_guard.leaks(roots, before, _ambient_control_plane)
|
||||
assert not found, _mam_state_guard.describe(found)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def subscriber_daemon_leak_guard(tmp_path_factory):
|
||||
"""Issue #19: no `reconcile.sh --subscribe` daemon anchored in this session's
|
||||
pytest basetemp may survive the suite. Mirrors the #15 registry guard: the
|
||||
pytest basetemp may survive the suite. Mirrors the #20 state guard: the
|
||||
per-sandbox finalizer is the fix, this is the regression alarm. Leftovers
|
||||
are reaped after being reported so a failing run still cleans up."""
|
||||
yield
|
||||
|
||||
Reference in new issue
Block a user