Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/chat-swarm-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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); } });

Expand Down
Loading