fix(web): make the web console work end-to-end

- Pair through the public POST /api/v1/pair and persist the device scopes;
  keep the allow-listed next deep link. Rename the manual field to pairing code.
- Authenticate the WebSocket with the raw device token (strip Bearer) and
  recover from a 401 by clearing the connection once.
- Fix chat payloads: setModel/setThinking, attention/diff responses, subagent
  dispatch items, queue ids/mode, task output and WS resume since.
- Render exactly one assistant message per turn: one-to-one snapshot/history
  merge plus a stale-delta guard after message_end (fixes PONGONG).
- Fix dialogs (content above the overlay), unknown-session deep links
  (error + retry, no silent fallback), device list/revoke, status identity and
  live pairing code, reconnect banner and Playwright selectors.
This commit is contained in:
yuez committed 2026-10-21 20:42:19 +08:00
1 parent 5572ac0d84
commit 0ef019f58d
57 files changed
+3549 -684

No files matched your search

+70 -6
View File
@@ -28,7 +28,7 @@ function attention(overrides: Partial<AttentionItem> = {}): AttentionItem {
}
describe("attention dialog", () => {
it("renders the request and responds with the chosen option", async () => {
it("renders the server title/options and answers `select` with the option id", async () => {
const item = attention();
const onRespond = vi.fn();
render(
@@ -40,8 +40,31 @@ describe("attention dialog", () => {
);
expect(await screen.findByText("Run this command?")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Allow once" }));
expect(onRespond).toHaveBeenCalledWith(item, "allow-once");
const option = screen.getByRole("button", { name: "Allow once" });
expect(option).toHaveAttribute("data-option-id", "allow-once");
fireEvent.click(option);
// `pi.attention.resolve` expects `{value: <option id>}`.
expect(onRespond).toHaveBeenCalledWith(item, { value: "allow-once" });
});
it("answers `confirm` with `{confirmed}` and cancels with `{cancelled}`", async () => {
const item = attention({ method: "confirm", options: undefined, title: "Proceed?" });
const onRespond = vi.fn();
render(
<AttentionDialog
session={sessionFixture({ attention: [item] })}
onRespond={onRespond}
onRemoteResolved={vi.fn()}
/>,
);
expect(await screen.findByText("Proceed?")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Confirm" }));
expect(onRespond).toHaveBeenLastCalledWith(item, { confirmed: true });
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
expect(onRespond).toHaveBeenLastCalledWith(item, { cancelled: true });
});
it("closes and reports when another client resolves the request", async () => {
@@ -57,6 +80,7 @@ describe("attention dialog", () => {
expect(await screen.findByText("Run this command?")).toBeInTheDocument();
expect(onRemoteResolved).not.toHaveBeenCalled();
// `pi2:attention_resolved` drops the request from `session.attention`.
rerender(
<AttentionDialog
session={sessionFixture({ attention: [] })}
@@ -67,6 +91,19 @@ describe("attention dialog", () => {
await waitFor(() => expect(onRemoteResolved).toHaveBeenCalledWith("att-1"));
});
it("closes itself when the server timeout has elapsed", async () => {
const item = attention({ timeoutSec: 1, receivedAt: Date.now() - 5_000 });
render(
<AttentionDialog
session={sessionFixture({ attention: [item] })}
onRespond={vi.fn()}
onRemoteResolved={vi.fn()}
/>,
);
await waitFor(() => expect(screen.queryByText("Run this command?")).not.toBeInTheDocument());
});
it("renders the diff review variant and sends the plugin's review JSON", async () => {
const item = attention({
method: "diff",
@@ -85,10 +122,37 @@ describe("attention dialog", () => {
);
expect(await screen.findByText("src/auth.ts")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Accept all" }));
const acceptAll = screen.getByRole("button", { name: "Accept all" });
expect(acceptAll).toHaveAttribute("data-decision", "accept");
fireEvent.click(acceptAll);
expect(onRespond).toHaveBeenCalledTimes(1);
// The plugin decodes `response.value` as JSON: `{result, path?}`.
const response = onRespond.mock.calls[0]?.[1];
expect(typeof response).toBe("string");
expect(JSON.parse(String(response))).toEqual({ result: "Accepted" });
expect(response).toHaveProperty("value");
expect(JSON.parse(String((response as { value: string }).value))).toEqual({ result: "Accepted" });
});
it("carries the reviewed path on per-file diff decisions", async () => {
const item = attention({
method: "diff",
title: "Review the edit",
payload: {
files: [{ path: "src/auth.ts", before: "a\n", after: "b\n" }],
},
});
const onRespond = vi.fn();
render(
<AttentionDialog
session={sessionFixture({ attention: [item] })}
onRespond={onRespond}
onRemoteResolved={vi.fn()}
/>,
);
expect(await screen.findByText("src/auth.ts")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Reject" }));
const answer = onRespond.mock.calls[0]?.[1] as { value: string };
expect(JSON.parse(answer.value)).toEqual({ result: "Rejected", path: "src/auth.ts" });
});
});