| 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 application event source", (it) => { |
| 12 | it.effect("baselines current V1 project state in the shared event log", () => |
| 13 | Effect.gen(function* () { |
| 14 | const sql = yield* SqlClient.SqlClient; |
| 15 | yield* runMigrations({ toMigrationInclusive: 49 }); |
| 16 | yield* sql` |
| 17 | INSERT INTO projection_projects ( |
| 18 | project_id, |
| 19 | title, |
| 20 | workspace_root, |
| 21 | default_model_selection_json, |
| 22 | scripts_json, |
| 23 | created_at, |
| 24 | updated_at, |
| 25 | deleted_at |
| 26 | ) VALUES ( |
| 27 | 'project:existing', |
| 28 | 'Existing project', |
| 29 | '/work/existing', |
| 30 | '{"instanceId":"codex","model":"gpt-5.4"}', |
| 31 | '[]', |
| 32 | '2026-06-19T00:00:00.000Z', |
| 33 | '2026-06-20T00:00:00.000Z', |
| 34 | NULL |
| 35 | ) |
| 36 | `; |
| 37 | |
| 38 | yield* runMigrations(); |
| 39 | |
| 40 | const events = yield* sql<{ |
| 41 | readonly aggregate_kind: string; |
| 42 | readonly stream_id: string; |
| 43 | readonly event_type: string; |
| 44 | readonly application_event_version: number; |
| 45 | }>` |
| 46 | SELECT aggregate_kind, stream_id, event_type, application_event_version |
| 47 | FROM orchestration_events |
| 48 | WHERE stream_id = 'project:existing' |
| 49 | ORDER BY sequence ASC |
| 50 | `; |
| 51 | assert.deepStrictEqual(events, [ |
| 52 | { |
| 53 | aggregate_kind: "project", |
| 54 | stream_id: "project:existing", |
| 55 | event_type: "project.created", |
| 56 | application_event_version: 2, |
| 57 | }, |
| 58 | ]); |
| 59 | }), |
| 60 | ); |
| 61 | }); |