diff options
| author | Adam Malczewski <[email protected]> | 2026-06-21 14:34:22 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-21 14:34:22 +0900 |
| commit | d56fe9cf64719bb330c17b2daee58c0bafa057c9 (patch) | |
| tree | b80a25aaee57f959454d468e03f100c38e224b82 /packages/todo/src/validate.test.ts | |
| parent | 8a4a624d16422467a8e85434c674bb591877e8ea (diff) | |
| download | dispatch-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/validate.test.ts')
| -rw-r--r-- | packages/todo/src/validate.test.ts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/packages/todo/src/validate.test.ts b/packages/todo/src/validate.test.ts new file mode 100644 index 0000000..c518041 --- /dev/null +++ b/packages/todo/src/validate.test.ts @@ -0,0 +1,66 @@ +import { describe, expect, it } from "vitest"; +import { validateTodos } from "./pure.js"; + +describe("validateTodos", () => { + it("validateTodos: accepts valid list", () => { + const result = validateTodos({ + todos: [ + { content: "Do thing A", status: "pending" }, + { content: "Do thing B", status: "in_progress" }, + { content: "Do thing C", status: "completed" }, + ], + }); + expect(result).toEqual([ + { content: "Do thing A", status: "pending" }, + { content: "Do thing B", status: "in_progress" }, + { content: "Do thing C", status: "completed" }, + ]); + }); + + it("validateTodos: accepts empty array (clears the list)", () => { + const result = validateTodos({ todos: [] }); + expect(result).toEqual([]); + }); + + it("validateTodos: rejects invalid status", () => { + const result = validateTodos({ + todos: [{ content: "x", status: "bogus" }], + }); + expect(result).toHaveProperty("error"); + }); + + it("validateTodos: rejects empty content", () => { + const empty = validateTodos({ + todos: [{ content: "", status: "pending" }], + }); + expect(empty).toHaveProperty("error"); + const whitespace = validateTodos({ + todos: [{ content: " ", status: "pending" }], + }); + expect(whitespace).toHaveProperty("error"); + }); + + it("validateTodos: rejects non-array todos", () => { + const result = validateTodos({ todos: "not-an-array" }); + expect(result).toHaveProperty("error"); + }); + + it("validateTodos: rejects null/non-object args", () => { + expect(validateTodos(null)).toHaveProperty("error"); + expect(validateTodos(undefined)).toHaveProperty("error"); + expect(validateTodos("string")).toHaveProperty("error"); + expect(validateTodos(42)).toHaveProperty("error"); + expect(validateTodos([])).toHaveProperty("error"); + }); + + it("validateTodos: does NOT enforce one in_progress (allows multiple — description guides the model)", () => { + const result = validateTodos({ + todos: [ + { content: "a", status: "in_progress" }, + { content: "b", status: "in_progress" }, + ], + }); + expect(Array.isArray(result)).toBe(true); + expect(result).toHaveLength(2); + }); +}); |
