Skip to content

Commit d489a12

Browse files
committed
test(sidechat): cover optional shell metadata serialization
1 parent 049d77a commit d489a12

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
type OrchestrationV2ProviderThread,
1212
type OrchestrationV2TurnItem,
1313
type OrchestrationV2ThreadShellSnapshot,
14+
OrchestrationV2ThreadShell,
1415
NodeId,
1516
PlanId,
1617
ProjectId,
@@ -187,6 +188,44 @@ const addRolledBackRecoveryCandidate = Effect.fn("addRolledBackRecoveryCandidate
187188
return threadId;
188189
});
189190

191+
it.effect.each([
192+
["memory", ProjectionStore.layerMemory],
193+
["SQL", layerTest],
194+
] as const)("%s shells preserve optional side-chat metadata across JSON", ([, layer]) =>
195+
Effect.gen(function* () {
196+
const store = yield* ProjectionStore.ProjectionStoreV2;
197+
const sourceId = yield* addRolledBackRecoveryCandidate("shell-side-chat");
198+
const { thread } = yield* store.getThreadProjection(sourceId);
199+
const codec = Schema.fromJsonString(Schema.toCodecJson(OrchestrationV2ThreadShell));
200+
for (const [index, sideChatOf] of [undefined, null, sourceId].entries()) {
201+
const threadId = ThreadId.make(`shell-side-chat:${index}`);
202+
yield* store.apply({
203+
id: EventId.make(`event:shell-side-chat:${index}`),
204+
type: "thread.created",
205+
threadId,
206+
occurredAt: thread.createdAt,
207+
payload: {
208+
...thread,
209+
id: threadId,
210+
...(sideChatOf === undefined ? {} : { sideChatOf }),
211+
},
212+
});
213+
const projection = yield* store.getThreadProjection(threadId);
214+
const listed = (yield* store.getShellSnapshot()).threads.find((row) => row.id === threadId);
215+
for (const shell of [
216+
yield* store.getThreadShell(threadId),
217+
listed,
218+
ProjectionStore.threadShellFromProjection(projection),
219+
]) {
220+
assert.isDefined(shell);
221+
assert.strictEqual(shell!.sideChatOf, sideChatOf);
222+
const encoded = yield* Schema.encodeEffect(codec)(shell!);
223+
assert.deepEqual(yield* Schema.decodeUnknownEffect(codec)(encoded), shell);
224+
}
225+
}
226+
}).pipe(Effect.provide(layer)),
227+
);
228+
190229
it.effect.each([
191230
["memory", ProjectionStore.layerMemory],
192231
["SQL", layerTest],

0 commit comments

Comments
 (0)