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") if __name__ == "__main__": unittest.main()