From 4ad622e3727163a340a0f13b87e4daed2e3acd81 Mon Sep 17 00:00:00 2001 From: Godopu Date: Mon, 14 Sep 2026 20:54:53 +0000 Subject: [PATCH] test(issue-21): rec 3 - T2-6 isolates MAM_LOOP_WORKTREE/MAM_LOOP_BASE with monkeypatch T2-6 set both variables in os.environ directly and restored them in a finally block; a failing assertion between the two could still leak them to later tests in the process. They are now set with monkeypatch.setenv (the wt_repo fixture already delenvs both). The assertions are unchanged. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_017R3Eg7MEpSWnm1oB9ZPP6G --- tests/test_issue21_worktree_prereqs.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/tests/test_issue21_worktree_prereqs.py b/tests/test_issue21_worktree_prereqs.py index 92b9a5e..b091832 100644 --- a/tests/test_issue21_worktree_prereqs.py +++ b/tests/test_issue21_worktree_prereqs.py @@ -362,23 +362,19 @@ def test_t2_5b_prompts_unchanged_without_options(wt_repo, monkeypatch, tmp_path) assert _roles(calls, "Reviewer")[0].startswith("다음 구현 사항(작업 목표: t21)") -def test_t2_6_worktree_env_fallback_and_no_base_env(wt_repo, tmp_path): +def test_t2_6_worktree_env_fallback_and_no_base_env(wt_repo, tmp_path, monkeypatch): main, wt = wt_repo wt2 = tmp_path / "wt2" _git(main, "worktree", "add", "-q", "-b", "feat2", str(wt2)) - os.environ["MAM_LOOP_WORKTREE"] = str(wt) - os.environ["MAM_LOOP_BASE"] = _git(main, "rev-parse", "HEAD") - try: - r = _runner() - r.parse_args() - assert r.worktree_root == Path(os.path.realpath(wt)) and r.worktree_given - assert r.base_ref is None and r.base_sha == "" and r.base_source == "head", "MAM_LOOP_BASE is ignored (D17)" - r = _runner("--worktree", str(wt2)) - r.parse_args() - assert r.worktree_root == Path(os.path.realpath(wt2)), "the CLI wins over MAM_LOOP_WORKTREE" - finally: - os.environ.pop("MAM_LOOP_WORKTREE", None) - os.environ.pop("MAM_LOOP_BASE", None) + monkeypatch.setenv("MAM_LOOP_WORKTREE", str(wt)) + monkeypatch.setenv("MAM_LOOP_BASE", _git(main, "rev-parse", "HEAD")) + r = _runner() + r.parse_args() + assert r.worktree_root == Path(os.path.realpath(wt)) and r.worktree_given + assert r.base_ref is None and r.base_sha == "" and r.base_source == "head", "MAM_LOOP_BASE is ignored (D17)" + r = _runner("--worktree", str(wt2)) + r.parse_args() + assert r.worktree_root == Path(os.path.realpath(wt2)), "the CLI wins over MAM_LOOP_WORKTREE" def test_t2_7_runner_reads_mam_jobs_dir(wt_repo, tmp_path, monkeypatch):