summaryrefslogtreecommitdiffhomepage
path: root/packages/api/tests
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-05-30 20:06:31 +0900
committerAdam Malczewski <[email protected]>2026-05-30 20:06:31 +0900
commit0f39b6f78957aacf206012ad2193d9b0c1940c1f (patch)
treeff5f2da8b4f3cdf56cf50d44b8fec75a489ad6fe /packages/api/tests
parent8c58a973b0d021689cebad5c0cc6d56956bbc2f6 (diff)
downloaddispatch-0f39b6f78957aacf206012ad2193d9b0c1940c1f.tar.gz
dispatch-0f39b6f78957aacf206012ad2193d9b0c1940c1f.zip
refactor(chunks): append-only chunk log with per-step cache-stable wire
Replace the message-as-container model with a flat, append-only chunk log. - chunks table (id, tab_id, seq, turn_id, step, role, type, data_json): one row per chunk; tool_call (assistant) and tool_result (tool) are SEPARATE rows linked by callId. Message/turn are derived groupings, not stored. - chunks/transform.ts: DB-free explode (Chunk[] -> rows) / group (rows -> messages), shared by backend and the browser frontend. - Cache fix: toModelMessages segments each turn at tool-batch boundaries into stable [assistant, tool] pairs per step, so earlier steps serialize byte-identically across requests (kills the prompt-cache churn). - agent-manager persists a turn's chunks on seal (once), discarding a failed fallback attempt's partial chunks; rebuilds agent history from the log. - GET /messages windows the log by chunk seq then groups; loadMoreMessages merges a turn split across the window boundary by turnId. - One-shot migration drops the legacy messages table and clears tabs; settings/credentials/keys/usage preserved. Full suite green (317 tests); biome, tsc, and svelte-check clean.
Diffstat (limited to 'packages/api/tests')
-rw-r--r--packages/api/tests/agent-manager.test.ts11
-rw-r--r--packages/api/tests/routes.test.ts20
2 files changed, 27 insertions, 4 deletions
diff --git a/packages/api/tests/agent-manager.test.ts b/packages/api/tests/agent-manager.test.ts
index ba14cad..6b016db 100644
--- a/packages/api/tests/agent-manager.test.ts
+++ b/packages/api/tests/agent-manager.test.ts
@@ -259,8 +259,15 @@ vi.mock("@dispatch/core", () => ({
getSetting(_key: string) {
return null;
},
- appendMessage() {},
- updateMessage() {},
+ appendChunks() {
+ return [];
+ },
+ explodeUserText() {
+ return [];
+ },
+ explodeTurn() {
+ return [];
+ },
getMessagesForTab(tabId: string) {
return fakeMessagesByTab.get(tabId) ?? [];
},
diff --git a/packages/api/tests/routes.test.ts b/packages/api/tests/routes.test.ts
index eba2226..f4de845 100644
--- a/packages/api/tests/routes.test.ts
+++ b/packages/api/tests/routes.test.ts
@@ -181,11 +181,27 @@ vi.mock("@dispatch/core", () => ({
getSetting(_key: string) {
return null;
},
- appendMessage() {},
- updateMessage() {},
+ appendChunks() {
+ return [];
+ },
+ explodeUserText() {
+ return [];
+ },
+ explodeTurn() {
+ return [];
+ },
getMessagesForTab() {
return [];
},
+ getChunksForTab() {
+ return [];
+ },
+ groupRowsToMessages() {
+ return [];
+ },
+ getTotalChunkCount() {
+ return 0;
+ },
appendEventToChunks(_chunks: unknown[], _event: unknown) {
// no-op stub
},