From 4ef3539bb9fa64d4ff420d35ef1bdc80a499eca7 Mon Sep 17 00:00:00 2001 From: host Date: Mon, 26 Oct 2026 00:16:54 +0800 Subject: [PATCH] host: real-tests --- tests/test_host.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/test_host.py diff --git a/tests/test_host.py b/tests/test_host.py new file mode 100644 index 0000000..d039ea0 --- /dev/null +++ b/tests/test_host.py @@ -0,0 +1,56 @@ +import json +import os +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path + + +REPO_ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(REPO_ROOT)) + +import host + + +class HostPureFunctionsTest(unittest.TestCase): + def test_save_state_merges_tasks_and_preserves_disk_tasks(self): + with tempfile.TemporaryDirectory() as tmp: + state_path = os.path.join(tmp, "host-state.json") + with open(state_path, "w", encoding="utf-8") as f: + json.dump({"tasks": {"disk-task": {"status": "running"}}, + "automations": []}, f) + + state = {"tasks": {"memory-task": {"status": "completed"}}, + "automations": []} + host.save_state(state_path, state) + + self.assertEqual(state["tasks"]["disk-task"], {"status": "running"}) + self.assertEqual(state["tasks"]["memory-task"], {"status": "completed"}) + loaded = host.load_state(state_path) + self.assertEqual(loaded, state) + + def test_task_diff_includes_untracked_text_contents(self): + with tempfile.TemporaryDirectory() as tmp: + subprocess.run(["git", "init", "-q"], cwd=tmp, check=True) + Path(tmp, "tracked.txt").write_text("tracked\n", encoding="utf-8") + subprocess.run(["git", "add", "tracked.txt"], cwd=tmp, check=True) + subprocess.run(["git", "-c", "user.name=Test", "-c", + "user.email=test@example.com", "commit", "-qm", + "initial"], cwd=tmp, check=True) + Path(tmp, "new.txt").write_text("new file contents\n", encoding="utf-8") + + result = host.task_diff(tmp) + + self.assertIn("new.txt", result["untracked"].splitlines()) + self.assertEqual(result["untracked_contents"]["new.txt"], + "new file contents\n") + + def test_load_config_file_returns_empty_dict_for_missing_file(self): + with tempfile.TemporaryDirectory() as tmp: + missing = os.path.join(tmp, "missing.json") + self.assertEqual(host._load_config_file(missing), {}) + + +if __name__ == "__main__": + unittest.main()