The 33 failures on the Linux / Python 3.14 host (#28) were environment dependencies, not regressions; each test is worth keeping, so fix the dependency instead of deleting the test: - test_workspace_scope: `source` under `shell=True` ran in dash; run the command string under bash. - conftest autouse: MAM_ENV_FILE points at an absent file for every test, so a workspace .mam.env with a reachable broker no longer breaks the "broker unavailable" tests (T1-4). - help-capture guard: compare normalized help text (whitespace collapsed, "optional arguments"/"options" unified) so argparse re-wrapping across Python versions is not drift. - deploy freshness D-11..D-19 and D-22..D-30: skip with a reason when the nats-docker submodule is not initialized. - lib_py.agents.base.conversation_in_use and heartbeat._process_table: `ps -eo pid=,ppid=,args=` (POSIX) instead of the BSD `-axo ... command=` form, the most likely cause of the 12 purge failures on Linux (the holder scan returned nothing); to be confirmed on that host. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VCgu9Fa9iT7TbJUSzdq4Ff
48 lines
2.3 KiB
Python
48 lines
2.3 KiB
Python
#!/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} && env -u HERDR_SESSION_NAME -u HERDR_SERVER_NAME bash -c 'source {lib_sh} && resolve_herdr_session \"test-session\" \"{self.ws_dir}\"'"
|
|
# `source` is a bash builtin; on hosts where /bin/sh is dash `shell=True`
|
|
# fails with "source: not found" (Issue #28), so run the string under bash.
|
|
res = subprocess.run(["bash", "-c", cmd], capture_output=True, text=True)
|
|
self.assertEqual(res.returncode, 0, f"Command failed: {res.stderr}")
|
|
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."""
|
|
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()
|