Sync the React console with the v0.1.1 prototype (20 CHGs): Quiet Workbench
shell, Chat IA v3, tool-family rendering, and the mobile page pill.
Shell / tokens (CHG-01/04/15/20):
- tokens.css rewritten from the prototype (three-layer light/dark/system),
`--tabbar-h` removed, new faint/border-subtle/surface-1-2/fs-*/dur-*/reading-max
- 56px icon-only nav rail/sidebar (44x44 hit targets, CSS tooltips, active is a
solid primary fill, no left bar), 52px topbar, merged preferences menu,
⌘K/Cmd-K palette
- `<600` gets a topbar page pill + page sheet; the bottom tabbar is gone
Pages (CHG-01): workspaces becomes a card grid with whole-card links and a
320px recent-activity column; status gets four metric tiles + a zero-primary
layout; connect gets a two-column hero, one primary per state and a collapsed
manual form.
Chat IA v3 (CHG-02/10-14/16-19): two columns, single-workspace tree with a
workspace switch, single-line rows with attention, body-level row popover,
session tray (todo/tasks) replacing the right panel, context ring moved into a
composer telemetry line, right-aligned user messages, queued messages as one
stream entity plus a composer status bar, and an in-place subagent child view.
Tool rendering (CHG-05/06/09): new `features/chat/tools` module — one row per
call, DTO adapter for the daemon's block shape, 11 kind families, state
semantics ("one state, one meaning"), 44px touch targets and the diff row
contrast fix.
i18n: 729 keys per language (zh/en parity checked), 0 unresolved keys.
Verification: web typecheck + 297 vitest + vite build green, root typecheck
green, `scripts/smoke.sh` green, and a new visual harness
(`scripts/ui-mock-server.mjs` + `scripts/ui-shots.mjs`, docs/ui-parity.md)
shoots 4 pages x 3 viewports x 2 themes = 24 screenshots clean with
overflow/console/primary/tabbar assertions. `scripts/e2e/ui-e2e.mjs` selectors
are updated to the new DOM; that suite still needs a real pi + nvim to run.
140 lines
6.2 KiB
TypeScript
140 lines
6.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import type { Block } from "@protocol/types";
|
|
|
|
import { diffFromArgs, fromPi2Block } from "@/features/chat/tools/adapt";
|
|
import { fileTarget } from "@/features/chat/tools/format";
|
|
import { normalizeTool } from "@/features/chat/tools/facts";
|
|
import type { ToolView } from "@/features/chat/tools/types";
|
|
|
|
type ToolBlock = Extract<Block, { type: "tool" }>;
|
|
|
|
function block(overrides: Partial<ToolBlock> = {}): ToolBlock {
|
|
return { type: "tool", toolCallId: "t1", name: "bash", state: "done", ...overrides };
|
|
}
|
|
|
|
const plain = (): ToolView => ({ id: "x", name: "mystery" });
|
|
|
|
describe("fromPi2Block — wire DTO", () => {
|
|
it("maps the four wire states onto the canonical vocabulary", () => {
|
|
expect(fromPi2Block(block({ state: "pending" }), "m1").state).toBe("queued");
|
|
expect(fromPi2Block(block({ state: "running" }), "m1").state).toBe("running");
|
|
expect(fromPi2Block(block({ state: "done" }), "m1").state).toBe("done");
|
|
expect(fromPi2Block(block({ state: "error" }), "m1").state).toBe("failed");
|
|
});
|
|
|
|
it("falls back to the alias table for wire states it does not know", () => {
|
|
const view = fromPi2Block({ ...block(), state: "interrupted" } as unknown as ToolBlock, "m1");
|
|
expect(view.state).toBe("interrupted");
|
|
});
|
|
|
|
it("only records startedAt while running, using the message timestamp", () => {
|
|
expect(fromPi2Block(block({ state: "running" }), "m1", { ts: 1000 }).startedAt).toBe(1000);
|
|
expect(fromPi2Block(block({ state: "done" }), "m1", { ts: 1000 }).startedAt).toBeUndefined();
|
|
expect(fromPi2Block(block({ state: "running" }), "m1").startedAt).toBeUndefined();
|
|
expect(fromPi2Block(block({ state: "running" }), "m1", { startedAt: 42 }).startedAt).toBe(42);
|
|
});
|
|
|
|
it("carries ids, names, kind, duration and agent", () => {
|
|
const view = fromPi2Block(block({ name: "grep", durationMs: 1234 }), "m7", { agent: "researcher" });
|
|
expect(view.id).toBe("t1");
|
|
expect(view.messageId).toBe("m7");
|
|
expect(view.kind).toBe("search");
|
|
expect(view.durationMs).toBe(1234);
|
|
expect(view.agent).toBe("researcher");
|
|
});
|
|
|
|
it("passes object args through as input and merges args.meta", () => {
|
|
const view = fromPi2Block(block({ args: { command: "ls -la", meta: { lines: 12 } } }), "m1");
|
|
expect(view.input).toEqual({ command: "ls -la", meta: { lines: 12 } });
|
|
expect(view.meta?.lines).toBe(12);
|
|
});
|
|
|
|
it("keeps non-object args in raw for the generic family", () => {
|
|
const view = fromPi2Block(block({ name: "mcp__x__y", args: "plain text" }), "m1");
|
|
expect(view.input).toBeUndefined();
|
|
expect(view.raw).toBe("plain text");
|
|
expect(view.kind).toBe("generic");
|
|
});
|
|
});
|
|
|
|
describe("fromPi2Block — legacy DTO degradation", () => {
|
|
it("splits legacy output text into text.lines", () => {
|
|
const view = fromPi2Block(block({ output: { text: "hello\nworld" } }), "m1");
|
|
expect(view.text?.lines).toEqual(["hello", "world"]);
|
|
expect(view.result?.error).toBeUndefined();
|
|
});
|
|
|
|
it("turns `output.details` text into text.lines and keeps it as legacy details", () => {
|
|
const view = fromPi2Block(block({ output: { details: "a\nb" } }), "m1");
|
|
expect(view.text?.lines).toEqual(["a", "b"]);
|
|
expect(view.result?.details).toBe("a\nb");
|
|
expect(view.result?.error).toBeUndefined();
|
|
});
|
|
|
|
it("promotes isError output to result.error", () => {
|
|
const view = fromPi2Block(block({ state: "error", output: { text: "boom\nstack", isError: true } }), "m1");
|
|
expect(view.result?.error).toBe("boom\nstack");
|
|
});
|
|
|
|
it("lifts structured details into meta facts without losing the payload", () => {
|
|
const details = { exitCode: 2, truncated: true, added: 3, removed: 1 };
|
|
const view = fromPi2Block(block({ output: { details } }), "m1");
|
|
expect(view.meta?.exitCode).toBe(2);
|
|
expect(view.meta?.added).toBe(3);
|
|
expect(view.meta?.removed).toBe(1);
|
|
expect(view.result?.exitCode).toBe(2);
|
|
expect(view.result?.truncated).toBe(true);
|
|
expect(view.result?.details).toEqual(details);
|
|
});
|
|
|
|
it("normalizes a legacy `details` string on a hand-built view without mutating it", () => {
|
|
const legacy: ToolView = { id: "x", name: "bash", details: "one\ntwo" };
|
|
const view = normalizeTool(legacy);
|
|
expect(view.text?.lines).toEqual(["one", "two"]);
|
|
expect(legacy.text).toBeUndefined();
|
|
|
|
const withLines: ToolView = { id: "x", name: "bash", details: "ignored", text: { lines: ["kept"] } };
|
|
expect(normalizeTool(withLines)).toBe(withLines);
|
|
});
|
|
|
|
it("uses the legacy `summary` as the row target when there is no structured input", () => {
|
|
expect(fileTarget({ ...plain(), summary: "Did a thing" })).toBe("Did a thing");
|
|
expect(fileTarget(plain())).toBe("mystery");
|
|
});
|
|
});
|
|
|
|
describe("diffFromArgs", () => {
|
|
it("rebuilds a diff from before/after snippets", () => {
|
|
const diff = diffFromArgs({ path: "a.ts", oldText: "a\nb", newText: "a\nc" });
|
|
expect(diff?.files).toHaveLength(1);
|
|
const file = diff?.files[0];
|
|
expect(file?.path).toBe("a.ts");
|
|
expect(file?.status).toBe("modified");
|
|
expect(file?.added).toBe(1);
|
|
expect(file?.removed).toBe(1);
|
|
const kinds = (file?.hunks ?? []).flatMap((hunk) => (hunk.lines ?? []).map((line) => line.t));
|
|
expect(kinds).toContain("add");
|
|
expect(kinds).toContain("del");
|
|
});
|
|
|
|
it("accepts a structured patch payload and numbers its lines", () => {
|
|
const diff = diffFromArgs({
|
|
diff: {
|
|
files: [{ path: "b.ts", status: "added", hunks: [{ header: "@@ -1,1 +1,2 @@", lines: ["+one", "+two"] }] }],
|
|
},
|
|
});
|
|
const lines = diff?.files[0]?.hunks?.[0]?.lines;
|
|
expect(lines?.map((line) => [line.t, line.new])).toEqual([
|
|
["add", 1],
|
|
["add", 2],
|
|
]);
|
|
});
|
|
|
|
it("returns undefined when there is nothing to diff", () => {
|
|
expect(diffFromArgs(undefined)).toBeUndefined();
|
|
expect(diffFromArgs({ path: "a.ts" })).toBeUndefined();
|
|
expect(diffFromArgs({ diff: { files: [] } })).toBeUndefined();
|
|
});
|
|
});
|