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

055_OrchestrationV2.test.ts

136 lines5.4 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: 61 }, (_, 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 [59, "McpAppModelContext"],
34 [60, "ThreadSnapshotWindowIndexes"],
35 [61, "PullRequestReviewGuides"],
36 ]);
37 assert.deepStrictEqual(yield* runMigrations(), []);
38​
39 const migrations = yield* sql<{
40 readonly migration_id: number;
41 readonly name: string;
42 }>`
43 SELECT migration_id, name
44 FROM effect_sql_migrations
45 WHERE migration_id >= 48
46 ORDER BY migration_id
47 `;
48 assert.deepStrictEqual(migrations, [
49 { migration_id: 48, name: "ProjectionThreadBranchPullRequest" },
50 { migration_id: 49, name: "ProjectionThreadsActiveOrderKey" },
51 { migration_id: 50, name: "ProjectionThreadPullRequests" },
52 { migration_id: 51, name: "ProjectionThreadMessageContext" },
53 { migration_id: 52, name: "ProjectionThreadTitleState" },
54 { migration_id: 53, name: "PullRequestFilesViewed" },
55 { migration_id: 54, name: "ProjectionThreadsAutoSettleDisabledAt" },
56 { migration_id: 55, name: "OrchestrationV2" },
57 { migration_id: 56, name: "RemoveRedundantProjectionIndexes" },
58 { migration_id: 57, name: "ScheduledTaskWebhooks" },
59 { migration_id: 58, name: "WebhookRelayDeliveries" },
60 { migration_id: 59, name: "McpAppModelContext" },
61 { migration_id: 60, name: "ThreadSnapshotWindowIndexes" },
62 { migration_id: 61, name: "PullRequestReviewGuides" },
63 ]);
64​
65 const tables = yield* sql<{ readonly name: string }>`
66 SELECT name
67 FROM sqlite_master
68 WHERE type = 'table'
69 AND name IN (
70 'orchestration_v2_projection_threads',
71 'orchestration_v2_projection_subagents',
72 'orchestration_v2_effect_outbox',
73 'orchestration_v2_turn_item_positions',
74 'orchestration_v2_projection_metadata',
75 'orchestration_v2_projection_provider_session_bindings',
76 'orchestration_v2_thread_launch_workflows',
77 'orchestration_v2_legacy_imports',
78 'scheduled_tasks'
79 )
80 ORDER BY name
81 `;
82 assert.deepStrictEqual(
83 tables.map(({ name }) => name),
84 [
85 "orchestration_v2_effect_outbox",
86 "orchestration_v2_legacy_imports",
87 "orchestration_v2_projection_metadata",
88 "orchestration_v2_projection_provider_session_bindings",
89 "orchestration_v2_projection_subagents",
90 "orchestration_v2_projection_threads",
91 "orchestration_v2_thread_launch_workflows",
92 "orchestration_v2_turn_item_positions",
93 "scheduled_tasks",
94 ],
95 );
96​
97 const eventColumns = yield* sql<{ readonly name: string }>`
98 PRAGMA table_info(orchestration_events)
99 `;
100 const receiptColumns = yield* sql<{ readonly name: string }>`
101 PRAGMA table_info(orchestration_command_receipts)
102 `;
103 const threadColumns = yield* sql<{ readonly name: string }>`
104 PRAGMA table_info(orchestration_v2_projection_threads)
105 `;
106 const subagentColumns = yield* sql<{ readonly name: string }>`
107 PRAGMA table_info(orchestration_v2_projection_subagents)
108 `;
109 assert.ok(eventColumns.some(({ name }) => name === "application_event_version"));
110 assert.ok(receiptColumns.some(({ name }) => name === "command_type"));
111 assert.ok(threadColumns.some(({ name }) => name === "provider_instance_id"));
112 assert.ok(subagentColumns.some(({ name }) => name === "driver"));
113 assert.ok(subagentColumns.some(({ name }) => name === "provider_instance_id"));
114​
115 const indexes = yield* sql<{ readonly name: string }>`
116 SELECT name
117 FROM sqlite_master
118 WHERE type = 'index'
119 AND name IN (
120 'idx_orchestration_events_application_high_water',
121 'orchestration_events_v2_created_threads_idx',
122 'orchestration_v2_projection_turn_items_shell_pending_idx'
123 )
124 ORDER BY name
125 `;
126 assert.deepStrictEqual(
127 indexes.map(({ name }) => name),
128 [
129 "idx_orchestration_events_application_high_water",
130 "orchestration_events_v2_created_threads_idx",
131 "orchestration_v2_projection_turn_items_shell_pending_idx",
132 ],
133 );
134 }),
135 );
136});