Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

055_OrchestrationV2.test.ts

130 lines5.1 KB

1import { assert, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as SqlClient from "effect/sql/SqlClient";
5​
6import { migrationEntries, runMigrations } from "../Migrations.ts";
7import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
8​
9const layer = it.layer(Layer.mergeAll(NodeSqliteClient.layer({ filename: ":memory:" })));
10​
11layer("055_OrchestrationV2", (it) => {
12 it.effect("keeps released migrations contiguous", () =>
13 Effect.sync(() => {
14 assert.deepStrictEqual(
15 migrationEntries.map(([id]) => id),
16 Array.from({ length: 58 }, (_, index) => index + 1),
17 );
18 }),
19 );
20​
21 it.effect("upgrades released schema 53 through the latest migrations", () =>
22 Effect.gen(function* () {
23 const sql = yield* SqlClient.SqlClient;
24 yield* runMigrations({ toMigrationInclusive: 53 });
25​
26 const executed = yield* runMigrations();
27 assert.deepStrictEqual(executed, [
28 [54, "ProjectionThreadsAutoSettleDisabledAt"],
29 [55, "OrchestrationV2"],
30 [56, "RemoveRedundantProjectionIndexes"],
31 [57, "ScheduledTaskWebhooks"],
32 [58, "WebhookRelayDeliveries"],
33 ]);
34 assert.deepStrictEqual(yield* runMigrations(), []);
35​
36 const migrations = yield* sql<{
37 readonly migration_id: number;
38 readonly name: string;
39 }>`
40 SELECT migration_id, name
41 FROM effect_sql_migrations
42 WHERE migration_id >= 48
43 ORDER BY migration_id
44 `;
45 assert.deepStrictEqual(migrations, [
46 { migration_id: 48, name: "ProjectionThreadBranchPullRequest" },
47 { migration_id: 49, name: "ProjectionThreadsActiveOrderKey" },
48 { migration_id: 50, name: "ProjectionThreadPullRequests" },
49 { migration_id: 51, name: "ProjectionThreadMessageContext" },
50 { migration_id: 52, name: "ProjectionThreadTitleState" },
51 { migration_id: 53, name: "PullRequestFilesViewed" },
52 { migration_id: 54, name: "ProjectionThreadsAutoSettleDisabledAt" },
53 { migration_id: 55, name: "OrchestrationV2" },
54 { migration_id: 56, name: "RemoveRedundantProjectionIndexes" },
55 { migration_id: 57, name: "ScheduledTaskWebhooks" },
56 { migration_id: 58, name: "WebhookRelayDeliveries" },
57 ]);
58​
59 const tables = yield* sql<{ readonly name: string }>`
60 SELECT name
61 FROM sqlite_master
62 WHERE type = 'table'
63 AND name IN (
64 'orchestration_v2_projection_threads',
65 'orchestration_v2_projection_subagents',
66 'orchestration_v2_effect_outbox',
67 'orchestration_v2_turn_item_positions',
68 'orchestration_v2_projection_metadata',
69 'orchestration_v2_projection_provider_session_bindings',
70 'orchestration_v2_thread_launch_workflows',
71 'orchestration_v2_legacy_imports',
72 'scheduled_tasks'
73 )
74 ORDER BY name
75 `;
76 assert.deepStrictEqual(
77 tables.map(({ name }) => name),
78 [
79 "orchestration_v2_effect_outbox",
80 "orchestration_v2_legacy_imports",
81 "orchestration_v2_projection_metadata",
82 "orchestration_v2_projection_provider_session_bindings",
83 "orchestration_v2_projection_subagents",
84 "orchestration_v2_projection_threads",
85 "orchestration_v2_thread_launch_workflows",
86 "orchestration_v2_turn_item_positions",
87 "scheduled_tasks",
88 ],
89 );
90​
91 const eventColumns = yield* sql<{ readonly name: string }>`
92 PRAGMA table_info(orchestration_events)
93 `;
94 const receiptColumns = yield* sql<{ readonly name: string }>`
95 PRAGMA table_info(orchestration_command_receipts)
96 `;
97 const threadColumns = yield* sql<{ readonly name: string }>`
98 PRAGMA table_info(orchestration_v2_projection_threads)
99 `;
100 const subagentColumns = yield* sql<{ readonly name: string }>`
101 PRAGMA table_info(orchestration_v2_projection_subagents)
102 `;
103 assert.ok(eventColumns.some(({ name }) => name === "application_event_version"));
104 assert.ok(receiptColumns.some(({ name }) => name === "command_type"));
105 assert.ok(threadColumns.some(({ name }) => name === "provider_instance_id"));
106 assert.ok(subagentColumns.some(({ name }) => name === "driver"));
107 assert.ok(subagentColumns.some(({ name }) => name === "provider_instance_id"));
108​
109 const indexes = yield* sql<{ readonly name: string }>`
110 SELECT name
111 FROM sqlite_master
112 WHERE type = 'index'
113 AND name IN (
114 'idx_orchestration_events_application_high_water',
115 'orchestration_events_v2_created_threads_idx',
116 'orchestration_v2_projection_turn_items_shell_pending_idx'
117 )
118 ORDER BY name
119 `;
120 assert.deepStrictEqual(
121 indexes.map(({ name }) => name),
122 [
123 "idx_orchestration_events_application_high_water",
124 "orchestration_events_v2_created_threads_idx",
125 "orchestration_v2_projection_turn_items_shell_pending_idx",
126 ],
127 );
128 }),
129 );
130});