import asyncio import json import os import sys import tempfile import unittest sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "files")) import claude_agents as ca # noqa: E402 class DefaultTheme(unittest.TestCase): def test_default_theme_matches_chat_profile(self): self.assertEqual(ca.DEFAULT_THEME, { "bg": "#002b36", "fg": "#aacace", "dim": "#668a91", "green": "#859900", "yellow": "#b58900", "red": "#dc322f", "font": "'MesloLGLNF', 'MesloLGLNF-Regular', ui-monospace, monospace", "size": 13}) class NoITermCoupling(unittest.TestCase): def test_iterm_coupling_removed(self): for name in ("theme_poller", "live_sessions", "USE_PROFILE_THEME", "THEME_VARIANT", "_app", "_mix", "_hex"): self.assertFalse(hasattr(ca, name), name) self.assertNotIn("use_profile_theme", ca.CONFIG_KEYS) self.assertNotIn("theme_variant", ca.CONFIG_KEYS) class Config(unittest.TestCase): def setUp(self): self.saved = (ca.CONFIG_PATH, ca.POLL_SEC, ca._config_mtime) self.tmp = tempfile.TemporaryDirectory() def tearDown(self): ca.CONFIG_PATH, ca.POLL_SEC, ca._config_mtime = self.saved self.tmp.cleanup() def test_old_theme_keys_ignored(self): path = os.path.join(self.tmp.name, "config.json") with open(path, "w", encoding="utf-8") as f: json.dump({"use_profile_theme": False, "theme_variant": "dark", "poll_sec": 2}, f) ca.CONFIG_PATH, ca._config_mtime = path, None ca.load_config() self.assertIsNone(ca.state.get("config_error")) self.assertEqual(ca.POLL_SEC, 2.0) class Actions(unittest.TestCase): def setUp(self): self.calls = [] self.saved = (ca._tmux, ca.known_roots, ca.FILE_MANAGER, ca.state["tree"]) ca._tmux = lambda sock, *args: self.calls.append((sock, *args)) ca._last_open.clear() self.tmp = tempfile.TemporaryDirectory() def tearDown(self): ca._tmux, ca.known_roots, ca.FILE_MANAGER, ca.state["tree"] = self.saved self.tmp.cleanup() def test_activate_tmux_target(self): ca.state["tree"] = [{"uuid": "tmux:/tmp/s|%3", "agents": []}] asyncio.run(ca.activate("tmux:/tmp/s|%3")) self.assertEqual(self.calls, [("/tmp/s", "switch-client", "-t", "%3"), ("/tmp/s", "select-window", "-t", "%3"), ("/tmp/s", "select-pane", "-t", "%3")]) def test_activate_non_tmux_is_noop(self): ca.state["tree"] = [{"uuid": "w0t0p0:ABC", "agents": []}] asyncio.run(ca.activate("w0t0p0:ABC")) self.assertEqual(self.calls, []) def test_open_worktree_non_tmux_is_noop(self): ca.state["tree"] = [{"uuid": "w0t0p0:ABC", "agents": []}] ca.known_roots = lambda: {self.tmp.name} asyncio.run(ca.open_worktree("w0t0p0:ABC", self.tmp.name)) self.assertEqual(self.calls, []) def test_open_worktree_tmux_splits(self): ca.state["tree"] = [{"uuid": "tmux:/tmp/s|%3", "agents": []}] ca.known_roots = lambda: {self.tmp.name} ca.FILE_MANAGER = "lf" asyncio.run(ca.open_worktree("tmux:/tmp/s|%3", self.tmp.name)) self.assertEqual(self.calls, [("/tmp/s", "split-window", "-h", "-t", "%3", "-c", self.tmp.name, "exec lf")]) if __name__ == "__main__": unittest.main()