test(issue-17): every test that sources lib.sh does it under its own WORKSPACE_ROOT (review grok, codex)
d198dd5fixed one helper; the same defect was in eleven more modules (reviews grok and codex R1/R2): their shells inherited the process environment, so each `source lib.sh` rewrote <WORKSPACE_ROOT>/.mam/shim/herdr - the checkout's own when the variable is unset or names this checkout (which pytest_configure keeps), another workspace's under --noconftest. - conftest: own_workspace_root, an opt-in fixture setting WORKSPACE_ROOT to <tmp_path>/.mam-test-state/workspace. Not autouse: runner.py and mqtt_common read WORKSPACE_ROOT in-process, and some tests unset it on purpose. mam_sandbox and explicit envs run later and still win. - pytestmark usefixtures("own_workspace_root") in test_version_consistency, test_b19_headless_reconcile_fixes, test_b8_send_keys_verification, test_issue6_fail_closed, test_loop_cli, test_issue5_phase3_loop, test_issue5_phase4_runtime, test_o3_scoped_guard, test_issue25_plan_reuse, test_orc_onboard (their shells inherit os.environ, many with no env at all). - test_orc_onboard (R2): SCRUBBED_ENV is taken at import and no longer carries WORKSPACE_ROOT; every call builds _scrubbed_env(root) with the root of the call (ws / cwd / mam_sandbox, else this test's). - test_workspace_scope (unittest) and test_issue21_worktree_prereqs._mutate pin the root they already create. Tests (test_issue17_workspace_root_isolation.py): W1 copies the checkout and runs one test of each of those modules there with WORKSPACE_ROOT naming the copy - the copy gets no .mam; W2 imports test_orc_onboard under a sentinel root, then calls it under another - the sentinel stays empty. Atd198dd5both fail (the copy gets .mam/shim/herdr; the sentinel gets it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HCGpJXhSZasJLU38ksDghe
This commit is contained in:
1 parent
d198dd50aa
commit
8b47cc76ee
14 files changed
+176
-16
No files matched your search
@@ -177,6 +177,21 @@ def _isolate_mam_state_dirs(_ambient_control_plane, tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("MAM_ENV_FILE", str(state / ".mam.env.absent"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def own_workspace_root(tmp_path, monkeypatch):
|
||||
"""Issue #17: every `source lib.sh` rewrites $WORKSPACE_ROOT/.mam/shim/herdr,
|
||||
and lib.sh derives this checkout when the variable is unset (a value naming
|
||||
this checkout survives pytest_configure). A module whose shells inherit the
|
||||
process environment opts in with `pytestmark = pytest.mark.usefixtures(
|
||||
"own_workspace_root")`: they then write under this test's tmp_path instead.
|
||||
mam_sandbox and a test's own WORKSPACE_ROOT run later and still win. Not
|
||||
autouse: in-process code reads WORKSPACE_ROOT too (runner.py, mqtt_common)."""
|
||||
root = tmp_path / ".mam-test-state" / "workspace"
|
||||
root.mkdir(parents=True, exist_ok=True)
|
||||
monkeypatch.setenv("WORKSPACE_ROOT", str(root))
|
||||
return root
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mam_sandbox(tmp_path, monkeypatch, request):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user