| 1 | import { assert, it } from "@effect/vitest"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as SqlClient from "effect/sql/SqlClient"; |
| 5 | |
| 6 | import { runMigrations } from "../Migrations.ts"; |
| 7 | import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient"; |
| 8 | |
| 9 | const layer = it.layer(Layer.mergeAll(NodeSqliteClient.layer({ filename: ":memory:" }))); |
| 10 | |
| 11 | layer("055_OrchestrationV2 effect cancellation", (it) => { |
| 12 | it.effect("creates the effect outbox with the cancelled terminal status", () => |
| 13 | Effect.gen(function* () { |
| 14 | const sql = yield* SqlClient.SqlClient; |
| 15 | yield* runMigrations(); |
| 16 | yield* sql` |
| 17 | INSERT INTO orchestration_v2_effect_outbox ( |
| 18 | effect_id, |
| 19 | command_id, |
| 20 | thread_id, |
| 21 | effect_type, |
| 22 | payload_json, |
| 23 | status, |
| 24 | attempt_count, |
| 25 | available_at, |
| 26 | created_at, |
| 27 | updated_at, |
| 28 | completed_at |
| 29 | ) VALUES ( |
| 30 | 'effect:cancelled', |
| 31 | 'command:cancelled', |
| 32 | 'thread:cancelled', |
| 33 | 'provider-turn.start', |
| 34 | '{"type":"provider-turn.start","runId":"run:cancelled"}', |
| 35 | 'cancelled', |
| 36 | 1, |
| 37 | '2026-06-20T00:00:00.000Z', |
| 38 | '2026-06-20T00:00:00.000Z', |
| 39 | '2026-06-20T00:01:00.000Z', |
| 40 | '2026-06-20T00:01:00.000Z' |
| 41 | ) |
| 42 | `; |
| 43 | |
| 44 | const rows = yield* sql<{ |
| 45 | readonly effect_id: string; |
| 46 | readonly status: string; |
| 47 | readonly attempt_count: number; |
| 48 | }>` |
| 49 | SELECT effect_id, status, attempt_count |
| 50 | FROM orchestration_v2_effect_outbox |
| 51 | `; |
| 52 | assert.deepStrictEqual(rows, [ |
| 53 | { |
| 54 | effect_id: "effect:cancelled", |
| 55 | status: "cancelled", |
| 56 | attempt_count: 1, |
| 57 | }, |
| 58 | ]); |
| 59 | }), |
| 60 | ); |
| 61 | }); |