Files
box/tests/test_swarm_prune.py
operator 0065d11e97 feat(supervision): add choice watcher daemon, HTTPS spec docs, and test suites
- bin/muse_choice_watcher.py + systemd/muse-choices-reconcile.*: automatic choice answering and timer reconciliation
- bin/digest.py: fleet log and health summarization
- docs/BOX-*-HTTPS.md: comprehensive HTTPS execution contracts and API documentation
- docs/MUSE-CHOICES-POLICY.md & docs/SUPERVISION-SPEC.md: autonomous execution specs
- tests/test_*.py: unit test suites for HTTPS API, choice watcher, fleet heal, and swarm pruning
2026-10-07 00:25:46 +00:00

51 lines
1.8 KiB
Python

"""Regression tests for the hyphenated swarm-prune branch.
`swarm-prune` was dispatched but had no handler branch, so it exited 0
with no output. It now mirrors `swarm prune` (preview counts without
--confirm, archive only with --confirm). These tests never pass
--confirm, so they never write.
"""
import json
import subprocess
import sys
import unittest
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
BOX_CTL = REPO_ROOT / "bin" / "box-ctl.py"
def _box_ctl(*args):
return subprocess.run(
[sys.executable, str(BOX_CTL), *args],
capture_output=True, text=True, timeout=120)
class SwarmPruneTests(unittest.TestCase):
def test_hyphenated_prune_previews_without_confirm(self):
r = _box_ctl("swarm-prune")
self.assertNotEqual(r.returncode, 0)
self.assertTrue(r.stdout.strip(), "hyphenated prune must emit JSON")
payload = json.loads(r.stdout)
self.assertEqual(payload["code"], "CONFIRM_REQUIRED")
self.assertIn("matching_count", payload["detail"])
self.assertEqual(payload["detail"]["stale_hours"], 6)
def test_hyphenated_matches_space_form(self):
hyphen = json.loads(_box_ctl("swarm-prune").stdout)
space = json.loads(_box_ctl("swarm", "prune").stdout)
self.assertEqual(hyphen["code"], "CONFIRM_REQUIRED")
self.assertEqual(space["code"], "CONFIRM_REQUIRED")
self.assertEqual(sorted(hyphen["detail"]),
sorted(space["detail"]))
def test_bad_stale_hours_falls_back_to_default(self):
r = _box_ctl("swarm-prune", "--stale-hours", "bogus")
payload = json.loads(r.stdout)
self.assertEqual(payload["code"], "CONFIRM_REQUIRED")
self.assertEqual(payload["detail"]["stale_hours"], 6)
if __name__ == "__main__":
unittest.main()