Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
3import * as Effect from "effect/Effect";
4import * as SqlClient from "effect/sql/SqlClient";
5
6import { runMigrations } from "../Migrations.ts";
7
8const layer = it.layer(NodeSqliteClient.layer({ filename: ":memory:" }));
9const updatedAt = "2026-09-01T00:00:00.000Z";
10const deliveredPayload = JSON.stringify({ completionDelivery: { state: "delivered" } });
11
12layer("075_SubagentDeliveryState", (it) => {
13 it.effect("backfills delivery state without failing on an unreadable payload", () =>
14 Effect.gen(function* () {
15 const sql = yield* SqlClient.SqlClient;
16 yield* runMigrations({ toMigrationInclusive: 74 });
17 const payloads = [
18 ["delivered", deliveredPayload],
19 ["unreadable", ""],
20 ];
21 for (const [id, payload] of payloads) {
22 yield* sql`
23 INSERT INTO orchestration_v2_projection_subagents (
24 subagent_id, thread_id, parent_node_id, provider, origin, status, updated_at,
25 payload_json
26 ) VALUES (
27 ${id}, 'thread-1', 'node-1', 'codex', 'delegated', 'cancelled', ${updatedAt},
28 ${payload}
29 )
30 `;
31 }
32
33 yield* runMigrations({ toMigrationInclusive: 75 });
34 const rows = yield* sql`
35 SELECT subagent_id, completion_delivery_state, payload_json
36 FROM orchestration_v2_projection_subagents ORDER BY subagent_id
37 `;
38 assert.deepStrictEqual(rows, [
39 {
40 subagent_id: "delivered",
41 completion_delivery_state: "delivered",
42 payload_json: deliveredPayload,
43 },
44 { subagent_id: "unreadable", completion_delivery_state: null, payload_json: "" },
45 ]);
46 }),
47 );
48});