summaryrefslogtreecommitdiffhomepage
path: root/packages/todo/src/store.test.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-21 14:34:22 +0900
committerAdam Malczewski <[email protected]>2026-06-21 14:34:22 +0900
commitd56fe9cf64719bb330c17b2daee58c0bafa057c9 (patch)
treeb80a25aaee57f959454d468e03f100c38e224b82 /packages/todo/src/store.test.ts
parent8a4a624d16422467a8e85434c674bb591877e8ea (diff)
downloaddispatch-d56fe9cf64719bb330c17b2daee58c0bafa057c9.tar.gz
dispatch-d56fe9cf64719bb330c17b2daee58c0bafa057c9.zip
feat(todo): per-conversation task list tool + surface
New standard tool extension with a single todo_write tool (opencode todowrite pattern: full-list replace, returns JSON, no business-rule enforcement — the description guides the model). Per-conversation in-memory state + per-conversation surface (rendererId: todo, scope: conversation) via subscriber-notify (message-queue pattern). Wave 0 (kernel contract): added conversationId?: string to ToolExecuteContext (additive, backward-compatible). Wired in dispatch.ts — the kernel already had it but wasn't passing it through to tools. Wave 1 (todo extension): pure core (validateTodos — shape only; getTodos/ setTodos/clearTodos; buildTodoSpec; formatTodoResult). Shell: createTodoWriteTool + surface provider. Tool description matches opencode's todowrite.txt depth (when-to-use, examples, task states). Priority field removed (bloats the tool with little value). 25 tests. Wave 2 (host-bin): registered todo in CORE_EXTENSIONS + dep + root tsconfig ref. Verified: tsc EXIT 0, 1123 vitest, biome clean (314 files). Boot smoke clean. FE handoff: frontend-todo-handoff.md.
Diffstat (limited to 'packages/todo/src/store.test.ts')
-rw-r--r--packages/todo/src/store.test.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/packages/todo/src/store.test.ts b/packages/todo/src/store.test.ts
new file mode 100644
index 0000000..92130a3
--- /dev/null
+++ b/packages/todo/src/store.test.ts
@@ -0,0 +1,47 @@
+import { describe, expect, it } from "vitest";
+import { clearTodos, getTodos, setTodos, type TodoState } from "./pure.js";
+
+describe("getTodos", () => {
+ it("getTodos: returns fresh array copy (not the live array)", () => {
+ const state: TodoState = new Map();
+ setTodos(state, "c1", [{ content: "a", status: "pending" }]);
+ const snap = getTodos(state, "c1");
+ expect(snap).toHaveLength(1);
+ // mutating the snapshot array does not affect live state
+ snap.push({ content: "evil", status: "completed" });
+ expect(getTodos(state, "c1")).toHaveLength(1);
+ });
+
+ it("getTodos: empty array for unknown conversation", () => {
+ const state: TodoState = new Map();
+ expect(getTodos(state, "nope")).toEqual([]);
+ });
+});
+
+describe("setTodos", () => {
+ it("setTodos: replaces the list and returns a copy", () => {
+ const state: TodoState = new Map();
+ setTodos(state, "c1", [{ content: "first", status: "pending" }]);
+ // replace with a different list
+ const snap = setTodos(state, "c1", [{ content: "second", status: "in_progress" }]);
+ expect(snap).toHaveLength(1);
+ const first = snap[0];
+ if (first === undefined) throw new Error("expected an item");
+ expect(first.content).toBe("second");
+ // the previous list is gone
+ expect(getTodos(state, "c1").map((t) => t.content)).toEqual(["second"]);
+ });
+});
+
+describe("clearTodos", () => {
+ it("clearTodos: deletes the conversation's list", () => {
+ const state: TodoState = new Map();
+ setTodos(state, "c1", [{ content: "x", status: "pending" }]);
+ expect(getTodos(state, "c1")).toHaveLength(1);
+ clearTodos(state, "c1");
+ expect(getTodos(state, "c1")).toEqual([]);
+ // a second clear is a no-op
+ clearTodos(state, "c1");
+ expect(getTodos(state, "c1")).toEqual([]);
+ });
+});