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:
1 parent
5572ac0d84
commit
0ef019f58d
57 files changed
+3549
-684
No files matched your search
+34
-3
@@ -1,6 +1,6 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { PiWsClient, type WebSocketLike, type WsFrame } from "@/lib/ws";
|
||||
import { PiWsClient, normalizeDeviceToken, type WebSocketLike, type WsFrame } from "@/lib/ws";
|
||||
|
||||
class FakeSocket implements WebSocketLike {
|
||||
readyState = 0;
|
||||
@@ -91,7 +91,34 @@ describe("PiWsClient", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("reconnects with exponential backoff and resumes with sinceSeq", () => {
|
||||
it("strips the `Bearer ` prefix the token store adds before the auth frame", () => {
|
||||
vi.useFakeTimers();
|
||||
// `setDeviceToken()` persists `Bearer <token>`; the daemon hashes the
|
||||
// frame verbatim, so the prefix must not reach the wire.
|
||||
const { client, sockets } = createClient("Bearer abc");
|
||||
client.connect();
|
||||
sockets[0]!.open();
|
||||
expect(sockets[0]!.frames("auth")).toEqual([{ v: 1, type: "auth", token: "abc" }]);
|
||||
|
||||
// The same normalization applies to every reconnect.
|
||||
sockets[0]!.receive({ type: "hello_ack" });
|
||||
sockets[0]!.serverClose(1006);
|
||||
vi.advanceTimersByTime(200);
|
||||
expect(sockets).toHaveLength(2);
|
||||
sockets[1]!.open();
|
||||
expect(sockets[1]!.frames("auth")).toEqual([{ v: 1, type: "auth", token: "abc" }]);
|
||||
});
|
||||
|
||||
it("normalizes case, whitespace and a prefix-only token", () => {
|
||||
expect(normalizeDeviceToken("bearer abc \n")).toBe("abc");
|
||||
expect(normalizeDeviceToken(" Bearer\tabc")).toBe("abc");
|
||||
expect(normalizeDeviceToken("abc")).toBe("abc");
|
||||
expect(normalizeDeviceToken("Bearer ")).toBeUndefined();
|
||||
expect(normalizeDeviceToken("")).toBeUndefined();
|
||||
expect(normalizeDeviceToken(null)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("reconnects with exponential backoff and resumes with the `since` cursor", () => {
|
||||
vi.useFakeTimers();
|
||||
const { client, sockets, states, snapshots } = createClient();
|
||||
client.connect();
|
||||
@@ -115,7 +142,11 @@ describe("PiWsClient", () => {
|
||||
sockets[1]!.receive({ type: "hello_ack" });
|
||||
expect(client.getState()).toBe("open");
|
||||
expect(sockets[1]!.frames("subscribe")).toEqual([
|
||||
{ v: 1, type: "subscribe", payload: { sessionIds: ["s1"], sinceSeq: { s1: 10 } } },
|
||||
{
|
||||
v: 1,
|
||||
type: "subscribe",
|
||||
payload: { sessionIds: ["s1"], since: { sessionId: "s1", epoch: "e1", seq: 10 } },
|
||||
},
|
||||
]);
|
||||
|
||||
// A successful hello_ack resets the backoff, so the next retry is 200ms again.
|
||||
|
||||
Reference in new issue
Block a user