|
| 1 | +import { assert, it } from "@effect/vitest"; |
| 2 | +import * as Effect from "effect/Effect"; |
| 3 | +import * as Queue from "effect/Queue"; |
| 4 | +import * as Ref from "effect/Ref"; |
| 5 | +import type * as EffectAcpSchema from "effect-acp/schema"; |
| 6 | + |
| 7 | +import { handleSessionUpdateForTest } from "./AcpSessionRuntime.ts"; |
| 8 | +import type { |
| 9 | + AcpParsedSessionEvent, |
| 10 | + AcpSessionModeState, |
| 11 | + AcpToolCallState, |
| 12 | +} from "./AcpRuntimeModel.ts"; |
| 13 | + |
| 14 | +it.effect("suppresses loaded-session replay updates until the first live prompt", () => |
| 15 | + Effect.gen(function* () { |
| 16 | + const queue = yield* Queue.unbounded<AcpParsedSessionEvent>(); |
| 17 | + const modeStateRef = yield* Ref.make<AcpSessionModeState | undefined>({ |
| 18 | + currentModeId: "ask", |
| 19 | + availableModes: [ |
| 20 | + { id: "ask", name: "Ask" }, |
| 21 | + { id: "code", name: "Code" }, |
| 22 | + ], |
| 23 | + }); |
| 24 | + const toolCallsRef = yield* Ref.make(new Map<string, AcpToolCallState>()); |
| 25 | + const assistantSegmentRef = yield* Ref.make({ nextSegmentIndex: 0 }); |
| 26 | + const suppressSessionUpdatesRef = yield* Ref.make(true); |
| 27 | + |
| 28 | + const handle = (params: EffectAcpSchema.SessionNotification) => |
| 29 | + handleSessionUpdateForTest({ |
| 30 | + queue, |
| 31 | + modeStateRef, |
| 32 | + toolCallsRef, |
| 33 | + assistantSegmentRef, |
| 34 | + suppressSessionUpdatesRef, |
| 35 | + params, |
| 36 | + }); |
| 37 | + |
| 38 | + yield* handle({ |
| 39 | + sessionId: "cursor-session", |
| 40 | + update: { |
| 41 | + sessionUpdate: "current_mode_update", |
| 42 | + currentModeId: "code", |
| 43 | + }, |
| 44 | + }); |
| 45 | + yield* handle({ |
| 46 | + sessionId: "cursor-session", |
| 47 | + update: { |
| 48 | + sessionUpdate: "plan", |
| 49 | + entries: [{ content: "Old replayed plan", priority: "high", status: "completed" }], |
| 50 | + }, |
| 51 | + }); |
| 52 | + yield* handle({ |
| 53 | + sessionId: "cursor-session", |
| 54 | + update: { |
| 55 | + sessionUpdate: "user_message_chunk", |
| 56 | + content: { type: "text", text: "old replayed user prompt" }, |
| 57 | + }, |
| 58 | + }); |
| 59 | + yield* handle({ |
| 60 | + sessionId: "cursor-session", |
| 61 | + update: { |
| 62 | + sessionUpdate: "agent_message_chunk", |
| 63 | + content: { type: "text", text: "old replayed assistant text" }, |
| 64 | + }, |
| 65 | + }); |
| 66 | + |
| 67 | + assert.equal(yield* Queue.size(queue), 0); |
| 68 | + assert.equal((yield* Ref.get(modeStateRef))?.currentModeId, "code"); |
| 69 | + |
| 70 | + yield* Ref.set(suppressSessionUpdatesRef, false); |
| 71 | + yield* handle({ |
| 72 | + sessionId: "cursor-session", |
| 73 | + update: { |
| 74 | + sessionUpdate: "agent_message_chunk", |
| 75 | + content: { type: "text", text: "new assistant text" }, |
| 76 | + }, |
| 77 | + }); |
| 78 | + |
| 79 | + const started = yield* Queue.take(queue); |
| 80 | + const delta = yield* Queue.take(queue); |
| 81 | + assert.equal(started._tag, "AssistantItemStarted"); |
| 82 | + assert.equal(delta._tag, "ContentDelta"); |
| 83 | + if (delta._tag === "ContentDelta") { |
| 84 | + assert.equal(delta.text, "new assistant text"); |
| 85 | + } |
| 86 | + assert.equal(yield* Queue.size(queue), 0); |
| 87 | + }), |
| 88 | +); |
0 commit comments