fix(chat): anchor the More popover outside the tooltip chain (#1862)
Nested inside TooltipTrigger as-child, PopoverTrigger's PopperAnchor ref resolved to a component object instead of the button, so the popover never became positioned and its content stayed parked off-screen at translate(0, -200%): the menu opened in state only, invisible to the user. Wrapping the tooltip in an explicit PopoverAnchor makes the anchor the real button element, so the menu renders beside it. The tooltip (accessible name More), the menu items, and the rename/branch dialog are unchanged. Adds ui/test/chat-more-menu.test.ts, a browser behaviour check (vite dev server + headless Chrome over CDP, API mocked in-page) that fails on the old nesting with the menu at (0, -526) and passes with it in the viewport; it skips when no Chrome binary is installed.
This commit is contained in:
2 files changed
+355
-15
No files matched your search
@@ -16,6 +16,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import {
|
||||
Popover,
|
||||
PopoverAnchor,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
@@ -100,21 +101,27 @@ function submitPrompt(): void {
|
||||
|
||||
<template>
|
||||
<Popover v-model:open="open">
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<PopoverTrigger as-child>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
class="flex-none"
|
||||
aria-label="More"
|
||||
>
|
||||
<Ellipsis />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>More</TooltipContent>
|
||||
</Tooltip>
|
||||
<!-- The anchor sits outside the tooltip chain on purpose: nested inside
|
||||
TooltipTrigger, the popper anchor ref resolves to a component object
|
||||
rather than the button, the content is never positioned, and the menu
|
||||
stays parked off-screen. -->
|
||||
<PopoverAnchor as-child>
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<PopoverTrigger as-child>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
class="flex-none"
|
||||
aria-label="More"
|
||||
>
|
||||
<Ellipsis />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>More</TooltipContent>
|
||||
</Tooltip>
|
||||
</PopoverAnchor>
|
||||
<PopoverContent align="end" class="grid w-64 gap-0.5 p-1">
|
||||
<template v-if="currentSession">
|
||||
<Button
|
||||
|
||||
@@ -0,0 +1,333 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { spawn, execFileSync, type ChildProcess } from "node:child_process";
|
||||
import { existsSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import net from "node:net";
|
||||
import test from "node:test";
|
||||
|
||||
/**
|
||||
* Behaviour check for the chat bar's "More" menu (issue #1862): the button
|
||||
* must open its popover on screen, the tooltip must keep its accessible name,
|
||||
* and the menu items must run. Rendered behavior needs a real browser, so this
|
||||
* drives the dev server in headless Chrome over CDP and mocks only the HTTP
|
||||
* API inside the page. It skips when no Chrome binary is installed.
|
||||
*/
|
||||
|
||||
const uiDir = fileURLToPath(new URL("..", import.meta.url));
|
||||
|
||||
// The page refuses to paint the chat dock until /api/auth/status answers with
|
||||
// a signed-in user, and the composer palette reads the session list, so the
|
||||
// mock answers just those and lets everything else fall through to empty JSON.
|
||||
const PAGE_MOCK = `(() => {
|
||||
const realFetch = window.fetch.bind(window);
|
||||
window.__archieSent = [];
|
||||
window.fetch = (input, init) => {
|
||||
const url = typeof input === "string" ? input : input.url;
|
||||
const json = (body, type = "application/json") =>
|
||||
Promise.resolve(new Response(typeof body === "string" ? body : JSON.stringify(body), { status: 200, headers: { "Content-Type": type } }));
|
||||
if (url.includes("/api/chat/stream")) {
|
||||
window.__archieSent.push(JSON.parse(init.body).text);
|
||||
return json('data: {"type":"delta","text":"ok","session_id":"s1"}\\n\\ndata: {"type":"done","text":"ok","session_id":"s1"}\\n\\n', "text/event-stream");
|
||||
}
|
||||
if (url.includes("/api/auth/status"))
|
||||
return json({ setup_required: false, user: { id: "u1", display_name: "Operator", kind: "operator" }, oidc: false, public_url: location.origin + "/", instance: "archie" });
|
||||
if (url.includes("/api/chat/sessions"))
|
||||
return json({ providers: ["test"], models: ["test-model"], models_by_provider: { test: ["test-model"] }, active_provider: "test", active_model: "test-model", commands: ["/retry", "/undo", "/title", "/branch", "/compress"], voice_available: false, sessions: [{ session_id: "s1", title: "Test session", created_at: "2026-01-01T00:00:00Z" }] });
|
||||
if (url.includes("/turns")) return json({ turns: [] });
|
||||
if (url.includes("/health")) return json({ status: "ok" });
|
||||
if (url.includes("/api/")) return json({});
|
||||
return realFetch(input, init);
|
||||
};
|
||||
window.EventSource = class {
|
||||
close() {}
|
||||
addEventListener() {}
|
||||
removeEventListener() {}
|
||||
};
|
||||
})();`;
|
||||
|
||||
function freePort(): Promise<number> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const server = net.createServer();
|
||||
server.unref();
|
||||
server.on("error", reject);
|
||||
server.listen(0, "127.0.0.1", () => {
|
||||
const { port } = server.address() as net.AddressInfo;
|
||||
server.close(() => resolve(port));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function findChrome(): string | null {
|
||||
const candidates = [
|
||||
process.env.CHROME_BIN,
|
||||
"google-chrome",
|
||||
"google-chrome-stable",
|
||||
"chromium",
|
||||
"chromium-browser",
|
||||
].filter((c): c is string => !!c);
|
||||
for (const candidate of candidates) {
|
||||
if (candidate.includes("/")) {
|
||||
if (existsSync(candidate)) return candidate;
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const found = execFileSync("which", [candidate], { stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
|
||||
if (found) return found;
|
||||
} catch {
|
||||
// not on PATH
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
interface Cdp {
|
||||
send(method: string, params?: Record<string, unknown>): Promise<any>;
|
||||
evaluate(expression: string): Promise<any>;
|
||||
close(): void;
|
||||
}
|
||||
|
||||
async function connectChrome(debugPort: number): Promise<Cdp> {
|
||||
let target: any;
|
||||
for (let attempt = 0; attempt < 60 && !target; attempt++) {
|
||||
try {
|
||||
const list = await (await fetch(`http://127.0.0.1:${debugPort}/json/list`)).json();
|
||||
target = (list as any[]).find((t) => t.type === "page");
|
||||
} catch {
|
||||
// devtools not up yet
|
||||
}
|
||||
if (!target) await new Promise((r) => setTimeout(r, 250));
|
||||
}
|
||||
if (!target) throw new Error("chrome devtools endpoint never came up");
|
||||
const ws = new WebSocket(target.webSocketDebuggerUrl);
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
ws.onopen = () => resolve();
|
||||
ws.onerror = () => reject(new Error("chrome websocket failed"));
|
||||
});
|
||||
let nextId = 0;
|
||||
const pending = new Map<number, { resolve: (v: any) => void; reject: (e: Error) => void }>();
|
||||
ws.onmessage = (event) => {
|
||||
const message = JSON.parse(String(event.data));
|
||||
if (message.id && pending.has(message.id)) {
|
||||
const { resolve, reject } = pending.get(message.id)!;
|
||||
pending.delete(message.id);
|
||||
if (message.error) reject(new Error(JSON.stringify(message.error)));
|
||||
else resolve(message.result);
|
||||
}
|
||||
};
|
||||
const send = (method: string, params: Record<string, unknown> = {}) =>
|
||||
new Promise<any>((resolve, reject) => {
|
||||
const id = ++nextId;
|
||||
pending.set(id, { resolve, reject });
|
||||
ws.send(JSON.stringify({ id, method, params }));
|
||||
});
|
||||
return {
|
||||
send,
|
||||
evaluate: async (expression) => {
|
||||
const result = await send("Runtime.evaluate", { expression, awaitPromise: true, returnByValue: true });
|
||||
if (result.exceptionDetails) throw new Error("page error: " + JSON.stringify(result.exceptionDetails).slice(0, 500));
|
||||
return result.result.value;
|
||||
},
|
||||
close: () => ws.close(),
|
||||
};
|
||||
}
|
||||
|
||||
async function startVite(): Promise<{ port: number; child: ChildProcess }> {
|
||||
const viteBin = join(uiDir, "node_modules", "vite", "bin", "vite.js");
|
||||
if (!existsSync(viteBin)) throw new Error("ui dependencies are not installed (run pnpm install)");
|
||||
let lastError = "";
|
||||
for (let attempt = 0; attempt < 5; attempt++) {
|
||||
const port = await freePort();
|
||||
const child = spawn(process.execPath, [viteBin, "--port", String(port), "--strictPort", "--host", "127.0.0.1"], {
|
||||
cwd: uiDir,
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
});
|
||||
child.stderr?.on("data", (chunk) => { lastError += chunk; });
|
||||
for (let poll = 0; poll < 60; poll++) {
|
||||
if (child.exitCode !== null) break;
|
||||
try {
|
||||
const response = await fetch(`http://127.0.0.1:${port}/`);
|
||||
if (response.ok) return { port, child };
|
||||
} catch {
|
||||
// not listening yet
|
||||
}
|
||||
await new Promise((r) => setTimeout(r, 250));
|
||||
}
|
||||
child.kill("SIGKILL");
|
||||
}
|
||||
throw new Error("vite dev server did not start: " + lastError.slice(0, 400));
|
||||
}
|
||||
|
||||
test("chat More menu opens on screen and its items run", { timeout: 90000 }, async (t) => {
|
||||
const chrome = findChrome();
|
||||
if (!chrome) {
|
||||
t.skip("no Chrome/Chromium binary available for the browser check");
|
||||
return;
|
||||
}
|
||||
|
||||
const { port: vitePort, child: vite } = await startVite();
|
||||
const debugPort = await freePort();
|
||||
const profile = join(tmpdir(), `archie-more-menu-test-${process.pid}-${Date.now()}`);
|
||||
const chromeChild = spawn(chrome, [
|
||||
"--headless=new",
|
||||
`--remote-debugging-port=${debugPort}`,
|
||||
"--no-sandbox",
|
||||
"--disable-gpu",
|
||||
"--disable-dev-shm-usage",
|
||||
`--user-data-dir=${profile}`,
|
||||
"--window-size=1280,900",
|
||||
"about:blank",
|
||||
], { stdio: "ignore" });
|
||||
|
||||
try {
|
||||
const cdp = await connectChrome(debugPort);
|
||||
try {
|
||||
await cdp.send("Page.enable");
|
||||
await cdp.send("Runtime.enable");
|
||||
await cdp.send("Page.addScriptToEvaluateOnNewDocument", { source: PAGE_MOCK });
|
||||
await cdp.send("Emulation.setDeviceMetricsOverride", { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });
|
||||
await cdp.send("Page.navigate", { url: `http://127.0.0.1:${vitePort}/` });
|
||||
|
||||
// Wait for the app shell and the collapsed dock, then expand it.
|
||||
await cdp.evaluate(`(async () => {
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
for (let i = 0; i < 60; i++) {
|
||||
if (document.querySelector('button[aria-label="Show conversation"]')) {
|
||||
document.querySelector('button[aria-label="Show conversation"]').click();
|
||||
for (let j = 0; j < 40 && !document.querySelector('button[aria-label="More"]'); j++) await sleep(250);
|
||||
return !!document.querySelector('button[aria-label="More"]');
|
||||
}
|
||||
await sleep(250);
|
||||
}
|
||||
return false;
|
||||
})()`).then((expanded: unknown) => assert.equal(expanded, true, "the chat dock expanded and rendered the More button"));
|
||||
|
||||
// Pick the open conversation first, so the menu's commands have a
|
||||
// session to act on (selectSession itself streams /resume s1).
|
||||
await cdp.evaluate(`(() => {
|
||||
document.querySelector('button[aria-label="Conversation"]').click();
|
||||
})()`);
|
||||
await new Promise((r) => setTimeout(r, 800));
|
||||
await cdp.evaluate(`(() => {
|
||||
const item = [...document.querySelectorAll('[data-slot="select-item"]')].find((el) => el.innerText.includes("Test session"));
|
||||
if (item) item.click();
|
||||
})()`);
|
||||
await cdp.evaluate(`(async () => {
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
for (let i = 0; i < 40 && !window.__archieSent.includes("/resume s1"); i++) await sleep(250);
|
||||
return window.__archieSent.includes("/resume s1");
|
||||
})()`).then((selected: unknown) => assert.equal(selected, true, "selecting the conversation opened it on the server"));
|
||||
|
||||
// Hover the More button: the tooltip keeps its accessible name.
|
||||
const moreBox = await cdp.evaluate(`(() => { const r = document.querySelector('button[aria-label="More"]').getBoundingClientRect(); return { x: r.x + r.width / 2, y: r.y + r.height / 2 }; })()`);
|
||||
await cdp.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: moreBox.x, y: moreBox.y });
|
||||
await new Promise((r) => setTimeout(r, 1200));
|
||||
const tooltip = await cdp.evaluate(`(() => {
|
||||
const tip = document.querySelector('[data-slot="tooltip-content"]');
|
||||
return tip && (tip.offsetWidth || tip.offsetHeight) ? tip.innerText.trim() : null;
|
||||
})()`);
|
||||
assert.ok(tooltip && tooltip.includes("More"), `hovering the More button shows the More tooltip, got ${JSON.stringify(tooltip)}`);
|
||||
|
||||
// Click it: the popover must open inside the viewport.
|
||||
await cdp.send("Input.dispatchMouseEvent", { type: "mousePressed", x: moreBox.x, y: moreBox.y, button: "left", clickCount: 1 });
|
||||
await cdp.send("Input.dispatchMouseEvent", { type: "mouseReleased", x: moreBox.x, y: moreBox.y, button: "left", clickCount: 1 });
|
||||
const opened = await cdp.evaluate(`(async () => {
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
for (let i = 0; i < 40 && !document.querySelector('[data-slot="popover-content"]'); i++) await sleep(250);
|
||||
const pop = document.querySelector('[data-slot="popover-content"]');
|
||||
if (!pop) return { exists: false };
|
||||
const r = pop.getBoundingClientRect();
|
||||
return {
|
||||
exists: true,
|
||||
inViewport: r.x >= 0 && r.y >= 0 && r.right <= innerWidth && r.bottom <= innerHeight,
|
||||
rect: { x: r.x, y: r.y, right: r.right, bottom: r.bottom },
|
||||
text: pop.innerText.replace(/\\s+/g, " ").trim(),
|
||||
ariaExpanded: document.querySelector('button[aria-label="More"]').getAttribute("aria-expanded"),
|
||||
};
|
||||
})()`);
|
||||
assert.equal(opened.exists, true, "clicking More opens the popover");
|
||||
assert.equal(opened.ariaExpanded, "true");
|
||||
assert.equal(opened.inViewport, true, `the menu must render on screen, got ${JSON.stringify(opened.rect)}`);
|
||||
for (const item of ["Retry", "Undo", "Rename", "Branch", "Preview compression", "Copy as Markdown"]) {
|
||||
assert.ok(opened.text.includes(item), `the menu lists ${item}`);
|
||||
}
|
||||
|
||||
// Run Retry from the menu: the command goes over the chat stream and
|
||||
// the menu closes.
|
||||
await cdp.evaluate(`(() => {
|
||||
const retry = [...document.querySelectorAll('[data-slot="popover-content"] button')].find((el) => el.innerText.includes("Retry"));
|
||||
if (retry) retry.click();
|
||||
})()`);
|
||||
await cdp.evaluate(`(async () => {
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
for (let i = 0; i < 40 && !window.__archieSent.includes("/retry"); i++) await sleep(250);
|
||||
return window.__archieSent.includes("/retry");
|
||||
})()`).then((sent: unknown) => assert.equal(sent, true, `Retry sends /retry over the chat stream, got ${JSON.stringify(sent)}`));
|
||||
const afterRetry = await cdp.evaluate(`(async () => {
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
for (let i = 0; i < 40; i++) {
|
||||
const pop = document.querySelector('[data-slot="popover-content"]');
|
||||
if (!pop || pop.getAttribute("data-state") === "closed") break;
|
||||
await sleep(250);
|
||||
}
|
||||
return {
|
||||
popoverClosed: !document.querySelector('[data-slot="popover-content"]') || document.querySelector('[data-slot="popover-content"]').getAttribute("data-state") === "closed",
|
||||
ariaExpanded: document.querySelector('button[aria-label="More"]').getAttribute("aria-expanded"),
|
||||
dockStillThere: !!document.querySelector('button[aria-label="More"]'),
|
||||
};
|
||||
})()`);
|
||||
assert.equal(afterRetry.popoverClosed, true, "running a command closes the menu");
|
||||
assert.equal(afterRetry.ariaExpanded, "false");
|
||||
assert.equal(afterRetry.dockStillThere, true);
|
||||
|
||||
// Reopen and use Rename: the labelled dialog opens from the menu.
|
||||
await cdp.evaluate(`(() => { document.querySelector('button[aria-label="More"]').click(); })()`);
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
await cdp.evaluate(`(() => {
|
||||
const rename = [...document.querySelectorAll('[data-slot="popover-content"] button')].find((el) => el.innerText.includes("Rename"));
|
||||
if (rename) rename.click();
|
||||
})()`);
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
const dialog = await cdp.evaluate(`(() => {
|
||||
const d = [...document.querySelectorAll('[role="dialog"]')].find((el) => !el.hasAttribute("data-slot") || el.getAttribute("data-slot") !== "popover-content");
|
||||
return d ? d.innerText.replace(/\\s+/g, " ").trim() : null;
|
||||
})()`);
|
||||
assert.ok(dialog && dialog.includes("Session title"), `Rename opens the session-title dialog, got ${JSON.stringify(dialog)}`);
|
||||
|
||||
// Cancel the dialog, reopen the menu, then Escape: it dismisses the menu
|
||||
// but leaves the conversation open.
|
||||
await cdp.evaluate(`(() => {
|
||||
const cancel = [...document.querySelectorAll('[role="dialog"] button')].find((el) => el.innerText.trim() === "Cancel");
|
||||
if (cancel) cancel.click();
|
||||
})()`);
|
||||
await new Promise((r) => setTimeout(r, 800));
|
||||
await cdp.evaluate(`(() => { document.querySelector('button[aria-label="More"]').click(); })()`);
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
await cdp.send("Input.dispatchKeyEvent", { type: "rawKeyDown", key: "Escape", windowsVirtualKeyCode: 27 });
|
||||
await cdp.send("Input.dispatchKeyEvent", { type: "keyUp", key: "Escape", windowsVirtualKeyCode: 27 });
|
||||
await new Promise((r) => setTimeout(r, 800));
|
||||
const afterEscape = await cdp.evaluate(`(async () => {
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
for (let i = 0; i < 40; i++) {
|
||||
const pop = document.querySelector('[data-slot="popover-content"]');
|
||||
if (!pop || pop.getAttribute("data-state") === "closed") break;
|
||||
await sleep(250);
|
||||
}
|
||||
return {
|
||||
popoverClosed: !document.querySelector('[data-slot="popover-content"]') || document.querySelector('[data-slot="popover-content"]').getAttribute("data-state") === "closed",
|
||||
dockStillThere: !!document.querySelector('button[aria-label="More"]'),
|
||||
ariaExpanded: document.querySelector('button[aria-label="More"]').getAttribute("aria-expanded"),
|
||||
};
|
||||
})()`);
|
||||
assert.equal(afterEscape.popoverClosed, true, "Escape closes the menu");
|
||||
assert.equal(afterEscape.ariaExpanded, "false");
|
||||
assert.equal(afterEscape.dockStillThere, true, "Escape leaves the conversation open");
|
||||
} finally {
|
||||
cdp.close();
|
||||
}
|
||||
} finally {
|
||||
chromeChild.kill("SIGKILL");
|
||||
vite.kill("SIGKILL");
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user