fix(refactor): address reviewer findings R-1..R-8, achieve 31/31 test pass

This commit is contained in:
2026-08-05 10:08:59 +09:00
parent 8dcb2b2d9e
commit ddd43ecbea
12 changed files with 684 additions and 58 deletions
+9 -3
View File
@@ -12,6 +12,8 @@ def run_lib_func(mam_sandbox, func_name, *args, env=None):
lib_path = mam_sandbox / "skills" / "lib.sh"
cmd_str = f"source {lib_path} && {func_name} " + " ".join(shlex.quote(str(a)) for a in args)
run_env = dict(os.environ)
run_env.pop("HERDR_SESSION_NAME", None)
run_env.pop("HERDR_SERVER_NAME", None)
if env:
run_env.update(env)
res = subprocess.run(["bash", "-c", cmd_str], capture_output=True, text=True, env=run_env)
@@ -111,10 +113,14 @@ def test_resume_resolve_herdr_session_default(mam_sandbox):
assert res.stdout.strip() != ""
def test_resume_resolve_herdr_session_env(mam_sandbox):
"""Test resolve_herdr_workspace fallback to HERDR_SERVER_NAME env var."""
res = run_lib_func(mam_sandbox, "resolve_herdr_workspace", "non-existent-session", env={"HERDR_SERVER_NAME": "custom_server"})
"""Test resolve_herdr_workspace fallback to HERDR_SESSION_NAME or HERDR_SERVER_NAME env var."""
res = run_lib_func(mam_sandbox, "resolve_herdr_workspace", "non-existent-session", env={"HERDR_SESSION_NAME": "custom_session"})
assert res.returncode == 0
assert res.stdout.strip() == "custom_server"
assert res.stdout.strip() == "custom_session"
res_legacy = run_lib_func(mam_sandbox, "resolve_herdr_workspace", "non-existent-session", env={"HERDR_SERVER_NAME": "custom_server"})
assert res_legacy.returncode == 0
assert res_legacy.stdout.strip() == "custom_server"
def test_resume_find_workspace_uuid_empty(mam_sandbox):
"""Test find_workspace_uuid returns empty string for non-existent workspace."""
+6 -3
View File
@@ -24,10 +24,13 @@ class TestWorkspaceScope(unittest.TestCase):
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
lib_sh = os.path.join(repo_root, ".agents", "skills", "lib.sh")
cmd = f"source {lib_sh} && cd {self.ws_dir} && resolve_herdr_session 'test-session'"
res = subprocess.run(["bash", "-c", cmd], capture_output=True, text=True)
cmd = f"source {lib_sh} && env -u HERDR_SESSION_NAME -u HERDR_SERVER_NAME bash -c 'source {lib_sh} && resolve_herdr_session \"test-session\" \"{self.ws_dir}\"'"
res = subprocess.run(cmd, shell=True, capture_output=True, text=True)
self.assertEqual(res.returncode, 0, f"Command failed: {res.stderr}")
self.assertEqual(res.stdout.strip(), "mam-my-project")
parent = os.path.basename(os.path.dirname(os.path.abspath(self.ws_dir))).lower().replace('_', '-')
work = os.path.basename(os.path.abspath(self.ws_dir)).lower().replace('_', '-')
expected_slug = f"mam-{parent}-{work}"
self.assertEqual(res.stdout.strip(), expected_slug)
def test_drift_b_cwd_gate(self):
"""Verify that reconcile.sh drift-B refuses to auto-register sessions with foreign cwd."""