fix(webui): restore full-project typechecking
This commit is contained in:
1 parent
f869212e7d
commit
a1bca7dc50
56 files changed
+622
-583
No files matched your search
@@ -87,7 +87,7 @@ jobs:
|
||||
tui_required=true
|
||||
docker_required=true
|
||||
;;
|
||||
webui/*|nanobot/channels/*/webui/*)
|
||||
webui/*|nanobot/channels/*/webui/*|nanobot/channels/*/tests/webui/*)
|
||||
webui_required=true
|
||||
# The Docker image builds and bundles both WebUI trees.
|
||||
docker_required=true
|
||||
@@ -313,6 +313,10 @@ jobs:
|
||||
working-directory: webui
|
||||
run: bun run lint
|
||||
|
||||
- name: Type check WebUI and unit tests
|
||||
working-directory: webui
|
||||
run: bun run typecheck
|
||||
|
||||
- name: Test WebUI
|
||||
working-directory: webui
|
||||
run: bun run test:coverage
|
||||
|
||||
@@ -296,7 +296,7 @@ describe("Linear channel UI", () => {
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(actionCalls()).toHaveLength(1));
|
||||
const params = actionCalls()[0][1] as { values: Record<string, unknown> };
|
||||
expect(params.values).toEqual({ "channels.linear.clientSecret": "replacement-secret" });
|
||||
@@ -317,7 +317,7 @@ describe("Linear channel UI", () => {
|
||||
fireEvent.change(screen.getByLabelText("OAuth client secret", { exact: true, selector: "input" }), {
|
||||
target: { value: "discarded-draft" },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
expect(screen.getAllByText("Saved", { exact: true })).toHaveLength(2);
|
||||
expect(screen.getByRole("button", { name: "Connect Linear" })).toBeEnabled();
|
||||
await act(async () => { await vi.advanceTimersByTimeAsync(750); });
|
||||
@@ -340,11 +340,11 @@ describe("Linear channel UI", () => {
|
||||
fireEvent.change(screen.getByLabelText("OAuth client secret", { exact: true, selector: "input" }), {
|
||||
target: { value: "retry-draft" },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
||||
expect(await screen.findByRole("alert")).toHaveTextContent("Could not confirm the save");
|
||||
expect(screen.getByLabelText("OAuth client secret", { exact: true, selector: "input" })).toHaveValue("retry-draft");
|
||||
expect(screen.queryByText("Settings saved.")).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
expect(screen.getAllByText("Saved", { exact: true })).toHaveLength(2);
|
||||
});
|
||||
|
||||
@@ -362,7 +362,7 @@ describe("Linear channel UI", () => {
|
||||
fireEvent.change(input, { target: { value: "first-secret" } });
|
||||
expect(screen.getByRole("button", { name: "Connect Linear" })).toBeDisabled();
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Replace OAuth client secret" })).toHaveFocus());
|
||||
expect(screen.getAllByText("Saved", { exact: true })).toHaveLength(2);
|
||||
expect(screen.queryByDisplayValue("first-secret")).not.toBeInTheDocument();
|
||||
@@ -388,12 +388,12 @@ describe("Linear channel UI", () => {
|
||||
target: { value: "client-draft" },
|
||||
});
|
||||
fireEvent.change(webhook, { target: { value: "unfinished-webhook" } });
|
||||
fireEvent.click(within(clientGroup).getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(within(clientGroup).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Replace OAuth client secret" })).toBeEnabled());
|
||||
expect(actionCalls()).toHaveLength(1);
|
||||
expect(actionCalls()[0][1].values).toEqual({ "channels.linear.clientSecret": "client-draft" });
|
||||
expect(webhook).toHaveValue("unfinished-webhook");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
expect(screen.getAllByText("Saved", { exact: true })).toHaveLength(2);
|
||||
});
|
||||
|
||||
@@ -409,9 +409,9 @@ describe("Linear channel UI", () => {
|
||||
fireEvent.change(screen.getByLabelText("OAuth client secret", { exact: true, selector: "input" }), {
|
||||
target: { value: "keep-draft" },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
||||
const dialog = screen.getByRole("dialog");
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Close" }));
|
||||
expect(dialog).toBeVisible();
|
||||
expect(actionCalls()).toHaveLength(1);
|
||||
await act(async () => failSave(new Error("Network unavailable")));
|
||||
@@ -449,10 +449,10 @@ describe("Linear channel UI", () => {
|
||||
target: { value: "replacement-client" },
|
||||
});
|
||||
const dialog = screen.getByRole("dialog");
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Close" }));
|
||||
expect(actionCalls()).toHaveLength(1);
|
||||
expect(dialog).toBeVisible();
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Close" }));
|
||||
expect(actionCalls()).toHaveLength(1);
|
||||
finishSave?.({ saved: true, nanobot_features: { features: [{
|
||||
...feature, config_values: { ...feature.config_values, "channels.linear.clientId": "replacement-client" },
|
||||
@@ -470,7 +470,7 @@ describe("Linear channel UI", () => {
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "OAuth client ID" }), {
|
||||
target: { value: "replacement-client" },
|
||||
});
|
||||
fireEvent.click(within(screen.getByRole("dialog")).getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(within(screen.getByRole("dialog")).getByRole("button", { name: "Close" }));
|
||||
expect(await screen.findByRole("alert")).toHaveTextContent("Connection lost");
|
||||
expect(screen.getByRole("dialog")).toBeVisible();
|
||||
expect(screen.getByRole("textbox", { name: "OAuth client ID" })).toHaveValue("replacement-client");
|
||||
@@ -523,7 +523,7 @@ describe("Linear channel UI", () => {
|
||||
expect(await screen.findByText(/No workspaces are authorized/)).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Connect Linear" })).toBeEnabled();
|
||||
expect(screen.queryByRole("button", { name: "Connect another workspace" })).not.toBeInTheDocument();
|
||||
fireEvent.click(within(screen.getByRole("dialog")).getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(within(screen.getByRole("dialog")).getByRole("button", { name: "Close" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
fireEvent.click(open);
|
||||
expect(within(screen.getByRole("dialog")).getByText("Channel running", { exact: true })).toBeVisible();
|
||||
@@ -694,7 +694,7 @@ describe("Linear channel UI", () => {
|
||||
// A second reconnect must revalidate even while the display cache is fresh.
|
||||
act(() => { onStatus?.("reconnecting"); onStatus?.("open"); });
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledTimes(3));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
expect(unsubscribe).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
+2
-1
@@ -113,13 +113,14 @@ The gateway picks up the new bundle on the next restart.
|
||||
```bash
|
||||
cd webui
|
||||
bun run lint
|
||||
bun run typecheck
|
||||
bun run test
|
||||
bun x playwright install chromium
|
||||
bun run test:browser
|
||||
bun run build
|
||||
```
|
||||
|
||||
`lint` runs ESLint; `test` runs Vitest, including channel-owned frontend tests; `test:browser` uses Chromium with the real components and stylesheet to check tall-dialog reachability and completed-history motion without a gateway; `build` runs TypeScript checking and produces the production bundle. Keep tests near the changed behavior and exercise settings save/reload in the browser. Browser-only preferences stay in the frontend; persistent configuration and security policy belong to the Python gateway. When changing that boundary, also run the relevant Python tests from [CONTRIBUTING.md](../CONTRIBUTING.md).
|
||||
`lint` runs ESLint; `typecheck` checks application and unit-test TypeScript, including channel-owned frontend code and tests; `test` runs Vitest; `test:browser` typechecks and runs Chromium tests with the real components and stylesheet to check tall-dialog reachability and completed-history motion without a gateway; `build` checks production TypeScript and produces the production bundle. Keep tests near the changed behavior and exercise settings save/reload in the browser. Browser-only preferences stay in the frontend; persistent configuration and security policy belong to the Python gateway. When changing that boundary, also run the relevant Python tests from [CONTRIBUTING.md](../CONTRIBUTING.md).
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"gallery": "vite --open /gallery.html",
|
||||
"build": "tsc -p tsconfig.build.json && vite build",
|
||||
"preview": "vite preview",
|
||||
"typecheck": "tsc -p tsconfig.json",
|
||||
"test": "vitest run",
|
||||
"test:coverage": "vitest run --coverage",
|
||||
"test:watch": "vitest",
|
||||
|
||||
@@ -162,7 +162,7 @@ describe("AgentActivityCluster", () => {
|
||||
expect(screen.getByText(`Reading file ${path}`)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("Using Blender, --json --background scene.blend")).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("Opening example.com, Browserbase")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited" })).toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent(path);
|
||||
|
||||
await act(async () => setAppLanguage("zh-CN"));
|
||||
@@ -171,7 +171,7 @@ describe("AgentActivityCluster", () => {
|
||||
expect(screen.getByText(`正在读取文件 ${path}`)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("正在使用 Blender, --json --background scene.blend")).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("正在打开 example.com, Browserbase")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "编辑", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "编辑" })).toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent(path);
|
||||
|
||||
await act(async () => setAppLanguage("ja"));
|
||||
@@ -180,7 +180,7 @@ describe("AgentActivityCluster", () => {
|
||||
expect(screen.getByText(`${path} ファイルを読み取り中`)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("Blender を使用中, --json --background scene.blend")).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("example.com 開いています, Browserbase")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "編集", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "編集" })).toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference").closest('[data-testid="activity-step"]'))
|
||||
.toHaveAttribute("aria-label", `${path} 編集`);
|
||||
});
|
||||
@@ -536,7 +536,7 @@ describe("AgentActivityCluster", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
assertBetween(screen.getByRole("img", { name: "Editing", exact: true }));
|
||||
assertBetween(screen.getByRole("img", { name: "Editing" }));
|
||||
|
||||
rerender(
|
||||
<AgentActivityCluster
|
||||
@@ -546,7 +546,7 @@ describe("AgentActivityCluster", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
assertBetween(screen.getByRole("img", { name: "Edited", exact: true }));
|
||||
assertBetween(screen.getByRole("img", { name: "Edited" }));
|
||||
});
|
||||
|
||||
it.each(["diff", "collapsed_diff"] as const)(
|
||||
@@ -677,7 +677,7 @@ describe("AgentActivityCluster", () => {
|
||||
expect(screen.getByTestId("file-edit-diff")).toBeInTheDocument();
|
||||
expect(screen.getByText("return <Old />;")).toBeInTheDocument();
|
||||
expect(screen.getByText("return <New />;")).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited" })).toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("src/app.tsx");
|
||||
expect(screen.getAllByTestId("activity-diff-pair")).toHaveLength(1);
|
||||
|
||||
@@ -685,7 +685,7 @@ describe("AgentActivityCluster", () => {
|
||||
writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, fileEditDisplayMode: "summary" });
|
||||
});
|
||||
expect(screen.queryByTestId("file-edit-diff")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited" })).toBeInTheDocument();
|
||||
|
||||
act(() => {
|
||||
writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, fileEditDisplayMode: "diff" });
|
||||
@@ -978,10 +978,10 @@ describe("AgentActivityCluster", () => {
|
||||
hasBodyBelow={false}
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByRole("img", { name: "Created", exact: true }).querySelector("svg"))
|
||||
expect(screen.getByRole("img", { name: "Created" }).querySelector("svg"))
|
||||
.toHaveClass("lucide-file-text");
|
||||
expect(screen.getByLabelText("Created tmp.txt")).toBeInTheDocument();
|
||||
expect(screen.queryByRole("img", { name: "Edited", exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("img", { name: "Edited" })).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("tmp.txt");
|
||||
expect(!!screen.queryByTestId("file-edit-diff")).toBe(hasDiff);
|
||||
} finally {
|
||||
@@ -1017,9 +1017,9 @@ describe("AgentActivityCluster", () => {
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
|
||||
|
||||
expect(screen.getByRole("img", { name: "Deleted", exact: true }).querySelector("svg"))
|
||||
expect(screen.getByRole("img", { name: "Deleted" }).querySelector("svg"))
|
||||
.toHaveClass("lucide-file-code2");
|
||||
expect(screen.queryByRole("img", { name: "Edited", exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("img", { name: "Edited" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders file-only edits without a redundant disclosure", () => {
|
||||
@@ -1051,9 +1051,9 @@ describe("AgentActivityCluster", () => {
|
||||
|
||||
expect(screen.queryByRole("button", { name: /edited app\.tsx/i })).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId("agent-activity-content")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited" })).toBeInTheDocument();
|
||||
expect(screen.queryByTestId("activity-header-file-reference")).not.toBeInTheDocument();
|
||||
const marker = screen.getByRole("img", { name: "Edited", exact: true });
|
||||
const marker = screen.getByRole("img", { name: "Edited" });
|
||||
expect(marker.querySelector("svg")).toHaveClass("lucide-file-code2");
|
||||
expect(marker.closest('[data-testid="activity-step"]')?.querySelectorAll("svg")).toHaveLength(1);
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("src/app.tsx");
|
||||
@@ -1804,7 +1804,7 @@ describe("AgentActivityCluster", () => {
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
|
||||
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited" })).toBeInTheDocument();
|
||||
expect(screen.queryByText("+0")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("-0")).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -1899,7 +1899,7 @@ describe("AgentActivityCluster", () => {
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
|
||||
|
||||
const row = screen.getByRole("img", { name: "Could not edit", exact: true }).closest('[data-testid="activity-step"]');
|
||||
const row = screen.getByRole("img", { name: "Could not edit" }).closest('[data-testid="activity-step"]');
|
||||
expect(row).toBeInTheDocument();
|
||||
expect(row).not.toHaveAttribute("title");
|
||||
expect(screen.queryByText("Target text was not found in angry-birds.html.")).not.toBeInTheDocument();
|
||||
@@ -1933,7 +1933,7 @@ describe("AgentActivityCluster", () => {
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
|
||||
|
||||
const row = screen.getByRole("img", { name: "Could not edit", exact: true }).closest('[data-testid="activity-step"]');
|
||||
const row = screen.getByRole("img", { name: "Could not edit" }).closest('[data-testid="activity-step"]');
|
||||
expect(row).toBeInTheDocument();
|
||||
expect(row).not.toHaveAttribute("title");
|
||||
expect(screen.queryByText("No permission to change this location.")).not.toBeInTheDocument();
|
||||
@@ -2014,7 +2014,7 @@ describe("AgentActivityCluster", () => {
|
||||
const fileRefs = screen.getAllByTestId("activity-file-reference");
|
||||
expect(fileRefs).toHaveLength(3);
|
||||
expect(fileRefs.every((ref) => ref.textContent?.includes("minecraft-fps/index.html"))).toBe(true);
|
||||
const failedRow = screen.getByRole("img", { name: "Could not edit", exact: true }).closest(
|
||||
const failedRow = screen.getByRole("img", { name: "Could not edit" }).closest(
|
||||
'[data-testid="activity-step"]',
|
||||
);
|
||||
expect(failedRow).toBeInTheDocument();
|
||||
@@ -2072,8 +2072,8 @@ describe("AgentActivityCluster", () => {
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
|
||||
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Could not edit", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Could not edit" })).toBeInTheDocument();
|
||||
expect(screen.getAllByTestId("activity-file-reference")).toHaveLength(2);
|
||||
});
|
||||
|
||||
|
||||
@@ -313,22 +313,22 @@ describe("webui API helpers", () => {
|
||||
});
|
||||
|
||||
it("aborts a WebUI thread request when its caller signal is aborted", async () => {
|
||||
let requestSignal: AbortSignal | null = null;
|
||||
const request: { signal?: AbortSignal | null } = {};
|
||||
vi.mocked(fetch).mockImplementation((_input, init) => new Promise((_resolve, reject) => {
|
||||
requestSignal = init?.signal ?? null;
|
||||
requestSignal?.addEventListener("abort", () => {
|
||||
request.signal = init?.signal;
|
||||
request.signal?.addEventListener("abort", () => {
|
||||
reject(new DOMException("Aborted", "AbortError"));
|
||||
});
|
||||
}));
|
||||
const controller = new AbortController();
|
||||
|
||||
const request = fetchWebuiThread("tok", "websocket:chat-1", {
|
||||
const pending = fetchWebuiThread("tok", "websocket:chat-1", {
|
||||
signal: controller.signal,
|
||||
});
|
||||
controller.abort();
|
||||
|
||||
await expect(request).rejects.toMatchObject({ name: "AbortError" });
|
||||
expect(requestSignal?.aborted).toBe(true);
|
||||
await expect(pending).rejects.toMatchObject({ name: "AbortError" });
|
||||
expect(request.signal?.aborted).toBe(true);
|
||||
});
|
||||
|
||||
it("percent-encodes websocket keys and paths when fetching file previews", async () => {
|
||||
|
||||
@@ -448,7 +448,7 @@ describe("App layout", () => {
|
||||
expect(await screen.findByRole("heading", { name: "连接到 nanobot" }))
|
||||
.toBeInTheDocument();
|
||||
expect(screen.getByLabelText("WebUI 密码")).toHaveValue("draft-password");
|
||||
expect(screen.getByRole("button", { name: "连接", exact: true })).toBeEnabled();
|
||||
expect(screen.getByRole("button", { name: "连接" })).toBeEnabled();
|
||||
expect(document.documentElement.lang).toBe("zh-CN");
|
||||
expect(localStorage.getItem("nanobot.locale")).toBe("zh-CN");
|
||||
expect(fetchBootstrap).toHaveBeenCalledTimes(1);
|
||||
@@ -754,7 +754,7 @@ describe("App layout", () => {
|
||||
expect(window.location.hash).toBe(originalHash);
|
||||
expect(document.title).toBe(originalTitle);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back" }));
|
||||
fireEvent.click(within(sidebar).getByRole("button", { name: "New topic" }));
|
||||
expect(window.location.hash).toBe("#/new");
|
||||
expect(screen.queryByRole("textbox", { name: "SSH address" })).not.toBeInTheDocument();
|
||||
@@ -1090,6 +1090,8 @@ describe("App layout", () => {
|
||||
key: "websocket:existing-chat",
|
||||
channel: "websocket",
|
||||
chatId: "existing-chat",
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
preview: "Existing topic",
|
||||
workspaceScope: projectScope,
|
||||
}];
|
||||
@@ -1264,16 +1266,16 @@ describe("App layout", () => {
|
||||
window.history.replaceState(null, "", "/#/settings?section=runtime");
|
||||
mockFetchRoutes({ "/api/settings": baseSettingsPayload() });
|
||||
render(<App />);
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Restart", exact: true }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Restart" }));
|
||||
expect(sendSystemCommandSpy).toHaveBeenCalledWith("restart-fixture", "/restart");
|
||||
expect(screen.getByRole("button", { name: "Restarting...", exact: true })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "Restarting..." })).toBeDisabled();
|
||||
act(() => {
|
||||
if (clearWhen === "before disconnect") localStorage.removeItem("nanobot-webui.restartStartedAt");
|
||||
for (const handler of statusHandlers) handler("reconnecting");
|
||||
localStorage.removeItem("nanobot-webui.restartStartedAt");
|
||||
for (const handler of statusHandlers) handler("open");
|
||||
});
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Restart", exact: true })).toBeEnabled());
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Restart" })).toBeEnabled());
|
||||
expect(createChatSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -1843,11 +1845,11 @@ describe("App layout", () => {
|
||||
);
|
||||
await user.keyboard("{Escape}");
|
||||
expect(detail.getByRole("button", { name: "More actions" })).toHaveFocus();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
expect(screen.getByText("WeChat quiz")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: /WeChat quiz/ }));
|
||||
expect(screen.getByText("WeChat")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
expect(screen.queryByText("weixin:wx-chat")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("memory with dream state")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /heartbeat/ })).not.toBeInTheDocument();
|
||||
@@ -1887,7 +1889,7 @@ describe("App layout", () => {
|
||||
});
|
||||
render(<App />);
|
||||
const sidebar = await screen.findByRole("navigation", { name: "Sidebar navigation" });
|
||||
await within(sidebar).findByRole("button", { name: "推特大战场", exact: true });
|
||||
await within(sidebar).findByRole("button", { name: "推特大战场" });
|
||||
fireEvent.click(within(sidebar).getByRole("button", { name: "Automations" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: /Drink water/ }));
|
||||
const dialog = screen.getByRole("dialog", { name: "Drink water" });
|
||||
@@ -1964,9 +1966,9 @@ describe("App layout", () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: /Past one-shot/ }));
|
||||
const runDetail = within(screen.getByRole("dialog", { name: "Past one-shot" }));
|
||||
expect(runDetail.getByText("Completed")).toBeVisible();
|
||||
expect(runDetail.queryByRole("button", { name: "Edit", exact: true })).not.toBeInTheDocument();
|
||||
fireEvent.click(runDetail.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
expect(runDetail.queryByRole("button", { name: "Edit" })).not.toBeInTheDocument();
|
||||
fireEvent.click(runDetail.getByRole("button", { name: "Close" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: /Past one-shot/ }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Edit" }));
|
||||
await screen.findByRole("dialog", { name: "Edit task" });
|
||||
@@ -2590,10 +2592,10 @@ describe("App layout", () => {
|
||||
addListener: vi.fn(), removeListener: vi.fn(), addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(), dispatchEvent: vi.fn(),
|
||||
})));
|
||||
let persisted: SidebarStatePayload | null = null;
|
||||
mockFetchRoutes({ "/api/webui/sidebar-state": () => persisted ?? {} });
|
||||
const persisted: { state?: SidebarStatePayload } = {};
|
||||
mockFetchRoutes({ "/api/webui/sidebar-state": () => persisted.state ?? {} });
|
||||
setSidebarStateSpy.mockImplementation(async (state: SidebarStatePayload) => {
|
||||
persisted = state;
|
||||
persisted.state = state;
|
||||
return state;
|
||||
});
|
||||
const firstRender = render(<App />);
|
||||
@@ -2604,7 +2606,7 @@ describe("App layout", () => {
|
||||
const sheet = await screen.findByRole("dialog");
|
||||
const startRename = async () => {
|
||||
await user.click(within(sheet).getByRole("button", { name: "Topic actions for Existing chat" }));
|
||||
await user.click(await within(sheet).findByRole("menuitem", { name: "Rename", exact: true }));
|
||||
await user.click(await within(sheet).findByRole("menuitem", { name: "Rename" }));
|
||||
return within(sheet).getByRole("textbox", { name: "Topic name" });
|
||||
};
|
||||
const firstInput = await startRename();
|
||||
@@ -2625,15 +2627,15 @@ describe("App layout", () => {
|
||||
await user.keyboard("{Enter}");
|
||||
expect(await within(sheet).findByRole("alert")).toHaveTextContent("Couldn't save the name. Try again.");
|
||||
expect(input).toHaveValue("Renamed topic");
|
||||
expect(persisted?.title_overrides["websocket:chat-a"]).toBeUndefined();
|
||||
expect(persisted.state?.title_overrides["websocket:chat-a"]).toBeUndefined();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(await within(sheet).findByRole("button", { name: "Renamed topic", exact: true })).toBeInTheDocument();
|
||||
expect(persisted?.title_overrides["websocket:chat-a"]).toBe("Renamed topic");
|
||||
expect(await within(sheet).findByRole("button", { name: "Renamed topic" })).toBeInTheDocument();
|
||||
expect(persisted.state?.title_overrides["websocket:chat-a"]).toBe("Renamed topic");
|
||||
expect(window.location.hash).toBe(route);
|
||||
expect(screen.getAllByRole("dialog")).toHaveLength(1);
|
||||
firstRender.unmount();
|
||||
render(<App />);
|
||||
expect(await screen.findByRole("button", { name: "Renamed topic", exact: true })).toBeInTheDocument();
|
||||
expect(await screen.findByRole("button", { name: "Renamed topic" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("retries a failed sidebar read before enabling edits without losing saved state", async () => {
|
||||
@@ -2787,7 +2789,7 @@ describe("App layout", () => {
|
||||
sessionsFail = false;
|
||||
act(() => sessionUpdateHandlers.forEach((handler) => handler("chat-a")));
|
||||
await within(sidebar).findByRole("button", { name: "Group: Saved group" });
|
||||
expect(await within(sidebar).findByRole("button", { name: "Saved B", exact: true })).toBeInTheDocument();
|
||||
expect(await within(sidebar).findByRole("button", { name: "Saved B" })).toBeInTheDocument();
|
||||
await waitFor(() => expect(setSidebarStateSpy).toHaveBeenLastCalledWith({
|
||||
...saved,
|
||||
view: expect.objectContaining(saved.view),
|
||||
@@ -3127,15 +3129,15 @@ describe("App layout", () => {
|
||||
.getByRole("button", { name: "Settings" }));
|
||||
const nav = await screen.findByRole("navigation", { name: "Settings sections" });
|
||||
for (const name of ["Overview", "Appearance", "Models", "Capabilities", "System", "Advanced", "About"]) {
|
||||
expect(within(nav).getByRole("button", { name, exact: true })).toBeInTheDocument();
|
||||
expect(within(nav).getByRole("button", { name })).toBeInTheDocument();
|
||||
}
|
||||
fireEvent.click(within(nav).getByRole("button", { name: "Appearance", exact: true }));
|
||||
fireEvent.click(within(nav).getByRole("button", { name: "Appearance" }));
|
||||
expect(await screen.findByRole("switch", { name: "Brand logos" })).toBeInTheDocument();
|
||||
fireEvent.click(within(nav).getByRole("button", { name: "Models", exact: true }));
|
||||
fireEvent.click(within(nav).getByRole("button", { name: "Models" }));
|
||||
expect(await screen.findByText("Model presets")).toBeInTheDocument();
|
||||
fireEvent.click(within(nav).getByRole("button", { name: "Capabilities", exact: true }));
|
||||
fireEvent.click(within(nav).getByRole("button", { name: "Capabilities" }));
|
||||
expect(screen.getByRole("switch", { name: "Image generation" })).toBeInTheDocument();
|
||||
fireEvent.click(within(nav).getByRole("button", { name: "About", exact: true }));
|
||||
fireEvent.click(within(nav).getByRole("button", { name: "About" }));
|
||||
expect(await screen.findByRole("button", { name: "Check for updates" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -3173,7 +3175,7 @@ describe("App layout", () => {
|
||||
expect(systemSection).not.toBeNull();
|
||||
const system = within(systemSection as HTMLElement);
|
||||
expect(system.getByText("Timezone")).toBeInTheDocument();
|
||||
expect(within(screen.getByRole("complementary")).getByRole("button", { name: "Restart", exact: true })).toBeInTheDocument();
|
||||
expect(within(screen.getByRole("complementary")).getByRole("button", { name: "Restart" })).toBeInTheDocument();
|
||||
expect(
|
||||
system.queryByText("Restart nanobot to apply runtime changes."),
|
||||
).not.toBeInTheDocument();
|
||||
@@ -3208,11 +3210,9 @@ describe("App layout", () => {
|
||||
const settingsNav = screen.getByRole("navigation", { name: "Settings sections" });
|
||||
const overviewButton = within(settingsNav).getByRole("button", {
|
||||
name: "Overview",
|
||||
exact: true,
|
||||
});
|
||||
const modelsButton = within(settingsNav).getByRole("button", {
|
||||
name: "Models",
|
||||
exact: true,
|
||||
});
|
||||
const settingsHighlight = within(settingsNav).getByTestId(
|
||||
"settings-selection-highlight",
|
||||
@@ -3233,7 +3233,6 @@ describe("App layout", () => {
|
||||
|
||||
const voiceButton = within(settingsNav).getByRole("button", {
|
||||
name: "Capabilities",
|
||||
exact: true,
|
||||
});
|
||||
fireEvent.click(voiceButton);
|
||||
|
||||
@@ -4235,7 +4234,7 @@ describe("App layout", () => {
|
||||
expires_in: 300,
|
||||
});
|
||||
vi.mocked(deriveWsUrl).mockImplementation(
|
||||
(_wsPath: string, token: string) => `ws://test?token=${token}`,
|
||||
(_wsPath, token) => `ws://test?token=${token}`,
|
||||
);
|
||||
|
||||
const { unmount } = render(<App />);
|
||||
@@ -4372,9 +4371,7 @@ describe("App layout", () => {
|
||||
if (visibilityDescriptor) {
|
||||
Object.defineProperty(document, "visibilityState", visibilityDescriptor);
|
||||
} else {
|
||||
delete (document as Document & {
|
||||
visibilityState?: DocumentVisibilityState;
|
||||
}).visibilityState;
|
||||
Reflect.deleteProperty(document, "visibilityState");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -98,13 +98,13 @@ describe("Automation run time picker", () => {
|
||||
const time = screen.getByRole("textbox", { name: "Run time" });
|
||||
await user.clear(time);
|
||||
await user.type(time, "09:45");
|
||||
await user.click(screen.getByRole("button", { name: "Save", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Save" }));
|
||||
expect(save).toHaveBeenCalledWith(job, {
|
||||
name: job.name, message: job.payload.message,
|
||||
schedule: { kind: "at", at_ms: new Date(2099, 8, 17, 9, 45).getTime() },
|
||||
});
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "Run date" }), { target: { value: "2099-02-31" } });
|
||||
expect(screen.getByRole("button", { name: "Save", exact: true })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
|
||||
expect(screen.getByText("Choose a run time.")).toBeVisible();
|
||||
});
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ function taskMenuItem(name: string) {
|
||||
if (!screen.queryByRole("menu")) {
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: i18n.t("settings.automations.moreActions") }), { button: 0, ctrlKey: false });
|
||||
}
|
||||
return screen.getByRole("menuitem", { name, exact: true });
|
||||
return screen.getByRole("menuitem", { name });
|
||||
}
|
||||
|
||||
function selectFilter(name: string) {
|
||||
@@ -107,10 +107,10 @@ describe("Automation task list and detail sheet", () => {
|
||||
expect(toolbar).not.toBeNull();
|
||||
expect(filters.closest(".automation-panel-toolbar")).toBe(toolbar);
|
||||
expect(toolbar?.closest(".automation-panel")).toContainElement(document.querySelector(".automation-calendar"));
|
||||
const tasksButton = screen.getByRole("button", { name: "Tasks", exact: true });
|
||||
const tasksButton = screen.getByRole("button", { name: "Tasks" });
|
||||
tasksButton.focus();
|
||||
fireEvent.click(tasksButton);
|
||||
expect(screen.getByRole("button", { name: "Tasks", exact: true })).toBe(tasksButton);
|
||||
expect(screen.getByRole("button", { name: "Tasks" })).toBe(tasksButton);
|
||||
expect(tasksButton).toHaveFocus();
|
||||
expect(screen.getByRole("button", { name: /^Filter/ }).closest(".automation-panel-toolbar")).toBe(toolbar);
|
||||
expect(screen.queryByRole("heading", { level: 2 })).not.toBeInTheDocument();
|
||||
@@ -127,7 +127,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness payload={{ jobs: [triggerTask, task] }} />);
|
||||
expect(screen.queryByRole("button", { name: /Review on request/ })).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Tasks" }));
|
||||
const row = screen.getByRole("button", { name: /Review on request/ });
|
||||
expect(within(row).getByText("Command trigger")).toBeVisible();
|
||||
expect(within(row).queryByText("Waiting for trigger")).not.toBeInTheDocument();
|
||||
@@ -135,7 +135,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
await user.click(row);
|
||||
const dialog = screen.getByRole("dialog", { name: "Review on request" });
|
||||
expect(within(dialog).getByText(triggerTask.trigger!.command)).toBeVisible();
|
||||
expect(within(dialog).getByRole("button", { name: "Copy", exact: true })).toBeVisible();
|
||||
expect(within(dialog).getByRole("button", { name: "Copy" })).toBeVisible();
|
||||
expect(within(dialog).queryByText("Next")).not.toBeInTheDocument();
|
||||
expect(within(dialog).queryByRole("button", { name: "Run now" })).not.toBeInTheDocument();
|
||||
await user.keyboard("{Escape}");
|
||||
@@ -155,18 +155,18 @@ describe("Automation task list and detail sheet", () => {
|
||||
it("defaults to Calendar on every visit regardless of the old saved view and shares filters", () => {
|
||||
window.localStorage.setItem(VIEW_STORAGE_KEY, "tasks");
|
||||
const first = render(<Harness payload={{ jobs: [triggerTask, task, systemTask] }} />);
|
||||
expect(screen.getByRole("button", { name: "Calendar", exact: true })).toHaveAttribute("aria-pressed", "true");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
expect(screen.getByRole("button", { name: "Calendar" })).toHaveAttribute("aria-pressed", "true");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks" }));
|
||||
expect(screen.queryByRole("button", { name: /heartbeat/ })).not.toBeInTheDocument();
|
||||
first.unmount();
|
||||
render(<Harness payload={{ jobs: [triggerTask, task, systemTask] }} />);
|
||||
expect(screen.getByRole("button", { name: "Calendar", exact: true })).toHaveAttribute("aria-pressed", "true");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
expect(screen.getByRole("button", { name: "Tasks", exact: true })).toHaveAttribute("aria-pressed", "true");
|
||||
expect(screen.getByRole("button", { name: "Calendar" })).toHaveAttribute("aria-pressed", "true");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks" }));
|
||||
expect(screen.getByRole("button", { name: "Tasks" })).toHaveAttribute("aria-pressed", "true");
|
||||
expect(screen.getByRole("button", { name: /Review on request/ })).toBeVisible();
|
||||
selectFilter("Disabled 0");
|
||||
expect(screen.getByText("No automations match this view.")).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Calendar", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Calendar" }));
|
||||
expect(screen.getByRole("button", { name: "Filter: Disabled" })).toBeVisible();
|
||||
expect(screen.queryByRole("switch", { name: "Show system tasks" })).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -177,7 +177,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
{ ...task, id: "busy", name: "Running task", state: { pending: true } },
|
||||
{ ...task, id: "error", name: "Failed task", state: { last_status: "error" } },
|
||||
] }} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks" }));
|
||||
expect(within(screen.getByRole("button", { name: /Review on request/ })).queryByText("Active")).not.toBeInTheDocument();
|
||||
expect(within(screen.getByRole("button", { name: /Disabled task/ })).getByText("Disabled")).toBeVisible();
|
||||
expect(within(screen.getByRole("button", { name: /Running task/ })).getByText("Running now")).toBeVisible();
|
||||
@@ -188,9 +188,9 @@ describe("Automation task list and detail sheet", () => {
|
||||
vi.spyOn(window.localStorage, "getItem").mockImplementation(() => { throw new Error("Blocked"); });
|
||||
vi.spyOn(window.localStorage, "setItem").mockImplementation(() => { throw new Error("Blocked"); });
|
||||
render(<Harness payload={{ jobs: [triggerTask] }} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks" }));
|
||||
expect(screen.getByRole("button", { name: /Review on request/ })).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Calendar", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Calendar" }));
|
||||
expect(screen.queryByRole("button", { name: /Review on request/ })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -201,7 +201,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
...systemTask.state, last_status: "error",
|
||||
} }] }} onAction={action} />);
|
||||
for (const view of ["Calendar", "Tasks"]) {
|
||||
fireEvent.click(screen.getByRole("button", { name: view, exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: view }));
|
||||
expect(screen.queryByRole("switch", { name: "Show system tasks" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /heartbeat/ })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /PR watch/ })).toBeVisible();
|
||||
@@ -242,7 +242,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
const dialog = screen.getByRole("dialog", { name: "PR watch" });
|
||||
if (action === "removed") rerender(<Harness payload={{ jobs: [] }} onRequestEdit={edit} />);
|
||||
else if (action === "Escape") fireEvent.keyDown(dialog, { key: "Escape" });
|
||||
else fireEvent.click(within(dialog).getByRole("button", { name: action.startsWith("Edit") ? "Edit" : action, exact: true }));
|
||||
else fireEvent.click(within(dialog).getByRole("button", { name: action.startsWith("Edit") ? "Edit" : action }));
|
||||
if (action === "Edit removed") rerender(<Harness payload={{ jobs: [] }} onRequestEdit={edit} />);
|
||||
expect(dialog).toBeInTheDocument();
|
||||
expect(dialog).toHaveAttribute("data-state", "closed");
|
||||
@@ -404,7 +404,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
|
||||
it("localizes historical results and zero durations in Chinese", async () => {
|
||||
const language = i18n.language;
|
||||
onTestFinished(() => i18n.changeLanguage(language));
|
||||
onTestFinished(async () => { await i18n.changeLanguage(language); });
|
||||
await act(() => i18n.changeLanguage("zh-CN"));
|
||||
render(<Harness payload={{ jobs: [{ ...task, state: {
|
||||
run_history: [{ run_at_ms: now, status: "ok", duration_ms: 0 }],
|
||||
@@ -598,7 +598,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
expect(screen.queryByRole("button", { name: "Open a chat" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /^Filter/ })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /heartbeat/ })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks" }));
|
||||
expect(screen.getByText("No automations yet.")).toBeVisible();
|
||||
});
|
||||
|
||||
@@ -757,7 +757,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
|
||||
it("localizes the monthly summary and retains the expression in the editor", async () => {
|
||||
const language = i18n.language;
|
||||
onTestFinished(() => i18n.changeLanguage(language));
|
||||
onTestFinished(async () => { await i18n.changeLanguage(language); });
|
||||
await act(() => i18n.changeLanguage("zh-CN"));
|
||||
const job: SessionAutomationJob = { ...task, schedule: { kind: "cron", expr: "30 13 25 * *" } };
|
||||
const { unmount } = render(<Harness payload={{ jobs: [job] }} />);
|
||||
@@ -774,7 +774,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
it("opens an icon-only filter with the keyboard and restores focus on Escape", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness />);
|
||||
const filterButton = screen.getByRole("button", { name: "Filter", exact: true });
|
||||
const filterButton = screen.getByRole("button", { name: "Filter" });
|
||||
expect(filterButton).toHaveTextContent("");
|
||||
expect(filterButton.querySelector(".lucide-list-filter")).not.toBeNull();
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
@@ -800,7 +800,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
expect(screen.getByRole("button", { name: /Weekly review/ })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Filter: Disabled" })).toBeVisible();
|
||||
selectFilter("All 2");
|
||||
expect(screen.queryByRole("button", { name: "Next run", exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Next run" })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /PR watch.*Planned/ })).toBeVisible();
|
||||
});
|
||||
|
||||
@@ -849,11 +849,11 @@ describe("Automation task list and detail sheet", () => {
|
||||
|
||||
it("uses enable and disable terminology throughout the Chinese automation flow", async () => {
|
||||
const language = i18n.language;
|
||||
onTestFinished(() => i18n.changeLanguage(language));
|
||||
onTestFinished(async () => { await i18n.changeLanguage(language); });
|
||||
await act(() => i18n.changeLanguage("zh-CN"));
|
||||
const action = vi.fn();
|
||||
const { rerender } = render(<Harness payload={{ jobs: [task] }} onAction={action} />);
|
||||
expect(screen.getByRole("button", { name: "筛选", exact: true })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "筛选" })).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
const dialog = screen.getByRole("dialog", { name: "PR watch" });
|
||||
fireEvent.click(taskMenuItem("停用"));
|
||||
@@ -974,7 +974,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
finishExit(detail);
|
||||
const confirmation = await screen.findByRole("dialog", { name: "Delete automation" });
|
||||
expect(document.body.style.pointerEvents).toBe("none");
|
||||
await user.click(within(confirmation).getByRole("button", { name: operation, exact: true }));
|
||||
await user.click(within(confirmation).getByRole("button", { name: operation }));
|
||||
finishExit(confirmation);
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(document.body.style.pointerEvents).not.toBe("none");
|
||||
@@ -1005,10 +1005,10 @@ describe("Automation task list and detail sheet", () => {
|
||||
const row = screen.getByRole("button", { name: /PR watch/ });
|
||||
for (const operation of ["Cancel", "Close"]) {
|
||||
if (!screen.queryByRole("dialog", { name: "PR watch" })) await user.click(row);
|
||||
await user.click(screen.getByRole("button", { name: "Edit", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Edit" }));
|
||||
const editor = await screen.findByRole("dialog", { name: "Edit task" });
|
||||
expect(screen.getAllByRole("dialog")).toHaveLength(1);
|
||||
await user.click(within(editor).getByRole("button", { name: operation, exact: true }));
|
||||
await user.click(within(editor).getByRole("button", { name: operation }));
|
||||
await waitFor(() => expect(screen.getByRole("dialog", { name: "PR watch" })).toBeVisible());
|
||||
expect(screen.getAllByRole("dialog")).toHaveLength(1);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import QRCode from "qrcode";
|
||||
import { ChannelQrConnectFlow } from "@/components/settings/channels/ChannelQrConnectFlow";
|
||||
import { FeishuConnectFlow } from "../../../nanobot/channels/feishu/webui/FeishuConnectFlow";
|
||||
import { FeishuAssistantsPanel } from "../../../nanobot/channels/feishu/webui/FeishuAssistantsPanel";
|
||||
import type { ChannelPluginPanelProps } from "@/channel-plugins/types";
|
||||
import type { NanobotFeatureInfo } from "@/lib/types";
|
||||
|
||||
const { requestMutation } = vi.hoisted(() => ({ requestMutation: vi.fn() }));
|
||||
@@ -46,8 +47,11 @@ describe("channel QR connect parameters", () => {
|
||||
runtime_status: "running", config_values: {}, configured_fields: [],
|
||||
}],
|
||||
};
|
||||
const onFeaturesUpdate = vi.fn();
|
||||
const props = { token: "tok", feature, showBrandLogos: false, onFeaturesUpdate };
|
||||
const onFeaturesUpdate = vi.fn<ChannelPluginPanelProps["onFeaturesUpdate"]>();
|
||||
const props = {
|
||||
token: "tok", feature, actionKey: null, showBrandLogos: false,
|
||||
onAction: vi.fn<ChannelPluginPanelProps["onAction"]>(), onFeaturesUpdate,
|
||||
} satisfies ChannelPluginPanelProps;
|
||||
const view = render(<FeishuAssistantsPanel {...props} />);
|
||||
requestMutation.mockResolvedValueOnce({
|
||||
session_id: "add-1", status: "pending", qr_url: "https://example.com/authorize",
|
||||
@@ -59,7 +63,7 @@ describe("channel QR connect parameters", () => {
|
||||
}, 150_000);
|
||||
expect(screen.getByText("First assistant")).toBeVisible();
|
||||
requestMutation.mockResolvedValueOnce({ session_id: "add-1", status: "cancelled" });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
await screen.findByRole("button", { name: "Add another assistant" });
|
||||
expect(requestMutation).toHaveBeenLastCalledWith("settings.channel.connect.cancel", {
|
||||
channel: "feishu", session_id: "add-1",
|
||||
@@ -84,13 +88,13 @@ describe("channel QR connect parameters", () => {
|
||||
});
|
||||
|
||||
it.each([false, true])("keeps QR generation enabled by default (minimal=%s)", async (minimalPending) => {
|
||||
const generateQr = vi.spyOn(QRCode, "toDataURL").mockResolvedValue("data:image/png;base64,preview");
|
||||
const generateQr = vi.spyOn(QRCode, "toDataURL").mockImplementation(async () => "data:image/png;base64,preview");
|
||||
requestMutation.mockResolvedValueOnce({
|
||||
session_id: "qr-session", status: "pending", qr_url: "https://example.com/connect",
|
||||
});
|
||||
render(<ChannelQrConnectFlow token="tok" channelName="plugin-chat" labels={labels}
|
||||
minimalPending={minimalPending} onFeaturesUpdate={vi.fn()} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
|
||||
expect(await screen.findByRole("img", { name: "Connection QR code" })).toHaveAttribute("src", "data:image/png;base64,preview");
|
||||
expect(generateQr).toHaveBeenCalledOnce();
|
||||
});
|
||||
@@ -103,14 +107,14 @@ describe("channel QR connect parameters", () => {
|
||||
render(<ChannelQrConnectFlow token="tok" channelName="plugin-chat" showQrCode={false}
|
||||
labels={{ ...labels, scanTitle: "Authorize in browser", scanDescription: "Continue in the browser." }}
|
||||
onFeaturesUpdate={vi.fn()} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
|
||||
expect(await screen.findByText("Continue in the browser.")).toBeVisible();
|
||||
expect(screen.getByText("Waiting")).toBeVisible();
|
||||
expect(generateQr).not.toHaveBeenCalled();
|
||||
expect(screen.queryByRole("img")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("Authorize in browser").parentElement?.parentElement)
|
||||
.not.toHaveClass("sm:grid-cols-[auto_minmax(0,1fr)]");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
expect(await screen.findByText("Stopped")).toBeVisible();
|
||||
expect(requestMutation).toHaveBeenLastCalledWith("settings.channel.connect.cancel", {
|
||||
channel: "plugin-chat", session_id: "browser-session",
|
||||
@@ -118,7 +122,7 @@ describe("channel QR connect parameters", () => {
|
||||
});
|
||||
|
||||
it("polls browser-only authorization to completion without generating QR", async () => {
|
||||
const generateQr = vi.spyOn(QRCode, "toDataURL").mockResolvedValue("data:image/png;base64,unused");
|
||||
const generateQr = vi.spyOn(QRCode, "toDataURL").mockImplementation(async () => "data:image/png;base64,unused");
|
||||
const onFeaturesUpdate = vi.fn();
|
||||
const features = { features: [], enabled_count: 0 };
|
||||
requestMutation
|
||||
@@ -126,7 +130,7 @@ describe("channel QR connect parameters", () => {
|
||||
.mockResolvedValueOnce({ session_id: "browser-session", status: "succeeded", nanobot_features: features });
|
||||
render(<ChannelQrConnectFlow token="tok" channelName="plugin-chat" showQrCode={false}
|
||||
labels={labels} onFeaturesUpdate={onFeaturesUpdate} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
|
||||
expect(await screen.findByText("Connected", {}, { timeout: 2000 })).toBeVisible();
|
||||
expect(onFeaturesUpdate).toHaveBeenCalledWith(features);
|
||||
expect(requestMutation).toHaveBeenLastCalledWith("settings.channel.connect.poll", {
|
||||
|
||||
@@ -64,7 +64,7 @@ describe("sidebar action focus", () => {
|
||||
])("returns Escape focus to %s and allows continued tabbing", async (name) => {
|
||||
const user = userEvent.setup();
|
||||
render(<SidebarFocusCase />);
|
||||
const trigger = screen.getByRole("button", { name, exact: true });
|
||||
const trigger = screen.getByRole("button", { name });
|
||||
trigger.focus();
|
||||
await user.keyboard("{Enter}");
|
||||
await screen.findByRole("menu");
|
||||
@@ -84,7 +84,7 @@ describe("sidebar action focus", () => {
|
||||
await user.keyboard("{Enter}{Escape}");
|
||||
await waitFor(() => expect(trigger).toHaveFocus());
|
||||
await user.keyboard("{Enter}");
|
||||
await user.click(await screen.findByRole("menuitem", { name: "Rename", exact: true }));
|
||||
await user.click(await screen.findByRole("menuitem", { name: "Rename" }));
|
||||
const input = await screen.findByPlaceholderText("Topic name");
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
await waitFor(() => expect(input).toHaveFocus());
|
||||
@@ -92,7 +92,7 @@ describe("sidebar action focus", () => {
|
||||
expect(input).toHaveValue("Updated");
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
await user.keyboard("{Escape}");
|
||||
expect(screen.getByRole("button", { name: "Review", exact: true })).toHaveFocus();
|
||||
expect(screen.getByRole("button", { name: "Review" })).toHaveFocus();
|
||||
});
|
||||
|
||||
it("keeps an outside click focused on its destination", async () => {
|
||||
@@ -114,7 +114,7 @@ describe("sidebar action focus", () => {
|
||||
const trigger = screen.getByRole("button", { name: "Topic actions for Review" });
|
||||
trigger.focus();
|
||||
await user.keyboard("{Enter}");
|
||||
const move = await screen.findByRole("menuitem", { name: "Move to", exact: true });
|
||||
const move = await screen.findByRole("menuitem", { name: "Move to" });
|
||||
act(() => move.focus());
|
||||
await user.keyboard("{ArrowRight}");
|
||||
await screen.findByRole("menuitem", { name: "Group 2/4" });
|
||||
@@ -129,14 +129,14 @@ describe("sidebar action focus", () => {
|
||||
const trigger = screen.getByRole("button", { name: "Topic actions for Review" });
|
||||
trigger.focus();
|
||||
await user.keyboard("{Enter}");
|
||||
const move = await screen.findByRole("menuitem", { name: "Move to", exact: true });
|
||||
const move = await screen.findByRole("menuitem", { name: "Move to" });
|
||||
act(() => move.focus());
|
||||
await user.keyboard("{ArrowRight}");
|
||||
await screen.findByRole("menuitem", { name: "Group 2/4" });
|
||||
await user.keyboard("{ArrowLeft}");
|
||||
await waitFor(() => expect(move).toHaveFocus());
|
||||
expect(screen.queryByRole("menuitem", { name: "Group 2/4" })).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole("menuitem", { name: "Rename", exact: true }));
|
||||
await user.click(screen.getByRole("menuitem", { name: "Rename" }));
|
||||
const input = await screen.findByPlaceholderText("Topic name");
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(input).toHaveFocus();
|
||||
@@ -148,7 +148,7 @@ describe("sidebar action focus", () => {
|
||||
const trigger = screen.getByRole("button", { name: "Topic actions for Review" });
|
||||
trigger.focus();
|
||||
await user.keyboard("{Enter}");
|
||||
await user.click(await screen.findByRole("menuitem", { name: "Select", exact: true }));
|
||||
await user.click(await screen.findByRole("menuitem", { name: "Select" }));
|
||||
await waitFor(() => expect(trigger).not.toBeInTheDocument());
|
||||
expect(trigger).not.toHaveFocus();
|
||||
await user.keyboard("{Escape}");
|
||||
|
||||
@@ -49,13 +49,13 @@ function RenameCase({
|
||||
|
||||
async function startRename(contextMenu = false, title = "Review") {
|
||||
if (contextMenu) {
|
||||
fireEvent.contextMenu(screen.getByRole("button", { name: title, exact: true }));
|
||||
fireEvent.contextMenu(screen.getByRole("button", { name: title }));
|
||||
} else {
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: `Topic actions for ${title}` }), {
|
||||
button: 0, ctrlKey: false,
|
||||
});
|
||||
}
|
||||
fireEvent.click(await screen.findByRole("menuitem", { name: "Rename", exact: true }));
|
||||
fireEvent.click(await screen.findByRole("menuitem", { name: "Rename" }));
|
||||
return screen.getByRole("textbox", { name: "Topic name" });
|
||||
}
|
||||
|
||||
@@ -85,11 +85,11 @@ describe("inline sidebar topic rename", () => {
|
||||
expect(save).toHaveBeenCalledWith(topic.key, "Updated name");
|
||||
expect(input).toHaveAttribute("readonly");
|
||||
expect(input.closest("form")).toHaveAttribute("aria-busy", "true");
|
||||
expect(screen.queryByRole("button", { name: "Updated name", exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Updated name" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(onSelect).not.toHaveBeenCalled();
|
||||
await act(async () => { confirm(); });
|
||||
expect(await screen.findByRole("button", { name: "Updated name", exact: true })).toHaveFocus();
|
||||
expect(await screen.findByRole("button", { name: "Updated name" })).toHaveFocus();
|
||||
expect(screen.queryByRole("textbox")).not.toBeInTheDocument();
|
||||
expect(onSelect).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -108,7 +108,7 @@ describe("inline sidebar topic rename", () => {
|
||||
expect(current).toBeInTheDocument();
|
||||
expect(current).toHaveValue("Newer draft");
|
||||
fireEvent.keyDown(current, { key: "Escape" });
|
||||
expect(screen.getByRole("button", { name: "First saved title", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "First saved title" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("retains a failed draft and allows retrying the same name", async () => {
|
||||
@@ -121,8 +121,8 @@ describe("inline sidebar topic rename", () => {
|
||||
expect(input).toHaveValue(" Keep this draft ");
|
||||
expect(input).toHaveAttribute("aria-invalid", "true");
|
||||
expect(input).toHaveFocus();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save", exact: true }));
|
||||
expect(await screen.findByRole("button", { name: "Keep this draft", exact: true })).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
||||
expect(await screen.findByRole("button", { name: "Keep this draft" })).toBeInTheDocument();
|
||||
expect(save).toHaveBeenCalledTimes(2);
|
||||
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -136,7 +136,7 @@ describe("inline sidebar topic rename", () => {
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
await screen.findByRole("alert");
|
||||
fireEvent.keyDown(input, { key: "Escape" });
|
||||
expect(screen.getByRole("button", { name: "Review", exact: true })).toHaveFocus();
|
||||
expect(screen.getByRole("button", { name: "Review" })).toHaveFocus();
|
||||
expect(screen.queryByRole("textbox")).not.toBeInTheDocument();
|
||||
expect(save).toHaveBeenCalledTimes(1);
|
||||
expect(onSelect).not.toHaveBeenCalled();
|
||||
@@ -148,7 +148,7 @@ describe("inline sidebar topic rename", () => {
|
||||
const input = await startRename();
|
||||
fireEvent.change(input, { target: { value: " " } });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
expect(screen.getByRole("button", { name: "Save", exact: true })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
|
||||
expect(save).not.toHaveBeenCalled();
|
||||
fireEvent.compositionStart(input);
|
||||
fireEvent.change(input, { target: { value: "新的话题" } });
|
||||
@@ -160,7 +160,7 @@ describe("inline sidebar topic rename", () => {
|
||||
fireEvent.keyDown(input, { key: "Enter", keyCode: 229 });
|
||||
expect(save).not.toHaveBeenCalled();
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
expect(await screen.findByRole("button", { name: "新的话题", exact: true })).toBeInTheDocument();
|
||||
expect(await screen.findByRole("button", { name: "新的话题" })).toBeInTheDocument();
|
||||
expect(save).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
@@ -169,7 +169,7 @@ describe("inline sidebar topic rename", () => {
|
||||
const save = vi.fn().mockResolvedValue(undefined);
|
||||
render(<RenameCase save={save} />);
|
||||
await startRename();
|
||||
const cancel = screen.getByRole("button", { name: "Cancel", exact: true });
|
||||
const cancel = screen.getByRole("button", { name: "Cancel" });
|
||||
cancel.focus();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(screen.queryByRole("textbox")).not.toBeInTheDocument();
|
||||
|
||||
@@ -700,7 +700,7 @@ describe("ChatList", () => {
|
||||
);
|
||||
|
||||
const tabButton = screen.getByRole("button", { name: "Group: Root topic" });
|
||||
const tabGroup = tabButton.closest("[data-sidebar-tab-group]")!;
|
||||
const tabGroup = tabButton.closest<HTMLElement>("[data-sidebar-tab-group]")!;
|
||||
const tabHeader = tabButton.closest("[data-workbench-tab]")!;
|
||||
const tabSurface = tabButton.closest("[data-workbench-tab-surface]")!;
|
||||
expect(tabGroup).toHaveAttribute("data-sidebar-tab-group", "true");
|
||||
|
||||
@@ -25,7 +25,7 @@ class TestSocket {
|
||||
const CHAT_ID = "replay-ownership";
|
||||
const TURN_ID = "running-turn";
|
||||
const INITIAL_MESSAGES: UIMessage[] = [
|
||||
{ id: "prompt", role: "user", content: "Read the fixtures", turnId: TURN_ID },
|
||||
{ id: "prompt", role: "user", content: "Read the fixtures", turnId: TURN_ID, createdAt: 1_700_000_000_000 },
|
||||
];
|
||||
|
||||
function toolMessage(callId: string): InboundEvent {
|
||||
@@ -46,7 +46,10 @@ function Thread({ children }: { children?: ReactNode }) {
|
||||
|
||||
function displayedCalls(): string[] {
|
||||
const messages: UIMessage[] = JSON.parse(screen.getByTestId("messages").textContent!);
|
||||
return messages.flatMap((message) => message.toolEvents?.map((event) => event.call_id) ?? []);
|
||||
return messages.flatMap((message) => message.toolEvents?.map((event) => {
|
||||
if (event.call_id === undefined) throw new Error("Expected a transcript tool call id");
|
||||
return event.call_id;
|
||||
}) ?? []);
|
||||
}
|
||||
|
||||
afterEach(() => { vi.unstubAllGlobals(); });
|
||||
|
||||
@@ -48,9 +48,9 @@ it("finds a shared component by its name and renders its working variants", asyn
|
||||
await screen.findByRole("heading", { name: "Button · 按钮" });
|
||||
await userEvent.type(screen.getByRole("searchbox", { name: "Search components" }), "toggle-button");
|
||||
expect(screen.getByRole("link", { name: /toggle-button/ })).toHaveAttribute("href", expect.stringContaining("toggle-button"));
|
||||
await userEvent.click(screen.getByRole("button", { name: "destructive", exact: true }));
|
||||
await userEvent.click(screen.getByRole("button", { name: "destructive" }));
|
||||
expect(screen.getByText("Button clicks: 1")).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Unavailable", exact: true })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "Unavailable" })).toBeDisabled();
|
||||
});
|
||||
|
||||
it("lets the developer retry a failed inventory request", async () => {
|
||||
@@ -134,7 +134,7 @@ it("switches the chat list preview between ready, loading, empty and archived st
|
||||
const preview = within(screen.getByRole("region", { name: "Component preview" }));
|
||||
const setMode = async (mode: string) => {
|
||||
await userEvent.click(preview.getByRole("combobox", { name: "会话列表状态" }));
|
||||
await userEvent.click(screen.getByRole("option", { name: mode, exact: true }));
|
||||
await userEvent.click(screen.getByRole("option", { name: mode }));
|
||||
};
|
||||
|
||||
expect(preview.getByRole("button", { name: "@design 组件设计" })).toBeVisible();
|
||||
@@ -183,21 +183,21 @@ it("uses the real provider manager and saves a new provider entirely in preview
|
||||
const preview = within(screen.getByRole("region", { name: "Component preview" }));
|
||||
await userEvent.click(preview.getByRole("button", { name: "Manage providers" }));
|
||||
let dialog = within(screen.getByRole("dialog", { name: "Manage providers" }));
|
||||
expect(dialog.getByRole("button", { name: "Anthropic", exact: true })).toBeVisible();
|
||||
expect(dialog.getByRole("button", { name: "Anthropic" })).toBeVisible();
|
||||
expect(dialog.getByTestId("provider-logo-anthropic")).toBeVisible();
|
||||
expect(dialog.queryByRole("button", { name: "OpenAI", exact: true })).not.toBeInTheDocument();
|
||||
expect(dialog.queryByRole("button", { name: "OpenAI" })).not.toBeInTheDocument();
|
||||
|
||||
await userEvent.click(dialog.getByRole("button", { name: "Add provider", exact: true }));
|
||||
await userEvent.click(screen.getByRole("option", { name: "OpenAI", exact: true }));
|
||||
await userEvent.click(dialog.getByRole("button", { name: "Add provider" }));
|
||||
await userEvent.click(screen.getByRole("option", { name: "OpenAI" }));
|
||||
dialog = within(screen.getByRole("dialog", { name: "OpenAI" }));
|
||||
await userEvent.type(dialog.getByLabelText("API key", { selector: "input" }), "gallery-example-key");
|
||||
const apiURL = dialog.getByLabelText("API URL");
|
||||
await userEvent.clear(apiURL);
|
||||
await userEvent.type(apiURL, "https://preview.example/v1");
|
||||
await userEvent.click(dialog.getByRole("button", { name: "Add provider", exact: true }));
|
||||
await userEvent.click(dialog.getByRole("button", { name: "Add provider" }));
|
||||
|
||||
dialog = within(await screen.findByRole("dialog", { name: "Manage providers" }));
|
||||
await userEvent.click(dialog.getByRole("button", { name: "OpenAI", exact: true }));
|
||||
await userEvent.click(dialog.getByRole("button", { name: "OpenAI" }));
|
||||
expect(screen.getByLabelText("API URL")).toHaveValue("https://preview.example/v1");
|
||||
await userEvent.keyboard("{Escape}{Escape}");
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
@@ -216,13 +216,13 @@ it("renders a registered channel's real secret fields and enable action without
|
||||
const preview = within(screen.getByRole("region", { name: "Component preview" }));
|
||||
const token = preview.getByLabelText("Bot token", { selector: "input" });
|
||||
expect(token).toHaveAttribute("type", "password");
|
||||
await userEvent.click(preview.getByRole("switch", { name: "Enable channel", exact: true }));
|
||||
await userEvent.click(preview.getByRole("switch", { name: "Enable channel" }));
|
||||
expect(token).toHaveAttribute("aria-invalid", "true");
|
||||
expect(preview.getByRole("switch", { name: "Enable channel", exact: true })).not.toBeChecked();
|
||||
expect(preview.getByRole("switch", { name: "Enable channel" })).not.toBeChecked();
|
||||
await userEvent.type(token, "gallery-example-token");
|
||||
await userEvent.click(preview.getByRole("switch", { name: "Enable channel", exact: true }));
|
||||
expect(preview.getByRole("switch", { name: "Enable channel", exact: true })).toBeChecked();
|
||||
await userEvent.click(preview.getByRole("button", { name: "Advanced", exact: true }));
|
||||
await userEvent.click(preview.getByRole("switch", { name: "Enable channel" }));
|
||||
expect(preview.getByRole("switch", { name: "Enable channel" })).toBeChecked();
|
||||
await userEvent.click(preview.getByRole("button", { name: "Advanced" }));
|
||||
expect(preview.getByRole("group", { name: "Connection mode" })).toBeVisible();
|
||||
expect(preview.getByRole("radio", { name: "Long polling" })).toBeChecked();
|
||||
expect(fetch).toHaveBeenCalledTimes(1);
|
||||
|
||||
@@ -82,8 +82,10 @@ describe("FilePreviewPanel", () => {
|
||||
vi.mocked(fetchFilePreview).mockImplementation(async (_token, _session, path) => {
|
||||
const details = path.endsWith("details.md");
|
||||
const name = details ? "details.md" : "REPORT.md";
|
||||
const content = details ? "# Details\n\n[Return](./REPORT.md)\n" : report;
|
||||
return { path: `/workspace/reports/${name}`, display_path: `reports/${name}`,
|
||||
language: "markdown", content: details ? "# Details\n\n[Return](./REPORT.md)\n" : report, truncated: false };
|
||||
project_path: "/workspace", size: new TextEncoder().encode(content).byteLength,
|
||||
language: "markdown", content, truncated: false };
|
||||
});
|
||||
const store = new FilePreviewStore();
|
||||
const resource = createFilePreviewResource(path => fetchFilePreview("test", "a", path));
|
||||
@@ -118,7 +120,7 @@ describe("FilePreviewPanel", () => {
|
||||
it("opens the sidebar image in the shared zoomable viewer and returns to the preview", async () => {
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({
|
||||
kind: "image", path: "/workspace/chart.png", display_path: "chart.png",
|
||||
size: 42, mime_type: "image/png", data_url: "data:image/png;base64,example",
|
||||
project_path: "/workspace", size: 42, mime_type: "image/png", data_url: "data:image/png;base64,example",
|
||||
});
|
||||
render(<FilePreviewPanel sessionKey="websocket:a" path="chart.png" token="test" />);
|
||||
const trigger = await screen.findByRole("button", { name: "View image: chart.png" });
|
||||
@@ -139,6 +141,8 @@ describe("FilePreviewPanel", () => {
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({
|
||||
path: "/Users/hr/workspace/quicksort.py",
|
||||
display_path: "quicksort.py",
|
||||
project_path: "/Users/hr/workspace",
|
||||
size: 11,
|
||||
language: "python",
|
||||
content: "print('ok')",
|
||||
truncated: false,
|
||||
@@ -162,7 +166,7 @@ describe("FilePreviewPanel", () => {
|
||||
});
|
||||
|
||||
it("paints cached content immediately, revalidates it, and does not restart when the cache ages", async () => {
|
||||
const cached = { path: "notes.txt", display_path: "notes.txt", language: "text", content: "Cached", truncated: false };
|
||||
const cached = { path: "notes.txt", display_path: "notes.txt", project_path: "/workspace", size: 6, language: "text", content: "Cached", truncated: false };
|
||||
let resolve!: (payload: typeof cached) => void;
|
||||
const loadPreview = vi.fn(() => new Promise<typeof cached>(r => { resolve = r; }));
|
||||
const view = (initialPreview?: typeof cached) => <FilePreviewPanel sessionKey="a" path="notes.txt"
|
||||
@@ -178,7 +182,7 @@ describe("FilePreviewPanel", () => {
|
||||
});
|
||||
|
||||
it("reports a failed revalidation rather than leaving stale cached content looking current", async () => {
|
||||
const cached = { path: "notes.txt", display_path: "notes.txt", language: "text", content: "Cached", truncated: false };
|
||||
const cached = { path: "notes.txt", display_path: "notes.txt", project_path: "/workspace", size: 6, language: "text", content: "Cached", truncated: false };
|
||||
render(<FilePreviewPanel sessionKey="a" path="notes.txt" token="test" initialPreview={cached}
|
||||
loadPreview={vi.fn().mockRejectedValue(new Error("Forbidden"))} />);
|
||||
await screen.findByText("Could not preview this file.");
|
||||
@@ -186,7 +190,7 @@ describe("FilePreviewPanel", () => {
|
||||
});
|
||||
|
||||
it("does not repaint a cache hit twice after its initial synchronous paint", async () => {
|
||||
const cached = { path: "notes.txt", display_path: "notes.txt", language: "text", content: "Cached", truncated: false };
|
||||
const cached = { path: "notes.txt", display_path: "notes.txt", project_path: "/workspace", size: 6, language: "text", content: "Cached", truncated: false };
|
||||
const loadPreview = vi.fn().mockResolvedValue(cached);
|
||||
render(<FilePreviewPanel sessionKey="a" path="notes.txt" token="test"
|
||||
initialPreview={cached} loadPreview={loadPreview} />);
|
||||
@@ -199,6 +203,8 @@ describe("FilePreviewPanel", () => {
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({
|
||||
path: "/workspace/notes.md",
|
||||
display_path: "notes.md",
|
||||
project_path: "/workspace",
|
||||
size: 7,
|
||||
language: "markdown",
|
||||
content: "# Notes",
|
||||
truncated: false,
|
||||
@@ -227,6 +233,7 @@ describe("FilePreviewPanel", () => {
|
||||
it("defaults old Markdown payloads to preview and switches to exact source without another read", async () => {
|
||||
const content = "# Report\n\n**Done**\n\n| Item | Status |\n| --- | --- |\n| Copy | OK |\n";
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({ path: "/workspace/REPORT.md", display_path: "REPORT.md",
|
||||
project_path: "/workspace", size: new TextEncoder().encode(content).byteLength,
|
||||
language: "markdown", content, truncated: true });
|
||||
render(<FilePreviewPanel sessionKey="a" path="REPORT.md" token="test" />);
|
||||
await screen.findByRole("heading", { name: "Report" });
|
||||
@@ -250,7 +257,7 @@ describe("FilePreviewPanel", () => {
|
||||
|
||||
it("resets the display for another file or session but keeps source on credential renewal", async () => {
|
||||
const payload = { path: "/workspace/notes.md", display_path: "notes.md", language: "markdown",
|
||||
content: "# Notes", truncated: false };
|
||||
project_path: "/workspace", size: 7, content: "# Notes", truncated: false };
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue(payload);
|
||||
const view = (path: string, sessionKey = "a", token = "old") =>
|
||||
<FilePreviewPanel sessionKey={sessionKey} path={path} token={token} />;
|
||||
@@ -270,14 +277,16 @@ describe("FilePreviewPanel", () => {
|
||||
|
||||
it("keeps document resources inert and opens relative links through the session preview callback", async () => {
|
||||
const open = vi.fn();
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({ path: "/workspace/reports/REPORT.mdx", display_path: "reports/REPORT.mdx",
|
||||
language: "markdown", truncated: false, content: [
|
||||
const content = [
|
||||
"# Report", "[Local](../notes%20one.md)", "",
|
||||
"- Reference — [Website](https://example.com)", "[Section](#details)", "[Chat](#/chat/websocket:other)",
|
||||
"[Unsafe](javascript:alert(1))", '<img src="https://example.com/raw.png" onerror="alert(1)">',
|
||||
'<iframe src="https://example.com/frame"></iframe>', '<script>alert(1)</script>',
|
||||
"`skills/cron/SKILL.md`", "<CustomComponent />",
|
||||
].join("\n\n") });
|
||||
].join("\n\n");
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({ path: "/workspace/reports/REPORT.mdx", display_path: "reports/REPORT.mdx",
|
||||
project_path: "/workspace", size: new TextEncoder().encode(content).byteLength,
|
||||
language: "markdown", truncated: false, content });
|
||||
const { container } = render(<FilePreviewPanel sessionKey="a" path="reports/REPORT.mdx" token="test" onOpenFilePreview={open} />);
|
||||
await screen.findByRole("heading", { name: "Report" });
|
||||
expect(container.querySelector("img, iframe, script, video, audio")).toBeNull();
|
||||
@@ -294,7 +303,7 @@ describe("FilePreviewPanel", () => {
|
||||
it("preserves the open image and zoom on token renewal, using the current token for the next file", async () => {
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({
|
||||
kind: "image", path: "/workspace/chart.png", display_path: "chart.png",
|
||||
size: 42, mime_type: "image/png", data_url: "data:image/png;base64,example",
|
||||
project_path: "/workspace", size: 42, mime_type: "image/png", data_url: "data:image/png;base64,example",
|
||||
});
|
||||
const view = (token: string, path = "chart.png") =>
|
||||
<FilePreviewPanel sessionKey="websocket:a" path={path} token={token} />;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { createFilePreviewResource } from "@/lib/file-preview-resource";
|
||||
import type { FilePreviewPayload } from "@/lib/types";
|
||||
|
||||
const payload: FilePreviewPayload = { path: "notes.txt", display_path: "notes.txt", content: "One", language: "text", truncated: false };
|
||||
const payload: FilePreviewPayload = { path: "notes.txt", display_path: "notes.txt", project_path: "/workspace", size: 3, content: "One", language: "text", truncated: false };
|
||||
|
||||
afterEach(() => vi.useRealTimers());
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ vi.mock("@/lib/remote-instances", async (original) => ({
|
||||
...await original<typeof import("@/lib/remote-instances")>(), readRemoteInstances: mocks.read,
|
||||
}));
|
||||
const ids = Array.from({ length: 4 }, (_, i) => `3b968d52-081d-4898-9970-ff0a1fc9381${i}`);
|
||||
const connections: RemoteConnection[] = ids.map((id, i) => ({ id, name: `Server ${i}`, hostname: `host-${i}`,
|
||||
gateway_id: `gateway-${i}`, url: `http://127.0.0.1:${24000 + i}/#/?bootstrapSecret=secret` }));
|
||||
const connections: RemoteConnection[] = ids.map((id, i) => ({ id, name: `Server ${i}`, host: `host-${i}`, hostname: `host-${i}`,
|
||||
config_path: "/home/test/.nanobot/config.json", gateway_id: `gateway-${i}`, url: `http://127.0.0.1:${24000 + i}/#/?bootstrapSecret=secret` }));
|
||||
const directory = { available: true, profiles: connections.map((item) => ({ ...item, connected: true })) };
|
||||
const deferred = <T,>() => {
|
||||
let resolve!: (value: T) => void;
|
||||
|
||||
@@ -59,7 +59,7 @@ async function openReset() {
|
||||
fireEvent.click(screen.getByRole("button", { name: "Reset Linear connection" }));
|
||||
const dialog = await screen.findByRole("alertdialog");
|
||||
return { dialog, onWorkspaceRemoved, onWorkspacesChange,
|
||||
confirm: () => fireEvent.click(within(dialog).getByRole("button", { name: "Reset", exact: true })) };
|
||||
confirm: () => fireEvent.click(within(dialog).getByRole("button", { name: "Reset" })) };
|
||||
}
|
||||
|
||||
describe("reset Linear connection", () => {
|
||||
@@ -79,7 +79,7 @@ describe("reset Linear connection", () => {
|
||||
expect(within(dialog).getByText("Keeps").tagName).toBe("DT");
|
||||
expect(within(dialog).getByText("Member access settings and this instance’s app configuration, including saved credentials.").tagName).toBe("DD");
|
||||
expect(within(dialog).getByRole("button", { name: "Cancel" })).toHaveFocus();
|
||||
expect(within(dialog).getByRole("button", { name: "Reset", exact: true })).toBeEnabled();
|
||||
expect(within(dialog).getByRole("button", { name: "Reset" })).toBeEnabled();
|
||||
});
|
||||
|
||||
it("inspects fresh installations, revokes each, stops the channel, then clears settings", async () => {
|
||||
|
||||
@@ -30,7 +30,7 @@ describe("Linear saved secret", () => {
|
||||
expect(input).toHaveAttribute("placeholder", "Enter secret");
|
||||
expect(screen.queryByText("Saved")).not.toBeInTheDocument();
|
||||
fireEvent.change(input, { target: { value: " " } });
|
||||
expect(screen.getByRole("button", { name: "Save", exact: true })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
expect(onSave).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -79,12 +79,12 @@ describe("Linear saved secret", () => {
|
||||
setup(onSave);
|
||||
const input = edit();
|
||||
fireEvent.change(input, { target: { value: "new-draft" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
||||
expect(await screen.findByRole("alert")).toHaveTextContent("Could not confirm the save");
|
||||
expect(screen.getByRole("alert")).not.toHaveTextContent("new-draft");
|
||||
expect(input).toHaveAccessibleDescription(/Could not confirm/);
|
||||
expect(input).toHaveValue("new-draft");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(screen.getByRole("status")).toHaveTextContent("Saved"));
|
||||
expect(onSave).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ describe("service worker registration in main entry", () => {
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
delete (navigator as Navigator & { serviceWorker?: unknown }).serviceWorker;
|
||||
Reflect.deleteProperty(navigator, "serviceWorker");
|
||||
});
|
||||
|
||||
it("registers /sw.js with updateViaCache none only after window load", async () => {
|
||||
|
||||
@@ -20,7 +20,7 @@ describe("main entry crypto shim", () => {
|
||||
createRoot.mockClear();
|
||||
render.mockClear();
|
||||
document.body.innerHTML = '<div id="root"></div>';
|
||||
delete (globalThis.crypto as Crypto & { randomUUID?: Crypto["randomUUID"] }).randomUUID;
|
||||
Reflect.deleteProperty(globalThis.crypto, "randomUUID");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -787,6 +787,7 @@ describe("MessageBubble", () => {
|
||||
id: "saved-app-name",
|
||||
role: "user",
|
||||
content: `Use @${name} please`,
|
||||
createdAt: 1,
|
||||
...(kind === "cli" ? {
|
||||
cliApps: [{ name, display_name: displayName, category: "test", entry_point: name }],
|
||||
} : {
|
||||
@@ -808,12 +809,12 @@ describe("MessageBubble", () => {
|
||||
const copy = vi.spyOn(clipboard, "copyTextToClipboard").mockResolvedValue(true);
|
||||
try {
|
||||
render(<ThreadMessages messages={[{
|
||||
id: "copy-display-name", role: "user", content: "Please use @drawio",
|
||||
id: "copy-display-name", role: "user", content: "Please use @drawio", createdAt: 1,
|
||||
cliApps: [{ name: "drawio", display_name: "Draw.io", category: "diagram", entry_point: "drawio" }],
|
||||
}]} />);
|
||||
expect(screen.getByTestId("message-cli-mention-drawio")).toHaveTextContent("@Draw.io");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Message actions" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Copy", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Copy" }));
|
||||
await waitFor(() => expect(copy).toHaveBeenCalledWith("Please use @drawio"));
|
||||
} finally {
|
||||
copy.mockRestore();
|
||||
|
||||
@@ -525,9 +525,9 @@ describe("NanobotClient", () => {
|
||||
});
|
||||
|
||||
it("uses the host socket bridge for native host URLs", async () => {
|
||||
let socketEventHandler:
|
||||
| ((event: { id: string; type: "open" | "close" | "error"; message?: string }) => void)
|
||||
| null = null;
|
||||
const socketEvents: {
|
||||
handler?: (event: { id: string; type: "open" | "close" | "error"; message?: string }) => void;
|
||||
} = {};
|
||||
const openSocket = vi.fn(async () => "host-socket-1");
|
||||
Object.defineProperty(window, "nanobotHost", {
|
||||
configurable: true,
|
||||
@@ -536,7 +536,7 @@ describe("NanobotClient", () => {
|
||||
sendSocket: vi.fn(async () => undefined),
|
||||
closeSocket: vi.fn(async () => undefined),
|
||||
onSocketEvent: vi.fn((handler) => {
|
||||
socketEventHandler = handler;
|
||||
socketEvents.handler = handler;
|
||||
return vi.fn();
|
||||
}),
|
||||
},
|
||||
@@ -550,7 +550,7 @@ describe("NanobotClient", () => {
|
||||
|
||||
client.connect();
|
||||
await Promise.resolve();
|
||||
socketEventHandler?.({ id: "host-socket-1", type: "open" });
|
||||
socketEvents.handler?.({ id: "host-socket-1", type: "open" });
|
||||
|
||||
expect(openSocket).toHaveBeenCalledWith("nanobot-host://engine/");
|
||||
expect(status).toHaveBeenLastCalledWith("open");
|
||||
@@ -1488,6 +1488,8 @@ describe("NanobotClient", () => {
|
||||
explicit: true,
|
||||
title: "Research",
|
||||
paneKeys: ["websocket:a", "websocket:b"],
|
||||
layoutPaneKeys: ["websocket:a", "websocket:b"],
|
||||
splitRatios: [0.5, 0.5],
|
||||
layout: "columns",
|
||||
},
|
||||
},
|
||||
@@ -2396,14 +2398,14 @@ describe("NanobotClient", () => {
|
||||
client.connect();
|
||||
lastSocket().fakeOpen();
|
||||
client.sendMessage("chat-x", "look", [
|
||||
{ data_url: "data:image/png;base64,AAAA", name: "shot.png" },
|
||||
{ reference: "uploaded-shot", name: "shot.png" },
|
||||
]);
|
||||
const lastFrame = JSON.parse(lastSocket().sent.at(-1) as string);
|
||||
expect(lastFrame).toEqual({
|
||||
type: "message",
|
||||
chat_id: "chat-x",
|
||||
content: "look",
|
||||
media: [{ data_url: "data:image/png;base64,AAAA", name: "shot.png" }],
|
||||
media: [{ reference: "uploaded-shot", name: "shot.png" }],
|
||||
webui: true,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,12 +20,12 @@ it.each([
|
||||
const dialog = screen.getByRole("dialog", { name: title });
|
||||
const editor = within(dialog).getByRole("textbox");
|
||||
fireEvent.change(editor, { target: { value: '{"X-Token":"••••••••"}' } });
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "保存", exact: true }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "保存" }));
|
||||
expect(await within(dialog).findByRole("alert")).toHaveTextContent("掩码没有对应的已保存密钥。请输入实际值,或删除该项。");
|
||||
expect(editor).toHaveValue('{"X-Token":"••••••••"}');
|
||||
expect(editor).toHaveFocus();
|
||||
fireEvent.change(editor, { target: { value: '{"X-Token":"fixture-value"}' } });
|
||||
await act(async () => { fireEvent.click(within(dialog).getByRole("button", { name: "保存", exact: true })); });
|
||||
await act(async () => { fireEvent.click(within(dialog).getByRole("button", { name: "保存" })); });
|
||||
expect(save).toHaveBeenLastCalledWith({ [formKey]: '{"X-Token":"fixture-value"}' });
|
||||
expect(screen.queryByRole("dialog", { name: title })).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -35,7 +35,7 @@ it("lets the gateway preserve an existing masked secret without rejecting it in
|
||||
const save = vi.fn().mockResolvedValue(undefined);
|
||||
render(<ProviderParameterFields inherit fields={["extra_headers"]} form={{ ...form, extraHeaders: masked }} onChange={vi.fn()} onSave={save} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Headers Entries: 1 Edit" }));
|
||||
await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Save", exact: true })); });
|
||||
await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Save" })); });
|
||||
expect(save).toHaveBeenCalledWith({ extraHeaders: masked });
|
||||
expect(screen.queryByRole("dialog", { name: "Headers" })).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -69,7 +69,7 @@ it("waits for persistence, keeps errors and drafts in place, and lets users canc
|
||||
const dialog = screen.getByRole("dialog", { name: "Body parameters" });
|
||||
const editor = within(dialog).getByRole("textbox");
|
||||
fireEvent.change(editor, { target: { value: '{"watermark":false}' } });
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||
expect(within(dialog).getByRole("button", { name: i18n.t("settings.actions.saving") })).toBeDisabled();
|
||||
expect(within(dialog).getByRole("button", { name: "Cancel" })).toBeDisabled();
|
||||
fireEvent.keyDown(editor, { key: "Escape" });
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
import postcss, { type Rule } from "postcss";
|
||||
import postcss, { type Document, type Rule } from "postcss";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const html = readFileSync(resolve(process.cwd(), "index.html"), "utf8");
|
||||
@@ -38,7 +38,7 @@ describe("iOS standalone status-bar surface", () => {
|
||||
const enabled = rules.filter((rule) => declarations(rule).display === "block");
|
||||
expect(enabled).toHaveLength(1);
|
||||
const conditions: Record<string, string> = {};
|
||||
for (let parent = enabled[0].parent; parent; parent = parent.parent) {
|
||||
for (let parent: Rule["parent"] | Document = enabled[0].parent; parent; parent = parent.parent) {
|
||||
if (parent.type === "atrule" && "name" in parent) conditions[parent.name] = parent.params;
|
||||
}
|
||||
expect(conditions.media).toBe("(display-mode: standalone)");
|
||||
|
||||
@@ -73,10 +73,10 @@ describe("quick pairing", () => {
|
||||
let finish!: (value: { id: string }) => void;
|
||||
mocks.action.mockImplementation(() => new Promise((resolve) => { finish = resolve; }));
|
||||
mocks.connect.mockRejectedValueOnce(new Error("ssh_connection_closed"));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
|
||||
act(() => { if (typeof expiry === "function") expiry(); });
|
||||
await act(async () => finish({ id: "paired-server" }));
|
||||
expect(await screen.findByRole("button", { name: "Retry", exact: true })).toBeEnabled();
|
||||
expect(await screen.findByRole("button", { name: "Retry" })).toBeEnabled();
|
||||
expect(screen.getByRole("heading", { name: "Open this nanobot?" })).toBeVisible();
|
||||
expect(screen.queryByRole("button", { name: "Get a new command" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -168,8 +168,8 @@ describe("remote instance UX", () => {
|
||||
origin: "http://127.0.0.1:23456", data: { channel: HOST_BRIDGE, type: "hello" } })));
|
||||
await openDirectory();
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Rename", exact: true }));
|
||||
const input = await screen.findByRole("textbox", { name: "Name", exact: true });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Rename" }));
|
||||
const input = await screen.findByRole("textbox", { name: "Name" });
|
||||
expect(input).toHaveValue("Team server");
|
||||
expect(input).toHaveAccessibleName("Name");
|
||||
expect(within(screen.getByRole("dialog")).queryByText("Name", { exact: true })).not.toBeInTheDocument();
|
||||
@@ -207,8 +207,8 @@ describe("remote instance UX", () => {
|
||||
it("rejects a blank name, preserves input on failure and lets the user retry or cancel", async () => {
|
||||
view(); await openDirectory();
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Rename", exact: true }));
|
||||
const input = await screen.findByRole("textbox", { name: "Name", exact: true });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Rename" }));
|
||||
const input = await screen.findByRole("textbox", { name: "Name" });
|
||||
fireEvent.change(input, { target: { value: " " } });
|
||||
expect(screen.getByRole("button", { name: "Save changes" })).toBeDisabled();
|
||||
fireEvent.submit(input.closest("form")!);
|
||||
@@ -220,7 +220,7 @@ describe("remote instance UX", () => {
|
||||
expect(input).toHaveAccessibleDescription(i18n.t("remote.errors.local_io_error"));
|
||||
expect(input).toHaveValue("Cloud");
|
||||
expect(screen.getByRole("button", { name: "Save changes" })).toBeEnabled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
expect(screen.getByRole("button", { name: "Manage Team server" })).toBeVisible();
|
||||
expect(mocks.request).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
@@ -231,8 +231,8 @@ describe("remote instance UX", () => {
|
||||
mocks.request.mockResolvedValue({ available: true, profiles: siblings.map((item) => ({ ...item, name: "Cloud" })) });
|
||||
view(); await openDirectory();
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Rename", exact: true }));
|
||||
fireEvent.change(await screen.findByRole("textbox", { name: "Name", exact: true }), { target: { value: "Cloud" } });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Rename" }));
|
||||
fireEvent.change(await screen.findByRole("textbox", { name: "Name" }), { target: { value: "Cloud" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save changes" }));
|
||||
await screen.findByRole("button", { name: "Manage Cloud" });
|
||||
expect(screen.getAllByRole("button", { name: "Cloud ubuntu@example.test" })).toHaveLength(1);
|
||||
@@ -253,7 +253,7 @@ describe("remote instance UX", () => {
|
||||
expect(await within(dialog).findByRole("button", { name: "Copied" })).toBeVisible();
|
||||
expect(copy).toHaveBeenCalledWith(command);
|
||||
expect(mocks.request).not.toHaveBeenCalled();
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Cancel", exact: true }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Cancel" }));
|
||||
expect(mocks.request).not.toHaveBeenCalled();
|
||||
});
|
||||
it("shows one verified instance in management and the switcher while retaining both grants in details", async () => {
|
||||
@@ -270,12 +270,12 @@ describe("remote instance UX", () => {
|
||||
fireEvent.pointerDown(within(details).getByRole("button", { name: "Manage connection 1" }), { button: 0, ctrlKey: false });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Forget connection" }));
|
||||
expect(await screen.findByRole("dialog", { name: "Forget this connection?" })).toHaveTextContent(i18n.t("remote.sameInstance.forgetHint"));
|
||||
expect(screen.getByRole("button", { name: "Forget", exact: true })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Forget", exact: true }).firstElementChild).not.toHaveClass("truncate");
|
||||
expect(screen.queryByRole("button", { name: "Remove connection", exact: true })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
|
||||
expect(screen.getByRole("button", { name: "Forget" })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Forget" }).firstElementChild).not.toHaveClass("truncate");
|
||||
expect(screen.queryByRole("button", { name: "Remove connection" })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
expect(mocks.request).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back" }));
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Switch host" }), { button: 0, ctrlKey: false });
|
||||
expect(await screen.findAllByRole("menuitem", { name: "Team server ubuntu@example.test" })).toHaveLength(1);
|
||||
});
|
||||
@@ -321,7 +321,7 @@ describe("remote instance UX", () => {
|
||||
expect(readSelectedRemote()?.id).toBe(profile.id);
|
||||
expect(window.location.hash).toBe(originalHash);
|
||||
expect(document.title).toBe(originalTitle);
|
||||
fireEvent.click(within(panel).getByRole("button", { name: "Back", exact: true }));
|
||||
fireEvent.click(within(panel).getByRole("button", { name: "Back" }));
|
||||
await waitFor(() => expect(panel).not.toBeInTheDocument());
|
||||
expect(screen.getByTitle("nanobot on Team server")).toBe(frame);
|
||||
expect(frame).toBeVisible();
|
||||
@@ -337,7 +337,7 @@ describe("remote instance UX", () => {
|
||||
fireEvent.change(draft, { target: { value: "Keep this unsent draft" } });
|
||||
await openDirectory();
|
||||
expect(screen.queryByRole("textbox", { name: "Local draft" })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back" }));
|
||||
await waitFor(() => expect(screen.queryByRole("region", { name: "Remote connections" })).not.toBeInTheDocument());
|
||||
expect(screen.getByRole("textbox", { name: "Local draft" })).toBe(draft);
|
||||
expect(draft).toHaveValue("Keep this unsent draft");
|
||||
@@ -351,7 +351,7 @@ describe("remote instance UX", () => {
|
||||
view();
|
||||
await chooseHost("Team server ubuntu@example.test");
|
||||
await openDirectory();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back" }));
|
||||
await act(async () => finish(connection));
|
||||
const frame = await readyRemote();
|
||||
expect(frame).toBeVisible();
|
||||
@@ -381,7 +381,7 @@ describe("remote instance UX", () => {
|
||||
const frame = await readyRemote();
|
||||
expect(frame).not.toBeVisible();
|
||||
expect(screen.getByRole("region", { name: "Remote connections" })).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back" }));
|
||||
expect(frame).toBeVisible();
|
||||
expect(readSelectedRemote()?.id).toBe(profile.id);
|
||||
});
|
||||
@@ -410,7 +410,7 @@ describe("remote instance UX", () => {
|
||||
const row = screen.getByRole("button", { name: "Team server ubuntu@example.test" });
|
||||
expect(row).not.toHaveAttribute("aria-current");
|
||||
expect(within(row).getByRole("status")).toHaveTextContent(label);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back" }));
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Switch host" }), { button: 0, ctrlKey: false });
|
||||
const item = await screen.findByRole("menuitem", { name: "Team server ubuntu@example.test" });
|
||||
expect(within(item).getByRole("status")).toHaveTextContent(label);
|
||||
@@ -1153,7 +1153,7 @@ describe("remote instance UX", () => {
|
||||
mocks.request.mockImplementation(() => new Promise<RemoteConnection>((resolve) => { finish = resolve; }));
|
||||
view(); await openDirectory();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Team server ubuntu@example.test" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back" }));
|
||||
await act(async () => { finish?.(connection); });
|
||||
expect(screen.getByText("Local conversations")).toBeVisible();
|
||||
expect(screen.queryByTitle("nanobot on Team server")).not.toBeInTheDocument();
|
||||
@@ -1170,7 +1170,7 @@ describe("remote instance UX", () => {
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "SSH address" }), { target: { value: "ubuntu@example.test" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back" }));
|
||||
await act(async () => { finish?.({ id: profile.id }); });
|
||||
expect(mocks.request).toHaveBeenCalledTimes(1);
|
||||
expect(screen.getByText("Local conversations")).toBeVisible();
|
||||
@@ -1312,7 +1312,13 @@ describe("remote instance UX", () => {
|
||||
|
||||
it("tolerates transient health failures and covers, rather than reloads, the remote frame", async () => {
|
||||
let tick: (() => void) | undefined;
|
||||
vi.spyOn(window, "setInterval").mockImplementation((callback, delay) => { if (delay === 5_000) tick = callback as () => void; return 1; });
|
||||
const setInterval = globalThis.setInterval;
|
||||
vi.spyOn(window, "setInterval").mockImplementation((callback, delay) => {
|
||||
if (delay === 5_000) tick = callback;
|
||||
const timer = setInterval(callback, delay);
|
||||
globalThis.clearInterval(timer);
|
||||
return timer;
|
||||
});
|
||||
view(); await openDirectory();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Team server ubuntu@example.test" }));
|
||||
const frame = await readyRemote();
|
||||
|
||||
@@ -167,10 +167,10 @@ describe("SessionInfoPopover", () => {
|
||||
|
||||
await user.click(screen.getByRole("button", { name: "Session details" }));
|
||||
await user.click(await screen.findByRole("button", { name: /Morning check/ }));
|
||||
await user.click(screen.getByRole("button", { name: "Edit", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Edit" }));
|
||||
const editor = await screen.findByRole("dialog", { name: "Edit task" });
|
||||
expect(screen.getAllByRole("dialog")).toHaveLength(1);
|
||||
await user.click(within(editor).getByRole("button", { name: "Cancel", exact: true }));
|
||||
await user.click(within(editor).getByRole("button", { name: "Cancel" }));
|
||||
|
||||
expect(await screen.findByRole("dialog", { name: "Morning check" })).toBeVisible();
|
||||
expect(screen.getAllByRole("dialog")).toHaveLength(1);
|
||||
|
||||
@@ -24,16 +24,16 @@ describe("Settings capabilities", () => {
|
||||
}));
|
||||
requestMutationMock.mockRejectedValueOnce(new Error("Could not save. Try again."));
|
||||
renderSettingsView({ initialSection: "image", initialSettings: payload });
|
||||
expect(screen.getByRole("combobox", { name: "SenseNova", exact: true })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Provider", exact: true })).toBeVisible();
|
||||
expect(screen.getByRole("combobox", { name: "SenseNova" })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Provider" })).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Body parameters Use provider settings Edit" }));
|
||||
const editor = screen.getByRole("dialog", { name: "Body parameters" });
|
||||
fireEvent.change(within(editor).getByRole("textbox", { name: "Body parameters" }), { target: { value: '{"watermark":false}' } });
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save" }));
|
||||
expect(await within(editor).findByRole("alert")).toHaveTextContent("Could not save. Try again.");
|
||||
expect(within(editor).getByRole("textbox")).toHaveValue('{"watermark":false}');
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.image_generation.update",
|
||||
expect.objectContaining({ provider: "custom-sensenova", extra_body: '{"watermark":false}' }),
|
||||
@@ -64,7 +64,7 @@ describe("Settings capabilities", () => {
|
||||
fireEvent.click(within(screen.getByRole("region", { name })).getByRole("button", { name: "Configure" }));
|
||||
const dialog = screen.getByRole("dialog", { name });
|
||||
expect(within(dialog).getAllByRole("combobox").length).toBeGreaterThan(0);
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Close" }));
|
||||
expect(screen.getByRole("switch", { name })).not.toBeChecked();
|
||||
}
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
@@ -119,7 +119,7 @@ describe("Settings capabilities", () => {
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Image generation" }));
|
||||
const image = within(screen.getByRole("dialog", { name: "Image generation" }));
|
||||
await waitFor(() => expect(image.getByRole("alert")).toHaveTextContent("Configure this provider before enabling image generation."));
|
||||
fireEvent.click(image.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(image.getByRole("button", { name: "Close" }));
|
||||
expect(screen.getByRole("region", { name: "Image generation" })).toContainElement(screen.getByRole("alert"));
|
||||
expect(screen.getAllByRole("alert")).toHaveLength(1);
|
||||
});
|
||||
@@ -131,13 +131,13 @@ describe("Settings capabilities", () => {
|
||||
payload.runtime_config = { "tools.web.enable": true, "agents.defaults.dream.enabled": true };
|
||||
renderSettingsView({ initialSection: "capabilities", initialSettings: payload });
|
||||
expect(screen.getAllByRole("switch")).toHaveLength(4);
|
||||
expect(screen.getByRole("button", { name: "Capabilities", exact: true })).toHaveAttribute("aria-current", "page");
|
||||
const editor = screen.getByRole("button", { name: "Image generation", exact: true });
|
||||
expect(screen.getByRole("button", { name: "Capabilities" })).toHaveAttribute("aria-current", "page");
|
||||
const editor = screen.getByRole("button", { name: "Image generation" });
|
||||
expect(editor).toHaveAttribute("aria-expanded", "false");
|
||||
fireEvent.click(editor);
|
||||
expect(editor).toHaveAttribute("aria-expanded", "true");
|
||||
expect(screen.getByRole("combobox", { name: "OpenRouter", exact: true })).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
expect(screen.getByRole("combobox", { name: "OpenRouter" })).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
expect(screen.getByRole("switch", { name: "Image generation" })).toBeChecked();
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -159,7 +159,7 @@ describe("Settings capabilities", () => {
|
||||
"settings.image_generation.update", expect.objectContaining({ enabled: true }), 20_000,
|
||||
));
|
||||
expect(await screen.findByText("Saved. Restart to apply changes.")).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Image generation" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
|
||||
"settings.image_generation.update", expect.objectContaining({
|
||||
@@ -309,7 +309,7 @@ describe("Settings capabilities", () => {
|
||||
renderSettingsView({ initialSection: "capabilities", initialSettings: payload });
|
||||
fireEvent.click(within(screen.getByRole("region", { name: "Web access" })).getByRole("button", { name: "Configure" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
const proxy = screen.getByRole("textbox", { name: "Web proxy", exact: true });
|
||||
const proxy = screen.getByRole("textbox", { name: "Web proxy" });
|
||||
expect(proxy).toHaveValue("http://old-proxy.example:8080");
|
||||
fireEvent.change(proxy, { target: { value: "http://new-proxy.example:7890" } });
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
@@ -320,10 +320,10 @@ describe("Settings capabilities", () => {
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
|
||||
"settings.runtime_config.update", { values: { "tools.web.proxy": null } }, 20_000,
|
||||
));
|
||||
fireEvent.click(within(screen.getByRole("dialog", { name: "Web access" })).getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(within(screen.getByRole("dialog", { name: "Web access" })).getByRole("button", { name: "Close" }));
|
||||
expect(screen.getByRole("switch", { name: "Web access" })).not.toBeChecked();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced", exact: true }));
|
||||
expect(screen.queryByRole("textbox", { name: "Web proxy", exact: true })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced" }));
|
||||
expect(screen.queryByRole("textbox", { name: "Web proxy" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("saves optional-key web search providers without an API key", async () => {
|
||||
|
||||
@@ -1467,7 +1467,7 @@ describe("Settings channels", () => {
|
||||
expect(screen.getByRole("dialog")).toHaveFocus();
|
||||
expect(within(screen.getByRole("dialog")).getByRole("heading", { name: "Email" })).toBeVisible();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
|
||||
expect(screen.getByRole("button", { name: "View Email settings" })).toBeInTheDocument();
|
||||
});
|
||||
@@ -1542,7 +1542,7 @@ describe("Settings channels", () => {
|
||||
renderSettingsView({ initialSection: "channels" });
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: "View Discord settings" }));
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Help", exact: true }), { button: 0, ctrlKey: false });
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Help" }), { button: 0, ctrlKey: false });
|
||||
expect(await screen.findByRole("menuitem", { name: "Open Discord setup" })).toHaveAttribute(
|
||||
"href",
|
||||
"https://nanobot.wiki/docs/0.2.2/getting-started/chat-apps#discord",
|
||||
@@ -1560,7 +1560,7 @@ describe("Settings channels", () => {
|
||||
"radio",
|
||||
{ name: "All messages" },
|
||||
));
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Enable channel", exact: true }));
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Enable channel" }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
@@ -1677,7 +1677,7 @@ describe("Settings channels", () => {
|
||||
const granted = within(consentGroup).getByRole("radio", { name: "Granted" });
|
||||
expect(notGranted).toBeChecked();
|
||||
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Enable channel", exact: true }));
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Enable channel" }));
|
||||
|
||||
await waitFor(() => expect(granted).toHaveFocus());
|
||||
expect(consentGroup).toHaveAttribute("aria-invalid", "true");
|
||||
@@ -1694,7 +1694,7 @@ describe("Settings channels", () => {
|
||||
expect(notGranted).toHaveAttribute("aria-invalid", "false");
|
||||
expect(granted).toHaveAttribute("aria-invalid", "false");
|
||||
expect(screen.queryByText("Required to complete setup.")).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Enable channel", exact: true }));
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Enable channel" }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
@@ -1779,7 +1779,7 @@ describe("Settings channels", () => {
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: "View Email settings" }));
|
||||
const dialog = screen.getByRole("dialog");
|
||||
expect(within(dialog).queryByRole("button", { name: "Save", exact: true })).not.toBeInTheDocument();
|
||||
expect(within(dialog).queryByRole("button", { name: "Save" })).not.toBeInTheDocument();
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Advanced" }));
|
||||
expect(within(dialog).queryByRole("button", { name: "Gmail" })).not.toBeInTheDocument();
|
||||
fireEvent.change(screen.getByLabelText("IMAP host"), {
|
||||
@@ -1798,7 +1798,7 @@ describe("Settings channels", () => {
|
||||
));
|
||||
expect(within(dialog).getByText("Saving")).toBeVisible();
|
||||
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Close" }));
|
||||
expect(screen.getByRole("dialog")).toBeInTheDocument();
|
||||
|
||||
await act(async () => {
|
||||
@@ -1885,7 +1885,7 @@ describe("Settings channels", () => {
|
||||
{ name: "All messages" },
|
||||
)).toBeChecked();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
fireEvent.click(screen.getByLabelText("Discord channel"));
|
||||
await waitFor(() =>
|
||||
expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
@@ -1928,7 +1928,7 @@ describe("Settings channels", () => {
|
||||
renderSettingsView({ initialSection: "channels" });
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: "View Telegram settings" }));
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Help", exact: true }), { button: 0, ctrlKey: false });
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Help" }), { button: 0, ctrlKey: false });
|
||||
expect(await screen.findByRole("menuitem", { name: "Open Telegram setup" })).toHaveAttribute(
|
||||
"href",
|
||||
"https://nanobot.wiki/docs/0.2.2/getting-started/chat-apps#telegram",
|
||||
@@ -1969,14 +1969,14 @@ describe("Settings channels", () => {
|
||||
display_name: displayName,
|
||||
webui: ["feishu", "weixin", "whatsapp"].includes(name) ? "webui/index.tsx" : "webui/index.ts",
|
||||
type: "channel",
|
||||
enabled: name === "websocket",
|
||||
enabled: false,
|
||||
installed: true,
|
||||
ready: name === "websocket",
|
||||
status: name === "websocket" ? "enabled" : "not_enabled",
|
||||
ready: false,
|
||||
status: "not_enabled",
|
||||
install_supported: true,
|
||||
requires_restart: true,
|
||||
})),
|
||||
enabled_count: 1,
|
||||
enabled_count: 0,
|
||||
});
|
||||
}
|
||||
return { ok: false, status: 404, json: async () => ({}) } as Response;
|
||||
@@ -1987,11 +1987,11 @@ describe("Settings channels", () => {
|
||||
|
||||
for (const [, displayName, guideLabel] of channels) {
|
||||
fireEvent.click(await screen.findByRole("button", { name: `View ${displayName} settings` }));
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Help", exact: true }), { button: 0, ctrlKey: false });
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Help" }), { button: 0, ctrlKey: false });
|
||||
const guide = await screen.findByRole("menuitem", { name: guideLabel });
|
||||
expect(guide).toHaveAttribute("href", expect.stringMatching(/^https:\/\//));
|
||||
fireEvent.keyDown(screen.getByRole("menu"), { key: "Escape" });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2032,14 +2032,14 @@ describe("Settings channels", () => {
|
||||
expect(within(consent).getByRole("radio", { name: "Not granted" })).toBeChecked();
|
||||
expect(within(consent).getByRole("radio", { name: "Granted" })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "View Feishu settings" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced" }));
|
||||
const region = screen.getByRole("group", { name: "Region" });
|
||||
expect(within(region).getByRole("radio", { name: "Feishu" })).toBeChecked();
|
||||
expect(within(region).getByRole("radio", { name: "Lark" })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "View Matrix settings" }));
|
||||
expect(screen.getByText("Credential method")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced" }));
|
||||
@@ -2047,7 +2047,7 @@ describe("Settings channels", () => {
|
||||
expect(within(matrixBehavior).getByRole("radio", { name: "All messages" })).toBeChecked();
|
||||
expect(within(matrixBehavior).getByRole("radio", { name: "Allowlist" })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "View QQ settings" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced" }));
|
||||
const format = screen.getByRole("group", { name: "Message format" });
|
||||
|
||||
@@ -4,10 +4,7 @@ import type { ProviderModelsPayload, SettingsPayload } from "@/lib/types";
|
||||
import { requestMutationMock, jsonResponse, settingsPayload, renderSettingsView, openPopover, installSettingsViewTestHooks } from "@/tests/settings-test-utils";
|
||||
|
||||
|
||||
function settingsPayloadWithBackup(): {
|
||||
payload: SettingsPayload;
|
||||
backupPreset: SettingsPayload["model_presets"][number];
|
||||
} {
|
||||
function settingsPayloadWithBackup() {
|
||||
const base = settingsPayload();
|
||||
const backupPreset = {
|
||||
...base.model_presets[0],
|
||||
@@ -36,7 +33,7 @@ function settingsPayloadWithBackup(): {
|
||||
configured: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
} satisfies SettingsPayload,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -103,8 +100,8 @@ async function openModelPicker() {
|
||||
}
|
||||
|
||||
function returnToPresetEditor() {
|
||||
const advanced = screen.queryByRole("dialog", { name: "Advanced options", exact: true });
|
||||
if (advanced) fireEvent.click(within(advanced).getByRole("button", { name: "Close", exact: true }));
|
||||
const advanced = screen.queryByRole("dialog", { name: "Advanced options" });
|
||||
if (advanced) fireEvent.click(within(advanced).getByRole("button", { name: "Close" }));
|
||||
}
|
||||
|
||||
function presetSaveButton() {
|
||||
@@ -133,19 +130,19 @@ describe("Settings models", () => {
|
||||
renderSettingsView({ initialSection: "models" });
|
||||
await openPresetAdvancedOptions();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Headers Use provider settings Edit" }));
|
||||
let editor = screen.getByRole("dialog", { name: "Headers", exact: true });
|
||||
let editor = screen.getByRole("dialog", { name: "Headers" });
|
||||
fireEvent.change(within(editor).getByRole("textbox", { name: "Headers" }), { target: { value: '{"X-Route":"preset"}' } });
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save" }));
|
||||
expect(await within(editor).findByRole("alert")).toHaveTextContent("Could not save. Try again.");
|
||||
expect(within(editor).getByRole("textbox")).toHaveValue('{"X-Route":"preset"}');
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.model_configuration.update", { name: "primary", extra_headers: '{"X-Route":"preset"}' }, 20_000,
|
||||
));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Headers Entries: 1 Edit" }));
|
||||
editor = screen.getByRole("dialog", { name: "Headers", exact: true });
|
||||
editor = screen.getByRole("dialog", { name: "Headers" });
|
||||
fireEvent.change(within(editor).getByRole("textbox", { name: "Headers" }), { target: { value: "" } });
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
|
||||
"settings.model_configuration.update", { name: "primary", extra_headers: "" }, 20_000,
|
||||
));
|
||||
@@ -186,7 +183,7 @@ describe("Settings models", () => {
|
||||
20_000,
|
||||
));
|
||||
await waitFor(() => expect(presetSaveButton()).toBeDisabled());
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
await openPresetAdvancedOptions();
|
||||
expect(screen.getByLabelText("API connection")).toHaveTextContent("Responses");
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Try Chat Completions if Responses is unsupported" }));
|
||||
@@ -198,7 +195,7 @@ describe("Settings models", () => {
|
||||
20_000,
|
||||
));
|
||||
await waitFor(() => expect(presetSaveButton()).toBeDisabled());
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
await openPresetAdvancedOptions();
|
||||
expect(screen.getByRole("switch", { name: "Try Chat Completions if Responses is unsupported" })).toBeChecked();
|
||||
await openPopover(screen.getByLabelText("API connection"));
|
||||
@@ -247,7 +244,7 @@ describe("Settings models", () => {
|
||||
20_000,
|
||||
));
|
||||
await waitFor(() => expect(presetSaveButton()).toBeDisabled());
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
await openPresetAdvancedOptions();
|
||||
expect(screen.getByLabelText("API connection")).toHaveTextContent("Anthropic Messages");
|
||||
expect(presetSaveButton()).toBeDisabled();
|
||||
@@ -628,7 +625,7 @@ describe("Settings models", () => {
|
||||
|
||||
fireEvent.click(advanced);
|
||||
|
||||
expect(within(screen.getByRole("dialog", { name: "Advanced options", exact: true })).getByText("Context window")).toBeInTheDocument();
|
||||
expect(within(screen.getByRole("dialog", { name: "Advanced options" })).getByText("Context window")).toBeInTheDocument();
|
||||
expect(screen.getByText("Temperature")).toBeInTheDocument();
|
||||
expect(screen.getByRole("textbox", { name: "Context window" })).toHaveValue("200k");
|
||||
returnToPresetEditor();
|
||||
@@ -756,7 +753,7 @@ describe("Settings models", () => {
|
||||
within(editor).getByText("Cannot delete the primary model"),
|
||||
).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
});
|
||||
|
||||
it("opens advanced options in a separate dialog and preserves the preset draft", async () => {
|
||||
@@ -764,14 +761,14 @@ describe("Settings models", () => {
|
||||
renderSettingsView({ initialSection: "models", initialSettings: settingsPayload() });
|
||||
await togglePresetEditor();
|
||||
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
|
||||
const advanced = screen.getByRole("dialog", { name: "Advanced options", exact: true });
|
||||
const advanced = screen.getByRole("dialog", { name: "Advanced options" });
|
||||
fireEvent.change(within(advanced).getByLabelText("Context window"), { target: { value: "128k" } });
|
||||
fireEvent.click(within(advanced).getByRole("button", { name: "Close", exact: true }));
|
||||
expect(screen.queryByRole("dialog", { name: "Advanced options", exact: true })).not.toBeInTheDocument();
|
||||
fireEvent.click(within(advanced).getByRole("button", { name: "Close" }));
|
||||
expect(screen.queryByRole("dialog", { name: "Advanced options" })).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId("model-preset-editor")).toBeVisible();
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
|
||||
expect(within(screen.getByRole("dialog", { name: "Advanced options", exact: true })).getByLabelText("Context window")).toHaveValue("128k");
|
||||
expect(within(screen.getByRole("dialog", { name: "Advanced options" })).getByLabelText("Context window")).toHaveValue("128k");
|
||||
});
|
||||
|
||||
it.each([true, false])("closes the preset editor only after deletion succeeds (success: %s)", async (success) => {
|
||||
@@ -784,10 +781,10 @@ describe("Settings models", () => {
|
||||
});
|
||||
else requestMutationMock.mockRejectedValueOnce(new Error("Delete failed"));
|
||||
renderSettingsView({ initialSection: "models", initialSettings: payload });
|
||||
fireEvent.click(within(screen.getByTestId("model-call-order-row-backup")).getByRole("button", { name: "Configure", exact: true }));
|
||||
fireEvent.click(within(screen.getByTestId("model-preset-editor")).getByRole("button", { name: "Delete", exact: true }));
|
||||
fireEvent.click(within(screen.getByTestId("model-call-order-row-backup")).getByRole("button", { name: "Configure" }));
|
||||
fireEvent.click(within(screen.getByTestId("model-preset-editor")).getByRole("button", { name: "Delete" }));
|
||||
const confirmation = screen.getByRole("dialog", { name: "Delete model preset?" });
|
||||
fireEvent.click(within(confirmation).getByRole("button", { name: "Delete", exact: true }));
|
||||
fireEvent.click(within(confirmation).getByRole("button", { name: "Delete" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.model_configuration.delete", { name: "backup" }, 20_000,
|
||||
));
|
||||
@@ -795,7 +792,7 @@ describe("Settings models", () => {
|
||||
await waitFor(() => expect(screen.queryByTestId("model-preset-editor")).not.toBeInTheDocument());
|
||||
expect(screen.queryByTestId("model-call-order-row-backup")).not.toBeInTheDocument();
|
||||
} else {
|
||||
await waitFor(() => expect(within(confirmation).getByRole("button", { name: "Delete", exact: true })).toBeEnabled());
|
||||
await waitFor(() => expect(within(confirmation).getByRole("button", { name: "Delete" })).toBeEnabled());
|
||||
expect(screen.getByTestId("model-preset-editor")).toBeInTheDocument();
|
||||
}
|
||||
});
|
||||
@@ -806,8 +803,8 @@ describe("Settings models", () => {
|
||||
payload.model_presets[0].max_tokens = 32_768;
|
||||
renderSettingsView({ initialSection: "models", initialSettings: payload, showSidebar });
|
||||
|
||||
expect(screen.queryAllByRole("heading", { name: "Models", exact: true })).toHaveLength(showSidebar ? 0 : 1);
|
||||
expect(screen.getByRole("heading", { name: "Model presets", exact: true })).toHaveClass("settings-section-title");
|
||||
expect(screen.queryAllByRole("heading", { name: "Models" })).toHaveLength(showSidebar ? 0 : 1);
|
||||
expect(screen.getByRole("heading", { name: "Model presets" })).toHaveClass("settings-section-title");
|
||||
expect(screen.queryByRole("heading", { name: "Fallback presets" })).not.toBeInTheDocument();
|
||||
const summary = within(screen.getByTestId("model-call-order-row-primary"));
|
||||
expect(summary.getByText(`${payload.model_presets[0].model} 256K Default`)).toBeInTheDocument();
|
||||
@@ -867,8 +864,8 @@ describe("Settings models", () => {
|
||||
fireEvent.change(screen.getByLabelText("Temperature"), {
|
||||
target: { value: "0.4" },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
const centers = mockPresetRowLayout();
|
||||
const draggedRow = screen.getByTestId(`model-call-order-row-${name}`);
|
||||
fireEvent.pointerDown(draggedRow, { button: 0, clientY: centers[from], pointerId: 1 });
|
||||
@@ -889,7 +886,7 @@ describe("Settings models", () => {
|
||||
const newPrimary = screen.getByTestId("model-call-order-row-backup");
|
||||
expect(within(newPrimary).getByText("Primary")).toBeInTheDocument();
|
||||
expect(within(newPrimary).getByText(`${backupPreset.model} 200K Default`)).toBeInTheDocument();
|
||||
fireEvent.click(within(screen.getByTestId("model-call-order-row-primary")).getByRole("button", { name: "Configure", exact: true }));
|
||||
fireEvent.click(within(screen.getByTestId("model-call-order-row-primary")).getByRole("button", { name: "Configure" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
|
||||
expect(screen.getByLabelText("Temperature")).toHaveValue(0.4);
|
||||
expect(presetSaveButton()).toBeEnabled();
|
||||
@@ -983,8 +980,8 @@ describe("Settings models", () => {
|
||||
fireEvent.click(secondBackupTrigger);
|
||||
expect(screen.getAllByTestId("model-preset-editor")).toHaveLength(1);
|
||||
expect(screen.getByRole("dialog", { name: "backup" })).toContainElement(screen.getByTestId("model-preset-editor"));
|
||||
expect(screen.getByRole("button", { name: "Delete", exact: true })).toBeDisabled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
expect(screen.getByRole("button", { name: "Delete" })).toBeDisabled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
|
||||
const centers = mockPresetRowLayout();
|
||||
fireEvent.pointerDown(primaryRow, { button: 0, clientY: centers[1], pointerId: 1 });
|
||||
@@ -1183,7 +1180,7 @@ describe("Settings models", () => {
|
||||
);
|
||||
});
|
||||
const writerRow = await screen.findByTestId("model-call-order-row-Writer");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
expect(within(writerRow).getByRole("switch", { name: "Disable preset" })).toBeChecked();
|
||||
expect(screen.getAllByText("Writer").length).toBeGreaterThan(0);
|
||||
});
|
||||
@@ -1571,9 +1568,9 @@ describe("Settings models", () => {
|
||||
const providerPicker = await screen.findByRole("combobox", { name: /DeepSeek/ });
|
||||
fireEvent.keyDown(providerPicker, { key: "ArrowDown" });
|
||||
|
||||
expect(await screen.findByRole("option", { name: "DeepSeek", exact: true })).toBeInTheDocument();
|
||||
expect(screen.queryByRole("option", { name: "OpenAI Codex", exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("option", { name: "GitHub Copilot", exact: true })).not.toBeInTheDocument();
|
||||
expect(await screen.findByRole("option", { name: "DeepSeek" })).toBeInTheDocument();
|
||||
expect(screen.queryByRole("option", { name: "OpenAI Codex" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("option", { name: "GitHub Copilot" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not fetch model lists for unsigned OAuth providers", async () => {
|
||||
@@ -1942,7 +1939,7 @@ describe("Settings models", () => {
|
||||
);
|
||||
fireEvent.keyDown(document.activeElement!, { key: "Escape" });
|
||||
await waitFor(() => expect(modelInput).toHaveFocus());
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
await waitFor(() => expect(within(screen.getByTestId("model-call-order-row-primary")).getAllByRole("button")[0]).toBeVisible());
|
||||
});
|
||||
|
||||
@@ -2061,15 +2058,15 @@ describe("Settings models", () => {
|
||||
await togglePresetEditor();
|
||||
const input = screen.getByRole("combobox", { name: "Reasoning effort" });
|
||||
fireEvent.click(input);
|
||||
fireEvent.click(await screen.findByRole("option", { name: "max", exact: true }));
|
||||
fireEvent.click(await screen.findByRole("option", { name: "max" }));
|
||||
await waitFor(() => expect(input).toHaveValue("max"));
|
||||
fireEvent.click(input);
|
||||
expect(screen.queryByRole("option", { name: "ultra", exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("option", { name: "medium", exact: true })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("option", { name: "none", exact: true }));
|
||||
expect(screen.queryByRole("option", { name: "ultra" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("option", { name: "medium" })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("option", { name: "none" }));
|
||||
await waitFor(() => expect(input).toHaveValue("none"));
|
||||
fireEvent.click(input);
|
||||
fireEvent.click(screen.getByRole("option", { name: "Default", exact: true }));
|
||||
fireEvent.click(screen.getByRole("option", { name: "Default" }));
|
||||
await waitFor(() => expect(input).toHaveValue(""));
|
||||
fireEvent.click(input);
|
||||
fireEvent.change(input, { target: { value: "provider-native-mode" } });
|
||||
|
||||
@@ -108,7 +108,7 @@ describe("Settings providers", () => {
|
||||
await user.click(screen.getByRole("option", { name: "Configure OpenAI Codex…" }));
|
||||
await user.click(screen.getByRole("button", { name: "Sign out" }));
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Sign in" })).toBeEnabled());
|
||||
await user.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Close" }));
|
||||
expect(screen.getByRole("dialog", { name: "New preset" })).toBeVisible();
|
||||
expect(screen.getByRole("textbox", { name: "Preset name" })).toHaveValue("OAuth draft");
|
||||
expect(picker).toHaveTextContent("OpenAI Codex");
|
||||
@@ -158,7 +158,7 @@ describe("Settings providers", () => {
|
||||
await user.click(providerPicker);
|
||||
await user.click(screen.getByRole("option", { name: "Add provider" }));
|
||||
await user.click(custom
|
||||
? screen.getByRole("button", { name: "Custom", exact: true })
|
||||
? screen.getByRole("button", { name: "Custom" })
|
||||
: screen.getByRole("option", { name: "Moonshot" }));
|
||||
if (custom) {
|
||||
await user.type(screen.getByPlaceholderText("My model provider"), "Company");
|
||||
@@ -212,13 +212,13 @@ describe("Settings providers", () => {
|
||||
await user.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
await user.type(screen.getByRole("combobox"), "does-not-exist");
|
||||
expect(screen.getByRole("status")).toHaveTextContent("No providers match this search.");
|
||||
await user.click(screen.getByRole("button", { name: "Custom", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Custom" }));
|
||||
expect(screen.getAllByRole("dialog")).toHaveLength(1);
|
||||
await user.type(screen.getByPlaceholderText("My model provider"), "Unsaved gateway");
|
||||
await user.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
await user.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
expect(screen.getByRole("combobox")).toHaveValue("");
|
||||
await user.click(screen.getByRole("button", { name: "Custom", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Custom" }));
|
||||
expect(screen.getByPlaceholderText("My model provider")).toHaveValue("");
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -233,7 +233,7 @@ describe("Settings providers", () => {
|
||||
const dialog = screen.getByRole("dialog", { name: "Add provider" });
|
||||
expect(dialog).toHaveClass("rounded-t-3xl", "bottom-0");
|
||||
expect(screen.getByRole("combobox")).not.toHaveFocus();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Custom", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Custom" }));
|
||||
expect(screen.getByRole("dialog", { name: "Custom" })).toBe(dialog);
|
||||
});
|
||||
|
||||
@@ -251,8 +251,8 @@ describe("Settings providers", () => {
|
||||
await user.type(screen.getByPlaceholderText("Enter API key"), "test-key");
|
||||
await user.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
await waitFor(() => expect(screen.getByRole("dialog", { name: "Manage providers" })).toBeVisible());
|
||||
expect(screen.getByRole("button", { name: "Moonshot", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Moonshot", exact: true })).toHaveFocus();
|
||||
expect(screen.getByRole("button", { name: "Moonshot" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Moonshot" })).toHaveFocus();
|
||||
await user.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
expect(screen.queryByRole("option", { name: "Moonshot" })).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -265,7 +265,7 @@ describe("Settings providers", () => {
|
||||
renderProviderManager({ initialSection: "models", initialSettings: payload });
|
||||
await user.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
await user.click(custom
|
||||
? screen.getByRole("button", { name: "Custom", exact: true })
|
||||
? screen.getByRole("button", { name: "Custom" })
|
||||
: screen.getByRole("option", { name: "Moonshot" }));
|
||||
const dialog = screen.getByRole("dialog");
|
||||
if (custom) {
|
||||
@@ -281,12 +281,12 @@ describe("Settings providers", () => {
|
||||
await user.click(within(dialog).getByRole("button", { name: "Back to providers" }));
|
||||
expect(screen.getByRole("dialog", { name: "Add provider" })).toBe(dialog);
|
||||
await user.click(custom
|
||||
? screen.getByRole("button", { name: "Custom", exact: true })
|
||||
? screen.getByRole("button", { name: "Custom" })
|
||||
: screen.getByRole("option", { name: "Moonshot" }));
|
||||
expect(screen.getByPlaceholderText("Enter API key")).toHaveValue("");
|
||||
await user.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
await waitFor(() => expect(screen.getByRole("dialog", { name: "Manage providers" })).toBeVisible());
|
||||
expect(screen.queryByRole("button", { name: "Moonshot", exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Moonshot" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps provider labels and keyboard configuration accessible with decorative logos", async () => {
|
||||
@@ -308,7 +308,7 @@ describe("Settings providers", () => {
|
||||
};
|
||||
renderProviderManager({ initialSection: "models", initialSettings: payload });
|
||||
|
||||
const provider = await screen.findByRole("button", { name: "OpenAI Codex", exact: true });
|
||||
const provider = await screen.findByRole("button", { name: "OpenAI Codex" });
|
||||
expect(within(provider).getByText("Configure")).toBeInTheDocument();
|
||||
expect(within(provider).queryByRole("img")).not.toBeInTheDocument();
|
||||
provider.focus();
|
||||
@@ -316,7 +316,7 @@ describe("Settings providers", () => {
|
||||
expect(await screen.findByRole("dialog", { name: "OpenAI Codex" })).toBeInTheDocument();
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(screen.getByRole("dialog", { name: "Manage providers" })).toBeVisible());
|
||||
expect(screen.getByRole("button", { name: "OpenAI Codex", exact: true })).toHaveFocus();
|
||||
expect(screen.getByRole("button", { name: "OpenAI Codex" })).toHaveFocus();
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -327,7 +327,7 @@ describe("Settings providers", () => {
|
||||
name: "xai_grok",
|
||||
label: "xAI Grok",
|
||||
configured: false,
|
||||
auth_type: "oauth" as const,
|
||||
auth_type: "oauth",
|
||||
api_key_required: false,
|
||||
api_key_hint: null,
|
||||
api_base: null,
|
||||
@@ -336,7 +336,7 @@ describe("Settings providers", () => {
|
||||
oauth_account: null,
|
||||
oauth_expires_at: null,
|
||||
oauth_login_supported: true,
|
||||
};
|
||||
} satisfies SettingsPayload["providers"][number];
|
||||
const payload: SettingsPayload = { ...base, providers: [xaiProvider] };
|
||||
const signedIn: SettingsPayload = {
|
||||
...payload,
|
||||
@@ -442,7 +442,7 @@ describe("Settings providers", () => {
|
||||
name: "xai_grok",
|
||||
label: "xAI Grok",
|
||||
configured: false,
|
||||
auth_type: "oauth" as const,
|
||||
auth_type: "oauth",
|
||||
api_key_required: false,
|
||||
api_key_hint: null,
|
||||
api_base: null,
|
||||
@@ -451,7 +451,7 @@ describe("Settings providers", () => {
|
||||
oauth_account: null,
|
||||
oauth_expires_at: null,
|
||||
oauth_login_supported: true,
|
||||
};
|
||||
} satisfies SettingsPayload["providers"][number];
|
||||
const payload: SettingsPayload = { ...base, providers: [xaiProvider] };
|
||||
const authorization = {
|
||||
status: "authorization_required",
|
||||
@@ -521,7 +521,7 @@ describe("Settings providers", () => {
|
||||
name: "openai_codex",
|
||||
label: "OpenAI Codex",
|
||||
configured: false,
|
||||
auth_type: "oauth" as const,
|
||||
auth_type: "oauth",
|
||||
api_key_required: false,
|
||||
api_key_hint: null,
|
||||
api_base: null,
|
||||
@@ -530,7 +530,7 @@ describe("Settings providers", () => {
|
||||
oauth_account: null,
|
||||
oauth_expires_at: null,
|
||||
oauth_login_supported: true,
|
||||
};
|
||||
} satisfies SettingsPayload["providers"][number];
|
||||
const payload: SettingsPayload = { ...base, providers: [codexProvider] };
|
||||
const signedIn: SettingsPayload = {
|
||||
...payload,
|
||||
@@ -599,7 +599,7 @@ describe("Settings providers", () => {
|
||||
name: "openai_codex",
|
||||
label: "OpenAI Codex",
|
||||
configured: false,
|
||||
auth_type: "oauth" as const,
|
||||
auth_type: "oauth",
|
||||
api_key_required: false,
|
||||
api_key_hint: null,
|
||||
api_base: null,
|
||||
@@ -608,7 +608,7 @@ describe("Settings providers", () => {
|
||||
oauth_account: null,
|
||||
oauth_expires_at: null,
|
||||
oauth_login_supported: true,
|
||||
};
|
||||
} satisfies SettingsPayload["providers"][number];
|
||||
const payload: SettingsPayload = { ...base, providers: [codexProvider] };
|
||||
const signedIn: SettingsPayload = {
|
||||
...payload,
|
||||
@@ -928,11 +928,11 @@ describe("Settings providers", () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: /^DeepSeek/ }));
|
||||
expect(screen.queryByRole("switch")).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back to providers" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "OpenAI", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "OpenAI" }));
|
||||
fireEvent.click(screen.getByRole("switch", { name: "OpenAI web search" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save provider" }));
|
||||
await waitFor(() => expect(
|
||||
screen.getByRole("button", { name: "OpenAI", exact: true }),
|
||||
screen.getByRole("button", { name: "OpenAI" }),
|
||||
).toBeVisible());
|
||||
|
||||
await waitFor(() => {
|
||||
@@ -999,7 +999,7 @@ describe("Settings providers", () => {
|
||||
|
||||
renderProviderManager({ initialSection: "models", initialSettings: payload });
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: "OpenAI", exact: true }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "OpenAI" }));
|
||||
const searchSwitch = screen.getByRole("switch", { name: "OpenAI web search" });
|
||||
expect(searchSwitch).toHaveAttribute("aria-checked", "true");
|
||||
fireEvent.click(searchSwitch);
|
||||
@@ -1120,7 +1120,7 @@ describe("Settings providers", () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: `${title} Not configured Edit` }));
|
||||
const editor = screen.getByRole("dialog", { name: title });
|
||||
fireEvent.change(within(editor).getByRole("textbox", { name: title }), { target: { value } });
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog", { name: title })).not.toBeInTheDocument());
|
||||
}
|
||||
fireEvent.change(screen.getByLabelText("Network proxy"), {
|
||||
@@ -1192,7 +1192,7 @@ describe("Settings providers", () => {
|
||||
await user.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
await waitFor(() => expect(screen.getByRole("dialog", { name: "Manage providers" })).toBeVisible());
|
||||
expect(requestMutationMock).toHaveBeenCalledWith("settings.provider.create", expect.objectContaining({ api }), 20_000);
|
||||
await user.click(screen.getByRole("button", { name: "Tenant", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Tenant" }));
|
||||
await user.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
expect(screen.getByRole("combobox", { name: "Default API" })).toHaveTextContent("Anthropic Messages");
|
||||
await user.click(screen.getByRole("switch", { name: "Responses" }));
|
||||
@@ -1202,7 +1202,7 @@ describe("Settings providers", () => {
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith("settings.provider.update", expect.objectContaining({
|
||||
provider: "tenant", api: { supported_apis: ["anthropic_messages", "responses"], preferred_api: "responses" },
|
||||
}), 20_000));
|
||||
await user.click(screen.getByRole("button", { name: "Tenant", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Tenant" }));
|
||||
await user.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
expect(screen.getByRole("combobox", { name: "Default API" })).toHaveTextContent("Responses");
|
||||
});
|
||||
@@ -1230,28 +1230,28 @@ describe("Settings providers", () => {
|
||||
return payload;
|
||||
});
|
||||
renderProviderManager({ initialSection: "models", initialSettings: payload });
|
||||
await user.click(screen.getByRole("button", { name: "OpenAI", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "OpenAI" }));
|
||||
expect(screen.queryByRole("combobox", { name: "Default API" })).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
expect(screen.getByRole("combobox", { name: "Default API" })).toHaveTextContent("Responses");
|
||||
await user.click(screen.getByRole("combobox", { name: "Default API" }));
|
||||
await user.click(screen.getByRole("option", { name: "Chat Completions", exact: true }));
|
||||
await user.click(screen.getByRole("option", { name: "Chat Completions" }));
|
||||
await user.click(screen.getByRole("button", { name: "Save provider" }));
|
||||
await waitFor(() => expect(screen.getByRole("dialog", { name: "Manage providers" })).toBeVisible());
|
||||
expect(requestMutationMock).toHaveBeenCalledWith("settings.provider.update", expect.objectContaining({
|
||||
provider: "openai", api: { supported_apis: ["chat_completions"], preferred_api: "chat_completions" },
|
||||
}), 20_000);
|
||||
await user.click(screen.getByRole("button", { name: "OpenAI", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "OpenAI" }));
|
||||
await user.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
expect(screen.getByRole("combobox", { name: "Default API" })).toHaveTextContent("Chat Completions");
|
||||
await user.click(screen.getByRole("combobox", { name: "Default API" }));
|
||||
await user.click(screen.getByRole("option", { name: "Auto", exact: true }));
|
||||
await user.click(screen.getByRole("option", { name: "Auto" }));
|
||||
await user.click(screen.getByRole("button", { name: "Save provider" }));
|
||||
await waitFor(() => expect(screen.getByRole("dialog", { name: "Manage providers" })).toBeVisible());
|
||||
expect(requestMutationMock).toHaveBeenCalledWith("settings.provider.update", expect.objectContaining({
|
||||
provider: "openai", api: null,
|
||||
}), 20_000);
|
||||
await user.click(screen.getByRole("button", { name: "OpenAI", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "OpenAI" }));
|
||||
await user.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
expect(screen.getByRole("combobox", { name: "Default API" })).toHaveTextContent("Auto");
|
||||
});
|
||||
@@ -1265,7 +1265,7 @@ describe("Settings providers", () => {
|
||||
extra_body: { tools: [{ type: "web_search" }] },
|
||||
}];
|
||||
renderProviderManager({ initialSection: "models", initialSettings: payload });
|
||||
fireEvent.click(screen.getByRole("button", { name: "OpenAI", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "OpenAI" }));
|
||||
expect(screen.queryByRole("combobox", { name: "Default API" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("switch", { name: "OpenAI web search" })).not.toBeInTheDocument();
|
||||
fireEvent.change(screen.getByLabelText("API URL"), { target: { value: "https://gateway.test/v1" } });
|
||||
|
||||
@@ -6,11 +6,12 @@ import { RUNTIME_CONFIG_FIELDS, RUNTIME_CONFIG_GROUPS } from "@/components/setti
|
||||
import runtimeConfigKeys from "../../../tests/webui/fixtures/runtime-config-keys.json";
|
||||
import { TimezonePicker } from "@/components/settings/shared/TimezonePicker";
|
||||
import { DEFAULT_AGENT_SETTINGS_DRAFT } from "@/components/settings/models/ModelsSettings";
|
||||
import type { SettingsPayload } from "@/lib/types";
|
||||
import { installSettingsViewTestHooks, jsonResponse, renderSettingsView, requestMutationMock, settingsPayload } from "@/tests/settings-test-utils";
|
||||
|
||||
function runtimeSettings() {
|
||||
const payload = settingsPayload();
|
||||
return { ...payload, advanced: { ...payload.advanced, exec_max_runtime_limit: 86400 }, runtime_config: {
|
||||
const runtimeConfig: NonNullable<SettingsPayload["runtime_config"]> = {
|
||||
"agents.defaults.bot_name": "nanobot",
|
||||
"agents.defaults.bot_icon": "🐈",
|
||||
"agents.defaults.timezone_mode": "auto",
|
||||
@@ -25,7 +26,8 @@ function runtimeSettings() {
|
||||
"tools.exec.sandbox_rw_binds": [],
|
||||
"agents.defaults.max_tool_iterations": 200,
|
||||
"tools.web.proxy": "http://localhost:8080",
|
||||
} };
|
||||
};
|
||||
return { ...payload, advanced: { ...payload.advanced, exec_max_runtime_limit: 86400 }, runtime_config: runtimeConfig };
|
||||
}
|
||||
|
||||
describe("Runtime configuration settings", () => {
|
||||
@@ -64,7 +66,7 @@ describe("Runtime configuration settings", () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: "Capabilities" }));
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Image generation" }));
|
||||
expect(document.getElementById("runtime-tools.image_generation.save_dir")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
expect(screen.getByRole("switch", { name: "Web access" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -90,7 +92,7 @@ describe("Runtime configuration settings", () => {
|
||||
requestMutationMock.mockResolvedValue({ ...payload, runtime_config: { ...payload.runtime_config, "tools.exec.sandbox": backend } });
|
||||
renderSettingsView({ initialSection: "advanced", initialSettings: payload });
|
||||
fireEvent.click(screen.getByRole("combobox", { name: "Command sandbox" }));
|
||||
fireEvent.click(screen.getByRole("option", { name: backend || "None", exact: true }));
|
||||
fireEvent.click(screen.getByRole("option", { name: backend || "None" }));
|
||||
if (backend) expect(document.getElementById("runtime-tools.exec.sandbox_ro_binds")).toBeVisible();
|
||||
else expect(document.getElementById("runtime-tools.exec.sandbox_ro_binds")).not.toBeInTheDocument();
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith("settings.runtime_config.update", { values: { "tools.exec.sandbox": backend } }, 20_000));
|
||||
@@ -117,7 +119,7 @@ describe("Runtime configuration settings", () => {
|
||||
expect(editor).toHaveValue("TERM");
|
||||
fireEvent.change(editor, { target: { value: " TERM \n\n COLORTERM " } });
|
||||
requestMutationMock.mockRejectedValueOnce(new Error("Could not save list"));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||
expect(await within(dialog).findByRole("alert")).toHaveTextContent("Could not save list");
|
||||
expect(editor).toHaveValue(" TERM \n\n COLORTERM ");
|
||||
expect(requestMutationMock).toHaveBeenLastCalledWith("settings.runtime_config.update", {
|
||||
@@ -125,7 +127,7 @@ describe("Runtime configuration settings", () => {
|
||||
}, 20_000);
|
||||
requestMutationMock.mockResolvedValueOnce({ ...payload, requires_restart: true,
|
||||
runtime_config: { ...payload.runtime_config, "tools.exec.allowed_env_keys": ["TERM", "COLORTERM"] } });
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save", exact: true }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(await screen.findByText("Saved. Restart to apply changes.")).toBeVisible();
|
||||
fireEvent.click(trigger);
|
||||
@@ -134,7 +136,7 @@ describe("Runtime configuration settings", () => {
|
||||
|
||||
it("starts the API with newly saved advanced settings", async () => {
|
||||
const payload = runtimeSettings();
|
||||
payload.api = { ...payload.api, host: "192.168.1.7", timeout: 77.5, api_key_hint: "set" };
|
||||
payload.api = { ...payload.api, host: "192.168.1.7", port: 8900, timeout: 77.5, api_key_hint: "set" };
|
||||
const action = vi.fn();
|
||||
render(<RuntimeSettings form={DEFAULT_AGENT_SETTINGS_DRAFT} settings={payload}
|
||||
requiresRestartPending={false} apiService={{
|
||||
@@ -212,7 +214,7 @@ describe("Runtime configuration settings", () => {
|
||||
expect(control).toHaveTextContent("1 hour");
|
||||
expect(screen.getByText("Timed runs: up to 24 hours")).toBeVisible();
|
||||
fireEvent.click(control);
|
||||
fireEvent.click(screen.getByRole("option", { name: label, exact: true }));
|
||||
fireEvent.click(screen.getByRole("option", { name: label }));
|
||||
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.runtime_config.update", { values: { "tools.exec.timeout": seconds } }, 20_000,
|
||||
@@ -227,7 +229,7 @@ describe("Runtime configuration settings", () => {
|
||||
} });
|
||||
renderSettingsView({ initialSection: "advanced", initialSettings: payload });
|
||||
fireEvent.click(screen.getByRole("combobox", { name: "Command runtime" }));
|
||||
fireEvent.click(screen.getByRole("option", { name: "Custom (seconds)", exact: true }));
|
||||
fireEvent.click(screen.getByRole("option", { name: "Custom (seconds)" }));
|
||||
const field = screen.getByRole("spinbutton", { name: "Custom runtime (seconds)" });
|
||||
expect(field).toHaveAttribute("max", "86400");
|
||||
fireEvent.change(field, { target: { value: "86401" } });
|
||||
@@ -246,8 +248,8 @@ describe("Runtime configuration settings", () => {
|
||||
expect(field).toHaveValue(86400);
|
||||
expect(screen.getAllByRole("alert")).toHaveLength(1);
|
||||
expect(screen.queryByText("Saved.", { exact: true })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "System", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "System" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced" }));
|
||||
expect(screen.getByRole("spinbutton", { name: "Custom runtime (seconds)" })).toHaveValue(86400);
|
||||
expect(screen.getByRole("alert")).toHaveTextContent("1 to 86,400");
|
||||
});
|
||||
@@ -260,7 +262,7 @@ describe("Runtime configuration settings", () => {
|
||||
} });
|
||||
renderSettingsView({ initialSection: "advanced", initialSettings: payload });
|
||||
fireEvent.click(screen.getByRole("combobox", { name: "Command runtime" }));
|
||||
fireEvent.click(screen.getByRole("option", { name: "Custom (seconds)", exact: true }));
|
||||
fireEvent.click(screen.getByRole("option", { name: "Custom (seconds)" }));
|
||||
const field = screen.getByRole("spinbutton", { name: "Custom runtime (seconds)" });
|
||||
expect(field).toHaveValue(null);
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
@@ -277,8 +279,8 @@ describe("Runtime configuration settings", () => {
|
||||
expect(screen.getByText("Timed runs: up to 2 hours")).toBeVisible();
|
||||
expect(screen.getByRole("spinbutton", { name: "Custom runtime (seconds)" })).toHaveAttribute("max", "7200");
|
||||
fireEvent.click(screen.getByRole("combobox", { name: "Command runtime" }));
|
||||
expect(screen.getByRole("option", { name: "2 hours", exact: true })).toBeVisible();
|
||||
expect(screen.queryByRole("option", { name: "24 hours", exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("option", { name: "2 hours" })).toBeVisible();
|
||||
expect(screen.queryByRole("option", { name: "24 hours" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps runtime editing available on a host without limit metadata", async () => {
|
||||
@@ -304,7 +306,7 @@ describe("Runtime configuration settings", () => {
|
||||
openWebSettings();
|
||||
const proxy = screen.getByRole("textbox", { name: "Web proxy" });
|
||||
fireEvent.change(proxy, { target: { value: "" } });
|
||||
fireEvent.click(within(screen.getByRole("dialog", { name: "Web access" })).getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(within(screen.getByRole("dialog", { name: "Web access" })).getByRole("button", { name: "Close" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "System" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Capabilities" }));
|
||||
openWebSettings();
|
||||
|
||||
@@ -51,7 +51,7 @@ describe("Settings navigation on mobile", () => {
|
||||
const menu = screen.getByRole("menu", { name: "Settings sections" });
|
||||
expect(trigger).toHaveAttribute("aria-haspopup", "menu");
|
||||
expect(menu).toHaveAttribute("data-side", "bottom");
|
||||
expect(within(menu).getByRole("menuitem", { name: "Models", exact: true }))
|
||||
expect(within(menu).getByRole("menuitem", { name: "Models" }))
|
||||
.toHaveAttribute("aria-current", "page");
|
||||
expect(within(menu).getByRole("menuitem", { name: "Restart" })).toBeVisible();
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
@@ -70,7 +70,7 @@ describe("Settings navigation on mobile", () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Sidebar activeSection="image" />);
|
||||
await user.click(screen.getByRole("button", { name: "Settings: Capabilities" }));
|
||||
expect(screen.getByRole("menuitem", { name: "Capabilities", exact: true }))
|
||||
expect(screen.getByRole("menuitem", { name: "Capabilities" }))
|
||||
.toHaveAttribute("aria-current", "page");
|
||||
expect(screen.queryByRole("menuitem", { name: "Restart" })).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -109,7 +109,7 @@ describe("Settings navigation on mobile", () => {
|
||||
render(<Sidebar />);
|
||||
screen.getByRole("button", { name: "Settings: Models" }).focus();
|
||||
await user.keyboard("{ArrowDown}");
|
||||
expect(screen.getByRole("menuitem", { name: "Overview", exact: true })).toHaveFocus();
|
||||
expect(screen.getByRole("menuitem", { name: "Overview" })).toHaveFocus();
|
||||
await user.keyboard("{ArrowDown}{Enter}");
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(screen.getByRole("button", { name: "Settings: Appearance" })).toHaveFocus();
|
||||
@@ -123,7 +123,7 @@ describe("Settings navigation on mobile", () => {
|
||||
{ keys: "[TouchA>]", target }, { keys: "[/TouchA]", target },
|
||||
]);
|
||||
await tap(screen.getByRole("button", { name: "Settings: Models" }));
|
||||
await tap(screen.getByRole("menuitem", { name: "System", exact: true }));
|
||||
await tap(screen.getByRole("menuitem", { name: "System" }));
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(screen.getByRole("button", { name: "Settings: System" })).toBeVisible();
|
||||
});
|
||||
@@ -147,11 +147,11 @@ describe("Settings navigation on mobile", () => {
|
||||
const restart = vi.fn();
|
||||
const { rerender } = render(<Sidebar onRestart={restart} restartPending />);
|
||||
expect(screen.getByRole("status")).toHaveTextContent("Saved. Restart to apply changes.");
|
||||
await user.click(screen.getByRole("button", { name: "Restart", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Restart" }));
|
||||
expect(restart).toHaveBeenCalledOnce();
|
||||
rerender(<Sidebar onRestart={restart} restartPending isRestarting />);
|
||||
const runningLabel = screen.getByRole("status").textContent!;
|
||||
expect(screen.getByRole("button", { name: runningLabel, exact: true })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: runningLabel })).toBeDisabled();
|
||||
await user.click(screen.getByRole("button", { name: "Settings: Models" }));
|
||||
expect(within(screen.getByRole("menu")).getByRole("menuitem", { name: runningLabel }))
|
||||
.toHaveAttribute("aria-disabled", "true");
|
||||
@@ -171,7 +171,7 @@ describe("Settings navigation on mobile", () => {
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(document.body.style.pointerEvents).not.toBe("none");
|
||||
expect(screen.queryByRole("button", { name: "Settings: Models" })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Models", exact: true })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Models" })).toBeVisible();
|
||||
await user.click(screen.getByRole("button", { name: "Restart" }));
|
||||
expect(restart).toHaveBeenCalledOnce();
|
||||
resize(true);
|
||||
@@ -187,7 +187,7 @@ describe("Settings navigation on mobile", () => {
|
||||
...settingsPayload(), requires_restart: true,
|
||||
}, onBackToChat: back });
|
||||
await user.click(screen.getByRole("button", { name: "Settings: Models" }));
|
||||
await user.click(screen.getByRole("menuitem", { name: "Appearance", exact: true }));
|
||||
await user.click(screen.getByRole("menuitem", { name: "Appearance" }));
|
||||
await user.click(screen.getByRole("button", { name: "Back to chat" }));
|
||||
const dialog = screen.getByRole("dialog", { name: "Restart before leaving?" });
|
||||
expect(back).not.toHaveBeenCalled();
|
||||
|
||||
@@ -3,6 +3,7 @@ import { expect, it, vi } from "vitest";
|
||||
import { installedMcpPresetsFromPayload } from "@/lib/mcp-preset-events";
|
||||
import { SkillsCatalogSettings } from "@/components/settings/SkillsCatalogSettings";
|
||||
import { ClientProvider } from "@/providers/ClientProvider";
|
||||
import type { McpPresetInfo } from "@/lib/types";
|
||||
import { __clearLogoFallbackCacheForTests } from "@/hooks/useLogoFallback";
|
||||
import { requestMutationMock, jsonResponse, settingsPayload, renderSettingsView, installSettingsViewTestHooks } from "@/tests/settings-test-utils";
|
||||
|
||||
@@ -29,6 +30,8 @@ const agentPlugin = {
|
||||
display_name: "Computer Use",
|
||||
category: "Plugin",
|
||||
description: "Control the desktop with a live preview.",
|
||||
docs_url: "",
|
||||
note: "",
|
||||
requires: "screen-recording, accessibility",
|
||||
transport: "stdio",
|
||||
install_supported: false,
|
||||
@@ -38,8 +41,9 @@ const agentPlugin = {
|
||||
available: false,
|
||||
status: "disabled",
|
||||
required_fields: [],
|
||||
connection_summary: "",
|
||||
source: "agent-plugin",
|
||||
};
|
||||
} satisfies McpPresetInfo;
|
||||
|
||||
function selectAutomationFilter(name: string) {
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: /^Filter/ }), { button: 0, ctrlKey: false });
|
||||
@@ -72,7 +76,7 @@ describe("Settings system domains", () => {
|
||||
...settingsPayload(), requires_restart: true,
|
||||
}, onRestart: restart });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back to chat" }));
|
||||
fireEvent.click(within(screen.getByRole("dialog")).getByRole("button", { name: "Restart", exact: true }));
|
||||
fireEvent.click(within(screen.getByRole("dialog")).getByRole("button", { name: "Restart" }));
|
||||
expect(restart).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
@@ -93,11 +97,11 @@ describe("Settings system domains", () => {
|
||||
},
|
||||
});
|
||||
const sidebar = screen.getByRole("complementary");
|
||||
const restart = within(sidebar).getByRole("button", { name: "Restart", exact: true });
|
||||
const restart = within(sidebar).getByRole("button", { name: "Restart" });
|
||||
for (const section of ["Capabilities", "Models", "Advanced", "System"]) {
|
||||
fireEvent.click(within(sidebar).getByRole("button", { name: section, exact: true }));
|
||||
fireEvent.click(within(sidebar).getByRole("button", { name: section }));
|
||||
await waitFor(() => {
|
||||
expect(screen.getAllByRole("button", { name: "Restart", exact: true })).toEqual([restart]);
|
||||
expect(screen.getAllByRole("button", { name: "Restart" })).toEqual([restart]);
|
||||
expect(screen.getAllByText("Saved. Restart to apply changes.")).toHaveLength(1);
|
||||
expect(within(sidebar).getByText("Saved. Restart to apply changes.")).toBeVisible();
|
||||
});
|
||||
@@ -233,7 +237,7 @@ describe("Settings system domains", () => {
|
||||
expect(title.nextElementSibling).not.toHaveClass(className);
|
||||
}
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "MCP", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "MCP" }));
|
||||
const mcpTitle = screen.getByRole("heading", { name: "MCP tools" });
|
||||
expect(mcpTitle.parentElement).toHaveClass("settings-section-heading");
|
||||
expect(mcpTitle.nextElementSibling).toHaveTextContent("0");
|
||||
@@ -265,7 +269,7 @@ describe("Settings system domains", () => {
|
||||
}));
|
||||
renderSettingsView({ initialSection: "apps", initialSettings: settingsPayload() });
|
||||
await screen.findByText("AnyGen");
|
||||
if (kind === "mcp") fireEvent.click(screen.getByRole("button", { name: "MCP", exact: true }));
|
||||
if (kind === "mcp") fireEvent.click(screen.getByRole("button", { name: "MCP" }));
|
||||
const row = (await screen.findByText(name)).closest("article")!;
|
||||
const image = row.querySelector("img")!;
|
||||
expect(image).toHaveAttribute("src", logoUrl);
|
||||
@@ -319,7 +323,7 @@ describe("Settings system domains", () => {
|
||||
]} />
|
||||
</ClientProvider>);
|
||||
for (const name of ["Custom", "Built-in", "Other"]) {
|
||||
const title = screen.getByRole("heading", { name, exact: true });
|
||||
const title = screen.getByRole("heading", { name });
|
||||
expect(title).toHaveClass("text-[13px]", "font-medium", "leading-5");
|
||||
for (const className of ["uppercase", "tracking-[0.08em]"]) {
|
||||
expect(title).not.toHaveClass(className);
|
||||
@@ -433,7 +437,7 @@ describe("Settings system domains", () => {
|
||||
}));
|
||||
renderSettingsView({ initialSection: "automations", initialSettings: settingsPayload(), showSidebar: false });
|
||||
|
||||
const trigger = await screen.findByRole("button", { name: "Filter", exact: true });
|
||||
const trigger = await screen.findByRole("button", { name: "Filter" });
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
fireEvent.pointerDown(trigger, { button: 0, ctrlKey: false });
|
||||
const menu = screen.getByRole("menu", { name: "Filter" });
|
||||
@@ -736,7 +740,7 @@ describe("Settings system domains", () => {
|
||||
expect(screen.getByLabelText("User ID")).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("Device ID")).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Matrix channel" }));
|
||||
|
||||
await waitFor(() =>
|
||||
|
||||
@@ -125,33 +125,22 @@ export function settingsPayload(): SettingsPayload {
|
||||
};
|
||||
}
|
||||
|
||||
export function renderSettingsView(
|
||||
options: {
|
||||
client?: NanobotClient;
|
||||
initialSection?:
|
||||
| "overview"
|
||||
| "appearance"
|
||||
| "apps"
|
||||
| "skills"
|
||||
| "channels"
|
||||
| "automations"
|
||||
| "advanced"
|
||||
| "models"
|
||||
| "image"
|
||||
| "browser"
|
||||
| "runtime";
|
||||
initialSettings?: SettingsPayload | null;
|
||||
skills?: React.ComponentProps<typeof SettingsView>["skills"];
|
||||
skillsLoading?: boolean;
|
||||
showSidebar?: boolean;
|
||||
mainNavigationExpanded?: boolean;
|
||||
onBackToChat?: () => void;
|
||||
onSettingsChange?: (payload: SettingsPayload) => void;
|
||||
onStartAutomationChat?: React.ComponentProps<typeof SettingsView>["onStartAutomationChat"];
|
||||
onNativeEngineRestart?: () => Promise<string>;
|
||||
onRestart?: () => void;
|
||||
} = {},
|
||||
) {
|
||||
type SettingsViewTestOptions = Partial<Pick<
|
||||
React.ComponentProps<typeof SettingsView>,
|
||||
| "initialSection"
|
||||
| "initialSettings"
|
||||
| "skills"
|
||||
| "skillsLoading"
|
||||
| "showSidebar"
|
||||
| "mainNavigationExpanded"
|
||||
| "onBackToChat"
|
||||
| "onSettingsChange"
|
||||
| "onStartAutomationChat"
|
||||
| "onNativeEngineRestart"
|
||||
| "onRestart"
|
||||
>> & { client?: NanobotClient };
|
||||
|
||||
export function renderSettingsView(options: SettingsViewTestOptions = {}) {
|
||||
render(
|
||||
<ClientProvider client={options.client ?? {
|
||||
requestMutation: requestMutationMock,
|
||||
|
||||
@@ -32,7 +32,7 @@ describe("settings text editor copy", () => {
|
||||
expect(dialog).toHaveAccessibleDescription(help);
|
||||
expect(within(dialog).getAllByText(help)).toHaveLength(1);
|
||||
fireEvent.change(within(dialog).getByRole("textbox", { name: "Headers" }), { target: { value: '{"Accept":"application/json"}' } });
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: i18n.t("settings.actions.save"), exact: true }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: i18n.t("settings.actions.save") }));
|
||||
expect(save).toHaveBeenCalledWith('{"Accept":"application/json"}');
|
||||
await waitFor(() => expect(dialog).not.toBeInTheDocument());
|
||||
expect(warning).not.toHaveBeenCalled();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
import postcss from "postcss";
|
||||
import postcss, { type Document, type Rule } from "postcss";
|
||||
import tailwindcss from "tailwindcss";
|
||||
import loadConfig from "tailwindcss/loadConfig";
|
||||
import { describe, expect, it } from "vitest";
|
||||
@@ -52,7 +52,7 @@ describe("sidebar touch hover isolation", () => {
|
||||
result.root.walkRules((rule) => {
|
||||
if (rule.selector.includes(":hover")) {
|
||||
hoverSelectors.push(rule.selector);
|
||||
let parent = rule.parent;
|
||||
let parent: Rule["parent"] | Document = rule.parent;
|
||||
let hoverMedia = false;
|
||||
while (parent) {
|
||||
if (parent.type === "atrule" && "name" in parent
|
||||
|
||||
@@ -144,7 +144,7 @@ it.each(supportedLocales.map(({ code }) => code))("localizes the complete invita
|
||||
].join(" "));
|
||||
expect(screen.getByRole("button", { name: i18n.t("starPrompt.later") })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: i18n.t("starPrompt.never") })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: i18n.t("common.close"), exact: true })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: i18n.t("common.close") })).toBeVisible();
|
||||
expect(screen.getByRole("link", { name: i18n.t("starPrompt.action") })).toHaveAttribute("rel", "noopener noreferrer");
|
||||
});
|
||||
|
||||
@@ -156,7 +156,7 @@ it.each(["close button", "Escape"])("restores focus after %s without permanently
|
||||
await enter();
|
||||
expect(screen.getByRole("heading", { name: "Glad we could help." })).toHaveFocus();
|
||||
if (method === "Escape") await user.keyboard("{Escape}");
|
||||
else await user.click(screen.getByRole("button", { name: "Close", exact: true }));
|
||||
else await user.click(screen.getByRole("button", { name: "Close" }));
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Previous control" })).toHaveFocus();
|
||||
expect(action).toHaveBeenCalledTimes(1);
|
||||
|
||||
@@ -30,8 +30,8 @@ function emitTask(snapshot: SubagentTaskSnapshot, chatId = "a") {
|
||||
act(() => { chatHandlers.get(chatId)?.forEach((handler) => handler({ event: "subagent_task", chat_id: chatId, task: snapshot })); });
|
||||
}
|
||||
const messages: UIMessage[] = [
|
||||
{ id: "prompt-a", role: "user", content: "Inspect config", turnId: "turn-a" },
|
||||
{ id: "answer-a", role: "assistant", content: "Main answer", turnId: "turn-a" },
|
||||
{ id: "prompt-a", role: "user", content: "Inspect config", turnId: "turn-a", createdAt: 100_000 },
|
||||
{ id: "answer-a", role: "assistant", content: "Main answer", turnId: "turn-a", createdAt: 101_000 },
|
||||
];
|
||||
|
||||
function task(overrides: Partial<SubagentTaskSnapshot> = {}): SubagentTaskSnapshot {
|
||||
@@ -337,7 +337,7 @@ describe("session-owned task UI", () => {
|
||||
});
|
||||
|
||||
it("anchors replay once when multiple prompts share a turn and preserves row order", async () => {
|
||||
const replay = [...messages, { id: "followup", role: "user", content: "Focus on errors", turnId: "turn-a" } satisfies UIMessage];
|
||||
const replay = [...messages, { id: "followup", role: "user", content: "Focus on errors", turnId: "turn-a", createdAt: 102_000 } satisfies UIMessage];
|
||||
const keys = unitKeysForDisplay(buildDisplayUnits(replay));
|
||||
expect(new Set(keys).size).toBe(keys.length);
|
||||
vi.mocked(fetch).mockImplementation(async () => response([
|
||||
@@ -362,7 +362,7 @@ describe("session-owned task UI", () => {
|
||||
|
||||
it("prefers the exact initiating follow-up over a turn fallback", async () => {
|
||||
vi.mocked(fetch).mockImplementation(async () => response([task({ origin_message_id: "followup" })]));
|
||||
render(layout({ threadMessages: [...messages, { id: "followup", role: "user", content: "Check more", turnId: "turn-a" }] }));
|
||||
render(layout({ threadMessages: [...messages, { id: "followup", role: "user", content: "Check more", turnId: "turn-a", createdAt: 102_000 }] }));
|
||||
await screen.findByRole("button", { name: /Config check Running/ });
|
||||
const group = screen.getByRole("region", { name: "Subtasks" });
|
||||
expect(screen.getByText("Check more").compareDocumentPosition(group) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
@@ -408,7 +408,7 @@ describe("session-owned task UI", () => {
|
||||
await user.click(within(otherWork).getByRole("button", { name: /Earlier check Running/ }));
|
||||
const detail = screen.getByRole("dialog", { name: "Earlier check" });
|
||||
view.rerender(layout({ threadMessages: [
|
||||
{ id: "older-prompt", role: "user", content: "Inspect earlier work", turnId: "older-turn" },
|
||||
{ id: "older-prompt", role: "user", content: "Inspect earlier work", turnId: "older-turn", createdAt: 99_000 },
|
||||
...messages,
|
||||
] }));
|
||||
expect(detail).toBeVisible();
|
||||
|
||||
@@ -172,7 +172,7 @@ describe("temporary chat navigation", () => {
|
||||
await screen.findByRole("button", { name: "Temporary chat" });
|
||||
act(() => TestSocket.current.open());
|
||||
await selectTopic("Regular topic");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Settings", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Settings" }));
|
||||
await screen.findByRole("button", { name: "Back to chat" });
|
||||
expect(window.location.hash).toBe("#/settings");
|
||||
first.unmount();
|
||||
@@ -191,7 +191,7 @@ describe("temporary chat navigation", () => {
|
||||
await screen.findByRole("button", { name: "Temporary chat" });
|
||||
act(() => TestSocket.current.open());
|
||||
const chatId = await startTemporaryChat("Temporary navigation check");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Settings", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Settings" }));
|
||||
await screen.findByRole("button", { name: "Back to chat" });
|
||||
expect(window.location.hash).toBe("#/settings");
|
||||
act(() => TestSocket.current.receive({ event: "message", chat_id: chatId, text: "Reply while in settings" }));
|
||||
@@ -405,7 +405,9 @@ describe("temporary chat navigation", () => {
|
||||
}));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "notes.txt" }));
|
||||
await screen.findByText("Preview of notes.txt");
|
||||
const store = update.mock.contexts.find((value) => value.get(`websocket:${chatId}`).tabs.length)!;
|
||||
const store = update.mock.contexts.find((value): value is FilePreviewStore =>
|
||||
value instanceof FilePreviewStore && value.get(`websocket:${chatId}`).tabs.length > 0,
|
||||
)!;
|
||||
expect(store.get(`websocket:${chatId}`).activeId).toBe("file:notes.txt");
|
||||
await selectTopic("Close temporary chat: Show example files");
|
||||
expect(store.get(`websocket:${chatId}`).tabs).toEqual([]);
|
||||
|
||||
@@ -629,7 +629,6 @@ describe("ThreadComposer", () => {
|
||||
modelPresets={[
|
||||
{
|
||||
name: "gpt-5-6-sol",
|
||||
label: "gpt-5.6-sol",
|
||||
model: "openai-codex/gpt-5.6-sol",
|
||||
provider: "openai_codex",
|
||||
},
|
||||
@@ -993,7 +992,9 @@ describe("ThreadComposer", () => {
|
||||
"running",
|
||||
[new Float32Array([0, 0.5, -0.5])],
|
||||
);
|
||||
const onTranscribeAudio = vi.fn(async () => "mimo voice");
|
||||
const onTranscribeAudio = vi.fn<NonNullable<React.ComponentProps<typeof ThreadComposer>["onTranscribeAudio"]>>(
|
||||
async () => "mimo voice",
|
||||
);
|
||||
render(
|
||||
<ThreadComposer
|
||||
onSend={vi.fn()}
|
||||
@@ -1029,9 +1030,9 @@ describe("ThreadComposer", () => {
|
||||
|
||||
it("does not start duplicate voice recordings while microphone access is pending", async () => {
|
||||
const { getUserMedia, stopTrack } = mockVoiceRecorder();
|
||||
let resolveStream: ((stream: MediaStream) => void) | undefined;
|
||||
let resolveStream: ((stream: Awaited<ReturnType<typeof getUserMedia>>) => void) | undefined;
|
||||
getUserMedia.mockImplementation(() => new Promise((resolve) => {
|
||||
resolveStream = resolve as (stream: MediaStream) => void;
|
||||
resolveStream = resolve;
|
||||
}));
|
||||
const onTranscribeAudio = vi.fn(async () => "one recording");
|
||||
render(
|
||||
@@ -1049,7 +1050,7 @@ describe("ThreadComposer", () => {
|
||||
expect(getUserMedia).toHaveBeenCalledTimes(1);
|
||||
|
||||
await act(async () => {
|
||||
resolveStream?.({ getTracks: () => [{ stop: stopTrack }] } as unknown as MediaStream);
|
||||
resolveStream?.({ getTracks: () => [{ stop: stopTrack }] });
|
||||
});
|
||||
expect(await screen.findByLabelText("Recording 0:00")).toBeInTheDocument();
|
||||
await waitForVoiceCapture();
|
||||
@@ -3011,7 +3012,7 @@ describe("ThreadComposer", () => {
|
||||
vi.spyOn(HTMLFormElement.prototype, "getBoundingClientRect").mockImplementation(
|
||||
() => rect({ top: landscape ? 44 : 274, width: landscape ? 744 : 388, height: 112 }),
|
||||
);
|
||||
vi.spyOn(HTMLDivElement.prototype, "getBoundingClientRect").mockImplementation(function () {
|
||||
vi.spyOn(HTMLDivElement.prototype, "getBoundingClientRect").mockImplementation(function (this: HTMLDivElement) {
|
||||
return this.id === "root"
|
||||
? rect({ top: 0, width: landscape ? 776 : 420, height: landscape ? 128 : 396 })
|
||||
: rect({ top: landscape ? 44 : 0, width: landscape ? 776 : 420, height: landscape ? 84 : 396 });
|
||||
|
||||
@@ -28,8 +28,8 @@ function assistantActionCounts(root: ParentNode = document) {
|
||||
const row = body.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
if (!row.querySelector("[data-message-block-menu-trigger]")) continue;
|
||||
const { menu } = openMessageBlockMenu(row);
|
||||
counts.copy += within(menu).queryAllByRole("button", { name: "Copy", exact: true }).length;
|
||||
counts.fork += within(menu).queryAllByRole("button", { name: "New chat from here", exact: true }).length;
|
||||
counts.copy += within(menu).queryAllByRole("button", { name: "Copy" }).length;
|
||||
counts.fork += within(menu).queryAllByRole("button", { name: "New chat from here" }).length;
|
||||
fireEvent.keyDown(menu, { key: "Escape" });
|
||||
}
|
||||
return counts;
|
||||
@@ -86,7 +86,7 @@ describe("ThreadMessages", () => {
|
||||
const assertIndependentDiff = () => {
|
||||
const diff = screen.getByTestId("file-edit-diff");
|
||||
expect(diff).toBeVisible();
|
||||
expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("img", { name: "Edited" })).toBeInTheDocument();
|
||||
expect(diff.closest('[aria-hidden="true"], [inert], [data-testid="agent-activity-content"]'))
|
||||
.toBeNull();
|
||||
expect(screen.getByText("File updated")).toBeVisible();
|
||||
@@ -94,7 +94,7 @@ describe("ThreadMessages", () => {
|
||||
};
|
||||
assertIndependentDiff();
|
||||
openAssistantBlockMenu(container);
|
||||
const disclosure = screen.getByRole("button", { name: "Worked for 5s", exact: true });
|
||||
const disclosure = screen.getByRole("button", { name: "Worked for 5s" });
|
||||
expect(disclosure).toHaveAttribute("aria-expanded", "false");
|
||||
const detailsId = disclosure.getAttribute("aria-controls")!;
|
||||
expect(container.querySelectorAll(`[id="${detailsId}"]`)).toHaveLength(1);
|
||||
@@ -260,7 +260,7 @@ describe("ThreadMessages", () => {
|
||||
content: "question",
|
||||
createdAt: 1,
|
||||
turnId,
|
||||
turnPhase: "prompt",
|
||||
turnPhase: "user",
|
||||
},
|
||||
{
|
||||
id: "live-answer",
|
||||
@@ -313,7 +313,7 @@ describe("ThreadMessages", () => {
|
||||
content: "next question",
|
||||
createdAt: 3,
|
||||
turnId: "turn-2",
|
||||
turnPhase: "prompt",
|
||||
turnPhase: "user",
|
||||
},
|
||||
]}
|
||||
isStreaming
|
||||
@@ -334,7 +334,7 @@ describe("ThreadMessages", () => {
|
||||
content: "research this",
|
||||
createdAt: 1,
|
||||
turnId,
|
||||
turnPhase: "prompt",
|
||||
turnPhase: "user",
|
||||
turnSeq: 0,
|
||||
};
|
||||
const commentary: UIMessage = {
|
||||
|
||||
@@ -19,17 +19,17 @@ function motionHarness(initial?: Partial<ThreadMotionGeometry>) {
|
||||
promptTop: 404,
|
||||
...initial,
|
||||
};
|
||||
const scheduler: ThreadMotionScheduler = {
|
||||
request: vi.fn((callback) => {
|
||||
const scheduler = {
|
||||
request: vi.fn<ThreadMotionScheduler["request"]>((callback) => {
|
||||
const id = nextFrameId;
|
||||
nextFrameId += 1;
|
||||
frames.set(id, callback);
|
||||
return id;
|
||||
}),
|
||||
cancel: vi.fn((id) => {
|
||||
cancel: vi.fn<ThreadMotionScheduler["cancel"]>((id) => {
|
||||
frames.delete(id);
|
||||
}),
|
||||
};
|
||||
} satisfies ThreadMotionScheduler;
|
||||
const camera = {
|
||||
cancel: vi.fn(() => {
|
||||
cameraFollowing = false;
|
||||
|
||||
@@ -304,11 +304,7 @@ function httpJson(body: unknown) {
|
||||
&& "messages" in body
|
||||
? canonicalThreadPayload(body as never)
|
||||
: body;
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => normalized,
|
||||
};
|
||||
return Response.json(normalized);
|
||||
}
|
||||
|
||||
function traceDetailThread(
|
||||
@@ -361,9 +357,7 @@ function restoreDocumentVisibility(
|
||||
if (descriptor) {
|
||||
Object.defineProperty(document, "visibilityState", descriptor);
|
||||
} else {
|
||||
delete (document as Document & {
|
||||
visibilityState?: DocumentVisibilityState;
|
||||
}).visibilityState;
|
||||
Reflect.deleteProperty(document, "visibilityState");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1738,7 +1732,7 @@ describe("ThreadShell", () => {
|
||||
completed_turn_ids: [],
|
||||
});
|
||||
vi.mocked(fetch).mockImplementation(async (input) => (
|
||||
String(input).includes("/webui-thread") ? initialHistory
|
||||
String(input).includes("/webui-thread") ? initialHistory.clone()
|
||||
: { ok: false, status: 404, json: async () => ({}) }
|
||||
) as Response);
|
||||
render(wrap(client, <ThreadShell session={session(chatId)} title="Queued chat" onToggleSidebar={() => {}} />));
|
||||
@@ -1778,7 +1772,7 @@ describe("ThreadShell", () => {
|
||||
act(() => client._emitChat(chatId, { event: "turn_end", chat_id: chatId, turn_id: nextTurnId }));
|
||||
expect(client.sendMessage).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
await act(async () => { finishRefresh(initialHistory as Response); });
|
||||
await act(async () => { finishRefresh(initialHistory.clone()); });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4597,7 +4591,6 @@ describe("ThreadShell", () => {
|
||||
(event) => event.event === "message" && event.text === "answer",
|
||||
);
|
||||
if (answer?.event === "message") answer.media_urls = [{
|
||||
kind: "image",
|
||||
url: "/api/media/stable/image",
|
||||
name: "answer.png",
|
||||
}];
|
||||
@@ -4651,7 +4644,6 @@ describe("ThreadShell", () => {
|
||||
(event) => event.event === "message" && event.text === "answer",
|
||||
);
|
||||
if (answer?.event === "message") answer.media_urls = [{
|
||||
kind: "image",
|
||||
url: "/api/media/stable/token-image",
|
||||
name: "token-answer.png",
|
||||
}];
|
||||
|
||||
@@ -115,11 +115,17 @@ function messageEvents(message: UIMessage): ThreadProjectionEvent[] {
|
||||
...eventBase(message, ":reasoning-end"),
|
||||
});
|
||||
}
|
||||
const media = message.media?.map((attachment) => {
|
||||
if (attachment.url === undefined) {
|
||||
throw new Error("Assistant history media fixtures require a resolved URL");
|
||||
}
|
||||
return { ...attachment, url: attachment.url };
|
||||
});
|
||||
events.push({
|
||||
event: "message",
|
||||
...base,
|
||||
text: message.content,
|
||||
...(message.media?.length ? { media_urls: message.media } : {}),
|
||||
...(media?.length ? { media_urls: media } : {}),
|
||||
...(message.latencyMs !== undefined ? { latency_ms: message.latencyMs } : {}),
|
||||
});
|
||||
const completion = completionEvent(message);
|
||||
@@ -127,28 +133,27 @@ function messageEvents(message: UIMessage): ThreadProjectionEvent[] {
|
||||
return events;
|
||||
}
|
||||
|
||||
export function canonicalThreadPayload(
|
||||
payload: WebuiThreadPersistedPayload | MessageFixturePayload,
|
||||
): WebuiThreadPersistedPayload;
|
||||
export function canonicalThreadPayload(
|
||||
payload: WebuiThreadPersistedPayload | MessageFixturePayload | null,
|
||||
): WebuiThreadPersistedPayload | null;
|
||||
export function canonicalThreadPayload(
|
||||
payload: WebuiThreadPersistedPayload | MessageFixturePayload | null,
|
||||
): WebuiThreadPersistedPayload | null {
|
||||
if (payload === null || "events" in payload) return payload;
|
||||
const events = payload.messages.flatMap(messageEvents);
|
||||
const boundary = payload.fork_boundary_message_count;
|
||||
const { messages, fork_boundary_message_count: boundary, ...rest } = payload;
|
||||
const events = messages.flatMap(messageEvents);
|
||||
const forkBoundaryEventIndex = typeof boundary === "number"
|
||||
? payload.messages.slice(0, boundary).flatMap(messageEvents).length
|
||||
? messages.slice(0, boundary).flatMap(messageEvents).length
|
||||
: undefined;
|
||||
const rest = { ...payload } as Record<string, unknown>;
|
||||
delete rest.messages;
|
||||
delete rest.fork_boundary_message_count;
|
||||
const canonical = payload as unknown as Record<string, unknown>;
|
||||
delete canonical.messages;
|
||||
delete canonical.fork_boundary_message_count;
|
||||
Object.assign(canonical, {
|
||||
return {
|
||||
...rest,
|
||||
projection: "events",
|
||||
events,
|
||||
...(forkBoundaryEventIndex !== undefined
|
||||
? { fork_boundary_event_index: forkBoundaryEventIndex }
|
||||
: {}),
|
||||
});
|
||||
return payload as unknown as WebuiThreadPersistedPayload;
|
||||
};
|
||||
}
|
||||
@@ -57,7 +57,7 @@ function mockScrollGeometry(scroller: HTMLElement, height: number, viewport: num
|
||||
});
|
||||
}
|
||||
|
||||
interface ResizeObserverInstance {
|
||||
interface ResizeObserverInstance extends ResizeObserver {
|
||||
elements: Element[];
|
||||
callback: ResizeObserverCallback;
|
||||
disconnect: ReturnType<typeof vi.fn>;
|
||||
@@ -119,7 +119,7 @@ function stubVisualViewport({
|
||||
function stubResizeObserver() {
|
||||
const original = globalThis.ResizeObserver;
|
||||
const observers: ResizeObserverInstance[] = [];
|
||||
class MockResizeObserver {
|
||||
class MockResizeObserver implements ResizeObserverInstance {
|
||||
elements: Element[] = [];
|
||||
callback: ResizeObserverCallback;
|
||||
disconnect = vi.fn();
|
||||
@@ -132,6 +132,10 @@ function stubResizeObserver() {
|
||||
observe(element: Element) {
|
||||
this.elements.push(element);
|
||||
}
|
||||
|
||||
unobserve(element: Element) {
|
||||
this.elements = this.elements.filter((candidate) => candidate !== element);
|
||||
}
|
||||
}
|
||||
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
||||
return {
|
||||
@@ -717,7 +721,7 @@ describe("ThreadViewport", () => {
|
||||
expect(contentObserver).toBeDefined();
|
||||
|
||||
act(() => {
|
||||
contentObserver!.callback([], contentObserver as unknown as ResizeObserver);
|
||||
contentObserver!.callback([], contentObserver!);
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
|
||||
@@ -815,7 +819,7 @@ describe("ThreadViewport", () => {
|
||||
value: 1948,
|
||||
});
|
||||
act(() => {
|
||||
contentObserver!.callback([], contentObserver as unknown as ResizeObserver);
|
||||
contentObserver!.callback([], contentObserver!);
|
||||
});
|
||||
expect(followTo).toHaveBeenCalledTimes(1);
|
||||
expect(followTo).toHaveBeenLastCalledWith(1448);
|
||||
@@ -854,7 +858,7 @@ describe("ThreadViewport", () => {
|
||||
value: 2560,
|
||||
});
|
||||
act(() => {
|
||||
contentObserver!.callback([], contentObserver as unknown as ResizeObserver);
|
||||
contentObserver!.callback([], contentObserver!);
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
expect(followTo).not.toHaveBeenCalled();
|
||||
@@ -1007,7 +1011,7 @@ describe("ThreadViewport", () => {
|
||||
expect(composerObserver).toBeDefined();
|
||||
|
||||
act(() => {
|
||||
composerObserver!.callback([], composerObserver as unknown as ResizeObserver);
|
||||
composerObserver!.callback([], composerObserver!);
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
|
||||
@@ -1117,7 +1121,7 @@ describe("ThreadViewport", () => {
|
||||
value: 1228,
|
||||
});
|
||||
act(() => {
|
||||
composerObserver!.callback([], composerObserver as unknown as ResizeObserver);
|
||||
composerObserver!.callback([], composerObserver!);
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
|
||||
@@ -1129,7 +1133,7 @@ describe("ThreadViewport", () => {
|
||||
value: 1268,
|
||||
});
|
||||
act(() => {
|
||||
composerObserver!.callback([], composerObserver as unknown as ResizeObserver);
|
||||
composerObserver!.callback([], composerObserver!);
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
|
||||
@@ -1171,6 +1175,13 @@ describe("ThreadViewport", () => {
|
||||
followTo.mockClear();
|
||||
|
||||
const composerDock = screen.getByTestId("thread-composer-dock");
|
||||
const composerEntry: ResizeObserverEntry = {
|
||||
target: composerDock,
|
||||
contentRect: composerDock.getBoundingClientRect(),
|
||||
borderBoxSize: [],
|
||||
contentBoxSize: [],
|
||||
devicePixelContentBoxSize: [],
|
||||
};
|
||||
const composerObserver = resizeObserver.observers.find(
|
||||
(observer) => observer.elements.includes(composerDock),
|
||||
);
|
||||
@@ -1182,8 +1193,8 @@ describe("ThreadViewport", () => {
|
||||
|
||||
act(() => {
|
||||
composerObserver!.callback(
|
||||
[{ target: composerDock }] as ResizeObserverEntry[],
|
||||
composerObserver as unknown as ResizeObserver,
|
||||
[composerEntry],
|
||||
composerObserver!,
|
||||
);
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
@@ -1204,8 +1215,8 @@ describe("ThreadViewport", () => {
|
||||
});
|
||||
act(() => {
|
||||
composerObserver!.callback(
|
||||
[{ target: composerDock }] as ResizeObserverEntry[],
|
||||
composerObserver as unknown as ResizeObserver,
|
||||
[composerEntry],
|
||||
composerObserver!,
|
||||
);
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
@@ -1625,7 +1636,7 @@ describe("ThreadViewport", () => {
|
||||
|
||||
const firstVisible = 300 - INITIAL_HISTORY_WINDOW;
|
||||
const anchor = screen.getByText(`message ${firstVisible}`)
|
||||
.closest<HTMLElement>("[data-thread-display-unit]");
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
expect(anchor).not.toBeNull();
|
||||
hitTarget = anchor;
|
||||
let anchorDocumentTop = 200;
|
||||
@@ -1661,7 +1672,7 @@ describe("ThreadViewport", () => {
|
||||
);
|
||||
expect(observer).toBeDefined();
|
||||
act(() => {
|
||||
observer?.callback([], observer as unknown as ResizeObserver);
|
||||
observer?.callback([], observer);
|
||||
});
|
||||
|
||||
expect(scroller.scrollTop).toBe(260);
|
||||
@@ -2265,7 +2276,7 @@ describe("ThreadViewport", () => {
|
||||
value: 3000,
|
||||
});
|
||||
act(() => {
|
||||
contentObserver!.callback([], contentObserver as unknown as ResizeObserver);
|
||||
contentObserver!.callback([], contentObserver!);
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
|
||||
@@ -2327,7 +2338,7 @@ describe("ThreadViewport", () => {
|
||||
value: 3000,
|
||||
});
|
||||
act(() => {
|
||||
contentObserver!.callback([], contentObserver as unknown as ResizeObserver);
|
||||
contentObserver!.callback([], contentObserver!);
|
||||
});
|
||||
await waitFor(() => expect(scroller.scrollTop).toBe(2400));
|
||||
|
||||
@@ -2345,7 +2356,7 @@ describe("ThreadViewport", () => {
|
||||
value: 3400,
|
||||
});
|
||||
act(() => {
|
||||
contentObserver!.callback([], contentObserver as unknown as ResizeObserver);
|
||||
contentObserver!.callback([], contentObserver!);
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ describe("Token usage card", () => {
|
||||
const plot = container.querySelector("[data-model-usage-plot]")!;
|
||||
const bars = within(screen.getByRole("group", { name: "Model trends" })).getAllByRole("img");
|
||||
expect(plot).toContainElement(bars[0]);
|
||||
const baseline = container.querySelector('[data-model-usage-gridline="2"]')!;
|
||||
const baseline = container.querySelector<HTMLElement>('[data-model-usage-gridline="2"]')!;
|
||||
expect(plot).toContainElement(baseline);
|
||||
expect(baseline.parentElement).toHaveStyle({ top: "100%" });
|
||||
expect(plot).not.toContainElement(screen.getByText("09-01"));
|
||||
|
||||
@@ -10,6 +10,7 @@ import type {
|
||||
ConnectionStatus,
|
||||
GoalStateWsPayload,
|
||||
InboundEvent,
|
||||
UIMediaAttachment,
|
||||
UIMessage,
|
||||
} from "@/lib/types";
|
||||
import { ClientProvider } from "@/providers/ClientProvider";
|
||||
@@ -418,7 +419,7 @@ describe("useNanobotStream", () => {
|
||||
requestFrame.mockRestore();
|
||||
now.mockRestore();
|
||||
if (descriptor) Object.defineProperty(document, "visibilityState", descriptor);
|
||||
else delete (document as Document & { visibilityState?: string }).visibilityState;
|
||||
else Reflect.deleteProperty(document, "visibilityState");
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
@@ -466,7 +467,7 @@ describe("useNanobotStream", () => {
|
||||
if (visibilityDescriptor) {
|
||||
Object.defineProperty(document, "visibilityState", visibilityDescriptor);
|
||||
} else {
|
||||
delete (document as Document & { visibilityState?: DocumentVisibilityState }).visibilityState;
|
||||
Reflect.deleteProperty(document, "visibilityState");
|
||||
}
|
||||
vi.useRealTimers();
|
||||
}
|
||||
@@ -2340,23 +2341,23 @@ describe("useNanobotStream", () => {
|
||||
{ wrapper: wrap(fake.client) },
|
||||
);
|
||||
|
||||
let submitted: ReturnType<typeof result.current.send> = null;
|
||||
const submitted: { current: ReturnType<typeof result.current.send> } = { current: null };
|
||||
act(() => {
|
||||
submitted = result.current.send("bind the camera");
|
||||
submitted.current = result.current.send("bind the camera");
|
||||
});
|
||||
|
||||
expect(submitted).not.toBeNull();
|
||||
expect(submitted?.sideChannel).toBe(false);
|
||||
expect(submitted.current).not.toBeNull();
|
||||
expect(submitted.current?.sideChannel).toBe(false);
|
||||
expect(result.current.messages[0]).toMatchObject({
|
||||
id: submitted?.userMessageId,
|
||||
turnId: submitted?.turnId,
|
||||
id: submitted.current?.userMessageId,
|
||||
turnId: submitted.current?.turnId,
|
||||
role: "user",
|
||||
});
|
||||
expect(fake.client.sendMessage).toHaveBeenCalledWith(
|
||||
"chat-submitted-turn",
|
||||
"bind the camera",
|
||||
undefined,
|
||||
expect.objectContaining({ turnId: submitted?.turnId }),
|
||||
expect.objectContaining({ turnId: submitted.current?.turnId }),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -2840,12 +2841,16 @@ describe("useNanobotStream", () => {
|
||||
wrapper: wrap(fake.client),
|
||||
});
|
||||
|
||||
// Some peers include a kind hint in addition to the message envelope's URL.
|
||||
const media = {
|
||||
kind: "image", url: "/api/media/sig/html", name: "index.html",
|
||||
} satisfies UIMediaAttachment;
|
||||
act(() => {
|
||||
fake.emit("chat-mislabelled-html", {
|
||||
event: "message",
|
||||
chat_id: "chat-mislabelled-html",
|
||||
text: "file ready",
|
||||
media_urls: [{ kind: "image", url: "/api/media/sig/html", name: "index.html" }],
|
||||
media_urls: [media],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ describe("usePageVisibility", () => {
|
||||
if (original) {
|
||||
Object.defineProperty(document, "visibilityState", original);
|
||||
} else {
|
||||
delete (document as Document & { visibilityState?: DocumentVisibilityState }).visibilityState;
|
||||
Reflect.deleteProperty(document, "visibilityState");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -19,16 +19,6 @@ vi.mock("@/lib/api", async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
const fetchThreadMock = vi.mocked(api.fetchWebuiThread);
|
||||
const rawMockResolvedValue = fetchThreadMock.mockResolvedValue.bind(fetchThreadMock);
|
||||
const rawMockResolvedValueOnce = fetchThreadMock.mockResolvedValueOnce.bind(fetchThreadMock);
|
||||
fetchThreadMock.mockResolvedValue = ((value) => rawMockResolvedValue(
|
||||
canonicalThreadPayload(value as never),
|
||||
)) as typeof fetchThreadMock.mockResolvedValue;
|
||||
fetchThreadMock.mockResolvedValueOnce = ((value) => rawMockResolvedValueOnce(
|
||||
canonicalThreadPayload(value as never),
|
||||
)) as typeof fetchThreadMock.mockResolvedValueOnce;
|
||||
|
||||
function fakeClient() {
|
||||
const sessionUpdateHandlers = new Set<(chatId: string, scope?: string) => void>();
|
||||
return {
|
||||
@@ -466,7 +456,7 @@ describe("useSessions", () => {
|
||||
});
|
||||
|
||||
it("passes through WebUI transcript user media as images and media", async () => {
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{
|
||||
@@ -486,7 +476,7 @@ describe("useSessions", () => {
|
||||
{ id: "a1", role: "assistant", content: "it's a cat", createdAt: 2 },
|
||||
{ id: "u2", role: "user", content: "follow-up without images", createdAt: 3 },
|
||||
],
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:chat-media"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -510,7 +500,7 @@ describe("useSessions", () => {
|
||||
});
|
||||
|
||||
it("passes through assistant video media from transcript replay", async () => {
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{
|
||||
@@ -521,7 +511,7 @@ describe("useSessions", () => {
|
||||
media: [{ kind: "video", url: "/api/media/sig-v/payload-v", name: "clip.mp4" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:chat-video"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -537,7 +527,7 @@ describe("useSessions", () => {
|
||||
});
|
||||
|
||||
it("passes through assistant reasoning from transcript replay", async () => {
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{
|
||||
@@ -548,7 +538,7 @@ describe("useSessions", () => {
|
||||
reasoning: "hidden but persisted reasoning",
|
||||
},
|
||||
],
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:chat-reasoning"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -563,7 +553,7 @@ describe("useSessions", () => {
|
||||
});
|
||||
|
||||
it("accepts transcript rows produced by the server replay reducer", async () => {
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "u1", role: "user", content: "research this", createdAt: 1 },
|
||||
@@ -577,7 +567,7 @@ describe("useSessions", () => {
|
||||
},
|
||||
{ id: "a1", role: "assistant", content: "summary", createdAt: 3 },
|
||||
],
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:chat-tools"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -596,7 +586,7 @@ describe("useSessions", () => {
|
||||
});
|
||||
|
||||
it("projects canonical transcript events with the live event reducer", async () => {
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue(api.parseWebuiThreadPayload({
|
||||
schemaVersion: 3,
|
||||
projection: "events",
|
||||
events: [
|
||||
@@ -646,7 +636,7 @@ describe("useSessions", () => {
|
||||
turn_seq: 5,
|
||||
},
|
||||
],
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:chat-event-history"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -665,13 +655,13 @@ describe("useSessions", () => {
|
||||
});
|
||||
|
||||
it("shows a cached transcript immediately while revalidating it", async () => {
|
||||
const cached = {
|
||||
const cached = canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
revision: "rev-cached",
|
||||
messages: [
|
||||
{ id: "a1", role: "assistant" as const, content: "cached answer", createdAt: 1 },
|
||||
{ id: "a1", role: "assistant", content: "cached answer", createdAt: 1 },
|
||||
],
|
||||
};
|
||||
});
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValueOnce(cached);
|
||||
|
||||
const first = renderHook(() => useSessionHistory("websocket:cached"), {
|
||||
@@ -731,7 +721,8 @@ describe("useSessions", () => {
|
||||
resolve: (body: Awaited<ReturnType<typeof api.fetchWebuiThread>>) => void;
|
||||
signal: AbortSignal | undefined;
|
||||
}> = [];
|
||||
vi.mocked(api.fetchWebuiThread).mockImplementation((_token, _key, options) => new Promise((resolve) => {
|
||||
vi.mocked(api.fetchWebuiThread).mockImplementation((_token, _key, optionsOrBase) => new Promise((resolve) => {
|
||||
const options = typeof optionsOrBase === "string" ? undefined : optionsOrBase;
|
||||
requests.push({ resolve, signal: options?.signal });
|
||||
}));
|
||||
const first = renderHook(() => useSessionHistory("websocket:shared-reconnect"), {
|
||||
@@ -773,13 +764,13 @@ describe("useSessions", () => {
|
||||
});
|
||||
|
||||
it("keeps rendered history visible when its LRU entry was evicted before refresh", async () => {
|
||||
const loaded = {
|
||||
const loaded = canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
revision: "rev-loaded",
|
||||
messages: [
|
||||
{ id: "a1", role: "assistant" as const, content: "still visible", createdAt: 1 },
|
||||
{ id: "a1", role: "assistant", content: "still visible", createdAt: 1 },
|
||||
],
|
||||
};
|
||||
});
|
||||
vi.mocked(api.fetchWebuiThread)
|
||||
.mockResolvedValueOnce(loaded)
|
||||
.mockImplementationOnce(() => new Promise(() => {}));
|
||||
@@ -801,7 +792,7 @@ describe("useSessions", () => {
|
||||
});
|
||||
|
||||
it("flags transcript ending with a trace row as pending", async () => {
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{
|
||||
@@ -813,7 +804,7 @@ describe("useSessions", () => {
|
||||
createdAt: 1,
|
||||
},
|
||||
],
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:chat-pending"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -825,7 +816,7 @@ describe("useSessions", () => {
|
||||
});
|
||||
|
||||
it("uses the server pending flag for completed tails that still end with trace rows", async () => {
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
has_pending_tool_calls: false,
|
||||
messages: [
|
||||
@@ -846,7 +837,7 @@ describe("useSessions", () => {
|
||||
createdAt: 2,
|
||||
},
|
||||
],
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:chat-cron-done"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -891,7 +882,7 @@ describe("useSessions", () => {
|
||||
active_turn_id: "incomplete-turn",
|
||||
completed_turn_ids: [],
|
||||
events: [
|
||||
{ event: "user_message", chat_id: "incomplete", text: "question", turn_id: "incomplete-turn" },
|
||||
{ event: "user_message", chat_id: "incomplete", text: "question", turn_id: "incomplete-turn", starts_turn: true },
|
||||
{ event: "turn_end", chat_id: "incomplete", turn_id: "incomplete-turn" },
|
||||
],
|
||||
});
|
||||
@@ -905,12 +896,12 @@ describe("useSessions", () => {
|
||||
});
|
||||
|
||||
it("does not flag transcript as pending when last row is not a trace", async () => {
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "a1", role: "assistant", content: "All done", createdAt: 1 },
|
||||
],
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:chat-done"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -936,12 +927,12 @@ describe("useSessions", () => {
|
||||
|
||||
it("does not reload history when only the auth token rotates", async () => {
|
||||
const tokenSource = { current: "tok-old" };
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
|
||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "a1", role: "assistant", content: "stable", createdAt: 1 },
|
||||
],
|
||||
});
|
||||
}));
|
||||
|
||||
const { result, rerender } = renderHook(
|
||||
() => useSessionHistory("websocket:token-rotation"),
|
||||
@@ -979,12 +970,12 @@ describe("useSessions", () => {
|
||||
reject(new DOMException("Aborted", "AbortError"));
|
||||
});
|
||||
}))
|
||||
.mockResolvedValueOnce({
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "a2", role: "assistant", content: "latest", createdAt: 2 },
|
||||
],
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(
|
||||
() => useSessionHistory("websocket:superseded"),
|
||||
@@ -1003,7 +994,7 @@ describe("useSessions", () => {
|
||||
|
||||
it("loads older transcript pages before the current history", async () => {
|
||||
vi.mocked(api.fetchWebuiThread)
|
||||
.mockResolvedValueOnce({
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "u2", role: "user", content: "new question", createdAt: 2 },
|
||||
@@ -1012,11 +1003,11 @@ describe("useSessions", () => {
|
||||
page: {
|
||||
before_cursor: "cursor-2",
|
||||
has_more_before: true,
|
||||
loaded_message_count: 2,
|
||||
loaded_event_count: 2,
|
||||
user_message_offset: 1,
|
||||
},
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
}))
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "u1", role: "user", content: "old question", createdAt: 0 },
|
||||
@@ -1025,10 +1016,10 @@ describe("useSessions", () => {
|
||||
page: {
|
||||
before_cursor: null,
|
||||
has_more_before: false,
|
||||
loaded_message_count: 2,
|
||||
loaded_event_count: 2,
|
||||
user_message_offset: 0,
|
||||
},
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:paged"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -1078,7 +1069,7 @@ describe("useSessions", () => {
|
||||
|
||||
it("keeps older-history failures separate and retries them explicitly", async () => {
|
||||
vi.mocked(api.fetchWebuiThread)
|
||||
.mockResolvedValueOnce({
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "u2", role: "user", content: "latest question", createdAt: 2 },
|
||||
@@ -1086,12 +1077,12 @@ describe("useSessions", () => {
|
||||
page: {
|
||||
before_cursor: "cursor-2",
|
||||
has_more_before: true,
|
||||
loaded_message_count: 1,
|
||||
loaded_event_count: 1,
|
||||
user_message_offset: 1,
|
||||
},
|
||||
})
|
||||
}))
|
||||
.mockRejectedValueOnce(new Error("offline"))
|
||||
.mockResolvedValueOnce({
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "u1", role: "user", content: "earliest question", createdAt: 1 },
|
||||
@@ -1099,10 +1090,10 @@ describe("useSessions", () => {
|
||||
page: {
|
||||
before_cursor: null,
|
||||
has_more_before: false,
|
||||
loaded_message_count: 1,
|
||||
loaded_event_count: 1,
|
||||
user_message_offset: 0,
|
||||
},
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:retry-older"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -1125,19 +1116,19 @@ describe("useSessions", () => {
|
||||
});
|
||||
|
||||
it("preserves a failed history cursor on refresh but clears it for another session", async () => {
|
||||
const latest = {
|
||||
schemaVersion: 3 as const,
|
||||
messages: [{ id: "u2", role: "user" as const, content: "question", createdAt: 2 }],
|
||||
const latest = canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [{ id: "u2", role: "user", content: "question", createdAt: 2 }],
|
||||
page: {
|
||||
before_cursor: "cursor-2", has_more_before: true,
|
||||
loaded_message_count: 1, user_message_offset: 1,
|
||||
loaded_event_count: 1, user_message_offset: 1,
|
||||
},
|
||||
};
|
||||
});
|
||||
vi.mocked(api.fetchWebuiThread)
|
||||
.mockResolvedValueOnce(latest)
|
||||
.mockRejectedValueOnce(new Error("offline"))
|
||||
.mockResolvedValueOnce({ ...latest })
|
||||
.mockResolvedValueOnce({ schemaVersion: 3, messages: [] });
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({ schemaVersion: 3, messages: [] }));
|
||||
const { result, rerender } = renderHook(({ sessionKey }) => useSessionHistory(sessionKey), {
|
||||
initialProps: { sessionKey: "websocket:failed-prefix" },
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -1161,7 +1152,7 @@ describe("useSessions", () => {
|
||||
it("aborts an older-history request when the consumer unmounts", async () => {
|
||||
let olderSignal: AbortSignal | undefined;
|
||||
vi.mocked(api.fetchWebuiThread)
|
||||
.mockResolvedValueOnce({
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "u2", role: "user", content: "latest question", createdAt: 2 },
|
||||
@@ -1169,10 +1160,10 @@ describe("useSessions", () => {
|
||||
page: {
|
||||
before_cursor: "cursor-2",
|
||||
has_more_before: true,
|
||||
loaded_message_count: 1,
|
||||
loaded_event_count: 1,
|
||||
user_message_offset: 1,
|
||||
},
|
||||
})
|
||||
}))
|
||||
.mockImplementationOnce((_token, _key, optionsOrBase) => new Promise((_resolve, reject) => {
|
||||
if (typeof optionsOrBase !== "string") olderSignal = optionsOrBase?.signal;
|
||||
olderSignal?.addEventListener("abort", () => {
|
||||
@@ -1200,7 +1191,7 @@ describe("useSessions", () => {
|
||||
|
||||
it("preserves a loaded prefix when a canonical latest window overlaps its tail", async () => {
|
||||
vi.mocked(api.fetchWebuiThread)
|
||||
.mockResolvedValueOnce({
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
has_pending_tool_calls: true,
|
||||
messages: [
|
||||
@@ -1210,11 +1201,11 @@ describe("useSessions", () => {
|
||||
page: {
|
||||
before_cursor: "cursor-middle",
|
||||
has_more_before: true,
|
||||
loaded_message_count: 2,
|
||||
loaded_event_count: 2,
|
||||
user_message_offset: 1,
|
||||
},
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
}))
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "u1", role: "user", content: "old question", createdAt: 0 },
|
||||
@@ -1223,11 +1214,11 @@ describe("useSessions", () => {
|
||||
page: {
|
||||
before_cursor: null,
|
||||
has_more_before: false,
|
||||
loaded_message_count: 2,
|
||||
loaded_event_count: 2,
|
||||
user_message_offset: 0,
|
||||
},
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
}))
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
has_pending_tool_calls: false,
|
||||
completed_turn_ids: ["turn-3"],
|
||||
@@ -1251,10 +1242,10 @@ describe("useSessions", () => {
|
||||
page: {
|
||||
before_cursor: "cursor-shifted",
|
||||
has_more_before: true,
|
||||
loaded_message_count: 3,
|
||||
loaded_event_count: 3,
|
||||
user_message_offset: 1,
|
||||
},
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:paged-refresh"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -1302,22 +1293,22 @@ describe("useSessions", () => {
|
||||
createdAt: 1_000 + index,
|
||||
}));
|
||||
vi.mocked(api.fetchWebuiThread)
|
||||
.mockResolvedValueOnce({
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: oldWindow,
|
||||
page: {
|
||||
before_cursor: "old-window-cursor",
|
||||
has_more_before: true,
|
||||
},
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
}))
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: newWindow,
|
||||
page: {
|
||||
before_cursor: "new-window-cursor",
|
||||
has_more_before: true,
|
||||
},
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:window-reset"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -1339,7 +1330,7 @@ describe("useSessions", () => {
|
||||
|
||||
it("uses the longest consecutive semantic overlap for legacy unstable replay metadata", async () => {
|
||||
vi.mocked(api.fetchWebuiThread)
|
||||
.mockResolvedValueOnce({
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "repeat-1-old", role: "user", content: "repeat", createdAt: 10 },
|
||||
@@ -1351,8 +1342,8 @@ describe("useSessions", () => {
|
||||
before_cursor: "legacy-cursor",
|
||||
has_more_before: true,
|
||||
},
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
}))
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "old-prefix", role: "user", content: "old prefix", createdAt: 1 },
|
||||
@@ -1361,8 +1352,8 @@ describe("useSessions", () => {
|
||||
before_cursor: null,
|
||||
has_more_before: false,
|
||||
},
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
}))
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "repeat-2-new", role: "user", content: "repeat", createdAt: 9_012 },
|
||||
@@ -1373,7 +1364,7 @@ describe("useSessions", () => {
|
||||
before_cursor: "shifted-legacy-cursor",
|
||||
has_more_before: true,
|
||||
},
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:legacy-overlap"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -1405,7 +1396,7 @@ describe("useSessions", () => {
|
||||
| ((value: Awaited<ReturnType<typeof api.fetchWebuiThread>>) => void)
|
||||
| null = null;
|
||||
vi.mocked(api.fetchWebuiThread)
|
||||
.mockResolvedValueOnce({
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "old-latest", role: "assistant", content: "old latest", createdAt: 10 },
|
||||
@@ -1414,11 +1405,11 @@ describe("useSessions", () => {
|
||||
before_cursor: "cursor-old-lineage",
|
||||
has_more_before: true,
|
||||
},
|
||||
})
|
||||
}))
|
||||
.mockImplementationOnce(() => new Promise((resolve) => {
|
||||
resolveOlder = resolve;
|
||||
}))
|
||||
.mockResolvedValueOnce({
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "new-latest", role: "assistant", content: "new latest", createdAt: 20 },
|
||||
@@ -1427,7 +1418,7 @@ describe("useSessions", () => {
|
||||
before_cursor: "cursor-new-lineage",
|
||||
has_more_before: true,
|
||||
},
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:paged-race"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -1466,7 +1457,7 @@ describe("useSessions", () => {
|
||||
|
||||
it("preserves authoritative active state while prepending older history", async () => {
|
||||
vi.mocked(api.fetchWebuiThread)
|
||||
.mockResolvedValueOnce({
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
has_pending_tool_calls: true,
|
||||
messages: [
|
||||
@@ -1476,11 +1467,11 @@ describe("useSessions", () => {
|
||||
page: {
|
||||
before_cursor: "cursor-active",
|
||||
has_more_before: true,
|
||||
loaded_message_count: 2,
|
||||
loaded_event_count: 2,
|
||||
user_message_offset: 1,
|
||||
},
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
}))
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
has_pending_tool_calls: false,
|
||||
messages: [
|
||||
@@ -1490,10 +1481,10 @@ describe("useSessions", () => {
|
||||
page: {
|
||||
before_cursor: null,
|
||||
has_more_before: false,
|
||||
loaded_message_count: 2,
|
||||
loaded_event_count: 2,
|
||||
user_message_offset: 0,
|
||||
},
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:paged-active"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
@@ -1513,7 +1504,7 @@ describe("useSessions", () => {
|
||||
|
||||
it("preserves authoritative completed state while prepending trace history", async () => {
|
||||
vi.mocked(api.fetchWebuiThread)
|
||||
.mockResolvedValueOnce({
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
has_pending_tool_calls: false,
|
||||
messages: [
|
||||
@@ -1529,11 +1520,11 @@ describe("useSessions", () => {
|
||||
page: {
|
||||
before_cursor: "cursor-complete",
|
||||
has_more_before: true,
|
||||
loaded_message_count: 1,
|
||||
loaded_event_count: 1,
|
||||
user_message_offset: 1,
|
||||
},
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
}))
|
||||
.mockResolvedValueOnce(canonicalThreadPayload({
|
||||
schemaVersion: 3,
|
||||
messages: [
|
||||
{ id: "u1", role: "user", content: "old question", createdAt: 0 },
|
||||
@@ -1542,10 +1533,10 @@ describe("useSessions", () => {
|
||||
page: {
|
||||
before_cursor: null,
|
||||
has_more_before: false,
|
||||
loaded_message_count: 2,
|
||||
loaded_event_count: 2,
|
||||
user_message_offset: 0,
|
||||
},
|
||||
});
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSessionHistory("websocket:paged-complete"), {
|
||||
wrapper: wrap(fakeClient()),
|
||||
|
||||
@@ -8,13 +8,18 @@ import { ViewportCodeRows } from "@/components/ViewportCodeRows";
|
||||
|
||||
SyntaxHighlighter.registerLanguage("markup", markup);
|
||||
|
||||
let notify: IntersectionObserverCallback;
|
||||
let notify: (entries: IntersectionObserverEntry[]) => void;
|
||||
const disconnect = vi.fn();
|
||||
const observe = vi.fn();
|
||||
function showChunks(indices: number[]) {
|
||||
const entries = [...document.querySelectorAll<HTMLElement>("[data-code-chunk]")]
|
||||
.map(target => ({ target, isIntersecting: indices.includes(Number(target.dataset.codeChunk)) }));
|
||||
act(() => notify(entries as IntersectionObserverEntry[], {} as IntersectionObserver));
|
||||
.map((target): IntersectionObserverEntry => {
|
||||
const isIntersecting = indices.includes(Number(target.dataset.codeChunk));
|
||||
const rect = target.getBoundingClientRect();
|
||||
return { target, isIntersecting, time: 0, boundingClientRect: rect,
|
||||
intersectionRect: rect, intersectionRatio: isIntersecting ? 1 : 0, rootBounds: null };
|
||||
});
|
||||
act(() => notify(entries));
|
||||
}
|
||||
function sourceText() {
|
||||
return [...document.querySelectorAll("[data-highlighted]")].map(node => node.textContent).join("");
|
||||
@@ -26,10 +31,15 @@ function preview(code: string) {
|
||||
|
||||
describe("viewport code highlighting", () => {
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal("IntersectionObserver", class {
|
||||
constructor(callback: IntersectionObserverCallback) { notify = callback; }
|
||||
vi.stubGlobal("IntersectionObserver", class implements IntersectionObserver {
|
||||
readonly root = null;
|
||||
readonly rootMargin = "0px";
|
||||
readonly thresholds = [0];
|
||||
constructor(callback: IntersectionObserverCallback) { notify = entries => callback(entries, this); }
|
||||
observe = observe;
|
||||
disconnect = disconnect;
|
||||
unobserve = vi.fn();
|
||||
takeRecords = () => [];
|
||||
});
|
||||
observe.mockClear();
|
||||
disconnect.mockClear();
|
||||
|
||||
@@ -4,7 +4,8 @@ import QRCode from "qrcode";
|
||||
|
||||
import type { NanobotFeatureInfo } from "@/lib/types";
|
||||
import { WeixinConnectFlow } from "../../../nanobot/channels/weixin/webui/WeixinConnectFlow";
|
||||
import { WeixinConnectFlowView } from "../../../nanobot/channels/weixin/webui/WeixinConnectFlowView";
|
||||
import { WeixinConnectFlowView, type WeixinConnectFlowViewProps } from "../../../nanobot/channels/weixin/webui/WeixinConnectFlowView";
|
||||
import type { WeixinVerificationPayload } from "../../../nanobot/channels/weixin/webui/presentation";
|
||||
|
||||
const { requestMutation, useClientMock } = vi.hoisted(() => ({
|
||||
requestMutation: vi.fn(), useClientMock: vi.fn(),
|
||||
@@ -12,9 +13,10 @@ const { requestMutation, useClientMock } = vi.hoisted(() => ({
|
||||
vi.mock("@/providers/ClientProvider", () => ({ useClient: useClientMock }));
|
||||
|
||||
const challenge = {
|
||||
session_id: "weixin-verification", status: "pending" as const,
|
||||
qr_url: "https://example.com/weixin", challenge: "verify_code" as const,
|
||||
};
|
||||
session_id: "weixin-verification", status: "pending",
|
||||
qr_url: "https://example.com/weixin", challenge: "verify_code",
|
||||
} satisfies WeixinVerificationPayload;
|
||||
const rejectedChallenge = { ...challenge, verification_failed: true } satisfies WeixinVerificationPayload;
|
||||
const feature: NanobotFeatureInfo = {
|
||||
name: "weixin", display_name: "WeChat", type: "channel", webui: "webui/index.tsx",
|
||||
enabled: false, configured: false, installed: true, ready: true, status: "not_enabled",
|
||||
@@ -24,13 +26,13 @@ const feature: NanobotFeatureInfo = {
|
||||
beforeEach(() => {
|
||||
requestMutation.mockReset();
|
||||
useClientMock.mockReset().mockReturnValue({ client: { requestMutation } });
|
||||
vi.spyOn(QRCode, "toDataURL").mockResolvedValue("data:image/png;base64,preview");
|
||||
vi.spyOn(QRCode, "toDataURL").mockImplementation(async () => "data:image/png;base64,preview");
|
||||
});
|
||||
afterEach(() => { cleanup(); vi.useRealTimers(); vi.restoreAllMocks(); });
|
||||
|
||||
describe("WeChat verification views", () => {
|
||||
it("renders without a runtime client and retains the verification draft after a rejected code", async () => {
|
||||
const onPoll = vi.fn().mockResolvedValue({ ...challenge, verification_failed: true });
|
||||
const onPoll = vi.fn<WeixinConnectFlowViewProps["onPoll"]>().mockResolvedValue(rejectedChallenge);
|
||||
const props = {
|
||||
connect: challenge, busy: false, error: null, minimalPending: true,
|
||||
onStart: vi.fn(), onCancel: vi.fn(), onPoll,
|
||||
@@ -38,13 +40,13 @@ describe("WeChat verification views", () => {
|
||||
const view = render(<WeixinConnectFlowView {...props} />);
|
||||
const code = screen.getByRole("textbox", { name: "Code" });
|
||||
fireEvent.change(code, { target: { value: " 987654 " } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Verify", exact: true }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Verify" }));
|
||||
await waitFor(() => expect(onPoll).toHaveBeenCalledWith({ verify_code: "987654" }));
|
||||
view.rerender(<WeixinConnectFlowView {...props} connect={{ ...challenge, verification_failed: true }} busy />);
|
||||
view.rerender(<WeixinConnectFlowView {...props} connect={rejectedChallenge} busy />);
|
||||
expect(code).toHaveValue(" 987654 ");
|
||||
expect(code).toHaveAttribute("aria-invalid", "true");
|
||||
expect(code).toHaveAttribute("aria-describedby", screen.getByRole("alert").id);
|
||||
expect(screen.getByRole("button", { name: "Verify", exact: true })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "Verify" })).toBeDisabled();
|
||||
expect(useClientMock).not.toHaveBeenCalled();
|
||||
expect(requestMutation).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -59,9 +61,9 @@ describe("WeChat verification views", () => {
|
||||
expect(requestMutation).toHaveBeenCalledTimes(1);
|
||||
expect(requestMutation).toHaveBeenCalledWith("settings.channel.connect.start", { channel: "weixin" }, 150_000);
|
||||
|
||||
requestMutation.mockResolvedValueOnce({ ...challenge, verification_failed: true });
|
||||
requestMutation.mockResolvedValueOnce(rejectedChallenge);
|
||||
fireEvent.change(code, { target: { value: "123456" } });
|
||||
await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Verify", exact: true })); });
|
||||
await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Verify" })); });
|
||||
expect(requestMutation).toHaveBeenLastCalledWith("settings.channel.connect.poll", {
|
||||
channel: "weixin", session_id: "weixin-verification", verify_code: "123456",
|
||||
}, 150_000);
|
||||
@@ -70,7 +72,7 @@ describe("WeChat verification views", () => {
|
||||
|
||||
const features = { features: [{ ...feature, configured: true }], enabled_count: 0 };
|
||||
requestMutation.mockResolvedValueOnce({ ...challenge, status: "succeeded", nanobot_features: features });
|
||||
await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Verify", exact: true })); });
|
||||
await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Verify" })); });
|
||||
expect(onFeaturesUpdate).toHaveBeenCalledWith(features);
|
||||
expect(screen.getByText("WeChat is connected.")).toBeVisible();
|
||||
expect(screen.queryByRole("textbox", { name: "Code" })).not.toBeInTheDocument();
|
||||
|
||||
@@ -60,17 +60,17 @@ describe("Workspace project picker", () => {
|
||||
await user.click(screen.getByRole("button", { name: "Switch directory" }));
|
||||
await user.click(await screen.findByRole("button", { name: "/srv/beta" }));
|
||||
await screen.findByRole("listbox", { name: "/srv/beta" });
|
||||
await user.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Back" }));
|
||||
await screen.findByRole("listbox", { name: scope.project_path });
|
||||
await user.click(screen.getByRole("button", { name: "Forward", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Forward" }));
|
||||
await screen.findByRole("listbox", { name: "/srv/beta" });
|
||||
await user.click(within(screen.getByRole("navigation", { name: "Current location" })).getByRole("button", { name: "srv", exact: true }));
|
||||
await user.click(within(screen.getByRole("navigation", { name: "Current location" })).getByRole("button", { name: "srv" }));
|
||||
await screen.findByRole("listbox", { name: "/srv" });
|
||||
await user.click(within(screen.getByRole("navigation", { name: "Current location" })).getByRole("button", { name: "/", exact: true }));
|
||||
await screen.findByRole("listbox", { name: "/", exact: true });
|
||||
await user.click(within(screen.getByRole("navigation", { name: "Current location" })).getByRole("button", { name: "/" }));
|
||||
await screen.findByRole("listbox", { name: "/" });
|
||||
expect(screen.queryByRole("button", { name: "Parent folder" })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Forward", exact: true })).toBeDisabled();
|
||||
await user.click(screen.getByRole("button", { name: "Cancel", exact: true }));
|
||||
expect(screen.getByRole("button", { name: "Forward" })).toBeDisabled();
|
||||
await user.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -85,7 +85,7 @@ describe("Workspace project picker", () => {
|
||||
expect(lastVisited).toBeDisabled();
|
||||
await user.click(await screen.findByRole("button", { name: "/srv/alpha" }));
|
||||
await screen.findByRole("listbox", { name: "/srv/alpha" });
|
||||
await user.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Back" }));
|
||||
await screen.findByRole("listbox", { name: scope.project_path });
|
||||
await user.click(lastVisited);
|
||||
await screen.findByRole("listbox", { name: "/srv/alpha" });
|
||||
@@ -95,7 +95,7 @@ describe("Workspace project picker", () => {
|
||||
await screen.findByRole("listbox", { name: "/srv/alpha" });
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
await user.click(screen.getByRole("button", { name: "Cancel", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
await user.click(screen.getByRole("button", { name: "Switch directory" }));
|
||||
expect(screen.getByRole("button", { name: "Last visited folder" })).toBeDisabled();
|
||||
});
|
||||
@@ -123,20 +123,20 @@ describe("Workspace project picker", () => {
|
||||
expect(screen.getAllByRole("listbox")).toHaveLength(2);
|
||||
expect(screen.getByRole("option", { name: "/srv/workspace/memory" })).toHaveAttribute("aria-selected", "true");
|
||||
expect(screen.getByRole("listbox", { name: scope.project_path }).scrollTop).toBe(44);
|
||||
await user.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Back" }));
|
||||
await screen.findByRole("listbox", { name: "/srv/workspace/prompts" });
|
||||
expect(screen.getAllByRole("listbox")).toHaveLength(2);
|
||||
expect(screen.getByRole("option", { name: "/srv/workspace/prompts" })).toHaveAttribute("aria-selected", "true");
|
||||
await user.click(screen.getByRole("button", { name: "Forward", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Forward" }));
|
||||
await screen.findByRole("option", { name: "/srv/workspace/memory/reference" });
|
||||
expect(screen.getAllByRole("listbox")).toHaveLength(2);
|
||||
await user.click(within(screen.getByRole("navigation", { name: "Current location" })).getByRole("button", { name: "workspace", exact: true }));
|
||||
await user.click(within(screen.getByRole("navigation", { name: "Current location" })).getByRole("button", { name: "workspace" }));
|
||||
await screen.findByRole("listbox", { name: scope.project_path });
|
||||
rootChanged = true;
|
||||
const systemNow = Date.now;
|
||||
const clock = vi.spyOn(Date, "now").mockImplementation(() => systemNow() + 31_000);
|
||||
try {
|
||||
await user.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Back" }));
|
||||
await screen.findByRole("option", { name: "/srv/workspace/new-folder" });
|
||||
expect(screen.getByRole("option", { name: "/srv/workspace/memory" })).toHaveAttribute("aria-selected", "true");
|
||||
expect(screen.getAllByRole("listbox")).toHaveLength(2);
|
||||
@@ -677,7 +677,7 @@ describe("Workspace project picker", () => {
|
||||
const filter = screen.getByRole("textbox", { name: "Filter folders" });
|
||||
await user.type(filter, "hjkl");
|
||||
expect(filter).toHaveValue("hjkl");
|
||||
expect(screen.getByRole("listbox", { name: "/srv/workspace", exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByRole("listbox", { name: "/srv/workspace" })).toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: /^Edit path:/ }));
|
||||
const editor = screen.getByRole("combobox");
|
||||
await user.clear(editor);
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
|
||||
"types": ["node", "vitest/globals", "@testing-library/jest-dom"],
|
||||
"types": ["node", "vite/client", "vitest/globals", "@testing-library/jest-dom"],
|
||||
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
|
||||
Reference in new issue
Block a user