web: chat reasoning block and tool calls for the whole lifecycle (C6)

This commit is contained in:
2026-10-19 06:14:48 +01:00
parent f48e53d5c8
commit 7df4891f14
6 changed files with 1200 additions and 17 deletions
+248
View File
@@ -2344,6 +2344,254 @@ try {
await shot("47b-chat-markdown-code.png");
await page.evaluate(`document.querySelector("#markdownCodeSample")?.remove()`);
// C6: the turn's reasoning block and its tool-call chip + panel. The live
// operator session carries one folded agent turn with real reasoning and tool
// parts, so the chip, the panel and the rows are exercised against live data.
// Labels, aria names and the C14 scroll-invariance are asserted, not assumed.
step("C6: the reasoning block and the tool-call chip + panel");
const reasoningNow = await page.evaluate(`(() => {
const block = document.querySelector("#chatTranscript .chat-reasoning");
if (!block) return null;
const icon = block.querySelector(".chat-reasoning-icon");
const body = block.querySelector(".chat-reasoning-body");
return {
label: block.querySelector(".chat-reasoning-label")?.textContent ?? "",
aria: icon?.getAttribute("aria-label") ?? "",
expanded: body ? !body.hidden : false,
};
})()`);
if (!reasoningNow) throw new Error("C6: no reasoning block rendered in the live transcript");
if (reasoningNow.aria !== "Hide reasoning") {
throw new Error(`C6: the expanded reasoning chevron should read 'Hide reasoning', got ${reasoningNow.aria}`);
}
if (!/^Reasoning( · \d+ steps)?( · \d+[a-z].*)?$/.test(reasoningNow.label)) {
throw new Error(`C6: settled reasoning label: ${reasoningNow.label}`);
}
const reasoningCollapsed = await page.evaluate(`(() => {
const block = document.querySelector("#chatTranscript .chat-reasoning");
block.querySelector(".chat-reasoning-toggle").click();
const el = document.querySelector("#chatTranscript");
const br = block.getBoundingClientRect();
el.scrollTop = Math.max(0, el.scrollTop + Math.round(br.top - el.getBoundingClientRect().top) - 60);
return {
hidden: block.querySelector(".chat-reasoning-body").hidden,
aria: block.querySelector(".chat-reasoning-icon").getAttribute("aria-label"),
expanded: block.querySelector(".chat-reasoning-toggle").getAttribute("aria-expanded"),
};
})()`);
if (!reasoningCollapsed.hidden || reasoningCollapsed.aria !== "Show reasoning" || reasoningCollapsed.expanded !== "false") {
throw new Error(`C6: collapsing the reasoning block: ${JSON.stringify(reasoningCollapsed)}`);
}
console.log(` reasoning block "${reasoningNow.label}" collapsed (chevron "Show reasoning")`);
await shot("51-chat-reasoning-collapsed.png");
const expandedReasoning = await page.evaluate(`(() => {
const block = document.querySelector("#chatTranscript .chat-reasoning");
block.querySelector(".chat-reasoning-toggle").click();
const el = document.querySelector("#chatTranscript");
const br = block.getBoundingClientRect();
el.scrollTop = Math.max(0, el.scrollTop + Math.round(br.top - el.getBoundingClientRect().top) - 60);
return {
hidden: block.querySelector(".chat-reasoning-body").hidden,
aria: block.querySelector(".chat-reasoning-icon").getAttribute("aria-label"),
length: block.querySelector(".chat-reasoning-body").textContent.length,
};
})()`);
if (expandedReasoning.hidden || expandedReasoning.aria !== "Hide reasoning" || expandedReasoning.length === 0) {
throw new Error(`C6: expanding the reasoning block: ${JSON.stringify(expandedReasoning)}`);
}
console.log(` reasoning block expanded again (${expandedReasoning.length} chars, chevron "Hide reasoning")`);
await shot("52-chat-reasoning-expanded.png");
// The chip: its count, its screen-reader announcement and its chevron. The
// count is the number of rows the panel carries, so the two can never disagree.
const chipInfo = await page.evaluate(`(() => {
const chip = document.querySelector("#chatTranscript .chat-tool-chip");
if (!chip) return null;
chip.scrollIntoView({ block: "center" });
return {
text: chip.textContent ?? "",
aria: chip.getAttribute("aria-label") ?? "",
chevron: chip.querySelector(".chat-tool-chevron")?.getAttribute("aria-label") ?? "",
rows: document.querySelectorAll(".chat-tool-panel .chat-tool-row").length,
};
})()`);
if (!chipInfo) throw new Error("C6: no tool-call chip rendered in the live transcript");
const toolCount = chipInfo.rows;
const toolLabel = toolCount === 1 ? "1 tool called" : `${toolCount} tools called`;
const toolAria =
toolCount === 1 ? "1 tool call, expand for details" : `${toolCount} tool calls, expand for details`;
if (!chipInfo.text.includes(toolLabel)) {
throw new Error(`C6: the chip should read "${toolLabel}", got ${JSON.stringify(chipInfo.text)}`);
}
if (chipInfo.aria !== toolAria) {
throw new Error(`C6: chip aria-label ${chipInfo.aria} (expected ${toolAria})`);
}
if (chipInfo.chevron !== "Show tool calls") {
throw new Error(`C6: collapsed chip chevron: ${chipInfo.chevron}`);
}
console.log(` tool chip "${toolLabel}" (aria "${chipInfo.aria}", ${toolCount} live row(s))`);
await shot("53-chat-tool-chip.png");
// Open the panel by dispatching the chip's own click (not a synthetic scroll),
// then assert the header, the close control and the C14 invariant: opening the
// panel must not move the transcript behind it.
const scrollBeforePanel = await page.evaluate(
`Math.round(document.querySelector("#chatTranscript").scrollTop)`,
);
const openedPanel = await page.evaluate(`(() => {
const chip = document.querySelector("#chatTranscript .chat-tool-chip");
chip.click();
const panel = document.querySelector(".chat-tool-panel");
return {
hidden: panel?.hidden ?? true,
head: panel?.querySelector(".chat-tool-panel-count")?.textContent ?? "",
close: panel?.querySelector(".chat-tool-close")?.getAttribute("aria-label") ?? "",
chevron: chip.querySelector(".chat-tool-chevron")?.getAttribute("aria-label") ?? "",
rows: panel?.querySelectorAll(".chat-tool-row").length ?? 0,
};
})()`);
if (openedPanel.hidden) throw new Error("C6: the tool panel did not open");
if (openedPanel.head !== toolLabel) throw new Error(`C6: panel header ${openedPanel.head}`);
if (openedPanel.close !== "Close tool calls") {
throw new Error(`C6: panel close control ${openedPanel.close}`);
}
if (openedPanel.chevron !== "Hide tool calls") {
throw new Error(`C6: open chip chevron ${openedPanel.chevron}`);
}
if (openedPanel.rows !== toolCount) {
throw new Error(`C6: the panel lists ${openedPanel.rows} rows, the chip counts ${toolCount}`);
}
const scrollAfterOpen = await page.evaluate(
`Math.round(document.querySelector("#chatTranscript").scrollTop)`,
);
if (Math.abs(scrollAfterOpen - scrollBeforePanel) > 2) {
throw new Error(`C6: opening the tool panel moved the transcript (${scrollBeforePanel} -> ${scrollAfterOpen})`);
}
console.log(
` tool panel open: header "${openedPanel.head}", close "Close tool calls", ${openedPanel.rows} row(s)`,
);
// Expand the first row in place and assert its chevron name, its INPUT and its
// OUTPUT (the live first call is a settled `read` carrying both).
const firstToolRow = await page.evaluate(`(() => {
const panel = document.querySelector(".chat-tool-panel");
const list = panel.querySelector(".chat-tool-list");
list.scrollTop = 0;
const first = () => panel.querySelector(".chat-tool-row-head");
const name = first().querySelector(".chat-tool-name")?.textContent ?? "";
const chevronBefore = first().querySelector(".chat-tool-row-chevron")?.getAttribute("aria-label") ?? "";
first().click();
const head = first();
const row = head.closest(".chat-tool-row");
return {
name,
chevronBefore,
chevronAfter: head.querySelector(".chat-tool-row-chevron")?.getAttribute("aria-label") ?? "",
sections: [...row.querySelectorAll(".chat-tool-section-label")].map((n) => n.textContent),
bodies: [...row.querySelectorAll(".chat-tool-section-body")].map((n) => n.textContent),
};
})()`);
if (firstToolRow.chevronBefore !== `Expand ${firstToolRow.name}`) {
throw new Error(`C6: collapsed row chevron ${firstToolRow.chevronBefore} for ${firstToolRow.name}`);
}
if (firstToolRow.chevronAfter !== `Collapse ${firstToolRow.name}`) {
throw new Error(`C6: expanded row chevron ${firstToolRow.chevronAfter} for ${firstToolRow.name}`);
}
if (!firstToolRow.sections.includes("INPUT") || !firstToolRow.sections.includes("OUTPUT")) {
throw new Error(`C6: first row sections ${JSON.stringify(firstToolRow.sections)}`);
}
if (firstToolRow.bodies.some((body) => body.trim() === "")) {
throw new Error(`C6: a first-row section rendered blank: ${JSON.stringify(firstToolRow.bodies)}`);
}
console.log(
` first row "${firstToolRow.name}": ${firstToolRow.sections.join(" + ")} (chevron "${firstToolRow.chevronAfter}")`,
);
await shot("54-chat-tool-panel.png");
// Closing it must put the transcript back exactly where it was.
const closedPanel = await page.evaluate(`(() => {
document.querySelector(".chat-tool-close").click();
const panel = document.querySelector(".chat-tool-panel");
const chip = document.querySelector("#chatTranscript .chat-tool-chip");
return {
hidden: panel.hidden,
chevron: chip.querySelector(".chat-tool-chevron").getAttribute("aria-label"),
top: Math.round(document.querySelector("#chatTranscript").scrollTop),
};
})()`);
if (!closedPanel.hidden || closedPanel.chevron !== "Show tool calls") {
throw new Error(`C6: closing the tool panel: ${JSON.stringify(closedPanel)}`);
}
if (Math.abs(closedPanel.top - scrollBeforePanel) > 2) {
throw new Error(`C6: opening/closing the tool panel moved the transcript (${scrollBeforePanel} -> ${closedPanel.top})`);
}
console.log(
` the tool panel left the transcript where it was across open/close (top ${scrollBeforePanel} -> ${closedPanel.top})`,
);
// The live history carries no failed call and no edit-family call, so render
// both through the page's own row builder (the 47b precedent): a failed row
// marked "Failed tool call" with an ERROR section, and an edit row with the LCS
// diff and its true "+N -M" stat. The sample is removed straight after.
const sampleRows = await page.evaluate(`(async () => {
const app = await import("/src/app.js");
const host = document.createElement("div");
host.id = "chatToolSample";
host.className = "chat-tool-sample";
const note = document.createElement("div");
note.className = "chat-tool-sample-note";
note.textContent =
"Page-rendered sample — the live history carries no failed or edit call " +
"(the chip, panel and rows above are live)";
host.append(note);
const failedPart = {
type: "tool", id: "sample-failed", name: "shell",
state: { status: "error", input: { command: "false" }, error: { message: "exit status 1" } },
};
const failedRow = app.renderToolCallRow(failedPart, { expanded: true });
host.append(failedRow);
const editPart = {
type: "tool", id: "sample-edit", name: "edit",
state: {
status: "completed",
input: { filePath: "web/src/chat.js", oldString: "const a = 1;\\nconst b = 2;", newString: "const a = 1;\\nconst b = 3;\\nconst c = 4;" },
content: [{ type: "text", text: "applied" }],
},
time: { created: 1, ran: 2, completed: 103 },
};
const editRow = app.renderToolCallRow(editPart, { expanded: true });
host.append(editRow);
document.body.append(host);
return {
failedAria: failedRow.querySelector('.chat-tool-icon[aria-label="Failed tool call"]') ? "Failed tool call" : "",
failedSections: [...failedRow.querySelectorAll(".chat-tool-section-label")].map((n) => n.textContent),
editStat: editRow.querySelector(".chat-tool-stat")?.textContent ?? "",
diffLines: [...editRow.querySelectorAll(".chat-tool-diff-line")].map((n) => ({ cls: n.className, text: n.textContent })),
};
})()`);
if (!sampleRows) throw new Error("C6: could not render the page-rendered tool-row samples");
if (sampleRows.failedAria !== "Failed tool call") {
throw new Error(`C6: the failed row is not marked 'Failed tool call': ${JSON.stringify(sampleRows)}`);
}
if (!sampleRows.failedSections.includes("INPUT") || !sampleRows.failedSections.includes("ERROR")) {
throw new Error(`C6: failed row sections ${JSON.stringify(sampleRows.failedSections)}`);
}
if (sampleRows.editStat !== "+2 -1") {
throw new Error(`C6: edit diff stat ${sampleRows.editStat}`);
}
if (
!sampleRows.diffLines.some((line) => line.cls.includes("diff-remove") && line.text === "- const b = 2;") ||
!sampleRows.diffLines.some((line) => line.cls.includes("diff-add") && line.text === "+ const b = 3;")
) {
throw new Error(`C6: the edit diff lines: ${JSON.stringify(sampleRows.diffLines)}`);
}
console.log(
` page-rendered samples: failed row "Failed tool call" (${sampleRows.failedSections.join(" + ")}), ` +
`edit row stat ${sampleRows.editStat} with ${sampleRows.diffLines.length} diff line(s)`,
);
await shot("55-chat-edit-diff-sample.png");
await page.evaluate(`document.querySelector("#chatToolSample")?.remove()`);
if (transcript.hasLoadOlder) {
// The control was present in capture 45. Press it and capture the honest
// result: the live session's own cursor returns an empty older page, so the