- 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.
42 lines
2.1 KiB
TypeScript
42 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { connectHref, safeNext } from "@/lib/routing";
|
|
|
|
describe("safeNext", () => {
|
|
it("keeps whitelisted navigation routes with their query", () => {
|
|
expect(safeNext("/workspaces")).toBe("/workspaces");
|
|
expect(safeNext("/status?tab=devices")).toBe("/status?tab=devices");
|
|
expect(safeNext("/chat/01a15368")).toBe("/chat/01a15368");
|
|
expect(safeNext("/workspace/ws-pi2?x=1")).toBe("/workspace/ws-pi2?x=1");
|
|
});
|
|
|
|
it("keeps paired deep links (session + workspace query) across the pairing round trip", () => {
|
|
expect(safeNext("/chat/01a15368?workspace=ws-1")).toBe("/chat/01a15368?workspace=ws-1");
|
|
expect(safeNext("/chat/01a1?workspace=ws-1&tab=todo")).toBe("/chat/01a1?workspace=ws-1&tab=todo");
|
|
expect(connectHref(safeNext("/chat/01a1?workspace=ws-1"))).toBe(
|
|
"/connect?next=%2Fchat%2F01a1%3Fworkspace%3Dws-1",
|
|
);
|
|
// The `next` param survives a full redirect → pairing → redirect cycle.
|
|
const href = connectHref("/chat/01a1?workspace=ws-1");
|
|
const next = new URLSearchParams(href.split("?")[1]).get("next");
|
|
expect(safeNext(next)).toBe("/chat/01a1?workspace=ws-1");
|
|
});
|
|
|
|
it("falls back for unknown or unsafe targets", () => {
|
|
expect(safeNext(undefined)).toBe("/workspaces");
|
|
expect(safeNext("/servers")).toBe("/workspaces");
|
|
expect(safeNext("/connect")).toBe("/workspaces");
|
|
expect(safeNext("/pair/ABCD1234")).toBe("/workspaces");
|
|
expect(safeNext("javascript:alert(1)")).toBe("/workspaces");
|
|
expect(safeNext("https://evil.example/not-a-page")).toBe("/workspaces");
|
|
// A protocol-relative link keeps only its path (the host is never used).
|
|
expect(safeNext("//evil.example/chat/1")).toBe("/chat/1");
|
|
expect(safeNext("//evil.example/not-a-page")).toBe("/workspaces");
|
|
});
|
|
|
|
it("builds an encoded connect redirect", () => {
|
|
expect(connectHref("/chat/01a1?tab=todo")).toBe("/connect?next=%2Fchat%2F01a1%3Ftab%3Dtodo");
|
|
expect(connectHref("/nope")).toBe("/connect?next=%2Fworkspaces");
|
|
});
|
|
});
|