Repository navigation
Expand file tree
/
Copy path024_BackfillProjectionThreadShellSummary.test.ts
More file actions
219 lines (207 loc) · 5.75 KB
/
Copy path024_BackfillProjectionThreadShellSummary.test.ts
File metadata and controls
219 lines (207 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import { assert, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as SqlClient from "effect/sql/SqlClient";
import { runMigrations } from "../Migrations.ts";
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
const layer = it.layer(Layer.mergeAll(NodeSqliteClient.layer({ filename: ":memory:" })));
layer("024_BackfillProjectionThreadShellSummary", (it) => {
it.effect("backfills thread shell summary fields and clears stale projected approvals", () =>
Effect.gen(function* () {
const sql = yield* SqlClient.SqlClient;
yield* runMigrations({ toMigrationInclusive: 23 });
yield* sql`
INSERT INTO projection_threads (
thread_id,
project_id,
title,
model_selection_json,
runtime_mode,
interaction_mode,
branch,
worktree_path,
latest_turn_id,
created_at,
updated_at,
archived_at,
latest_user_message_at,
pending_approval_count,
pending_user_input_count,
has_actionable_proposed_plan,
deleted_at
)
VALUES (
'thread-1',
'project-1',
'Thread 1',
'{"provider":"codex","model":"gpt-5-codex"}',
'approval-required',
'plan',
NULL,
NULL,
'turn-1',
'2026-02-24T00:00:00.000Z',
'2026-02-24T00:00:00.000Z',
NULL,
NULL,
0,
0,
0,
NULL
)
`;
yield* sql`
INSERT INTO projection_thread_messages (
message_id,
thread_id,
turn_id,
role,
text,
attachments_json,
is_streaming,
created_at,
updated_at
)
VALUES (
'message-user-1',
'thread-1',
'turn-1',
'user',
'Need help',
NULL,
0,
'2026-02-24T00:01:00.000Z',
'2026-02-24T00:01:00.000Z'
)
`;
yield* sql`
INSERT INTO projection_thread_activities (
activity_id,
thread_id,
turn_id,
tone,
kind,
summary,
payload_json,
sequence,
created_at
)
VALUES
(
'activity-approval-requested',
'thread-1',
'turn-1',
'approval',
'approval.requested',
'Command approval requested',
'{"requestId":"approval-1","requestKind":"command"}',
NULL,
'2026-02-24T00:02:00.000Z'
),
(
'activity-approval-stale',
'thread-1',
'turn-1',
'error',
'provider.approval.respond.failed',
'Provider approval response failed',
'{"requestId":"approval-1","detail":"Unknown pending permission request: approval-1"}',
NULL,
'2026-02-24T00:03:00.000Z'
),
(
'activity-user-input-requested',
'thread-1',
'turn-1',
'info',
'user-input.requested',
'User input requested',
'{"requestId":"input-1","questions":[{"id":"area","header":"Area","question":"Which repo area should I inspect next?","options":[{"label":"Server","description":"Server orchestration."}]}]}',
NULL,
'2026-02-24T00:04:00.000Z'
)
`;
yield* sql`
INSERT INTO projection_thread_proposed_plans (
plan_id,
thread_id,
turn_id,
plan_markdown,
implemented_at,
implementation_thread_id,
created_at,
updated_at
)
VALUES (
'plan-1',
'thread-1',
'turn-1',
'# Do the thing',
NULL,
NULL,
'2026-02-24T00:05:00.000Z',
'2026-02-24T00:05:00.000Z'
)
`;
yield* sql`
INSERT INTO projection_pending_approvals (
request_id,
thread_id,
turn_id,
status,
decision,
created_at,
resolved_at
)
VALUES (
'approval-1',
'thread-1',
'turn-1',
'pending',
NULL,
'2026-02-24T00:02:00.000Z',
NULL
)
`;
yield* runMigrations({ toMigrationInclusive: 24 });
const threadRows = yield* sql<{
readonly latestUserMessageAt: string | null;
readonly pendingApprovalCount: number;
readonly pendingUserInputCount: number;
readonly hasActionableProposedPlan: number;
}>`
SELECT
latest_user_message_at AS "latestUserMessageAt",
pending_approval_count AS "pendingApprovalCount",
pending_user_input_count AS "pendingUserInputCount",
has_actionable_proposed_plan AS "hasActionableProposedPlan"
FROM projection_threads
WHERE thread_id = 'thread-1'
`;
assert.deepStrictEqual(threadRows, [
{
latestUserMessageAt: "2026-02-24T00:01:00.000Z",
pendingApprovalCount: 0,
pendingUserInputCount: 1,
hasActionableProposedPlan: 1,
},
]);
const approvalRows = yield* sql<{
readonly status: string;
readonly resolvedAt: string | null;
}>`
SELECT
status,
resolved_at AS "resolvedAt"
FROM projection_pending_approvals
WHERE request_id = 'approval-1'
`;
assert.deepStrictEqual(approvalRows, [
{
status: "resolved",
resolvedAt: "2026-02-24T00:03:00.000Z",
},
]);
}),
);
});