Files
archie/ui/test/chat-tools.test.js
T
sam ea1017af94 feat(webui): dashboard-aware chat — Archie sees the page, points you there
The web chat is now a persistent slide-over drawer available on any page
(not just the /chat route), and the agent is told which dashboard page the
operator is on so it can point them to the relevant page with a clickable chip.

Backend (gateway):
- Message gains a per-message Page field; the system prompt renders it in
  the <env> block (Current page), so Archie knows where the operator is.
- New dashboard_tools.go: a DashboardPages registry plus two web-only tools
  — page_index (lists every page and what it shows) and dashboard_navigate
  (validates a path, returns {path,label}; rejects unknown/empty paths).
- The web chat sink emits a dedicated navigate stream event when the model
  calls dashboard_navigate, independent of ShowToolCalls.

Frontend (webui):
- chat sends currentPage() (location.hash) with each stream request; a
  dashboard_navigate result renders as a clickable link chip (href=#/path).
- The chat is mounted once in a slide-over drawer with a topbar launcher,
  scrim and Esc-to-close; /chat opens the drawer instead of a second page.
- ui/dist rebuilt (committed) with the bundled changes.
- .gitignore: ignore .impeccable/ (impeccable tool critique snapshots).

New capability (per scope discipline): designed in
docs/prds/dashboard-aware-chat-navigation.md.

Tests: dashboard_tools_test (registry, resolve/reject, web-only gating),
prompt page-line cases, webui Message.Page + navigate-frame capture, and
chat-tools chip tests. task check is green.
2026-08-28 22:28:10 +10:00

119 lines
4.7 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import "./shim.js";
import { assistantBubble } from "../src/chat/chat-render.js";
import { appendToolCall, appendNavigateChip } from "../src/chat/chat-tools.js";
// childIndex reports where a node sits among its parent's children, which is
// how the tests assert that the work is listed above the answer.
function childIndex(parent, selector) {
const node = parent.querySelector(selector);
return parent.childNodes.indexOf(node);
}
test("a tool call is listed above the answer it produced", () => {
const row = assistantBubble();
const host = row.querySelector(".chat-bubble");
appendToolCall(host, { tool: "shell", parameters: '{"cmd":"true"}', text: "exit 0" });
const tools = host.querySelector(".chat-tools");
assert.equal(tools.childNodes.length, 1);
assert.equal(host.querySelector(".chat-tool-name").textContent, "shell");
assert.equal(host.querySelector(".chat-tool-parameters").textContent, '{"cmd":"true"}');
assert.equal(host.querySelector(".chat-tool-summary").textContent, "exit 0");
assert.ok(
childIndex(host, ".chat-tools") < childIndex(host, ".chat-bubble-text"),
"tool activity must render above the reply text",
);
});
test("further tool calls join the same list in order", () => {
const row = assistantBubble();
const host = row.querySelector(".chat-bubble");
appendToolCall(host, { tool: "memory_edit", text: "added entry" });
appendToolCall(host, { tool: "shell", text: "exit 0" });
const list = host.querySelector(".chat-tools");
const names = list.childNodes.map((line) => line.querySelector(".chat-tool-name").textContent);
assert.deepEqual(names, ["memory_edit", "shell"]);
});
test("a failed tool call is marked so it does not read as success", () => {
const row = assistantBubble();
const host = row.querySelector(".chat-bubble");
appendToolCall(host, { tool: "read", text: "failed: no such file", failed: true });
const line = host.querySelector(".chat-tool");
assert.match(line.className, /failed/);
});
test("a successful tool call is not marked as failed", () => {
const row = assistantBubble();
const host = row.querySelector(".chat-bubble");
appendToolCall(host, { tool: "read", text: "42 lines", failed: false });
assert.doesNotMatch(host.querySelector(".chat-tool").className, /failed/);
});
// The styling decision reads the structured `failed` field, not the summary
// text: a successful tool's own output can start with "failed:" (a grep
// hit, a log line it read back), and that must not be styled as an error.
test("a successful tool whose output starts with 'failed:' is not marked as failed", () => {
const row = assistantBubble();
const host = row.querySelector(".chat-bubble");
appendToolCall(host, { tool: "shell", text: "failed: no such file (grep match, exit 0)", failed: false });
assert.doesNotMatch(host.querySelector(".chat-tool").className, /failed/);
});
test("a tool event with no name is ignored rather than rendered blank", () => {
const row = assistantBubble();
const host = row.querySelector(".chat-bubble");
appendToolCall(host, { tool: "", text: "exit 0" });
assert.equal(host.querySelector(".chat-tools").childNodes.length, 0);
});
// A bubble that predates the tool list -- a retried turn reusing an older
// one -- must still show tool activity rather than silently dropping it.
test("a bubble without a tool list still records tool activity", () => {
const row = assistantBubble();
const host = row.querySelector(".chat-bubble");
host.childNodes = host.childNodes.filter((node) => node.className !== "chat-tools");
appendToolCall(host, { tool: "shell", text: "exit 0" });
assert.equal(host.querySelector(".chat-tool-name").textContent, "shell");
});
// A dashboard_navigate call is an explicit point-the-operator-somewhere
// result, so it renders as a clickable chip link rather than a muted tool
// line, and the chip must be a real link (the app routes on location.hash).
test("a navigate chip is a clickable link to the resolved page", () => {
const row = assistantBubble();
const host = row.querySelector(".chat-bubble");
appendNavigateChip(host, { path: "/tasks", label: "Tasks" });
const chip = host.querySelector(".chat-nav-chip");
assert.ok(chip, "navigate chip should render");
assert.equal(chip.getAttribute("href"), "#/tasks");
assert.equal(chip.querySelector(".chat-nav-chip-label").textContent, "Tasks");
assert.equal(chip.getAttribute("aria-label"), "Go to Tasks");
});
test("a navigate chip without a path is not rendered", () => {
const row = assistantBubble();
const host = row.querySelector(".chat-bubble");
appendNavigateChip(host, { path: "", label: "Tasks" });
assert.equal(host.querySelector(".chat-nav-chip"), null);
});