|
1 | 1 | import { assert, it } from "@effect/vitest"; |
2 | 2 | import { |
| 3 | + ChatAttachmentId, |
3 | 4 | EnvironmentId, |
4 | 5 | EventId, |
5 | 6 | CommandId, |
|
8 | 9 | CheckpointScopeId, |
9 | 10 | MessageId, |
10 | 11 | type ModelSelection, |
| 12 | + type OrchestrationV2AppThread, |
11 | 13 | type OrchestrationV2ProviderThread, |
12 | 14 | type OrchestrationV2TurnItem, |
13 | 15 | type OrchestrationV2ThreadShellSnapshot, |
@@ -5644,3 +5646,106 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => { |
5644 | 5646 | }), |
5645 | 5647 | ); |
5646 | 5648 | }); |
| 5649 | + |
| 5650 | +for (const storage of ["sqlite", "memory"] as const) { |
| 5651 | + it.effect.each(["source", "relaunch"] as const)( |
| 5652 | + `preserves shared attachments when deleting %s first in ${storage}`, |
| 5653 | + (deletedFirst) => |
| 5654 | + Effect.gen(function* () { |
| 5655 | + const store = yield* ProjectionStore.ProjectionStoreV2; |
| 5656 | + const now = yield* DateTime.now; |
| 5657 | + const instanceId = ProviderInstanceId.make("codex"); |
| 5658 | + const shared = [ |
| 5659 | + "source-00000000-0000-4000-8000-000000000001", |
| 5660 | + "source-00000000-0000-4000-8000-000000000002-pdf", |
| 5661 | + "legacy_screenshot", |
| 5662 | + ]; |
| 5663 | + const threads = new Map<string, OrchestrationV2AppThread>(); |
| 5664 | + for (const name of ["source", "relaunch"] as const) { |
| 5665 | + const threadId = ThreadId.make(name); |
| 5666 | + const thread: OrchestrationV2AppThread = { |
| 5667 | + id: threadId, |
| 5668 | + projectId: ProjectId.make("attachment-cleanup"), |
| 5669 | + title: name, |
| 5670 | + providerInstanceId: instanceId, |
| 5671 | + modelSelection: { instanceId, model: "test" }, |
| 5672 | + runtimeMode: "full-access", |
| 5673 | + interactionMode: "default", |
| 5674 | + branch: null, |
| 5675 | + worktreePath: null, |
| 5676 | + activeProviderThreadId: null, |
| 5677 | + lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId }, |
| 5678 | + forkedFrom: null, |
| 5679 | + createdBy: "user", |
| 5680 | + creationSource: "mobile", |
| 5681 | + createdAt: now, |
| 5682 | + updatedAt: now, |
| 5683 | + archivedAt: name === "source" ? now : null, |
| 5684 | + settledOverride: null, |
| 5685 | + settledAt: null, |
| 5686 | + lastVisitedAt: null, |
| 5687 | + deletedAt: null, |
| 5688 | + }; |
| 5689 | + threads.set(name, thread); |
| 5690 | + yield* store.apply({ |
| 5691 | + id: EventId.make(`thread:${name}`), |
| 5692 | + type: "thread.created", |
| 5693 | + threadId, |
| 5694 | + occurredAt: now, |
| 5695 | + payload: thread, |
| 5696 | + }); |
| 5697 | + yield* store.apply({ |
| 5698 | + id: EventId.make(`message:${name}`), |
| 5699 | + type: "message.updated", |
| 5700 | + threadId, |
| 5701 | + occurredAt: now, |
| 5702 | + payload: { |
| 5703 | + id: MessageId.make(`message:${name}`), |
| 5704 | + threadId, |
| 5705 | + runId: null, |
| 5706 | + nodeId: null, |
| 5707 | + role: "user", |
| 5708 | + text: "Shared uploads", |
| 5709 | + attachments: [...shared, `legacy_${name}_only`].map((id) => ({ |
| 5710 | + type: "file" as const, |
| 5711 | + id: ChatAttachmentId.make(id), |
| 5712 | + name: "attachment.pdf", |
| 5713 | + mimeType: "application/pdf", |
| 5714 | + sizeBytes: 10, |
| 5715 | + })), |
| 5716 | + streaming: false, |
| 5717 | + createdBy: "user", |
| 5718 | + creationSource: "mobile", |
| 5719 | + createdAt: now, |
| 5720 | + updatedAt: now, |
| 5721 | + }, |
| 5722 | + }); |
| 5723 | + } |
| 5724 | + |
| 5725 | + for (const name of threads.keys()) { |
| 5726 | + assert.deepEqual(yield* store.getThreadAttachmentIds(ThreadId.make(name)), [ |
| 5727 | + `legacy_${name}_only`, |
| 5728 | + ]); |
| 5729 | + } |
| 5730 | + const deleted = threads.get(deletedFirst)!; |
| 5731 | + yield* store.apply({ |
| 5732 | + id: EventId.make(`delete:${deletedFirst}`), |
| 5733 | + type: "thread.deleted", |
| 5734 | + threadId: deleted.id, |
| 5735 | + occurredAt: now, |
| 5736 | + payload: { ...deleted, deletedAt: now }, |
| 5737 | + }); |
| 5738 | + const survivor = deletedFirst === "source" ? "relaunch" : "source"; |
| 5739 | + assert.deepEqual( |
| 5740 | + (yield* store.getThreadAttachmentIds(ThreadId.make(survivor))).toSorted(), |
| 5741 | + [...shared, `legacy_${survivor}_only`].toSorted(), |
| 5742 | + ); |
| 5743 | + }).pipe( |
| 5744 | + Effect.provide( |
| 5745 | + storage === "sqlite" |
| 5746 | + ? ProjectionStore.layer.pipe(Layer.provide(SqlitePersistence.layerMemory)) |
| 5747 | + : ProjectionStore.layerMemory, |
| 5748 | + ), |
| 5749 | + ), |
| 5750 | + ); |
| 5751 | +} |
0 commit comments