Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, it } from "@effect/vitest";
3import {
4 CommandId,
5 EventId,
6 type OrchestrationV2AppThread,
7 ProjectId,
8 ProviderInstanceId,
9 ThreadId,
10} from "@t3tools/contracts";
11import * as DateTime from "effect/DateTime";
12import * as Effect from "effect/Effect";
13import * as Layer from "effect/Layer";
14import * as Option from "effect/Option";
15import * as Schema from "effect/Schema";
16import { TestClock } from "effect/testing";
17import * as SqlClient from "effect/sql/SqlClient";
18
19import * as ServerConfig from "../config.ts";
20import { OrchestrationEffectRequestV2 } from "../orchestration-v2/EffectOutbox.ts";
21import * as EventSink from "../orchestration-v2/EventSink.ts";
22import * as EventStore from "../orchestration-v2/EventStore.ts";
23import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
24import * as LegacyV1ThreadImporter from "../orchestration-v2/legacy/LegacyV1ThreadImporter.ts";
25import * as ProjectionReplay from "../orchestration-v2/testkit/ProjectionReplay.ts";
26import * as ProjectionStore from "../orchestration-v2/ProjectionStore.ts";
27import * as ProjectStore from "../orchestration-v2/ProjectStore.ts";
28import * as ThreadCommandExecutor from "../orchestration-v2/ThreadCommandExecutor.ts";
29import { planThreadDeletion } from "../orchestration-v2/ThreadDeletion.ts";
30import * as SqlitePersistence from "../persistence/Sqlite.ts";
31import * as ProjectSettingsOverrideSweep from "../provider/ProjectSettingsOverrideSweep.ts";
32import * as ServerSettings from "../serverSettings.ts";
33import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
34import * as ProjectEnrichmentService from "./ProjectEnrichmentService.ts";
35import * as ProjectFaviconResolver from "./ProjectFaviconResolver.ts";
36import * as ProjectService from "./ProjectService.ts";
37import * as RepositoryIdentityResolver from "./RepositoryIdentityResolver.ts";
38
39const layerEventPersistence = EventSink.layer.pipe(
40 Layer.provideMerge(Layer.merge(EventStore.layer, ProjectionStore.layer)),
41);
42const layerServices = Layer.mergeAll(
43 LegacyV1ThreadImporter.layer.pipe(Layer.provideMerge(layerEventPersistence)),
44 ProjectionReplay.layer.pipe(Layer.provide(layerEventPersistence)),
45 ProjectStore.layer,
46 IdAllocator.layer,
47 ThreadCommandExecutor.layer,
48 Layer.succeed(WorkspacePaths.WorkspacePaths, {
49 normalizeWorkspaceRoot: (workspaceRoot) => Effect.succeed(workspaceRoot),
50 resolveRelativePathWithinRoot: ({ workspaceRoot, relativePath }) =>
51 Effect.succeed({ absolutePath: `${workspaceRoot}/${relativePath}`, relativePath }),
52 }),
53).pipe(
54 Layer.provideMerge(
55 ProjectEnrichmentService.layer.pipe(
56 Layer.provide(
57 Layer.merge(
58 Layer.succeed(RepositoryIdentityResolver.RepositoryIdentityResolver, {
59 resolve: () => Effect.succeed(null),
60 }),
61 Layer.succeed(ProjectFaviconResolver.ProjectFaviconResolver, {
62 invalidate: () => Effect.void,
63 resolvePath: () => Effect.succeed(null),
64 }),
65 ),
66 ),
67 ),
68 ),
69 Layer.provideMerge(ServerSettings.layerTest()),
70);
71const layerDatabase = SqlitePersistence.layerMemory.pipe(
72 Layer.provideMerge(ServerConfig.layerTest(process.cwd(), { prefix: "project-deletion-test-" })),
73 Layer.provideMerge(NodeServices.layer),
74);
75const decodeEffectRequest = Schema.decodeUnknownEffect(
76 Schema.fromJsonString(OrchestrationEffectRequestV2),
77);
78
79const seedProject = Effect.fn("ProjectDeletionTest.seedProject")(function* (projectId: ProjectId) {
80 const sql = yield* SqlClient.SqlClient;
81 yield* sql`
82 INSERT INTO projection_projects (
83 project_id, title, workspace_root, default_model_selection_json,
84 scripts_json, created_at, updated_at, deleted_at
85 ) VALUES (
86 ${projectId}, 'Deletion test', ${`/work/${projectId}`}, NULL,
87 '[]', '2026-01-01T00:00:00.000Z', '2026-01-01T00:00:00.000Z', NULL
88 )
89 `;
90});
91
92function nativeThreadCreated(projectId: ProjectId, threadId: ThreadId) {
93 const createdAt = DateTime.makeUnsafe("2026-01-01T00:00:00.000Z");
94 const providerInstanceId = ProviderInstanceId.make("codex");
95 const payload: OrchestrationV2AppThread = {
96 createdBy: "user",
97 creationSource: "web",
98 id: threadId,
99 projectId,
100 title: threadId,
101 providerInstanceId,
102 modelSelection: { instanceId: providerInstanceId, model: "gpt-5" },
103 runtimeMode: "full-access",
104 interactionMode: "default",
105 branch: null,
106 worktreePath: null,
107 activeProviderThreadId: null,
108 lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
109 forkedFrom: null,
110 createdAt,
111 updatedAt: createdAt,
112 archivedAt: null,
113 settledOverride: null,
114 settledAt: null,
115 lastVisitedAt: null,
116 deletedAt: null,
117 };
118 return {
119 id: EventId.make(`created:${threadId}`),
120 type: "thread.created" as const,
121 threadId,
122 providerInstanceId,
123 occurredAt: createdAt,
124 payload,
125 };
126}
127
128it.effect("retries a partial project deletion without repeating child events or cleanup", () =>
129 Effect.gen(function* () {
130 const sql = yield* SqlClient.SqlClient;
131 const projectId = ProjectId.make("project:partial-deletion");
132 const threadIds = [ThreadId.make("thread:delete-a"), ThreadId.make("thread:delete-b")] as const;
133 const commandId = CommandId.make("command:partial-project-delete");
134 yield* seedProject(projectId);
135 yield* TestClock.setTime(Date.parse("2026-09-04T12:00:00.000Z"));
136
137 yield* Effect.gen(function* () {
138 const eventSink = yield* EventSink.EventSinkV2;
139 const projections = yield* ProjectionStore.ProjectionStoreV2;
140 yield* eventSink.write({
141 events: threadIds.map((threadId) => nativeThreadCreated(projectId, threadId)),
142 });
143 const attempts: ThreadId[] = [];
144 const failingEventSink = EventSink.EventSinkV2.of({
145 ...eventSink,
146 commitCommand: Effect.fn("ProjectDeletionTest.failSecondChild")(function* (
147 input: Parameters<EventSink.EventSinkV2Shape["commitCommand"]>[0],
148 ) {
149 attempts.push(input.threadId);
150 if (attempts.length === 2) {
151 return yield* new EventSink.EventSinkWriteError({
152 commandId: input.commandId,
153 eventCount: input.events.length,
154 cause: new Error("Injected failure for the second child"),
155 });
156 }
157 return yield* eventSink.commitCommand(input);
158 }),
159 });
160 const service = yield* ProjectService.make.pipe(
161 Effect.provideService(EventSink.EventSinkV2, failingEventSink),
162 );
163 const input = { commandId, projectId, force: true };
164 const failure = yield* service.delete(input).pipe(Effect.flip);
165 assert.instanceOf(failure, ProjectService.ProjectOperationError);
166 if (failure._tag !== "ProjectOperationError") return assert.fail("Expected a child failure");
167 assert.equal(failure.operation, "delete-thread");
168 assert.lengthOf(attempts, 2);
169 const firstThreadId = attempts[0] ?? assert.fail("The first child was not attempted");
170 const failedThreadId = attempts[1] ?? assert.fail("The second child was not attempted");
171 assert.notEqual(firstThreadId, failedThreadId);
172 assert.isTrue(Option.isSome(yield* service.getById(projectId)));
173 assert.isNotNull((yield* projections.getThreadProjection(firstThreadId)).thread.deletedAt);
174 assert.isNull((yield* projections.getThreadProjection(failedThreadId)).thread.deletedAt);
175
176 const readDeletions = sql<{
177 readonly sequence: number;
178 readonly stream_id: string;
179 readonly command_id: string;
180 readonly event_type: string;
181 }>`
182 SELECT sequence, stream_id, command_id, event_type
183 FROM orchestration_events
184 WHERE event_type IN ('thread.deleted', 'project.deleted')
185 AND stream_id IN (${threadIds[0]}, ${threadIds[1]}, ${projectId})
186 ORDER BY sequence ASC
187 `;
188 const readCleanup = sql<{
189 readonly effect_id: string;
190 readonly thread_id: string;
191 readonly command_id: string;
192 readonly effect_type: string;
193 }>`
194 SELECT effect_id, thread_id, command_id, effect_type
195 FROM orchestration_v2_effect_outbox
196 WHERE thread_id IN (${threadIds[0]}, ${threadIds[1]})
197 ORDER BY effect_id ASC
198 `;
199 const partialEvents = yield* readDeletions;
200 const partialCleanup = yield* readCleanup;
201 assert.lengthOf(partialEvents, 1);
202 assert.equal(partialEvents[0]?.stream_id, firstThreadId);
203 assert.equal(partialEvents[0]?.event_type, "thread.deleted");
204 assert.deepEqual(
205 partialCleanup.map((effect) => [effect.thread_id, effect.effect_type]),
206 [
207 [firstThreadId, "preview.cleanup"],
208 [firstThreadId, "scheduled-tasks.cleanup"],
209 [firstThreadId, "terminal.cleanup"],
210 [firstThreadId, "thread-content.purge"],
211 ],
212 );
213
214 const deletedProject = yield* service.delete(input);
215 assert.isNotNull(deletedProject.deletedAt);
216 assert.isTrue(Option.isNone(yield* service.getById(projectId)));
217 assert.deepEqual(attempts, [firstThreadId, failedThreadId, failedThreadId]);
218 for (const threadId of threadIds) {
219 assert.isNotNull((yield* projections.getThreadProjection(threadId)).thread.deletedAt);
220 }
221 const finalEvents = yield* readDeletions;
222 assert.deepEqual(
223 finalEvents.map((event) => [event.stream_id, event.event_type]),
224 [
225 [firstThreadId, "thread.deleted"],
226 [failedThreadId, "thread.deleted"],
227 [projectId, "project.deleted"],
228 ],
229 );
230 assert.deepEqual(finalEvents[0], partialEvents[0]);
231 assert.equal(finalEvents[2]?.command_id, commandId);
232 const finalCleanup = yield* readCleanup;
233 assert.lengthOf(finalCleanup, 8);
234 assert.deepEqual(
235 finalCleanup.filter((effect) => effect.thread_id === firstThreadId),
236 partialCleanup,
237 );
238 for (const threadId of threadIds) {
239 const expectedCommandId = `${commandId}:delete-thread:${threadId}`;
240 assert.deepEqual(
241 finalCleanup.filter((effect) => effect.thread_id === threadId),
242 [
243 {
244 effect_id: `effect:${expectedCommandId}:preview.cleanup`,
245 thread_id: threadId,
246 command_id: expectedCommandId,
247 effect_type: "preview.cleanup",
248 },
249 {
250 effect_id: `effect:${expectedCommandId}:scheduled-tasks.cleanup`,
251 thread_id: threadId,
252 command_id: expectedCommandId,
253 effect_type: "scheduled-tasks.cleanup",
254 },
255 {
256 effect_id: `effect:${expectedCommandId}:terminal.cleanup`,
257 thread_id: threadId,
258 command_id: expectedCommandId,
259 effect_type: "terminal.cleanup",
260 },
261 {
262 effect_id: `effect:${expectedCommandId}:thread-content.purge`,
263 thread_id: threadId,
264 command_id: expectedCommandId,
265 effect_type: "thread-content.purge",
266 },
267 ],
268 );
269 }
270 }).pipe(Effect.provide(layerServices));
271 }).pipe(Effect.provide(layerDatabase)),
272);
273
274it.effect(
275 "hydrates a migrated transcript before deleting its project and cleaning attachments",
276 () =>
277 Effect.gen(function* () {
278 const sql = yield* SqlClient.SqlClient;
279 const projectId = ProjectId.make("project:legacy-deletion");
280 const threadId = ThreadId.make("thread:legacy-deletion");
281 const commandId = CommandId.make("command:legacy-project-delete");
282 yield* seedProject(projectId);
283 yield* sql`
284 INSERT INTO projection_threads (
285 thread_id, project_id, title, model_selection_json,
286 runtime_mode, interaction_mode, branch, worktree_path, latest_turn_id,
287 created_at, updated_at, archived_at, deleted_at
288 ) VALUES (
289 ${threadId}, ${projectId}, 'Legacy thread', '{"instanceId":"codex","model":"gpt-5.4"}',
290 'full-access', 'default', NULL, NULL, NULL,
291 '2026-01-01T00:00:00.000Z', '2026-01-04T00:00:00.000Z', NULL, NULL
292 )
293 `;
294 yield* sql`
295 INSERT INTO projection_thread_messages (
296 message_id, thread_id, turn_id, role, text, attachments_json,
297 is_streaming, created_at, updated_at
298 ) VALUES
299 (
300 'message:legacy-delete:1', ${threadId}, NULL, 'user', 'First question with screenshot',
301 '[{"type":"image","id":"legacy_screenshot","name":"screenshot.png","mimeType":"image/png","sizeBytes":128}]',
302 0, '2026-01-01T01:00:00.000Z', '2026-01-01T01:00:00.000Z'
303 ),
304 (
305 'message:legacy-delete:2', ${threadId}, NULL, 'assistant', 'First answer', '[]',
306 0, '2026-01-02T01:00:00.000Z', '2026-01-02T01:00:00.000Z'
307 ),
308 (
309 'message:legacy-delete:3', ${threadId}, NULL, 'user', 'Follow-up question', '[]',
310 0, '2026-01-03T01:00:00.000Z', '2026-01-03T01:00:00.000Z'
311 ),
312 (
313 'message:legacy-delete:4', ${threadId}, NULL, 'assistant', 'Follow-up answer', '[]',
314 0, '2026-01-04T01:00:00.000Z', '2026-01-04T01:00:00.000Z'
315 )
316 `;
317 yield* TestClock.setTime(Date.parse("2026-09-04T12:00:00.000Z"));
318
319 yield* Effect.gen(function* () {
320 const importer = yield* LegacyV1ThreadImporter.LegacyV1ThreadImporter;
321 const maintenance = yield* ProjectionReplay.ProjectionReplay;
322 const projections = yield* ProjectionStore.ProjectionStoreV2;
323 const service = yield* ProjectService.make;
324 assert.deepEqual(yield* importer.reconcileShells, {
325 importedThreadCount: 1,
326 importedMessageCount: 2,
327 });
328 assert.equal(yield* importer.pendingThreadCount, 1);
329 assert.isTrue((yield* maintenance.rebuild).valid);
330 const shellProjection = yield* projections.getThreadProjection(threadId);
331 assert.deepEqual(
332 shellProjection.messages.map((message) => message.id),
333 ["message:legacy-delete:3", "message:legacy-delete:4"],
334 );
335 assert.deepEqual(
336 shellProjection.messages.flatMap((message) => message.attachments),
337 [],
338 );
339
340 const deletedProject = yield* service.delete({ commandId, projectId, force: true });
341 assert.isNotNull(deletedProject.deletedAt);
342 assert.isTrue(Option.isNone(yield* service.getById(projectId)));
343 const projection = yield* projections.getThreadProjection(threadId);
344 assert.isNotNull(projection.thread.deletedAt);
345 assert.lengthOf(projection.messages, 4);
346 assert.equal(yield* importer.pendingThreadCount, 0);
347 const rows = yield* sql<{
348 readonly v2_deleted_at: string | null;
349 readonly project_deleted_at: string | null;
350 }>`
351 SELECT v2.deleted_at AS v2_deleted_at,
352 project.deleted_at AS project_deleted_at
353 FROM orchestration_v2_projection_threads AS v2
354 JOIN projection_projects AS project ON project.project_id = v2.project_id
355 WHERE v2.thread_id = ${threadId}
356 `;
357 assert.lengthOf(rows, 1);
358 assert.isNotNull(rows[0]?.v2_deleted_at);
359 assert.isNotNull(rows[0]?.project_deleted_at);
360 const legacyEvents = yield* sql`
361 SELECT sequence FROM orchestration_events
362 WHERE application_event_version = 1 AND stream_id = ${threadId}
363 `;
364 assert.deepEqual(legacyEvents, []);
365
366 const cleanup = yield* sql<{
367 readonly command_id: string;
368 readonly payload_json: string;
369 readonly status: string;
370 }>`
371 SELECT command_id, payload_json, status
372 FROM orchestration_v2_effect_outbox
373 WHERE thread_id = ${threadId} AND effect_type = 'attachment.cleanup'
374 `;
375 assert.lengthOf(cleanup, 1);
376 assert.equal(cleanup[0]?.command_id, `${commandId}:delete-thread:${threadId}`);
377 assert.equal(cleanup[0]?.status, "pending");
378 const request = yield* decodeEffectRequest(cleanup[0]?.payload_json);
379 assert.deepEqual(request, {
380 type: "attachment.cleanup",
381 attachmentIds: ["legacy_screenshot"],
382 });
383 }).pipe(Effect.provide(layerServices));
384 }).pipe(Effect.provide(layerDatabase)),
385);
386
387it.effect("rejects a child deletion command ID already accepted for an unrelated thread", () =>
388 Effect.gen(function* () {
389 const sql = yield* SqlClient.SqlClient;
390 const projectId = ProjectId.make("project:receipt-collision");
391 const otherProjectId = ProjectId.make("project:unrelated-receipt");
392 const threadId = ThreadId.make("thread:receipt-collision");
393 const otherThreadId = ThreadId.make("thread:unrelated-receipt");
394 const commandId = CommandId.make("command:collision-project-delete");
395 yield* seedProject(projectId);
396 yield* seedProject(otherProjectId);
397
398 yield* Effect.gen(function* () {
399 const eventSink = yield* EventSink.EventSinkV2;
400 const projections = yield* ProjectionStore.ProjectionStoreV2;
401 const service = yield* ProjectService.make;
402 yield* eventSink.write({ events: [nativeThreadCreated(projectId, threadId)] });
403 const accepted = yield* eventSink.commitCommand({
404 commandId: CommandId.make(`${commandId}:delete-thread:${threadId}`),
405 commandType: "thread.create",
406 threadId: otherThreadId,
407 acceptedAt: DateTime.makeUnsafe("2026-01-01T00:00:00.000Z"),
408 events: [nativeThreadCreated(otherProjectId, otherThreadId)],
409 effects: [],
410 });
411 assert.equal(accepted.receipt.status, "accepted");
412
413 const failure = yield* service
414 .delete({ commandId, projectId, force: true })
415 .pipe(Effect.flip);
416 assert.instanceOf(failure, ProjectService.ProjectOperationError);
417 if (failure._tag !== "ProjectOperationError") return assert.fail("Expected a child failure");
418 assert.equal(failure.operation, "delete-thread");
419 assert.isTrue(Option.isSome(yield* service.getById(projectId)));
420 assert.isNull((yield* projections.getThreadProjection(threadId)).thread.deletedAt);
421 assert.isNull((yield* projections.getThreadProjection(otherThreadId)).thread.deletedAt);
422 const deletions = yield* sql`
423 SELECT sequence FROM orchestration_events
424 WHERE event_type IN ('thread.deleted', 'project.deleted')
425 AND stream_id IN (${threadId}, ${otherThreadId}, ${projectId})
426 `;
427 assert.deepEqual(deletions, []);
428 const cleanup = yield* sql`
429 SELECT effect_id FROM orchestration_v2_effect_outbox
430 WHERE thread_id = ${threadId}
431 `;
432 assert.deepEqual(cleanup, []);
433 }).pipe(Effect.provide(layerServices));
434 }).pipe(Effect.provide(layerDatabase)),
435);
436
437it.effect("deletes a project without force once its imported threads were deleted in V2", () =>
438 Effect.gen(function* () {
439 const sql = yield* SqlClient.SqlClient;
440 const projectId = ProjectId.make("project:imported-emptied");
441 const threadId = ThreadId.make("thread:imported-emptied");
442 yield* seedProject(projectId);
443 yield* sql`
444 INSERT INTO projection_threads (
445 thread_id, project_id, title, model_selection_json,
446 runtime_mode, interaction_mode, branch, worktree_path, latest_turn_id,
447 created_at, updated_at, archived_at, deleted_at
448 ) VALUES (
449 ${threadId}, ${projectId}, 'Imported thread', '{"instanceId":"codex","model":"gpt-5.4"}',
450 'full-access', 'default', NULL, NULL, NULL,
451 '2026-01-01T00:00:00.000Z', '2026-01-01T00:00:00.000Z', NULL, NULL
452 )
453 `;
454 yield* TestClock.setTime(Date.parse("2026-09-04T12:00:00.000Z"));
455
456 yield* Effect.gen(function* () {
457 const importer = yield* LegacyV1ThreadImporter.LegacyV1ThreadImporter;
458 const projections = yield* ProjectionStore.ProjectionStoreV2;
459 const eventSink = yield* EventSink.EventSinkV2;
460 const idAllocator = yield* IdAllocator.IdAllocatorV2;
461 const service = yield* ProjectService.make;
462 yield* importer.reconcileShells;
463 const early = yield* service
464 .delete({ commandId: CommandId.make("command:emptied:early"), projectId })
465 .pipe(Effect.flip);
466 assert.equal(early._tag, "ProjectNotEmptyError");
467
468 yield* importer.ensureTranscript(threadId);
469 const command = {
470 type: "thread.delete" as const,
471 commandId: CommandId.make("command:emptied:thread-delete"),
472 threadId,
473 };
474 const now = yield* DateTime.now;
475 const plan = yield* planThreadDeletion({
476 command,
477 projection: yield* projections.getThreadRecords(threadId, [
478 "runs",
479 "attempts",
480 "nodes",
481 "runtimeRequests",
482 "subagents",
483 "providerSessions",
484 ]),
485 attachmentIds: [],
486 now,
487 idAllocator,
488 });
489 yield* eventSink.commitCommand({
490 commandId: command.commandId,
491 commandType: command.type,
492 threadId,
493 acceptedAt: now,
494 events: plan.events,
495 effects: plan.effects,
496 });
497 const legacy = yield* sql<{ readonly deleted_at: string | null }>`
498 SELECT deleted_at FROM projection_threads WHERE thread_id = ${threadId}
499 `;
500 assert.deepEqual(legacy, [{ deleted_at: null }]);
501
502 const deleted = yield* service.delete({
503 commandId: CommandId.make("command:emptied:project-delete"),
504 projectId,
505 });
506 assert.isNotNull(deleted.deletedAt);
507 assert.isTrue(Option.isNone(yield* service.getById(projectId)));
508 }).pipe(Effect.provide(layerServices));
509 }).pipe(Effect.provide(layerDatabase)),
510);
511
512it.effect.each([
513 { policy: "no", worktreeCleanup: undefined },
514 { policy: "its off", worktreeCleanup: { mode: "off" } as const },
515 { policy: "its legacy", worktreeCleanup: null },
516])(
517 "clears a deleted project's settings overrides, keeping $policy worktree cleanup policy, so a machine-disabled instance cannot stay alive",
518 ({ worktreeCleanup }) =>
519 Effect.gen(function* () {
520 const projectId = ProjectId.make("project:overrides-cleanup");
521 const instanceId = ProviderInstanceId.make("codex_work");
522 yield* seedProject(projectId);
523
524 yield* Effect.gen(function* () {
525 const service = yield* ProjectService.make;
526 const serverSettings = yield* ServerSettings.ServerSettingsService;
527 yield* serverSettings.updateSettings({
528 projectSettingsOverrides: {
529 [projectId]: {
530 providerInstances: { [instanceId]: { enabled: true } },
531 defaultAutoPull: true,
532 ...(worktreeCleanup === undefined ? {} : { worktreeCleanup }),
533 },
534 },
535 });
536
537 yield* service.delete({
538 commandId: CommandId.make("command:overrides-cleanup:project-delete"),
539 projectId,
540 });
541
542 const entry = (yield* serverSettings.getSettings).projectSettingsOverrides[projectId];
543 if (worktreeCleanup === undefined) {
544 assert.isUndefined(entry);
545 } else {
546 assert.deepStrictEqual(entry, { worktreeCleanup, providerInstances: {} });
547 }
548
549 const liveProjectId = ProjectId.make("project:still-live");
550 const missingProjectId = ProjectId.make("project:missing");
551 yield* seedProject(liveProjectId);
552 // Older deletions or interrupted best-effort cleanup can leave the original overrides on restart.
553 yield* serverSettings.updateSettings({
554 projectSettingsOverrides: {
555 [projectId]: {
556 providerInstances: { [instanceId]: { enabled: true } },
557 defaultAutoPull: true,
558 ...(worktreeCleanup === undefined ? {} : { worktreeCleanup }),
559 },
560 [liveProjectId]: { defaultAutoPull: true },
561 [missingProjectId]: { worktreeCleanup: { mode: "off" } },
562 },
563 });
564 yield* ProjectSettingsOverrideSweep.sweep;
565 assert.deepStrictEqual((yield* serverSettings.getSettings).projectSettingsOverrides, {
566 [liveProjectId]: { defaultAutoPull: true },
567 ...(worktreeCleanup === undefined
568 ? {}
569 : { [projectId]: { worktreeCleanup, providerInstances: {} } }),
570 });
571 }).pipe(Effect.provide(layerServices));
572 }).pipe(Effect.provide(layerDatabase)),
573);