The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { assert, it } from "@effect/vitest"; |
| 2 | import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as SqlClient from "effect/sql/SqlClient"; |
| 5 | |
| 6 | import { runMigrations } from "../Migrations.ts"; |
| 7 | |
| 8 | const layer = it.layer(NodeSqliteClient.layer({ filename: ":memory:" })); |
| 9 | |
| 10 | layer("086_QueuedTurnInputIndex", (it) => { |
| 11 | it.effect("keeps a user message with a malformed payload migratable and writable", () => |
| 12 | Effect.gen(function* () { |
| 13 | const sql = yield* SqlClient.SqlClient; |
| 14 | yield* runMigrations({ toMigrationInclusive: 85 }); |
| 15 | const insertUserMessage = (id: string) => sql` |
| 16 | INSERT INTO orchestration_v2_projection_turn_items ( |
| 17 | turn_item_id, thread_id, run_id, ordinal, type, status, updated_at, payload_json |
| 18 | ) |
| 19 | VALUES ( |
| 20 | ${id}, 'thread-1', 'run-1', 1, 'user_message', 'completed', |
| 21 | '2026-11-14T00:00:00.000Z', '{not json' |
| 22 | ) |
| 23 | `; |
| 24 | yield* insertUserMessage("before-86"); |
| 25 | |
| 26 | yield* runMigrations(); |
| 27 | yield* insertUserMessage("after-86"); |
| 28 | |
| 29 | const rows = yield* sql<{ readonly turn_item_id: string }>` |
| 30 | SELECT turn_item_id FROM orchestration_v2_projection_turn_items ORDER BY turn_item_id |
| 31 | `; |
| 32 | assert.deepEqual( |
| 33 | rows.map((row) => row.turn_item_id), |
| 34 | ["after-86", "before-86"], |
| 35 | ); |
| 36 | }), |
| 37 | ); |
| 38 | |
| 39 | it.effect("re-guards the index on a database that ran the unguarded migration 86", () => |
| 40 | Effect.gen(function* () { |
| 41 | const sql = yield* SqlClient.SqlClient; |
| 42 | yield* runMigrations({ toMigrationInclusive: 91 }); |
| 43 | yield* sql`DROP INDEX orchestration_v2_projection_turn_items_queued_input_idx`; |
| 44 | yield* sql` |
| 45 | CREATE INDEX orchestration_v2_projection_turn_items_queued_input_idx |
| 46 | ON orchestration_v2_projection_turn_items(run_id) |
| 47 | WHERE type = 'user_message' AND json_extract(payload_json, '$.inputIntent') = 'queued_turn' |
| 48 | `; |
| 49 | |
| 50 | yield* runMigrations(); |
| 51 | yield* sql` |
| 52 | INSERT INTO orchestration_v2_projection_turn_items ( |
| 53 | turn_item_id, thread_id, run_id, ordinal, type, status, updated_at, payload_json |
| 54 | ) |
| 55 | VALUES ( |
| 56 | 'malformed', 'thread-1', 'run-1', 1, 'user_message', 'completed', |
| 57 | '2026-11-14T00:00:00.000Z', '{not json' |
| 58 | ) |
| 59 | `; |
| 60 | }).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))), |
| 61 | ); |
| 62 | }); |