121 lines
5.0 KiB
Python
121 lines
5.0 KiB
Python
import os
|
|
import sys
|
|
import unittest
|
|
import tempfile
|
|
import json
|
|
from pathlib import Path
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
sys.path.insert(0, str(REPO_ROOT / "bin"))
|
|
|
|
import box_work
|
|
|
|
class TestBoxWork(unittest.TestCase):
|
|
def test_workers_topology(self):
|
|
worker_names = [w["name"] for w in box_work.WORKERS]
|
|
self.assertIn("opm", worker_names)
|
|
self.assertIn("646", worker_names)
|
|
self.assertIn("dev", worker_names)
|
|
self.assertIn("pip", worker_names)
|
|
self.assertIn("def", worker_names)
|
|
self.assertIn("muse", worker_names)
|
|
self.assertIn("muse-main", worker_names)
|
|
|
|
def test_gitea_config_resolution(self):
|
|
api_base, token = box_work.get_gitea_config()
|
|
self.assertTrue(api_base.startswith("http"))
|
|
self.assertTrue(len(token) > 10)
|
|
|
|
def test_color_helpers(self):
|
|
self.assertTrue(len(box_work.c_bold("test")) >= 4)
|
|
self.assertTrue(len(box_work.c_green("test")) >= 4)
|
|
self.assertTrue(len(box_work.c_red("test")) >= 4)
|
|
|
|
def test_find_repo_root(self):
|
|
root = box_work.find_repo_root()
|
|
self.assertTrue(root.exists())
|
|
|
|
def test_claimed_tasks_empty_or_dict(self):
|
|
res = box_work.get_claimed_tasks()
|
|
self.assertIsInstance(res, dict)
|
|
|
|
def test_recent_done_tasks_list(self):
|
|
res = box_work.get_recent_done_tasks(limit=5)
|
|
self.assertIsInstance(res, list)
|
|
|
|
def test_check_agent_preflight_structure(self):
|
|
res = box_work.check_agent_preflight("opm")
|
|
self.assertIn("hatch", res)
|
|
self.assertIn("restore", res)
|
|
self.assertIn("git", res)
|
|
self.assertIn("status", res["hatch"])
|
|
self.assertIn("status", res["restore"])
|
|
self.assertIn("status", res["git"])
|
|
self.assertIn("ready", res)
|
|
|
|
def test_check_agent_preflight_unknown_fails(self):
|
|
res = box_work.check_agent_preflight("nonexistent_agent_xyz")
|
|
self.assertFalse(res["ready"])
|
|
self.assertEqual(res["overall"], "FAIL")
|
|
|
|
def test_cli_alone_prints_usage_reference(self):
|
|
import subprocess
|
|
proc = subprocess.run([sys.executable, str(REPO_ROOT / "bin" / "super-cli.py")], capture_output=True, text=True)
|
|
self.assertEqual(proc.returncode, 0)
|
|
self.assertIn("BOX ORCHESTRATOR: INPUT PARAMETERS & USAGE REFERENCE", proc.stdout)
|
|
self.assertIn("PRIMARY DOMAINS & INPUT PARAMETERS:", proc.stdout)
|
|
self.assertIn("box work", proc.stdout)
|
|
self.assertIn("box tasks", proc.stdout)
|
|
self.assertIn("box fleet", proc.stdout)
|
|
|
|
def test_cli_help_prints_master_manual(self):
|
|
import subprocess
|
|
proc = subprocess.run([sys.executable, str(REPO_ROOT / "bin" / "super-cli.py"), "help"], capture_output=True, text=True)
|
|
self.assertEqual(proc.returncode, 0)
|
|
self.assertIn("BOX ORCHESTRATOR COMPREHENSIVE CLI & RUNTIME MANUAL", proc.stdout)
|
|
self.assertIn("DOMAINS & ACTION SPECIFICATIONS:", proc.stdout)
|
|
|
|
def test_cli_domain_help_prints_subcommands_and_examples(self):
|
|
import subprocess
|
|
proc = subprocess.run([sys.executable, str(REPO_ROOT / "bin" / "super-cli.py"), "work", "help"], capture_output=True, text=True)
|
|
self.assertEqual(proc.returncode, 0)
|
|
self.assertIn("SHORTHAND EXAMPLES:", proc.stdout)
|
|
self.assertIn("OPERATIONAL GUIDELINES:", proc.stdout)
|
|
self.assertIn("box work start", proc.stdout)
|
|
|
|
def test_cli_missing_args_prints_error_and_shorthand_helper(self):
|
|
import subprocess
|
|
proc = subprocess.run([sys.executable, str(REPO_ROOT / "bin" / "super-cli.py"), "work", "start"], capture_output=True, text=True)
|
|
self.assertEqual(proc.returncode, 2)
|
|
err = proc.stderr
|
|
self.assertIn("CLI ERROR:", err)
|
|
self.assertIn("SHORTHAND USAGE HELPER:", err)
|
|
self.assertIn("title", err)
|
|
self.assertIn("--to", err)
|
|
self.assertIn("Quick Examples:", err)
|
|
|
|
def test_cli_invalid_subcommand_prints_shorthand_helper(self):
|
|
import subprocess
|
|
proc = subprocess.run([sys.executable, str(REPO_ROOT / "bin" / "super-cli.py"), "work", "invalid_action_xyz"], capture_output=True, text=True)
|
|
self.assertEqual(proc.returncode, 2)
|
|
err = proc.stderr
|
|
self.assertIn("CLI ERROR:", err)
|
|
self.assertIn("SHORTHAND USAGE HELPER:", err)
|
|
self.assertIn("Available Subcommands:", err)
|
|
self.assertIn("status", err)
|
|
self.assertIn("start", err)
|
|
|
|
def test_cli_invalid_domain_prints_shorthand_helper(self):
|
|
import subprocess
|
|
proc = subprocess.run([sys.executable, str(REPO_ROOT / "bin" / "super-cli.py"), "invalid_domain_xyz"], capture_output=True, text=True)
|
|
self.assertEqual(proc.returncode, 2)
|
|
err = proc.stderr
|
|
self.assertIn("CLI ERROR:", err)
|
|
self.assertIn("SHORTHAND USAGE HELPER:", err)
|
|
self.assertIn("Primary Domains & Commands:", err)
|
|
self.assertIn("work", err)
|
|
self.assertIn("fleet", err)
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|