host: real-tests
This commit is contained in:
commit
7f4e2edb3c
1 file changed
+56
@@ -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()
|
||||
Reference in new issue
Block a user