888
getThreadDetailById: () => Effect.succeed(Option.none()),
889
getThreadDetailSnapshot: () => Effect.succeed(Option.none()),
890
getCounts: () => Effect.succeed({ projectCount: 0, threadCount: 0 }),
891
+ getEventReplayStats: ({ fromSequenceExclusive, toSequenceInclusive }) =>
892
+ Effect.succeed({
893
+ eventCount: Math.max(0, toSequenceInclusive - fromSequenceExclusive),
894
+ payloadBytes: 0,
895
+ }),
896
getActiveProjectByWorkspaceRoot: () => Effect.succeed(Option.none()),
897
getFirstActiveThreadIdByProjectId: () => Effect.succeed(Option.none()),
898
getThreadCheckpointContext: () => Effect.succeed(Option.none()),
7371
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
7372
);
7373
7374
+ it.effect("subscriptions snapshot instead of decoding an oversized replay range", () =>
7375
+ Effect.gen(function* () {
7376
+ let readEventsCalls = 0;
7377
+ let replayStatsCalls = 0;
7378
+ const thread = makeDefaultOrchestrationReadModel().threads[0]!;
7379
+ const shell = makeDefaultOrchestrationThreadShell({ id: thread.id });
7380
+
7381
+ yield* buildAppUnderTest({
7382
+ layers: {
7383
+ orchestrationEngine: {
7384
+ latestSequence: Effect.succeed(5),
7385
+ readEvents: () =>
7386
+ Stream.sync(() => {
7387
+ readEventsCalls += 1;
7388
+ return {} as OrchestrationEvent;
7389
+ }),
7390
+ },
7391
+ projectionSnapshotQuery: {
7392
+ getEventReplayStats: () =>
7393
+ Effect.sync(() => {
7394
+ replayStatsCalls += 1;
7395
+ return { eventCount: 5, payloadBytes: 8 * 1024 * 1024 + 1 };
7396
+ }),
7397
+ getThreadDetailSnapshot: () =>
7398
+ Effect.succeed(Option.some({ snapshotSequence: 5, thread })),
7399
+ getShellSnapshot: () =>
7400
+ Effect.succeed({
7401
+ snapshotSequence: 5,
7402
+ projects: [],
7403
+ threads: [shell],
7404
+ updatedAt: "2026-01-01T00:00:00.000Z",
7405
+ }),
7406
+ },
7407
+ },
7408
+ });
7409
+
7410
+ const wsUrl = yield* getWsServerUrl("/ws");
7411
+ const threadItems = yield* Effect.scoped(
7412
+ withWsRpcClient(wsUrl, (client) =>
7413
+ client[ORCHESTRATION_WS_METHODS.subscribeThread]({
7414
+ threadId: thread.id,
7415
+ afterSequence: 0,
7416
+ requestCompletionMarker: true,
7417
+ }).pipe(Stream.take(2), Stream.runCollect),
7418
+ ),
7419
+ );
7420
+ const shellItems = yield* Effect.scoped(
7421
+ withWsRpcClient(wsUrl, (client) =>
7422
+ client[ORCHESTRATION_WS_METHODS.subscribeShell]({
7423
+ afterSequence: 0,
7424
+ requestCompletionMarker: true,
7425
+ }).pipe(Stream.take(2), Stream.runCollect),
7426
+ ),
7427
+ );
7428
+
7429
+ assert.equal(threadItems[0]?.kind, "snapshot");
7430
+ assert.equal(threadItems[1]?.kind, "synchronized");
7431
+ assert.equal(shellItems[0]?.kind, "snapshot");
7432
+ assert.equal(shellItems[1]?.kind, "synchronized");
7433
+ assert.equal(replayStatsCalls, 2);
7434
+ assert.equal(readEventsCalls, 0);
7435
+ }).pipe(Effect.provide(NodeHttpServer.layerTest)),
7436
+ );
7437
+
7438
it.effect("subscribeShell replaces a cursor ahead of the authoritative head", () =>
7439
Effect.gen(function* () {
7440
let readEventsCalls = 0;