From 19dbc41a21a48e9a96cec64a9ba092bd899c368f Mon Sep 17 00:00:00 2001 From: Antigravity Date: Sat, 26 Sep 2026 16:43:15 +0800 Subject: [PATCH] test: align Chat Swarm schema expectation with v22 --- src/chat-swarm-store.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chat-swarm-store.test.ts b/src/chat-swarm-store.test.ts index 07072efc3..52dc128f9 100644 --- a/src/chat-swarm-store.test.ts +++ b/src/chat-swarm-store.test.ts @@ -19,7 +19,7 @@ test("RESULT_READY releases worker while retaining immutable result until collec test("restart converts possibly started work to reconciliation but keeps queued work queued", () => { const f = fixture(); let queuedId: string; let runningId: string; try { queuedId = f.store.createTask({ swarmId: f.swarm.id, taskKey: "queued", prompt: "q" }).task.id; runningId = f.store.createTask({ swarmId: f.swarm.id, taskKey: "running", prompt: "r" }).task.id; f.store.claimTask(runningId, f.worker.id); f.store.startTask(runningId, f.worker.id); const attempt = f.store.listAttempts(runningId)[0]!; f.store.close(); f.store = new ChatSwarmStore(f.root); assert.equal(f.store.getTask(runningId)?.lifecycleState, "RUNNING"); f.store.recoverAfterRestart(); assert.equal(f.store.getTask(queuedId)?.lifecycleState, "QUEUED"); assert.equal(f.store.getTask(runningId)?.lifecycleState, "RECONCILE_REQUIRED"); assert.throws(() => f.store.claimTask(runningId, f.worker.id), (e: unknown) => e instanceof ChatSwarmError && e.code === "RECONCILIATION_REQUIRED"); assert.throws(() => f.store.resolveReconciliation(runningId, "REQUEUE"), (e: unknown) => e instanceof ChatSwarmError && e.code === "RECONCILIATION_REQUIRED"); assert.equal(f.store.resolveReconciliation(runningId, "REQUEUE", undefined, { taskId: runningId, attemptId: attempt.id, disposition: "NO_EFFECT", evidenceRef: "restart-probe-1" }).lifecycleState, "QUEUED"); } finally { cleanup(f); } }); -test("migration is idempotent and payload boundaries are enforced", () => { const f = fixture(); try { const sqlite = (f.store as unknown as { sqlite: { prepare: (sql: string) => { get: () => { version: number } } } }).sqlite; assert.equal(sqlite.prepare("select max(version) as version from devspace_schema_migrations").get().version, 21); const prompt = f.store.createTask({ swarmId: f.swarm.id, taskKey: "max", prompt: "x".repeat(MAX_PROMPT_BYTES) }).task; f.store.claimTask(prompt.id, f.worker.id); assert.equal(f.store.submitResult(prompt.id, f.worker.id, "x".repeat(MAX_RESULT_BYTES)).result?.length, MAX_RESULT_BYTES); const overflow = f.store.createTask({ swarmId: f.swarm.id, taskKey: "overflow", prompt: "p" }).task; f.store.claimTask(overflow.id, f.worker.id); assert.throws(() => f.store.submitResult(overflow.id, f.worker.id, "x".repeat(MAX_RESULT_BYTES + 1)), ChatSwarmError); f.store.close(); f.store = new ChatSwarmStore(f.root); f.store.recoverAfterRestart(); assert.equal(f.store.getTask(overflow.id)?.lifecycleState, "RECONCILE_REQUIRED"); } finally { cleanup(f); } }); +test("migration is idempotent and payload boundaries are enforced", () => { const f = fixture(); try { const sqlite = (f.store as unknown as { sqlite: { prepare: (sql: string) => { get: () => { version: number } } } }).sqlite; assert.equal(sqlite.prepare("select max(version) as version from devspace_schema_migrations").get().version, 22); const prompt = f.store.createTask({ swarmId: f.swarm.id, taskKey: "max", prompt: "x".repeat(MAX_PROMPT_BYTES) }).task; f.store.claimTask(prompt.id, f.worker.id); assert.equal(f.store.submitResult(prompt.id, f.worker.id, "x".repeat(MAX_RESULT_BYTES)).result?.length, MAX_RESULT_BYTES); const overflow = f.store.createTask({ swarmId: f.swarm.id, taskKey: "overflow", prompt: "p" }).task; f.store.claimTask(overflow.id, f.worker.id); assert.throws(() => f.store.submitResult(overflow.id, f.worker.id, "x".repeat(MAX_RESULT_BYTES + 1)), ChatSwarmError); f.store.close(); f.store = new ChatSwarmStore(f.root); f.store.recoverAfterRestart(); assert.equal(f.store.getTask(overflow.id)?.lifecycleState, "RECONCILE_REQUIRED"); } finally { cleanup(f); } }); test("unknown persisted task state fails closed", () => { const f = fixture(); try { const sqlite = (f.store as unknown as { sqlite: { prepare: (sql: string) => { run: (...args: unknown[]) => void } } }).sqlite; const task = f.store.createTask({ swarmId: f.swarm.id, taskKey: "corrupt", prompt: "p" }).task; sqlite.prepare("update chat_swarm_tasks set lifecycle_state=? where id=?").run("CORRUPT", task.id); assert.throws(() => f.store.getTask(task.id), (e: unknown) => e instanceof ChatSwarmError && e.code === "INVALID_STATE"); } finally { cleanup(f); } });