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

ProjectService.deletion.test.ts

579 lines24.0 KB

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