51 lines
1.8 KiB
Python
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()
|