|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import { completeFollowupRunLifecycle, markFollowupRunEnqueued } from "./queue/types.js"; |
| 3 | +import { |
| 4 | + buildStrandedReplyRetryFollowupRun, |
| 5 | + STRANDED_REPLY_RETRY_MARKER, |
| 6 | +} from "./stranded-reply-recovery.js"; |
| 7 | +import { createMockFollowupRun } from "./test-helpers.js"; |
| 8 | + |
| 9 | +describe("buildStrandedReplyRetryFollowupRun lifecycle ownership", () => { |
| 10 | + it("does not share the client turn's queuedLifecycle with the system retry", () => { |
| 11 | + const onComplete = vi.fn(); |
| 12 | + const onEnqueued = vi.fn(() => true); |
| 13 | + const parent = createMockFollowupRun({ |
| 14 | + prompt: "user question", |
| 15 | + transcriptPrompt: "user question", |
| 16 | + queuedLifecycle: { onComplete, onEnqueued }, |
| 17 | + admissionSessionId: "sess-rotated", |
| 18 | + onFollowupAdmissionWaitChange: vi.fn(), |
| 19 | + }); |
| 20 | + |
| 21 | + const retry = buildStrandedReplyRetryFollowupRun(parent, { |
| 22 | + finalText: "A substantive stranded final that must be re-delivered via message(action=send).", |
| 23 | + sourceReplyDeliveryMode: "message_tool_only", |
| 24 | + }); |
| 25 | + |
| 26 | + expect(retry.queuedLifecycle).toBeUndefined(); |
| 27 | + expect(retry.strandedReplyRetry).toBe(true); |
| 28 | + expect(retry.summaryLine).toBe(STRANDED_REPLY_RETRY_MARKER); |
| 29 | + // Session routing stays; only the client-turn lifecycle identity is detached. |
| 30 | + expect(retry.admissionSessionId).toBe("sess-rotated"); |
| 31 | + expect(retry.onFollowupAdmissionWaitChange).toBe(parent.onFollowupAdmissionWaitChange); |
| 32 | + expect(retry.run.sessionKey).toBe(parent.run.sessionKey); |
| 33 | + |
| 34 | + // mark/complete no-op when lifecycle is absent (drop-policy onDrop path too). |
| 35 | + expect(markFollowupRunEnqueued(retry)).toBe(true); |
| 36 | + expect(onEnqueued).not.toHaveBeenCalled(); |
| 37 | + completeFollowupRunLifecycle(retry); |
| 38 | + expect(onComplete).not.toHaveBeenCalled(); |
| 39 | + |
| 40 | + // Parent still owns the one-shot lifecycle; retry completion must not steal it. |
| 41 | + expect(markFollowupRunEnqueued(parent)).toBe(true); |
| 42 | + expect(onEnqueued).toHaveBeenCalledTimes(1); |
| 43 | + completeFollowupRunLifecycle(parent); |
| 44 | + expect(onComplete).toHaveBeenCalledTimes(1); |
| 45 | + completeFollowupRunLifecycle(parent); |
| 46 | + expect(onComplete).toHaveBeenCalledTimes(1); |
| 47 | + }); |
| 48 | +}); |
0 commit comments