web: chat — session list, open/close, history paging, markdown, scroll (C1/C3/C4/C7/C14)

Browser Chat destination for parity with the Android app:
- session list grouped by directory (closed grouped under "Closed"), kind
  chip, activity badge, work-label meta line, "Search chats" filter (C1)
- open/close/reopen with the Android copy verbatim (C3)
- conversation history paging via the opaque next_cursor (C4)
- markdown subset renderer + code blocks (C7)
- scroll follow / "Jump to latest" / per-session saved position (C14)

Request builders in src/repository.js; pure merge/format/markdown/paging
logic in src/chat.js and src/markdown.js; view in app.js. Every server
string set with textContent, markdown built as DOM nodes.
This commit is contained in:
2026-10-19 05:39:29 +01:00
parent 3d98c60de6
commit 0688127253
10 changed files with 2863 additions and 6 deletions
+279
View File
@@ -1924,6 +1924,285 @@ try {
});
}
// C1/C3/C4/C7/C14: the chat list, its transcript (markdown + the code the live
// session carries), paging and the close dialog. The one live operator session
// is never mutated: the close confirm is shown and dismissed with Cancel.
step("C1/C3/C4/C7/C14: the chat list, transcript, paging and close dialog");
await ensureConnected();
await page.clickText("nav.tabs button.tab", "Chat");
await page.waitForSelector("#chatRows .chat-row", { timeout: 25000 });
const chatList = await page.evaluate(`(() => ({
label: document.querySelector("#chatSearch")?.getAttribute("aria-label") ?? "",
placeholder: document.querySelector("#chatSearch")?.getAttribute("placeholder") ?? "",
rows: [...document.querySelectorAll("#chatRows .chat-row")].map((row) => ({
id: row.dataset.session ?? "",
title: row.querySelector(".chat-row-title")?.textContent ?? "",
chips: [...row.querySelectorAll(".chip")].map((chip) => chip.textContent),
meta: row.querySelector(".chat-row-meta")?.textContent ?? "",
close: !!row.querySelector(".chat-close"),
})),
}))()`);
if (chatList.label !== "Search chats") throw new Error(`chat search label: ${chatList.label}`);
if (chatList.placeholder !== "Search chats") throw new Error(`chat search placeholder: ${chatList.placeholder}`);
if (chatList.rows.length === 0) throw new Error("no chat sessions rendered");
if (!chatList.rows[0].title) throw new Error("the first chat row has no title");
if (!chatList.rows[0].chips.includes("Operator")) {
throw new Error(`chat kind chip: ${chatList.rows[0].chips.join(", ")}`);
}
if (!chatList.rows[0].close) throw new Error("the open chat row offers no Close chat action");
console.log(
` chat list: ${chatList.rows.length} session(s); "${chatList.rows[0].title}" ` +
`[${chatList.rows[0].chips.join(", ")}] — ${chatList.rows[0].meta}`,
);
await shot("44-chat-sessions.png");
// The row's own Close chat… action with NO conversation open: the list offers
// it on every open row, so the confirm must still appear. Shown and dismissed
// with Cancel; no chat_close is ever sent for the operator's live session.
await page.click(`#chatRows .chat-row[data-session="${chatList.rows[0].id}"] .chat-close`);
await page.waitForSelector(".confirm-chat-close", { timeout: 15000 });
const listClose = await page.evaluate(
`document.querySelector(".confirm-chat-close .confirm-message")?.textContent ?? ""`,
);
if (!listClose.startsWith('Closes "')) {
throw new Error(`row-level close message with no conversation open: ${listClose}`);
}
await page.click(".confirm-chat-close .confirm-dismiss");
await eventually(() => page.evaluate(`!document.querySelector(".confirm-chat-close")`), {
timeout: 5000,
what: "the row-level close dialog to close",
});
console.log(
" row-level 'Close chat…' (no conversation open) showed its confirm; dismissed with Cancel",
);
// The narrowed-to-nothing empty state and its Clear search action (the field
// itself is the narrowing; the list's order is never touched).
await page.fill("#chatSearch", "zzz-no-such-chat");
await page.waitForText('No chats match "zzz-no-such-chat".', { timeout: 10000 });
await shot("50-chat-no-match.png");
await page.clickText(".chat-rows .empty button", "Clear search");
await page.waitForSelector("#chatRows .chat-row", { timeout: 10000 });
const cleared = await page.evaluate(`document.querySelector("#chatSearch")?.value ?? null`);
if (cleared !== "") throw new Error(`Clear search left the query: ${JSON.stringify(cleared)}`);
const expectedSession = "ses_eae413f50ffeLQDExlg8cYnscN";
const openedId = chatList.rows[0].id;
if (openedId !== expectedSession) {
console.log(` -- the live server's first session is ${openedId}, not the expected ${expectedSession}`);
}
await page.click(`#chatRows .chat-row[data-session="${openedId}"]`);
await page.waitForSelector("#chatTranscript", { timeout: 25000 });
const transcript = await page.evaluate(`(() => {
const el = document.querySelector("#chatTranscript");
if (!el) return null;
return {
userBubbles: el.querySelectorAll(".chat-turn-user").length,
agentBubbles: el.querySelectorAll(".chat-turn-agent").length,
markdown: el.querySelectorAll(".markdown").length,
tables: el.querySelectorAll(".md-table").length,
inlineCode: el.querySelectorAll(".md-code").length,
codeBlocks: el.querySelectorAll(".md-code-block").length,
toolChips: [...el.querySelectorAll(".chat-tool-chip")].map((chip) => chip.textContent),
reasoning: el.querySelectorAll(".chat-reasoning").length,
client: el.querySelector(".chat-turn-user .chat-client")?.textContent ?? "",
hasLoadOlder: !!document.querySelector(".chat-load-older"),
};
})()`);
if (!transcript) throw new Error("the opened transcript did not render");
if (transcript.userBubbles !== 1) throw new Error(`expected one user bubble, got ${transcript.userBubbles}`);
if (transcript.agentBubbles !== 1) {
throw new Error(`expected one folded agent turn, got ${transcript.agentBubbles}`);
}
if (transcript.markdown === 0) throw new Error("the agent turn rendered no markdown");
if (transcript.tables === 0) throw new Error("the agent answer rendered no markdown table");
if (transcript.inlineCode === 0) throw new Error("the agent answer rendered no inline code");
if (transcript.toolChips.length !== 1) {
throw new Error(`expected one tool-call chip, got ${transcript.toolChips.length}`);
}
console.log(
` transcript: ${transcript.userBubbles} user + ${transcript.agentBubbles} folded agent turn; ` +
`markdown ${transcript.tables} table(s), ${transcript.inlineCode} inline code span(s), ` +
`${transcript.toolChips[0]}; client label "${transcript.client}"`,
);
await shot("45-chat-transcript-newest.png");
// The top of the conversation, reached by a genuine operator wheel gesture on
// the transcript (the app's own listener). Only the operator's gesture changes
// follow intent — a programmatic scrollTo cannot — so this is the only way
// "Jump to latest" may appear; the control is asserted, not assumed.
const wheelGesture = await page.evaluate(`(() => {
const el = document.querySelector("#chatTranscript");
if (!el) return null;
el.scrollTop = 0;
el.dispatchEvent(new WheelEvent("wheel", { deltaY: -240, bubbles: true }));
return {
jumpHidden: document.querySelector("#chatJump")?.hidden ?? null,
top: el.scrollTop,
};
})()`);
if (!wheelGesture || wheelGesture.jumpHidden !== false) {
throw new Error(`Jump to latest was not offered after a real wheel gesture: ${JSON.stringify(wheelGesture)}`);
}
await shot("46-chat-transcript-top.png");
console.log(
` after a real wheel gesture (scrollTop ${wheelGesture.top}) 'Jump to latest' is offered at the top`,
);
// The live assistant answer carries markdown but no fenced block: the session's
// fenced code lives in its reasoning, which the app renders as plain text
// (Markdown.kt draws reasoning with a plain Text, never the markdown subset).
if (transcript.reasoning > 0) {
const expanded = await page.evaluate(`(() => {
const block = document.querySelector("#chatTranscript .chat-reasoning");
if (!block) return null;
block.querySelector(".chat-reasoning-toggle")?.click();
const body = block.querySelector(".chat-reasoning-body");
if (!body) return null;
// Bring the reasoning's own fenced block into view, so the capture shows
// the code the live session actually carries.
const fence = String.fromCharCode(96).repeat(3);
const text = body.textContent ?? "";
const index = text.indexOf(fence);
const transcript = document.querySelector("#chatTranscript");
if (index >= 0 && transcript && body.firstChild && body.firstChild.nodeType === 3) {
const range = document.createRange();
range.setStart(body.firstChild, index);
range.setEnd(body.firstChild, index + fence.length);
const rect = range.getBoundingClientRect();
const tRect = transcript.getBoundingClientRect();
transcript.scrollTop += Math.round(rect.top - tRect.top) - 120;
}
return {
label: block.querySelector(".chat-reasoning-label")?.textContent ?? "",
hasFence: index >= 0,
};
})()`);
await eventually(
() =>
page.evaluate(
`(() => { const b = document.querySelector("#chatTranscript .chat-reasoning-body"); return !!b && !b.hidden; })()`,
),
{ timeout: 5000, what: "the reasoning block to expand" },
);
if (expanded) {
console.log(` reasoning block "${expanded.label}" expanded; carries a fenced block: ${expanded.hasFence}`);
}
await shot("47-chat-reasoning-code.png");
}
// C7's code-block path. The live assistant answer carries no fenced block (its
// fences live in the reasoning transcript, drawn as plain text — capture 47),
// so exercise the page's own markdown renderer on a labelled sample and capture
// the rendered <pre> block; the sample is removed again straight after.
const fence = String.fromCharCode(96).repeat(3);
const codeSample = `${fence}js\nconst answer = 42;\n${fence}`;
const codeBlock = await page.evaluate(`(async () => {
const mod = await import("/src/app.js");
const node = mod.renderMarkdown(${JSON.stringify(codeSample)});
node.id = "markdownCodeSample";
const wrap = document.querySelector(".chat-detail .chat-transcript-wrap");
if (!wrap || !wrap.parentNode) return null;
wrap.parentNode.insertBefore(node, wrap);
return {
label: node.querySelector(".md-code-label")?.textContent ?? "",
hasPre: !!node.querySelector("pre.md-pre code"),
text: node.querySelector("pre.md-pre code")?.textContent ?? "",
};
})()`);
if (!codeBlock || !codeBlock.hasPre) {
throw new Error("the page's markdown renderer drew no fenced code block");
}
if (codeBlock.label !== "js") throw new Error(`code block label: ${codeBlock.label}`);
console.log(
` markdown code block (page renderer sample): label "${codeBlock.label}", text ${JSON.stringify(codeBlock.text)}`,
);
await shot("47b-chat-markdown-code.png");
await page.evaluate(`document.querySelector("#markdownCodeSample")?.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
// control disappears (the prepend path itself is unit-tested).
await page.evaluate(`document.querySelector(".chat-load-older")?.click()`);
await eventually(() => page.evaluate(`!document.querySelector(".chat-load-older")`), {
timeout: 15000,
what: "the empty older history page to settle",
});
await shot("48-chat-load-older-empty.png");
console.log(
" 'Load older messages' was shown while has_more (capture 45); the server's own next_cursor returned an empty older page and the control disappeared",
);
} else {
console.log(" -- no 'Load older messages' control: the server did not report has_more");
}
// The close confirm: shown, then dismissed with Cancel. The operator's only
// live session is never mutated, so no chat_close is sent. The transcript is
// mid-scroll (following false), so this also asserts the C14 fix: opening and
// dismissing the dialog must not move the operator's view.
const beforeDialog = await page.evaluate(`(() => {
const el = document.querySelector("#chatTranscript");
return {
top: el ? Math.round(el.scrollTop) : null,
jumpHidden: document.querySelector("#chatJump")?.hidden ?? null,
};
})()`);
if (!beforeDialog || beforeDialog.top == null || beforeDialog.top === 0) {
throw new Error(`the transcript was not mid-scroll before the dialog: ${JSON.stringify(beforeDialog)}`);
}
await page.click(`#chatRows .chat-row[data-session="${openedId}"] .chat-close`);
await page.waitForSelector(".confirm-chat-close", { timeout: 15000 });
const closeDialog = await page.evaluate(`(() => ({
title: document.querySelector(".confirm-chat-close .confirm-title")?.textContent ?? "",
message: document.querySelector(".confirm-chat-close .confirm-message")?.textContent ?? "",
confirm: document.querySelector(".confirm-chat-close .confirm-accept")?.textContent ?? "",
dismiss: document.querySelector(".confirm-chat-close .confirm-dismiss")?.textContent ?? "",
}))()`);
if (closeDialog.title !== "Close chat?") throw new Error(`close title: ${closeDialog.title}`);
if (!closeDialog.message.startsWith("Closes \"")) throw new Error(`close message: ${closeDialog.message}`);
if (!closeDialog.message.includes("marks it closed on every device")) {
throw new Error(`close message: ${closeDialog.message}`);
}
if (!closeDialog.message.includes("Nothing is deleted")) {
throw new Error(`close message: ${closeDialog.message}`);
}
if (closeDialog.confirm !== "Close chat") throw new Error(`close confirm: ${closeDialog.confirm}`);
if (closeDialog.dismiss !== "Cancel") throw new Error(`close dismiss: ${closeDialog.dismiss}`);
const whileDialog = await page.evaluate(`(() => {
const el = document.querySelector("#chatTranscript");
return {
top: el ? Math.round(el.scrollTop) : null,
jumpHidden: document.querySelector("#chatJump")?.hidden ?? null,
};
})()`);
if (Math.abs((whileDialog.top ?? -1) - beforeDialog.top) > 2 || whileDialog.jumpHidden !== false) {
throw new Error(
`opening the close dialog moved the transcript: ${JSON.stringify(beforeDialog)} -> ${JSON.stringify(whileDialog)}`,
);
}
console.log(` close dialog (shown, NOT executed): "${closeDialog.title}" — ${closeDialog.message}`);
console.log(` the transcript stayed put across the dialog (top ${beforeDialog.top} -> ${whileDialog.top})`);
await shot("49-chat-close-confirm.png");
await page.click(".confirm-chat-close .confirm-dismiss");
await eventually(() => page.evaluate(`!document.querySelector(".confirm-chat-close")`), {
timeout: 5000,
what: "the close dialog to close",
});
const afterDialog = await page.evaluate(`(() => {
const el = document.querySelector("#chatTranscript");
return el ? Math.round(el.scrollTop) : null;
})()`);
if (afterDialog == null || Math.abs(afterDialog - beforeDialog.top) > 2) {
throw new Error(`dismissing the close dialog moved the transcript: ${beforeDialog.top} -> ${afterDialog}`);
}
console.log(
" the mutating confirm was NOT executed: no chat_close was sent for the operator's live session " +
`${openedId}`,
);
console.log("\nUI SMOKE PASS");
for (const shot of shots) console.log(` ${shot}`);
} catch (error) {