Skip to content

Commit 1e4ccd7

Browse files
committed
test(server): move shared-attachment cases into ProjectionStore.test.ts
AGENTS.md puts regression tests in the module's existing test file. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DrdVGEmdN2qsKpaCV9dBFT
1 parent e6a27ca commit 1e4ccd7

2 files changed

Lines changed: 105 additions & 119 deletions

File tree

‎apps/server/src/orchestration-v2/ProjectionStore.attachments.test.ts‎

Lines changed: 0 additions & 119 deletions
This file was deleted.

‎apps/server/src/orchestration-v2/ProjectionStore.test.ts‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { assert, it } from "@effect/vitest";
22
import {
3+
ChatAttachmentId,
34
EnvironmentId,
45
EventId,
56
CommandId,
@@ -8,6 +9,7 @@ import {
89
CheckpointScopeId,
910
MessageId,
1011
type ModelSelection,
12+
type OrchestrationV2AppThread,
1113
type OrchestrationV2ProviderThread,
1214
type OrchestrationV2TurnItem,
1315
type OrchestrationV2ThreadShellSnapshot,
@@ -5644,3 +5646,106 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
56445646
}),
56455647
);
56465648
});
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

Comments
 (0)