| 1 | import assert from "node:assert/strict"; |
| 2 | import { act } from "react"; |
| 3 | import { createTranscriptHarness } from "./transcript-dom-harness"; |
| 4 | import { applySessionExperience } from "../lib/sessionExperience"; |
| 5 | import type { Item } from "../lib/useController"; |
| 6 | |
| 7 | const harness = await createTranscriptHarness({ deterministic: true }); |
| 8 | const user: Item = { kind: "user", id: "u", text: "question" }; |
| 9 | const answer: Item = { kind: "assistant", id: "a", text: "", reasoning: "first line\n\nlatest line", streaming: true }; |
| 10 | try { |
| 11 | for (const mode of ["standard", "deep"] as const) { |
| 12 | await act(async () => applySessionExperience(mode)); |
| 13 | await harness.render([user, answer], { running: true }); |
| 14 | await harness.settle(); |
| 15 | const heading = harness.container.querySelector<HTMLElement>(".chat-reasoning [data-disclosure-row]")!; |
| 16 | assert.ok(heading.textContent?.includes("latest line")); |
| 17 | assert.equal(heading.getAttribute("aria-expanded"), "false", "old display preferences cannot auto-open thought bodies"); |
| 18 | assert.equal(harness.container.querySelector(".chat-reasoning__body"), null); |
| 19 | } |
| 20 | const heading = harness.container.querySelector<HTMLElement>(".chat-reasoning [data-disclosure-row]")!; |
| 21 | await act(async () => heading.click()); |
| 22 | assert.ok(harness.container.querySelector(".chat-reasoning__body")); |
| 23 | await harness.render([user, { ...answer, reasoning: "first line\n\nnew line", streaming: false, reasoningDurationMs: 1200 }]); |
| 24 | await harness.settle(); |
| 25 | assert.equal(heading.getAttribute("aria-expanded"), "true", "manual disclosure survives settlement"); |
| 26 | assert.ok(!heading.textContent?.includes("latest line"), "expanded row does not repeat its summary"); |
| 27 | await act(async () => heading.click()); |
| 28 | assert.equal(harness.container.querySelector(".chat-reasoning__body"), null, "collapsed content is unmounted"); |
| 29 | console.log("thought presentation: latest/first line, duration, manual disclosure and legacy preference independence passed"); |
| 30 | } finally { |
| 31 | await act(async () => applySessionExperience("standard")); |
| 32 | await harness.unmount(); await harness.close(); |
| 33 | } |
| 34 |