| 1 | import { act } from "react"; |
| 2 | import type { useController } from "../../lib/useController"; |
| 3 | |
| 4 | export async function verifyExplicitTranscriptRetry(options: { |
| 5 | controller: () => ReturnType<typeof useController> | undefined; |
| 6 | historyCalls: () => number; |
| 7 | ancillaryCalls: () => number; |
| 8 | releaseAncillary: () => void; |
| 9 | waitFor: (label: string, predicate: () => boolean) => Promise<void>; |
| 10 | flush: () => Promise<void>; |
| 11 | ok: (value: boolean, label: string) => void; |
| 12 | }) { |
| 13 | const { controller, historyCalls, ancillaryCalls, releaseAncillary, waitFor, flush, ok } = options; |
| 14 | await waitFor("Follow cut remains independent of metadata", () => controller()?.state.items.some(item => item.kind === "user" && item.text === "stale M v1") ?? false); |
| 15 | ok(historyCalls() === 1, "metadata does not attach a later version to earlier body data"); |
| 16 | await waitFor("old ancillary read is pending", () => ancillaryCalls() === 1); |
| 17 | let retry: Promise<void> | undefined; |
| 18 | await act(async () => { retry = controller()?.retrySessionHistory("tab-m"); await flush(); }); |
| 19 | try { |
| 20 | await waitFor("explicit retry requests a fresh cut before ancillary completion", () => historyCalls() === 2); |
| 21 | await act(async () => { await retry; await flush(); }); |
| 22 | ok(controller()?.state.items.some(item => item.kind === "user" && item.text === "history M v2") === true, "explicit retry installs the new snapshot"); |
| 23 | } finally { |
| 24 | await act(async () => { releaseAncillary(); await flush(); }); |
| 25 | } |
| 26 | ok(controller()?.state.context.used !== 99999, "superseded ancillary completion cannot overwrite the retry"); |
| 27 | } |
| 28 |