From 25f457df9200fb0361f45c24f07f3f13699932b0 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 9 Nov 2026 17:04:53 +0000 Subject: [PATCH 1/2] feat(ui-react): open a spoken turn's details from the turn, not a glyph (#3700) Each recognized and voice-reply turn passes its existing qualifier props as SpokenTurn details, so the kit's hidden Details stop, right-click, Shift+F10 and long-press open the unchanged transcript-details dialog. The glyph trigger under each spoken turn is removed. Browser tests cover live, settled and reloaded chats, the keyboard path, and right-click with and without a selection. Co-Authored-By: Claude Opus 5.5 --- .changeset/spoken-turn-details-chat.md | 5 ++ .../components/voice/conversation-outputs.tsx | 43 +++++----- .../conversation-contextual.offline.tsx | 5 +- .../browser/dialogue-qualifiers.offline.tsx | 13 +-- .../browser/dialogue-recovery.offline.tsx | 3 +- .../ui-react/tests/browser/spoken-details.ts | 15 ++++ .../browser/spoken-turn-marks.offline.tsx | 81 ++++++++++++++++++- .../transcript-qualifiers-r2.offline.tsx | 12 +-- .../browser/transcript-qualifiers.offline.tsx | 51 ++++++------ 9 files changed, 168 insertions(+), 60 deletions(-) create mode 100644 .changeset/spoken-turn-details-chat.md create mode 100644 packages/ui-react/tests/browser/spoken-details.ts diff --git a/.changeset/spoken-turn-details-chat.md b/.changeset/spoken-turn-details-chat.md new file mode 100644 index 0000000000..e19e84144a --- /dev/null +++ b/.changeset/spoken-turn-details-chat.md @@ -0,0 +1,5 @@ +--- +"@schlessera/brain-ui-react": patch +--- + +A spoken turn's transcript details now open from the turn itself (#3700). The glyph button under each recognized or voice-reply turn is gone. Each turn has one hidden "Details" control that shows as a pill when you Tab to it, or after you hover the turn. A right-click, Shift+F10, the ContextMenu key or a touch long-press opens the same dialog. A right-click while you have text selected in the turn keeps the browser's own menu, so Copy still works. The details themselves and their wording are unchanged. diff --git a/packages/ui-react/src/components/voice/conversation-outputs.tsx b/packages/ui-react/src/components/voice/conversation-outputs.tsx index feadc2eea3..e9fba74686 100644 --- a/packages/ui-react/src/components/voice/conversation-outputs.tsx +++ b/packages/ui-react/src/components/voice/conversation-outputs.tsx @@ -37,16 +37,19 @@ export function ConversationPermissionOutcomes({ sessionId }: { sessionId: strin * It reads as brain's spoken turn: the teal speaker mark, never a heard claim. * No text is dimmed as unplayed: the client knows which chunks drained, not * which words they carried (`playedSamples` does not align text to audio). - * `cutOff` comes only from a retained interruption naming this output. + * `cutOff` comes only from a retained interruption naming this output. The + * turn's evidence opens from its own Details stop (#3728), never a glyph. */ export function ConversationOutput({ output, restored = false, arrivalKey, cutOff = false }: { output: ConversationClientOutput; restored?: boolean; arrivalKey?: string; cutOff?: boolean }) { return
- {output.generated} -
-

Conversation {output.conversationId} · epoch {output.epoch} · output {output.outputId}

- {output.playedSamples &&

Reported local samples: {output.playedSamples.start}–{output.playedSamples.end}. This does not align text to audio.

} -
+ +

Conversation {output.conversationId} · epoch {output.epoch} · output {output.outputId}

+ {output.playedSamples &&

Reported local samples: {output.playedSamples.start}–{output.playedSamples.end}. This does not align text to audio.

} + , + }}>{output.generated}
; } @@ -80,7 +83,8 @@ export function ConversationTaskContext({ message, sessionId, result, entries = * bubble with a cursor while live recognition is still updating, and a dotted * underline only where a calibrated score is low. Restored text never shows as * still being recognized. Provider, timing and speaker evidence stay in the - * details, outside user-message and live-announcement regions. + * details the turn opens (#3728), outside user-message and live-announcement + * regions. */ export function ConversationRecognitionRow({ fragments, introduction = false }: { fragments: ConversationRecognition[]; introduction?: boolean }) { const first = fragments[0]!; @@ -91,17 +95,18 @@ export function ConversationRecognitionRow({ fragments, introduction = false }: const moved = fragments.every(f => f.moved); return
{introduction &&
Voice · {service}
} - 0}>{moved ? "Moved to voice review" : fragments.map(f => )} -
f.orderUnknown)} evidenceLabel={`Technical evidence (${fragments.length} fragment${fragments.length === 1 ? "" : "s"})`}> -

Recognized text evidence. Display order does not establish an exact response pairing.

-
    {fragments.map(f =>
  1. - Epoch {f.epoch} · fragment {f.sequence} · {f.kind === "input_fragment" ? `Captured input ${f.utteranceId}; speaker unverified` : "Unassigned input; speaker unverified"}. - {f.kind === "input_fragment" ? f.certainty === "known" && f.confidence !== undefined ? ` Service confidence ${Math.round(f.confidence * 100)}%.` : " No calibrated confidence." : ""} - {f.kind === "unassigned_input_fragment" && f.sessionInterval ? ` Provider session timing; approximate: ${f.sessionInterval.startMs}–${f.sessionInterval.endMs} ms.` : f.kind === "input_fragment" && f.interval ? ` Provider input timing: ${f.interval.startMs}–${f.interval.endMs} ms.` : " Timing unavailable; speaker unverified."} - {f.finalization === "final" ? " Service finish marker received." : f.finalization === "interim" ? " Updating recognition." : " No finish evidence."} -
  2. )}
-
+ 0} details={{ + kind: "recognized", source: service, finish, unsaved: first.unsaved, restored, orderUnknown: fragments.some(f => f.orderUnknown), evidenceLabel: `Technical evidence (${fragments.length} fragment${fragments.length === 1 ? "" : "s"})`, + children: <> +

Recognized text evidence. Display order does not establish an exact response pairing.

+
    {fragments.map(f =>
  1. + Epoch {f.epoch} · fragment {f.sequence} · {f.kind === "input_fragment" ? `Captured input ${f.utteranceId}; speaker unverified` : "Unassigned input; speaker unverified"}. + {f.kind === "input_fragment" ? f.certainty === "known" && f.confidence !== undefined ? ` Service confidence ${Math.round(f.confidence * 100)}%.` : " No calibrated confidence." : ""} + {f.kind === "unassigned_input_fragment" && f.sessionInterval ? ` Provider session timing; approximate: ${f.sessionInterval.startMs}–${f.sessionInterval.endMs} ms.` : f.kind === "input_fragment" && f.interval ? ` Provider input timing: ${f.interval.startMs}–${f.interval.endMs} ms.` : " Timing unavailable; speaker unverified."} + {f.finalization === "final" ? " Service finish marker received." : f.finalization === "interim" ? " Updating recognition." : " No finish evidence."} +
  2. )}
+ , + }}>{moved ? "Moved to voice review" : fragments.map(f => )}
; } diff --git a/packages/ui-react/tests/browser/conversation-contextual.offline.tsx b/packages/ui-react/tests/browser/conversation-contextual.offline.tsx index 0401c2006a..f667b30afc 100644 --- a/packages/ui-react/tests/browser/conversation-contextual.offline.tsx +++ b/packages/ui-react/tests/browser/conversation-contextual.offline.tsx @@ -12,6 +12,7 @@ import { BrainUiProvider } from "../../src/root-context.js"; import { AppShell } from "../../src/components/layout/app-shell.js"; import { ChatPage } from "../../src/components/chat/chat-page.js"; import { installFaultNetwork } from "./offline/fault-network.js"; +import { pointDetails } from "./spoken-details.js"; const SESSION = "odysseus-ithaca"; const CAPS: ConversationCapabilities = { nonblockingWork: "supported", manualEndpoint: "supported", finalTranscript: "unproven", remoteOutputCancelAck: "unproven", exactPermissionSpeech: "unproven", echoIsolatedInput: "unproven", outputWordAlignment: "unproven" }; @@ -593,7 +594,7 @@ test("cold restored speech explicitly has unknown original discussion position", await expect.poll(() => s.host.querySelector("[data-conversation-output]")?.textContent).toContain("An earlier voyage reply."); // #3700: the unknown position is evidence in the details, not a diagnostic line in the chat. expect(s.host.querySelector("[data-conversation-output]")!.textContent).not.toContain("Original discussion position unknown"); - await userEvent.click(s.host.querySelector('[data-conversation-output] [data-transcript-qualifiers="generated"]')!); + await pointDetails(s.host.querySelector('[data-conversation-output] [data-transcript-qualifiers="generated"]')!); await expect.poll(() => document.querySelector("dialog[open]")?.textContent).toContain("Original discussion position unknown"); await userEvent.keyboard("{Escape}"); expect(s.client.state.getState().micOn).toBe(false); @@ -1027,7 +1028,7 @@ test("recognition namespaces, finish evidence, duplicates, transfer and epoch fe expect(s.client.state.getState().recognition[1]).toMatchObject({ kind: "input_fragment", utteranceId: s.socket.frames("conversation_audio").at(-1)!.utteranceId, sequence: 0 }); s.event({ kind: "unassigned_input_fragment", sequence: 1, text: "", timing: { kind: "unavailable" }, finalization: "final" }); const finishTrigger = s.host.querySelector("[data-transcript-qualifiers=recognized]")!; - await userEvent.click(finishTrigger); + await pointDetails(finishTrigger); await expect.poll(() => document.querySelector("dialog[open]")?.textContent).toContain("Service finish marker received"); await userEvent.keyboard("{Escape}"); expect(s.host.querySelectorAll("[data-conversation-recognition]")).toHaveLength(2); diff --git a/packages/ui-react/tests/browser/dialogue-qualifiers.offline.tsx b/packages/ui-react/tests/browser/dialogue-qualifiers.offline.tsx index 55073dc0ca..0cd183e9cc 100644 --- a/packages/ui-react/tests/browser/dialogue-qualifiers.offline.tsx +++ b/packages/ui-react/tests/browser/dialogue-qualifiers.offline.tsx @@ -9,6 +9,7 @@ import { ChatPage } from "../../src/components/chat/chat-page.js"; import { CONVERSATION_LIMITS, type ServerConversationOpened } from "@schlessera/brain-ui-sdk/protocol"; import type { ConversationRecognition } from "../../src/voice/conversation-client.js"; import { installFaultNetwork } from "./offline/fault-network.js"; +import { pointDetails } from "./spoken-details.js"; const SESSION = "odysseus-raft"; let styles: HTMLStyleElement; @@ -62,24 +63,24 @@ for(const theme of ["light","dark"] as const)for(const width of [320,1280])for(c await page.screenshot({element:s.host,path:`../../.vitest-attachments/durable-dialogue/rows-${theme}-${width}-${zoom}.png`}); scroll.scrollTop=scroll.scrollHeight; await page.screenshot({element:s.host,path:`../../.vitest-attachments/durable-dialogue/tail-${theme}-${width}-${zoom}.png`}); - const trigger=unsaved.find(q=>q.dataset.transcriptQualifiers==="recognized")!;trigger.scrollIntoView({block:"center"});await userEvent.hover(trigger); - await expect.poll(()=>document.querySelector('[role="tooltip"]')?.textContent).toContain("Unsaved text evidence"); + const trigger=unsaved.find(q=>q.dataset.transcriptQualifiers==="recognized")!;trigger.scrollIntoView({block:"center"}); + expect(trigger.closest(".bk-spoken-turn")!.querySelector(".bk-transcript-glyphs"),"no glyph on a spoken turn (#3700)").toBeNull(); trigger.focus();await userEvent.keyboard("{Enter}"); const dialog=document.querySelector("dialog[open]")!; - expect(dialog.textContent).toContain("These words are not saved and are unavailable after reload."); + expect(dialog.textContent).toContain("Unsaved text evidence. These words are not saved and are unavailable after reload."); expect(dialog.textContent).toContain("Words may be uncertain; speaker unverified."); expect(dialog.querySelector("details")!.open).toBe(false);expect(dialog.scrollWidth).toBeLessThanOrEqual(dialog.clientWidth+1); [...dialog.querySelectorAll("p")].find(p=>p.textContent?.startsWith("Unsaved text evidence"))!.scrollIntoView({block:"center"}); await page.screenshot({element:dialog,path:`../../.vitest-attachments/durable-dialogue/unsaved-details-${theme}-${width}-${zoom}.png`}); await closeDetails();expect(document.activeElement).toBe(trigger); - await userEvent.click(unsaved.find(q=>q.dataset.transcriptQualifiers==="generated")!);expect(document.querySelector("dialog[open]")!.textContent).toContain("Playback unknown");await closeDetails(); + await pointDetails(unsaved.find(q=>q.dataset.transcriptQualifiers==="generated")!);expect(document.querySelector("dialog[open]")!.textContent).toContain("Playback unknown");await closeDetails(); }); for(const unsaved of [true,false])for(const kind of ["recognition","speech"] as const)test(`paging and live-tail windowing preserve the ${kind} unsaved=${unsaved} reader until real source removal`,async ctx=>{ const s=await scene(ctx);evidence(s); const voice=s.ui.connection.conversation.state; const trigger=[...s.host.querySelectorAll(`[data-transcript-qualifiers="${kind==="recognition"?"recognized":"generated"}"]`)].find(q=>q.getAttribute("aria-label")!.includes("unsaved")===unsaved)!; const key=trigger.closest("[data-arrival-key]")!.dataset.arrivalKey; - await userEvent.click(trigger);expect(document.querySelector("dialog[open]")).not.toBeNull(); + await pointDetails(trigger);expect(document.querySelector("dialog[open]")).not.toBeNull(); flushSync(()=>voice.setState(current=>({dialogue:{[SESSION]:{...current.dialogue[SESSION]!,records:[retained(0,"Earlier mast note. "),...current.dialogue[SESSION]!.records]}},recognition:[...current.recognition,{...fragments("gemini-live",1)[0]!,sequence:4,text:" Keep the sail within reach.",unsaved:true}],outputs:[...current.outputs.map(o=>o.unsavedGenerated ? {...o,unsavedGenerated:o.unsavedGenerated+" Keep the rigging clear."} : o),...Array.from({length:41},(_,i)=>({conversationId:"tail",epoch:1,sessionId:SESSION,providerId:"gpt-live",outputId:`tail-${i}`,generated:`Later report ${i}.`,playback:"unknown" as const}))]}))); expect(trigger.isConnected).toBe(true);expect(trigger.closest("[data-arrival-key]")!.dataset.arrivalKey).toBe(key); expect(s.host.querySelectorAll("[data-arrival-key]").length).toBeLessThanOrEqual(41);expect(document.querySelector("dialog[open]")).not.toBeNull();await closeDetails();expect(document.activeElement).toBe(trigger); @@ -87,7 +88,7 @@ for(const unsaved of [true,false])for(const kind of ["recognition","speech"] as // Reveal earlier history with the actual existing window control. const earlier=[...s.host.querySelectorAll('button,[role="button"]')].find(b=>b.textContent?.includes("earlier message"))!;await userEvent.click(earlier); const restored=[...s.host.querySelectorAll(`[data-transcript-qualifiers="${kind==="recognition"?"recognized":"generated"}"]`)].find(q=>q.getAttribute("aria-label")!.includes("unsaved")===unsaved)!; - await userEvent.click(restored);const anchor=s.host.querySelector("[data-reading-column]"); + await pointDetails(restored);const anchor=s.host.querySelector("[data-reading-column]"); flushSync(()=>voice.setState(current=>unsaved ? kind==="recognition"?{recognition:[]}:{outputs:current.outputs.filter(o=>!o.unsavedGenerated)} : {dialogue:{[SESSION]:{...current.dialogue[SESSION]!,records:current.dialogue[SESSION]!.records.filter(r=>r.evidence.kind!=="voice" || (kind==="recognition" ? r.evidence.event.kind==="output_transcript" : r.evidence.event.kind!=="output_transcript"))}}})); await expect.poll(()=>document.querySelector("dialog[open]")).toBeNull();expect(document.activeElement).toBe(anchor); }); diff --git a/packages/ui-react/tests/browser/dialogue-recovery.offline.tsx b/packages/ui-react/tests/browser/dialogue-recovery.offline.tsx index 81d883914f..252e9f8b9c 100644 --- a/packages/ui-react/tests/browser/dialogue-recovery.offline.tsx +++ b/packages/ui-react/tests/browser/dialogue-recovery.offline.tsx @@ -859,7 +859,8 @@ for (const provider of ["gemini", "gpt"] as const) for (const failure of ["quota expect(qualifiers).toHaveLength(2); expect(qualifiers[0]!.getAttribute("aria-label")).not.toContain("unsaved"); expect(qualifiers[1]!.getAttribute("aria-label"),"UNSAVED_ROW_QUALIFIER").toContain("unsaved"); - expect(qualifiers[1]!.querySelectorAll("svg").length).toBeGreaterThan(qualifiers[0]!.querySelectorAll("svg").length); + // #3700: the unsaved state is named on the Details stop and in its dialog, never drawn as a glyph. + expect(qualifiers.map(q=>q.querySelectorAll("svg").length),"no glyph on a spoken turn").toEqual([0,0]); expect(rows.flatMap(e=>e.fragments.map(f=>f.text))).toEqual(events.map(f=>"text" in f.event ? f.event.text : "")); expect(result.rows).toHaveLength(events.filter(f=>f.retention!=="unsaved").length); diff --git a/packages/ui-react/tests/browser/spoken-details.ts b/packages/ui-react/tests/browser/spoken-details.ts new file mode 100644 index 0000000000..d9e721a16c --- /dev/null +++ b/packages/ui-react/tests/browser/spoken-details.ts @@ -0,0 +1,15 @@ +/// +// A spoken turn's details are reached through its hidden Details stop +// (#3728, #3700): there is no glyph to click at rest. These open it the +// ways a reader does. +import { expect } from "vitest"; +import { userEvent } from "vitest/browser"; + +/** Hover the turn until the pill shows, then click the pill. */ +export async function pointDetails(trigger: HTMLButtonElement) { + const turn = trigger.closest(".bk-spoken-turn"); + expect(turn, "the Details stop belongs to a spoken turn").not.toBeNull(); + await userEvent.hover(turn!.firstElementChild!); + await expect.poll(() => turn!.dataset.reveal, "hovering the turn shows the pill").toBe("true"); + await userEvent.click(trigger); +} diff --git a/packages/ui-react/tests/browser/spoken-turn-marks.offline.tsx b/packages/ui-react/tests/browser/spoken-turn-marks.offline.tsx index 1dd2273ae7..08165c792e 100644 --- a/packages/ui-react/tests/browser/spoken-turn-marks.offline.tsx +++ b/packages/ui-react/tests/browser/spoken-turn-marks.offline.tsx @@ -3,7 +3,7 @@ // only by recorded provenance. Live, settled and reloaded chats are each // rendered through the real ChatPage and transcript timeline. import { afterAll, beforeAll, expect, test, vi, type TestContext } from "vitest"; -import { commands, page } from "vitest/browser"; +import { commands, page, userEvent } from "vitest/browser"; import { createRoot } from "react-dom/client"; import { flushSync } from "react-dom"; import axe from "axe-core"; @@ -47,6 +47,14 @@ const marks = (root: ParentNode) => ({ you: root.querySelectorAll('.bk-spoken-mark[data-speaker="you"]').length, brain: root.querySelectorAll('.bk-spoken-mark[data-speaker="brain"]').length, }); +/** + * #3728/#3700: every recognized or generated spoken turn carries exactly one + * Details stop inside the turn, and no glyph trigger sits inside or beside it. + */ +const details = (root: ParentNode) => [...root.querySelectorAll("[data-conversation-recognition], [data-conversation-output]")].map(row => ({ + stops: row.querySelectorAll('.bk-spoken-turn [data-transcript-trigger="reveal"]').length, + glyphs: row.querySelectorAll(".bk-transcript-qualifiers, .bk-transcript-glyphs").length, +})); const uncertainWords = (root: ParentNode) => [...root.querySelectorAll(".bk-uncertain")].map(w => w.firstChild?.textContent); test("a live spoken exchange carries the mic and speaker marks; only a low calibrated score is uncertain", async ctx => { @@ -64,6 +72,7 @@ test("a live spoken exchange carries the mic and speaker marks; only a low calib expect(s.host.querySelector(".bk-unplayed"), "no text position is known, so nothing is dimmed as unplayed").toBeNull(); expect(s.host.querySelector(".bk-cut-off"), "a cut-off claim needs retained barge-in evidence, which this chat has none of").toBeNull(); expect(s.host.textContent, "the old turn labels are gone").not.toMatch(/Recognized speech|Voice reply/); + expect(details(s.host), "live: one Details stop per spoken turn, no glyph").toEqual([{ stops: 1, glyphs: 0 }, { stops: 1, glyphs: 0 }]); // The spoken turns only: the header time stamp is outside this change. for (const turn of s.host.querySelectorAll("[data-conversation-recognition], [data-conversation-output]")) expect((await axe.run(turn)).violations.flatMap(v => v.nodes.map(n => `${v.id} ${n.target.join(" ")}: ${n.failureSummary}`))).toEqual([]); await page.screenshot({ element: s.host, path: "../../.vitest-attachments/spoken-turn-marks/live-320.png" }); @@ -72,6 +81,7 @@ test("a live spoken exchange carries the mic and speaker marks; only a low calib flushSync(() => s.ui.connection.conversation.state.setState(state => ({ recognition: state.recognition.map(f => f.sequence === 3 ? { ...f, finalization: "final" as const } : f) }))); expect(row.querySelector(".bk-spoken-bubble")!.hasAttribute("data-in-progress")).toBe(false); expect(row.querySelector(".bk-voice-cursor")).toBeNull(); + expect(details(s.host), "settled: the same Details stops").toEqual([{ stops: 1, glyphs: 0 }, { stops: 1, glyphs: 0 }]); }); // #3729: one retained barge-in on one reply, and one retained end. The live @@ -158,5 +168,74 @@ test("a reloaded chat renders the same marks from retained evidence; a legacy tu const typed = [...s.host.querySelectorAll(".chat-message-body")].find(b => b.textContent === "Which timber is left for the raft?")!; expect(typed.closest(".bk-spoken-turn"), "a turn with no voice source renders plain").toBeNull(); expect(s.host.querySelector(".bk-unplayed")).toBeNull(); + expect(details(s.host), "reloaded: the same Details stops as live").toEqual([{ stops: 1, glyphs: 0 }, { stops: 1, glyphs: 0 }]); + expect(typed.closest("[data-arrival-key]")!.querySelector("[data-transcript-trigger], .bk-transcript-qualifiers"), "a typed turn has no details control").toBeNull(); await page.screenshot({ element: s.host, path: "../../.vitest-attachments/spoken-turn-marks/reloaded-320.png" }); }); + +/** One reloaded exchange: your recognized turn and brain's reply. */ +async function exchange(ctx: TestContext) { + const s = await scene(ctx); + flushSync(() => s.ui.connection.conversation.state.setState({ sessionId: SESSION, dialogueRestoredThrough: { [SESSION]: 2 }, dialogue: { [SESSION]: retained([ + voiceRecord(1, { kind: "input_fragment", utteranceId: "calypso-axe", sequence: 1, text: "Is the raft ready?", finalization: "final", certainty: "known", confidence: 0.98, origin: "user" }), + voiceRecord(2, { kind: "output_transcript", outputId: "raft-reply", sequence: 0, text: "The raft is lashed and ready." }), + ]) } })); + const you = await vi.waitFor(() => s.host.querySelector('[data-conversation-recognition] .bk-spoken-turn')!); + const brain = s.host.querySelector('[data-conversation-output] .bk-spoken-turn')!; + return { ...s, you, brain }; +} +const stop = (turn: HTMLElement) => turn.querySelector('[data-transcript-trigger="reveal"]')!; +const dialogText = () => document.querySelector("dialog[open]")?.textContent ?? null; +async function close() { await userEvent.keyboard("{Escape}"); await expect.poll(() => document.querySelector("dialog[open]")).toBeNull(); } + +test("keyboard: Tab reaches each turn's Details stop, Enter opens the details, Escape returns focus", async ctx => { + const s = await exchange(ctx); + for (const [turn, copy] of [[s.you, "Service confidence 98%."], [s.brain, "output raft-reply"]] as const) { + const control = stop(turn); + expect(getComputedStyle(control).clipPath, "hidden at rest").toBe("inset(50%)"); + for (let n = 0; n < 60 && document.activeElement !== control; n++) await userEvent.tab(); + expect(document.activeElement, "Tab reaches the Details stop").toBe(control); + expect(getComputedStyle(control).clipPath, "focus shows the pill").toBe("none"); + expect(control.textContent).toBe("Details"); + await userEvent.keyboard("{Enter}"); + await expect.poll(dialogText).toContain("Transcript details"); + const dialog = document.querySelector("dialog[open]")!; + expect(dialog.id).toBe(control.getAttribute("aria-controls")); + await userEvent.click(dialog.querySelector("summary")!); + expect(dialog.textContent, "the details content is the turn's own evidence").toContain(copy); + await close(); + expect(document.activeElement, "focus returns to the Details stop").toBe(control); + } + // Shift+F10 from inside the turn opens the same details. + stop(s.you).focus(); + await userEvent.keyboard("{Shift>}{F10}{/Shift}"); + await expect.poll(dialogText).toContain("Recognized speech. Words may be uncertain; speaker unverified."); + await close(); + expect(document.activeElement).toBe(stop(s.you)); +}); + +test("right-click opens a spoken turn's details; with words selected inside it, the native menu stays", async ctx => { + const s = await exchange(ctx); + const words = s.brain.querySelector(".bk-spoken-prose > .whitespace-pre-wrap")!; + await userEvent.click(words, { button: "right" }); + await expect.poll(dialogText, "a right-click opens the details").toContain("Generated voice reply."); + await close(); + expect(document.activeElement, "focus returns to the turn's Details stop").toBe(stop(s.brain)); + + const selection = document.getSelection()!; + const range = document.createRange(); range.selectNodeContents(words); + selection.removeAllRanges(); selection.addRange(range); + let prevented: boolean | undefined; + const seen = (event: Event) => { prevented = event.defaultPrevented; }; + addEventListener("contextmenu", seen); ctx.onTestFinished(() => removeEventListener("contextmenu", seen)); + await userEvent.click(words, { button: "right" }); + expect(prevented, "the native menu is not suppressed while text is selected").toBe(false); + expect(document.querySelector("dialog[open]"), "a selection keeps Copy: no details dialog").toBeNull(); + expect(selection.toString()).toBe("The raft is lashed and ready."); + selection.removeAllRanges(); + + // Your turn behaves the same. + await userEvent.click(s.you.querySelector("[data-recognized-text]")!, { button: "right" }); + await expect.poll(dialogText).toContain("Recognized speech. Words may be uncertain; speaker unverified."); + await close(); +}); diff --git a/packages/ui-react/tests/browser/transcript-qualifiers-r2.offline.tsx b/packages/ui-react/tests/browser/transcript-qualifiers-r2.offline.tsx index 0b56e318aa..ebd477af6e 100644 --- a/packages/ui-react/tests/browser/transcript-qualifiers-r2.offline.tsx +++ b/packages/ui-react/tests/browser/transcript-qualifiers-r2.offline.tsx @@ -11,6 +11,7 @@ import { TranscriptQualifiers } from "@schlessera/brain-ui-kit/internal"; import { transcriptTimelineFor } from "../../src/lib/transcript-timeline.js"; import type { ConversationRecognition } from "../../src/voice/conversation-client.js"; import { installFaultNetwork } from "./offline/fault-network.js"; +import { pointDetails } from "./spoken-details.js"; const SESSION = "odysseus-raft"; let styles: HTMLStyleElement; @@ -83,7 +84,7 @@ test("review: incoming rows preserve open details and focus fallback", async ctx const s=await scene(ctx); const outputs=Array.from({length:40},(_,i)=>({conversationId:"odysseus-voice",epoch:1,sessionId:SESSION,providerId:"gemini-live",outputId:`raft-${i}`,generated:`Raft report ${i}.`,playback:"unknown" as const})); flushSync(()=>s.ui.connection.conversation.state.setState({outputs})); - const trigger=qualifier(s.host,"generated"); trigger.scrollIntoView(); await userEvent.click(trigger); + const trigger=qualifier(s.host,"generated"); trigger.scrollIntoView(); await pointDetails(trigger); expect(document.querySelector("dialog[open]")).not.toBeNull(); flushSync(()=>s.ui.connection.conversation.state.setState({outputs:[...outputs,{...outputs[0]!,outputId:"raft-new",generated:"A new report."}]})); console.log("REVIEW_WINDOW",JSON.stringify({dialog:!!document.querySelector("dialog[open]"),connected:trigger.isConnected,focus:document.activeElement?.tagName})); @@ -125,7 +126,7 @@ test("canonical source removal closes details onto a surviving reading anchor", const s = await scene(ctx); const output = {conversationId:"odysseus-voice",epoch:1,sessionId:SESSION,providerId:"gemini-live",outputId:"raft-source",generated:"The raft source.",playback:"unknown" as const}; flushSync(()=>s.ui.connection.conversation.state.setState({outputs:[output]})); - const trigger=qualifier(s.host,"generated"); const readingAnchor = trigger.closest("[data-reading-column]"); await userEvent.click(trigger); + const trigger=qualifier(s.host,"generated"); const readingAnchor = trigger.closest("[data-reading-column]"); await pointDetails(trigger); expect(document.querySelector("dialog[open]")).not.toBeNull(); flushSync(()=>s.ui.connection.conversation.state.setState({outputs:[{...output,outputId:"raft-retained",generated:"Another retained report."}]})); await expect.poll(()=>document.querySelector("dialog[open]")).toBeNull(); @@ -155,15 +156,16 @@ for (const kind of ["recognized", "legend"] as const) test(`recognition ${kind} expect(s.host.querySelectorAll("[data-arrival-key]")).toHaveLength(40); }); -test("focused qualifier explanation retains its source before activation", async ctx => { +test("a focused Details stop retains its source before activation", async ctx => { const s=await scene(ctx); const outputs=Array.from({length:40},(_,i)=>({conversationId:"odysseus-voice",epoch:1,sessionId:SESSION,providerId:"gemini-live",outputId:`focus-raft-${i}`,generated:`Report ${i}.`,playback:"unknown" as const})); flushSync(()=>s.ui.connection.conversation.state.setState({outputs})); const trigger=qualifier(s.host,"generated"); trigger.scrollIntoView(); trigger.focus(); - await expect.poll(()=>document.querySelector('[role="tooltip"]')).not.toBeNull(); + await expect.poll(()=>getComputedStyle(trigger).clipPath, "focus shows the Details pill").toBe("none"); flushSync(()=>s.ui.connection.conversation.state.setState({outputs:[...outputs,{...outputs[0]!,outputId:"focus-tail"}]})); expect(document.activeElement).toBe(trigger); - expect(document.querySelector('[role="tooltip"]')).not.toBeNull(); + expect(trigger.isConnected, "the focused stop's row stays mounted").toBe(true); + expect(getComputedStyle(trigger).clipPath).toBe("none"); await userEvent.keyboard("{Escape}{Tab}"); await expect.poll(()=>s.host.querySelectorAll("[data-arrival-key]").length).toBe(40); expect(trigger.isConnected).toBe(false); diff --git a/packages/ui-react/tests/browser/transcript-qualifiers.offline.tsx b/packages/ui-react/tests/browser/transcript-qualifiers.offline.tsx index 5f6f6cf983..fca15eb378 100644 --- a/packages/ui-react/tests/browser/transcript-qualifiers.offline.tsx +++ b/packages/ui-react/tests/browser/transcript-qualifiers.offline.tsx @@ -57,25 +57,25 @@ for (const theme of ["light", "dark"] as const) for (const width of [320, 1280]) expect(row.getAttribute("aria-label"), "do not repeat qualifier name on section").toBeNull(); expect(trigger.getAttribute("aria-label"), "original Gemini source survives current GPT picker").toBe("Recognized speech; Gemini Live; unverified. Transcript details."); expect(qualifier(s.host, "generated").getAttribute("aria-label")).toContain("Gemini Live; playback unknown"); + // A spoken turn's details are its Details stop (#3728): no glyph, no + // tooltip, clipped at rest and shown as a pill once focused. + expect(row.querySelector(".bk-transcript-glyphs"), "no glyph inside or beside the spoken turn").toBeNull(); + expect(trigger.closest(".bk-spoken-turn"), "the stop belongs to the spoken turn").not.toBeNull(); + expect(trigger.dataset.transcriptTrigger).toBe("reveal"); + expect(getComputedStyle(trigger).clipPath, "hidden at rest").toBe("inset(50%)"); trigger.scrollIntoView({ block: "center" }); + // The kit's 300 ms hover delay runs on a fake clock, so "every pending + // timer has run" is a step, not a window. + vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] }); ctx.onTestFinished(() => { vi.useRealTimers(); }); + await userEvent.tab(); while (document.activeElement !== trigger) await userEvent.tab(); + flushSync(() => vi.advanceTimersByTime(300)); + expect(getComputedStyle(trigger).clipPath, "focus shows the pill").toBe("none"); const box = trigger.getBoundingClientRect(); expect(box.width).toBeGreaterThanOrEqual(44); expect(box.height).toBeGreaterThanOrEqual(44); for (const [x,y] of [[box.left + 2,box.top + box.height/2],[box.right-2,box.top+box.height/2],[box.left+box.width/2,box.top+2],[box.left+box.width/2,box.bottom-2]]) expect(document.elementFromPoint(x,y)?.closest("button")).toBe(trigger); - // The qualifier's 300 ms show delay and 150 ms hide grace run on a fake - // clock, so "every pending timer has run" is a step, not a window. - vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] }); ctx.onTestFinished(() => { vi.useRealTimers(); }); - trigger.focus(); - flushSync(() => vi.advanceTimersByTime(300)); - await expect.poll(() => document.querySelector('[role="tooltip"]')?.textContent).toContain("Words may be uncertain; speaker unverified."); - const hint = document.querySelector('[role="tooltip"]')!; - expect(hint.getBoundingClientRect().left).toBeGreaterThanOrEqual(0); - expect(hint.getBoundingClientRect().right).toBeLessThanOrEqual(width); - expect(trigger.hasAttribute("title"), "single custom explanation").toBe(false); - expect(getComputedStyle(trigger).outlineWidth).toBe("2px"); - await userEvent.keyboard("{Escape}"); - await expect.poll(() => document.querySelector('[role="tooltip"]')).toBeNull(); - flushSync(() => vi.runOnlyPendingTimers()); - expect(document.querySelector('[role="tooltip"]'), "Escape suppresses while still focused").toBeNull(); + expect(document.querySelector('[role="tooltip"]'), "the Details stop has no tooltip").toBeNull(); + expect(trigger.hasAttribute("title"), "no native tooltip either").toBe(false); + expect(getComputedStyle(trigger.querySelector(".bk-transcript-pill")!).outlineWidth).toBe("2px"); vi.useRealTimers(); await userEvent.keyboard("{Enter}"); const dialog = document.querySelector('dialog[open]')!; @@ -83,6 +83,7 @@ for (const theme of ["light", "dark"] as const) for (const width of [320, 1280]) expect(dialog.id).toBe(trigger.getAttribute("aria-controls")); expect(document.activeElement?.textContent).toBe("Transcript details"); expect(dialog.textContent).toContain("Source: Gemini Live"); + expect(dialog.textContent, "the explanation the glyph tooltip carried").toContain("Words may be uncertain; speaker unverified."); expect(dialog.querySelector("details")!.open, "technical evidence starts collapsed").toBe(false); await userEvent.click(dialog.querySelector("summary")!); expect(dialog.textContent).toContain("Timing unavailable; speaker unverified."); @@ -105,27 +106,25 @@ for (const theme of ["light", "dark"] as const) for (const width of [320, 1280]) expect(qualifier(s.host).getAttribute("aria-label")).toContain("GPT-Live; unverified"); }); -test("pointer can read tooltip then tap details; playback and restoration are independent evidence", async ctx => { +test("pointer reveals the Details pill after hovering, then a tap opens details; playback and restoration are independent evidence", async ctx => { const s = await scene(ctx, 320, "light", 1, false); s.render(<>); const trigger = qualifier(s.host, "generated"); - // As above: the show delay and hide grace run on a fake clock. + const turn = trigger.closest(".bk-spoken-turn")!; + expect(turn, "the stop belongs to brain's spoken turn").not.toBeNull(); + // The kit's 300 ms hover delay runs on a fake clock. vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] }); ctx.onTestFinished(() => { vi.useRealTimers(); }); - await userEvent.hover(trigger); + await userEvent.hover(turn.querySelector(".bk-spoken-prose")!); flushSync(() => vi.advanceTimersByTime(300)); - await expect.poll(() => document.querySelector('[role="tooltip"]')?.textContent).toContain("Remaining reply not spoken locally. Earlier spoken portion unknown."); - const hint = document.querySelector('[role="tooltip"]')!; - await userEvent.hover(hint); - flushSync(() => vi.runOnlyPendingTimers()); - expect(hint.isConnected, "hoverable explanation persists").toBe(true); + expect(turn.dataset.reveal, "hovering the turn shows the pill").toBe("true"); + expect(document.querySelector('[role="tooltip"]'), "no tooltip").toBeNull(); vi.useRealTimers(); - await userEvent.keyboard("{Escape}"); - expect(document.querySelector('[role="tooltip"]')).toBeNull(); const box = trigger.getBoundingClientRect(); await commands.rankTap({ x: box.left+box.width/2, y: box.top+box.height/2 }); await expect.poll(() => document.querySelector('dialog[open]')?.textContent).toContain("Restored text evidence. This does not prove playback or that the current voice engine received it."); + expect(document.querySelector('dialog[open]')?.textContent).toContain("Remaining reply not spoken locally. Earlier spoken portion unknown."); expect(document.querySelector('dialog[open]')?.textContent).toContain("Original discussion position unknown"); - expect(trigger.querySelectorAll("svg")).toHaveLength(3); + expect(trigger.querySelectorAll("svg"), "no glyph").toHaveLength(0); await closeDetails(); await userEvent.click(page.getByRole("button", { name: "Transcript symbols", exact: true })); expect(document.querySelector('dialog[open]')?.textContent).toContain("Received audio chunks played locally; spoken portion unknown."); From 43f26bdeb70552fdfbdf23b4f66f59515158e14a Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 9 Nov 2026 17:35:24 +0000 Subject: [PATCH 2/2] test(ui-react): pass poll messages as options for the strict typecheck (#3700) Co-Authored-By: Claude Opus 5.5 --- packages/ui-react/tests/browser/spoken-details.ts | 2 +- packages/ui-react/tests/browser/spoken-turn-marks.offline.tsx | 2 +- .../ui-react/tests/browser/transcript-qualifiers-r2.offline.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ui-react/tests/browser/spoken-details.ts b/packages/ui-react/tests/browser/spoken-details.ts index d9e721a16c..748afa81a2 100644 --- a/packages/ui-react/tests/browser/spoken-details.ts +++ b/packages/ui-react/tests/browser/spoken-details.ts @@ -10,6 +10,6 @@ export async function pointDetails(trigger: HTMLButtonElement) { const turn = trigger.closest(".bk-spoken-turn"); expect(turn, "the Details stop belongs to a spoken turn").not.toBeNull(); await userEvent.hover(turn!.firstElementChild!); - await expect.poll(() => turn!.dataset.reveal, "hovering the turn shows the pill").toBe("true"); + await expect.poll(() => turn!.dataset.reveal, { message: "hovering the turn shows the pill" }).toBe("true"); await userEvent.click(trigger); } diff --git a/packages/ui-react/tests/browser/spoken-turn-marks.offline.tsx b/packages/ui-react/tests/browser/spoken-turn-marks.offline.tsx index 08165c792e..6d832a4bfa 100644 --- a/packages/ui-react/tests/browser/spoken-turn-marks.offline.tsx +++ b/packages/ui-react/tests/browser/spoken-turn-marks.offline.tsx @@ -218,7 +218,7 @@ test("right-click opens a spoken turn's details; with words selected inside it, const s = await exchange(ctx); const words = s.brain.querySelector(".bk-spoken-prose > .whitespace-pre-wrap")!; await userEvent.click(words, { button: "right" }); - await expect.poll(dialogText, "a right-click opens the details").toContain("Generated voice reply."); + await expect.poll(dialogText, { message: "a right-click opens the details" }).toContain("Generated voice reply."); await close(); expect(document.activeElement, "focus returns to the turn's Details stop").toBe(stop(s.brain)); diff --git a/packages/ui-react/tests/browser/transcript-qualifiers-r2.offline.tsx b/packages/ui-react/tests/browser/transcript-qualifiers-r2.offline.tsx index ebd477af6e..27470b2e90 100644 --- a/packages/ui-react/tests/browser/transcript-qualifiers-r2.offline.tsx +++ b/packages/ui-react/tests/browser/transcript-qualifiers-r2.offline.tsx @@ -161,7 +161,7 @@ test("a focused Details stop retains its source before activation", async ctx => const outputs=Array.from({length:40},(_,i)=>({conversationId:"odysseus-voice",epoch:1,sessionId:SESSION,providerId:"gemini-live",outputId:`focus-raft-${i}`,generated:`Report ${i}.`,playback:"unknown" as const})); flushSync(()=>s.ui.connection.conversation.state.setState({outputs})); const trigger=qualifier(s.host,"generated"); trigger.scrollIntoView(); trigger.focus(); - await expect.poll(()=>getComputedStyle(trigger).clipPath, "focus shows the Details pill").toBe("none"); + await expect.poll(()=>getComputedStyle(trigger).clipPath, { message: "focus shows the Details pill" }).toBe("none"); flushSync(()=>s.ui.connection.conversation.state.setState({outputs:[...outputs,{...outputs[0]!,outputId:"focus-tail"}]})); expect(document.activeElement).toBe(trigger); expect(trigger.isConnected, "the focused stop's row stays mounted").toBe(true);