feat(scope): implement workspace-scoped session isolation (A-1) and native Herdr session naming (A-5)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
tests/test_workspace_scope.py — Unit tests for A-1 & A-5: Workspace-scoped Herdr session isolation and native naming.
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
class TestWorkspaceScope(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp_dir = tempfile.mkdtemp(prefix="mam_scope_test_")
|
||||
self.ws_dir = os.path.join(self.tmp_dir, "my_project")
|
||||
self.mam_dir = os.path.join(self.ws_dir, ".mam")
|
||||
os.makedirs(self.mam_dir, exist_ok=True)
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.tmp_dir, ignore_errors=True)
|
||||
|
||||
def test_derived_herdr_session_name(self):
|
||||
"""Verify that resolve_herdr_session derives 'mam-<slug>' per workspace."""
|
||||
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)
|
||||
self.assertEqual(res.returncode, 0, f"Command failed: {res.stderr}")
|
||||
self.assertEqual(res.stdout.strip(), "mam-my-project")
|
||||
|
||||
def test_drift_b_cwd_gate(self):
|
||||
"""Verify that reconcile.sh drift-B refuses to auto-register sessions with foreign cwd."""
|
||||
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||
reconcile_sh = os.path.join(repo_root, ".agents", "skills", "multi-agent-mux-monitor", "scripts", "reconcile.sh")
|
||||
|
||||
# Verify bash syntax for reconcile.sh
|
||||
res = subprocess.run(["bash", "-n", reconcile_sh], capture_output=True, text=True)
|
||||
self.assertEqual(res.returncode, 0, f"Syntax error in reconcile.sh: {res.stderr}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user