aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-10 12:16:40 +0100
committerDanilo M. <danix@danix.xyz>2026-11-10 12:16:40 +0100
commita9a737c7fd0efd8f82db78ce19e7858803e0f6b2 (patch)
treeb0a2272e2924b14e08d205091acec64ed3a3ff16 /tests
parent0271cd26ead61e05cf4e1f1ac4c80931421509b5 (diff)
downloaddeck-it-a9a737c7fd0efd8f82db78ce19e7858803e0f6b2.tar.gz
deck-it-a9a737c7fd0efd8f82db78ce19e7858803e0f6b2.zip
feat(assistant): fold daemon events into the tab's state
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_assistant.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/test_assistant.py b/tests/test_assistant.py
new file mode 100644
index 0000000..f91f3cd
--- /dev/null
+++ b/tests/test_assistant.py
@@ -0,0 +1,98 @@
+# deck-it - tests for assistant
+# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
+
+import unittest
+
+from deckit.modules import assistant as a
+
+
+def folded(*events):
+ st = a.blank()
+ for e in events:
+ a.fold(st, e)
+ return st
+
+
+class Fold(unittest.TestCase):
+ def test_hello_with_a_reply_in_flight(self):
+ st = folded({"type": "hello", "state": "thinking", "model": "m1", "chat_model": "c1",
+ "turns": [{"user": "hi", "reply": "yo", "tools": ["now"], "files": []}],
+ "pending": {"user": "and?", "reply": "par", "think": "", "tools": [], "files": []}})
+ self.assertEqual((st["state"], st["model"], st["chatModel"]), ("thinking", "m1", "c1"))
+ self.assertEqual(st["turns"][0]["tools"], ["now"])
+ self.assertEqual(st["pending"]["reply"], "par")
+
+ def test_a_turn_streams_and_settles(self):
+ st = folded({"type": "user", "text": "q"}, {"type": "think", "delta": "h"},
+ {"type": "tool", "name": "web", "done": False}, {"type": "tool", "name": "web", "done": True},
+ {"type": "token", "delta": "a"}, {"type": "token", "delta": "b"},
+ {"type": "done", "id": 3})
+ self.assertIsNone(st["pending"])
+ self.assertEqual(st["turns"], [{"user": "q", "reply": "ab", "think": "h", "tools": ["web"],
+ "stopped": False}])
+
+ def test_stop_keeps_the_partial_reply_marked(self):
+ st = folded({"type": "user", "text": "q"}, {"type": "token", "delta": "a"},
+ {"type": "error", "message": "stopped", "turn": True},
+ {"type": "done", "id": None, "stopped": True})
+ self.assertEqual(st["turns"][-1]["error"], "stopped")
+ self.assertIsNone(st["pending"])
+
+ def test_command_error_is_a_notice(self):
+ self.assertEqual(folded({"type": "error", "message": "bad id"})["notice"], "bad id")
+
+ def test_conversation_replaces_the_transcript(self):
+ st = folded({"type": "user", "text": "q"},
+ {"type": "conversation", "id": None, "turns": [], "model": None})
+ self.assertEqual((st["turns"], st["pending"], st["epoch"]), ([], None, 1))
+
+ def test_written_ends_the_op(self):
+ st = a.blank()
+ st["op"] = {"label": "To .md", "running": True, "ok": False, "out": [], "error": ""}
+ a.fold(st, {"type": "written", "path": "/x/doc.md"})
+ self.assertEqual((st["op"]["running"], st["op"]["ok"], st["op"]["out"]), (False, True, ["/x/doc.md"]))
+
+ def test_refused_write_ends_the_op(self):
+ st = a.blank()
+ st["op"] = {"label": "To .md", "running": True, "ok": False, "out": [], "error": ""}
+ a.fold(st, {"type": "error", "message": "bad write", "turn": True})
+ self.assertEqual((st["op"]["running"], st["op"]["error"]), (False, "bad write"))
+
+
+class Hears(unittest.TestCase):
+ MODELS = [{"id": "deaf", "status": "loaded", "cloud": False, "inputs": ["text"]},
+ {"id": "ears", "status": "unloaded", "cloud": False, "inputs": ["text", "audio"]},
+ {"id": "p:big", "provider": "p", "cloud": True}]
+
+ def test_local_pick_decides(self):
+ self.assertTrue(a.hears(self.MODELS, "ears"))
+ self.assertFalse(a.hears(self.MODELS, "deaf"))
+
+ def test_cloud_or_no_pick_uses_the_loaded_model(self):
+ self.assertFalse(a.hears(self.MODELS, "p:big"))
+ self.assertFalse(a.hears(self.MODELS, None))
+
+ def test_unknown_is_yes(self):
+ self.assertTrue(a.hears([], None))
+ self.assertTrue(a.hears([{"id": "x", "status": "loaded", "cloud": False, "inputs": None}], None))
+
+
+if __name__ == "__main__":
+ unittest.main()