feat(network): centralize proxy settings and add MCP routing (NAN-315) (#6372)
* feat(network): share proxy settings across features and MCP (NAN-315) * fix(network): address shared proxy review regressions * test(network): align rebased OAuth fixtures with runtime admission * fix(webui): configure shared proxy without leaving connection drafts * feat(webui): add optional shared proxy authentication editor * fix(webui): align proxy save tests and loading skeleton
This commit is contained in:
1 parent
872a83340d
commit
084b6bb394
181 files changed
+3740
-807
No files matched your search
@@ -841,7 +841,7 @@ describe("webui API helpers", () => {
|
||||
it("serializes OAuth provider advanced settings", async () => {
|
||||
await updateProviderSettings(mutationTransport, {
|
||||
provider: "xai_grok",
|
||||
proxy: "http://127.0.0.1:7890",
|
||||
use_proxy: true,
|
||||
extraBody: '{"tools":[]}',
|
||||
});
|
||||
|
||||
@@ -849,7 +849,7 @@ describe("webui API helpers", () => {
|
||||
"settings.provider.update",
|
||||
{
|
||||
provider: "xai_grok",
|
||||
proxy: "http://127.0.0.1:7890",
|
||||
use_proxy: true,
|
||||
extraBody: '{"tools":[]}',
|
||||
},
|
||||
20_000,
|
||||
@@ -864,7 +864,7 @@ describe("webui API helpers", () => {
|
||||
extraHeaders: '{"X-Tenant":"engineering"}',
|
||||
extraBody: '{"service_tier":"priority"}',
|
||||
extraQuery: '{"api-version":"2026-01-01"}',
|
||||
proxy: "http://127.0.0.1:7890",
|
||||
use_proxy: true,
|
||||
thinkingStyle: "enable_thinking",
|
||||
};
|
||||
await createProviderSettings(mutationTransport, update);
|
||||
@@ -1182,6 +1182,18 @@ describe("webui API helpers", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.each(["true", "false"])("preserves explicit MCP proxy flag %s across setup and edits", async (use_proxy) => {
|
||||
await runMcpPresetAction(mutationTransport, "enable", "notion", { use_proxy });
|
||||
expect(requestMutation).toHaveBeenLastCalledWith("settings.mcp.enable", { name: "notion", use_proxy }, 20_000);
|
||||
await startMcpOAuth(mutationTransport, "notion", false, { use_proxy });
|
||||
expect(requestMutation).toHaveBeenLastCalledWith("settings.mcp.oauth_start", { name: "notion", use_proxy }, 30_000);
|
||||
await runMcpPresetAction(mutationTransport, "proxy", "notion", { use_proxy });
|
||||
expect(requestMutation).toHaveBeenLastCalledWith("settings.mcp.proxy", { name: "notion", use_proxy }, 20_000);
|
||||
const custom = { name: "docs", transport: "sse", url: "https://example.com/sse", use_proxy };
|
||||
await saveCustomMcpServer(mutationTransport, custom);
|
||||
expect(requestMutation).toHaveBeenLastCalledWith("settings.mcp.custom", custom, 20_000);
|
||||
});
|
||||
|
||||
it("serializes custom MCP, mcp.json import, and tool allowlist actions", async () => {
|
||||
const custom = {
|
||||
name: "docs",
|
||||
|
||||
@@ -122,7 +122,7 @@ function baseSettingsPayload() {
|
||||
},
|
||||
web: {
|
||||
enable: true,
|
||||
proxy: null,
|
||||
use_proxy: false,
|
||||
user_agent: null,
|
||||
search: { max_results: 5, timeout: 30 },
|
||||
fetch: { use_jina_reader: true },
|
||||
@@ -3482,7 +3482,7 @@ describe("App layout", () => {
|
||||
},
|
||||
web: {
|
||||
enable: true,
|
||||
proxy: null,
|
||||
use_proxy: false,
|
||||
user_agent: null,
|
||||
search: { max_results: 5, timeout: 30 },
|
||||
fetch: { use_jina_reader: true },
|
||||
|
||||
@@ -54,6 +54,32 @@ describe("CredentialForm", () => {
|
||||
expect(onChange).toHaveBeenCalledWith(key, "");
|
||||
});
|
||||
|
||||
it.each(["telegram", "discord", "matrix", "slack", "whatsapp"])("renders %s proxy configuration as a switch and submits both boolean states", (channel) => {
|
||||
const key = `channels.${channel}.useProxy`;
|
||||
const setup = channelSetup({
|
||||
name: channel, display_name: channel, type: "channel", enabled: true,
|
||||
webui: channel === "whatsapp" ? "webui/index.tsx" : "webui/index.ts",
|
||||
installed: true, ready: true, status: "enabled",
|
||||
install_supported: true, requires_restart: false,
|
||||
setup: { fields: [{ key, field: "use_proxy", kind: "bool", choices: [], required: false, default_value: "false" }] },
|
||||
});
|
||||
const proxyFields = [...setup.fields ?? [], ...setup.manualFields ?? []];
|
||||
expect(proxyFields[0].section).toBe("connection");
|
||||
const onChange = vi.fn();
|
||||
const { rerender } = render(<CredentialForm fields={proxyFields} values={{ [key]: "true" }}
|
||||
visibleSecrets={{}} onChange={onChange} onToggleSecret={vi.fn()} />);
|
||||
const useProxy = screen.getByRole("switch", { name: "Use proxy" });
|
||||
expect(useProxy).toBeChecked();
|
||||
expect(screen.queryByRole("textbox")).not.toBeInTheDocument();
|
||||
fireEvent.click(useProxy);
|
||||
expect(onChange).toHaveBeenCalledWith(key, "false");
|
||||
expect(channelValuesForSubmit(proxyFields, { [key]: "false" }, new Set([key]))).toEqual({ [key]: "false" });
|
||||
rerender(<CredentialForm fields={proxyFields} values={{ [key]: "false" }}
|
||||
visibleSecrets={{}} onChange={onChange} onToggleSecret={vi.fn()} />);
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Use proxy" }));
|
||||
expect(onChange).toHaveBeenLastCalledWith(key, "true");
|
||||
});
|
||||
|
||||
it("uses native radio semantics for option fields", () => {
|
||||
const onChange = vi.fn();
|
||||
render(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { act, fireEvent, render, renderHook, screen, waitFor, within } from "@testing-library/react";
|
||||
import { useState } from "react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
@@ -6,8 +6,18 @@ import {
|
||||
McpManagementDialog,
|
||||
type McpManagementTab,
|
||||
} from "@/components/settings/system/McpManagementDialog";
|
||||
import { createSystemSettingsActions } from "@/components/settings/system/createSystemSettingsActions";
|
||||
import { useSystemSettingsState } from "@/components/settings/system/useSystemSettingsState";
|
||||
import i18n from "@/i18n";
|
||||
import type { McpPresetInfo } from "@/lib/types";
|
||||
import { NanobotClient } from "@/lib/nanobot-client";
|
||||
import type { McpPresetInfo, McpPresetsPayload } from "@/lib/types";
|
||||
import {
|
||||
installSettingsViewTestHooks,
|
||||
jsonResponse,
|
||||
renderSettingsView,
|
||||
requestMutationMock,
|
||||
settingsPayload,
|
||||
} from "@/tests/settings-test-utils";
|
||||
|
||||
const connectedPreset: McpPresetInfo = {
|
||||
name: "docs",
|
||||
@@ -83,6 +93,51 @@ describe("McpManagementDialog", () => {
|
||||
expect(onAction).toHaveBeenCalledWith("reconnect", "docs", {});
|
||||
});
|
||||
|
||||
it.each(["streamableHttp", "sse"])("edits an existing %s proxy flag without restarting OAuth", (transport) => {
|
||||
const onAction = vi.fn();
|
||||
const { updateDialog } = renderDialog({
|
||||
initialTab: "connection", onAction,
|
||||
preset: { ...connectedPreset, transport, use_proxy: true },
|
||||
});
|
||||
const useProxy = screen.getByRole("switch", { name: "Use proxy" });
|
||||
expect(useProxy).toBeChecked();
|
||||
expect(screen.queryByRole("textbox", { name: /proxy/i })).not.toBeInTheDocument();
|
||||
fireEvent.click(useProxy);
|
||||
expect(onAction).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save changes" }));
|
||||
expect(onAction).toHaveBeenCalledWith("proxy", "docs", { use_proxy: "false" });
|
||||
updateDialog({ ...connectedPreset, transport, use_proxy: false });
|
||||
expect(useProxy).not.toBeChecked();
|
||||
expect(screen.queryByRole("button", { name: "Save changes" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows proxy guidance on demand without changing the connection draft", async () => {
|
||||
const onAction = vi.fn();
|
||||
renderDialog({ initialTab: "connection", onAction });
|
||||
expect(screen.queryByText("Uses the shared proxy in Advanced.")).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Use proxy" }));
|
||||
expect(await screen.findByRole("tooltip")).toHaveTextContent("Uses the shared proxy in Advanced.");
|
||||
expect(onAction).not.toHaveBeenCalled();
|
||||
expect(screen.getByRole("switch", { name: "Use proxy" })).not.toBeChecked();
|
||||
expect(screen.queryByRole("button", { name: "Save changes" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("preserves the configured proxy flag when reconnecting OAuth", () => {
|
||||
const onOAuthConnect = vi.fn();
|
||||
renderDialog({
|
||||
initialTab: "connection", onOAuthConnect,
|
||||
preset: { ...connectedPreset, auth: "oauth", use_proxy: true },
|
||||
});
|
||||
expect(screen.getByRole("switch", { name: "Use proxy" })).toBeChecked();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Reconnect" }));
|
||||
expect(onOAuthConnect).toHaveBeenCalledWith("docs", true, { use_proxy: "true" });
|
||||
});
|
||||
|
||||
it("does not offer a proxy switch for stdio servers", () => {
|
||||
renderDialog({ initialTab: "connection", preset: { ...connectedPreset, transport: "stdio" } });
|
||||
expect(screen.queryByRole("switch", { name: "Use proxy" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("loads tools on entry and replaces passive inspection copy with recovery", async () => {
|
||||
const onAction = vi.fn();
|
||||
renderDialog({
|
||||
@@ -154,21 +209,24 @@ function renderDialog({
|
||||
initialTab,
|
||||
onAction = vi.fn(),
|
||||
onToolsChange = vi.fn(),
|
||||
onOAuthConnect = vi.fn(),
|
||||
preset = connectedPreset,
|
||||
actionKey = null,
|
||||
}: {
|
||||
initialTab: McpManagementTab;
|
||||
onAction?: ReturnType<typeof vi.fn>;
|
||||
onToolsChange?: ReturnType<typeof vi.fn>;
|
||||
onOAuthConnect?: ReturnType<typeof vi.fn>;
|
||||
preset?: McpPresetInfo;
|
||||
actionKey?: string | null;
|
||||
}) {
|
||||
function Harness({ preset, actionKey }: { preset: McpPresetInfo; actionKey: string | null }) {
|
||||
const [tab, setTab] = useState(initialTab);
|
||||
const [values, setValues] = useState<Record<string, string>>({});
|
||||
return (
|
||||
<McpManagementDialog
|
||||
preset={preset}
|
||||
values={{}}
|
||||
values={values}
|
||||
actionKey={actionKey}
|
||||
statusLabel="Connected"
|
||||
statusTone="success"
|
||||
@@ -176,9 +234,9 @@ function renderDialog({
|
||||
icon={<span aria-hidden>DM</span>}
|
||||
onTabChange={setTab}
|
||||
onOpenChange={vi.fn()}
|
||||
onFieldChange={vi.fn()}
|
||||
onFieldChange={(_name, field, value) => setValues((prev) => ({ ...prev, [field]: value }))}
|
||||
onAction={onAction}
|
||||
onOAuthConnect={vi.fn()}
|
||||
onOAuthConnect={onOAuthConnect}
|
||||
onToolsChange={onToolsChange}
|
||||
/>
|
||||
);
|
||||
@@ -191,3 +249,241 @@ function renderDialog({
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("MCP connection draft lifecycle", () => {
|
||||
installSettingsViewTestHooks();
|
||||
|
||||
const metabasePreset: McpPresetInfo = {
|
||||
...connectedPreset,
|
||||
name: "metabase",
|
||||
display_name: "Metabase",
|
||||
auth: "oauth",
|
||||
source: "preset",
|
||||
required_fields: [{
|
||||
name: "mcp_url", label: "MCP server URL", secret: false, required: true, configured: true,
|
||||
}],
|
||||
};
|
||||
|
||||
it("reopens and reconnects without proxy after OAuth with proxy and a same-endpoint import", async () => {
|
||||
const endpoint = "https://app.xmind.com/api/mcp";
|
||||
let preset: McpPresetInfo = {
|
||||
...connectedPreset,
|
||||
name: "xmind",
|
||||
display_name: "Xmind",
|
||||
auth: "oauth",
|
||||
source: "preset",
|
||||
installed: false,
|
||||
configured: false,
|
||||
available: false,
|
||||
status: "not_installed",
|
||||
runtime_status: undefined,
|
||||
connection_summary: "",
|
||||
use_proxy: false,
|
||||
};
|
||||
const importedConfig = JSON.stringify({
|
||||
mcpServers: { Xmind: { url: endpoint, auth: "oauth", useProxy: false } },
|
||||
});
|
||||
vi.stubGlobal("open", vi.fn(() => null));
|
||||
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/settings") return jsonResponse(settingsPayload());
|
||||
if (url === "/api/settings/cli-apps") return jsonResponse({ apps: [], installed_count: 0 });
|
||||
if (url === "/api/settings/mcp-presets") {
|
||||
return jsonResponse({ presets: [preset], installed_count: Number(preset.installed) });
|
||||
}
|
||||
if (url === "/api/settings/mcp-oauth/status?flow_id=flow-proxy") {
|
||||
preset = {
|
||||
...preset,
|
||||
installed: true,
|
||||
configured: true,
|
||||
available: true,
|
||||
status: "configured",
|
||||
runtime_status: "connected",
|
||||
connection_summary: endpoint,
|
||||
use_proxy: true,
|
||||
};
|
||||
return jsonResponse({
|
||||
flow_id: "flow-proxy", name: "xmind", status: "connected", expires_in: 299,
|
||||
});
|
||||
}
|
||||
return { ok: false, status: 404, text: async () => "Not found" } as Response;
|
||||
}));
|
||||
requestMutationMock.mockImplementation(async (action: string) => {
|
||||
if (action === "settings.mcp.oauth_start") {
|
||||
return {
|
||||
flow_id: "flow-proxy", name: "xmind", status: "authorization_required", expires_in: 300,
|
||||
authorization_url: "https://accounts.xmind.test/authorize?state=proxy",
|
||||
};
|
||||
}
|
||||
if (action === "settings.mcp.import") {
|
||||
preset = { ...preset, use_proxy: false };
|
||||
return {
|
||||
presets: [preset], installed_count: 1,
|
||||
last_action: { ok: true, message: "Imported 1 MCP server(s)." },
|
||||
};
|
||||
}
|
||||
if (action === "settings.mcp.oauth_cancel") {
|
||||
return { flow_id: "flow-proxy", name: "xmind", status: "cancelled", expires_in: 299 };
|
||||
}
|
||||
throw new Error(`Unexpected mutation: ${action}`);
|
||||
});
|
||||
|
||||
renderSettingsView({ initialSection: "apps" });
|
||||
fireEvent.click(await screen.findByRole("button", { name: "MCP" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Connect Xmind" }));
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Use proxy" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.mcp.oauth_start", { name: "xmind", use_proxy: "true" }, 30_000,
|
||||
));
|
||||
await screen.findByRole("button", { name: "Manage Xmind" });
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Import" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Import mcp.json" }));
|
||||
const editor = screen.getByRole("dialog", { name: "Import mcp.json" });
|
||||
fireEvent.change(within(editor).getByRole("textbox", { name: "Import mcp.json" }), {
|
||||
target: { value: importedConfig },
|
||||
});
|
||||
await act(async () => fireEvent.click(within(editor).getByRole("button", { name: "Save" })));
|
||||
await act(async () => fireEvent.click(screen.getAllByRole("button", { name: "Import" })[1]));
|
||||
expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.mcp.import", { config: importedConfig }, 20_000,
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Manage Xmind" }));
|
||||
fireEvent.click(screen.getByRole("tab", { name: "Connection" }));
|
||||
expect(screen.getByRole("switch", { name: "Use proxy" })).not.toBeChecked();
|
||||
expect(screen.getByText(endpoint)).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Reconnect" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
|
||||
"settings.mcp.oauth_start", { name: "xmind", reset: true, use_proxy: "false" }, 30_000,
|
||||
));
|
||||
const cancel = await screen.findByRole("button", { name: "Cancel" });
|
||||
await act(async () => fireEvent.click(cancel));
|
||||
});
|
||||
|
||||
it("retires the consumed OAuth proxy draft only after success, preserving a failed attempt", async () => {
|
||||
const { result } = renderMcpActions();
|
||||
const drafts = { docs: { use_proxy: "true" }, metabase: { mcp_url: "https://analytics.example.com/mcp", use_proxy: "true" } };
|
||||
await act(async () => result.current.state.setMcpFieldValues(drafts));
|
||||
vi.stubGlobal("open", vi.fn(() => null));
|
||||
requestMutationMock.mockResolvedValueOnce({
|
||||
flow_id: "flow-failed", name: "docs", status: "failed", error: "Proxy connection failed", expires_in: 300,
|
||||
});
|
||||
|
||||
await act(async () => result.current.actions.handleMcpOAuthConnect("docs", false, drafts.docs));
|
||||
expect(result.current.state.mcpError).toBe("Proxy connection failed");
|
||||
expect(result.current.state.mcpFieldValues).toEqual(drafts);
|
||||
|
||||
requestMutationMock.mockResolvedValueOnce({
|
||||
flow_id: "flow-connected", name: "docs", status: "connected", expires_in: 300,
|
||||
});
|
||||
vi.stubGlobal("fetch", vi.fn(async () => jsonResponse({
|
||||
presets: [{ ...connectedPreset, auth: "oauth", use_proxy: true }], installed_count: 1,
|
||||
})));
|
||||
await act(async () => result.current.actions.handleMcpOAuthConnect("docs", false, drafts.docs));
|
||||
expect(result.current.state.mcpPresets?.presets[0].use_proxy).toBe(true);
|
||||
expect(result.current.state.mcpFieldValues).toEqual({ docs: {}, metabase: drafts.metabase });
|
||||
});
|
||||
|
||||
it.each([true, false])("reconciles only accepted import names (mcpServers wrapper: %s)", async (wrapped) => {
|
||||
const { result } = renderMcpActions();
|
||||
const drafts = {
|
||||
metabase: { use_proxy: "true", mcp_url: "https://analytics.example.com/mcp" },
|
||||
docs: { use_proxy: "true" },
|
||||
};
|
||||
const servers = { Metabase: { url: metabasePreset.connection_summary, auth: "oauth", useProxy: false } };
|
||||
const config = JSON.stringify(wrapped ? { mcpServers: servers } : servers);
|
||||
await act(async () => {
|
||||
result.current.state.setMcpFieldValues(drafts);
|
||||
result.current.state.setMcpConfigImport(config);
|
||||
});
|
||||
requestMutationMock.mockRejectedValueOnce(new Error("Import could not be saved"));
|
||||
await act(async () => result.current.actions.handleImportMcpConfig());
|
||||
expect(result.current.state.mcpFieldValues).toEqual(drafts);
|
||||
expect(result.current.state.mcpConfigImport).toBe(config);
|
||||
|
||||
requestMutationMock.mockResolvedValueOnce({
|
||||
presets: [{ ...metabasePreset, use_proxy: false }, connectedPreset],
|
||||
installed_count: 2,
|
||||
last_action: { ok: true, message: "Imported 1 MCP server(s)." },
|
||||
});
|
||||
await act(async () => result.current.actions.handleImportMcpConfig());
|
||||
expect(result.current.state.mcpFieldValues).toEqual({
|
||||
metabase: { mcp_url: drafts.metabase.mcp_url }, docs: drafts.docs,
|
||||
});
|
||||
expect(result.current.state.mcpConfigImport).toBe("");
|
||||
});
|
||||
|
||||
it("reconciles a saved custom replacement even while its OAuth authorization is pending", async () => {
|
||||
const { result } = renderMcpActions();
|
||||
await act(async () => {
|
||||
result.current.state.setMcpFieldValues({
|
||||
metabase: { use_proxy: "true", mcp_url: "https://analytics.example.com/mcp" }, docs: { use_proxy: "true" },
|
||||
});
|
||||
result.current.state.setCustomMcpForm((prev) => ({
|
||||
...prev, name: "Metabase", transport: "streamableHttp", auth: "oauth",
|
||||
url: metabasePreset.connection_summary, useProxy: false,
|
||||
}));
|
||||
});
|
||||
requestMutationMock.mockResolvedValueOnce({
|
||||
presets: [{ ...metabasePreset, configured: false, use_proxy: false, status: "authorization_required" }],
|
||||
installed_count: 1,
|
||||
last_action: { ok: true, message: "Saved MCP server metabase." },
|
||||
hot_reload: { ok: false, message: "Authorization required", failed: ["metabase"] },
|
||||
});
|
||||
await act(async () => result.current.actions.handleSaveCustomMcp());
|
||||
expect(result.current.state.mcpError).toBeNull();
|
||||
expect(result.current.state.mcpFieldValues).toEqual({
|
||||
metabase: { mcp_url: "https://analytics.example.com/mcp" }, docs: { use_proxy: "true" },
|
||||
});
|
||||
});
|
||||
|
||||
it("retains failed proxy drafts, then retires applied or removed flags without discarding other edits", async () => {
|
||||
const { result } = renderMcpActions();
|
||||
const drafts = {
|
||||
metabase: { use_proxy: "true", mcp_url: "https://analytics.example.com/mcp" }, docs: { use_proxy: "true" },
|
||||
};
|
||||
await act(async () => result.current.state.setMcpFieldValues(drafts));
|
||||
const payload: McpPresetsPayload = { presets: [{ ...metabasePreset, use_proxy: true }], installed_count: 1 };
|
||||
requestMutationMock.mockRejectedValueOnce(new Error("Proxy could not be saved"));
|
||||
await act(async () => result.current.actions.handleMcpPresetAction("proxy", "metabase", { use_proxy: "true" }));
|
||||
expect(result.current.state.mcpFieldValues).toEqual(drafts);
|
||||
|
||||
requestMutationMock.mockResolvedValueOnce(payload);
|
||||
await act(async () => result.current.actions.handleMcpPresetAction("proxy", "metabase", { use_proxy: "true" }));
|
||||
expect(result.current.state.mcpFieldValues).toEqual({
|
||||
metabase: { mcp_url: drafts.metabase.mcp_url }, docs: drafts.docs,
|
||||
});
|
||||
|
||||
await act(async () => result.current.state.setMcpFieldValues(drafts));
|
||||
requestMutationMock.mockResolvedValueOnce({
|
||||
presets: [], installed_count: 0, last_action: { ok: true, removed: true, message: "Removed MCP server metabase." },
|
||||
});
|
||||
await act(async () => result.current.actions.handleMcpPresetAction("remove", "metabase"));
|
||||
expect(result.current.state.mcpFieldValues).toEqual({
|
||||
metabase: { mcp_url: drafts.metabase.mcp_url }, docs: drafts.docs,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function renderMcpActions() {
|
||||
const client = new NanobotClient({ url: "ws://example.test" });
|
||||
client.requestMutation = requestMutationMock;
|
||||
return renderHook(() => {
|
||||
const state = useSystemSettingsState();
|
||||
const actions = createSystemSettingsActions({
|
||||
state,
|
||||
featureCatalog: [],
|
||||
client,
|
||||
token: "tok",
|
||||
getToken: () => "tok",
|
||||
t: i18n.t,
|
||||
applyPayload: vi.fn(),
|
||||
maybeRestartHostEngine: vi.fn(),
|
||||
setPendingRestartSections: vi.fn(),
|
||||
refreshAutomations: vi.fn(),
|
||||
});
|
||||
return { state, actions };
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { changeProxyAddress, changeProxyAuthentication, splitProxyUrl } from "@/lib/proxy-url";
|
||||
|
||||
describe("Proxy URL credentials", () => {
|
||||
it("separates encoded credentials without changing the address or decoded content", () => {
|
||||
const raw = "socks5://user%40org:p%3Aa%2F%25%2B%E5%AF%86@[::1]:1080/";
|
||||
const parts = splitProxyUrl(raw);
|
||||
expect(parts.address).toBe("socks5://[::1]:1080/");
|
||||
expect(parts.username).toBe("user@org");
|
||||
expect(parts.password).toBe("p:a/%+密");
|
||||
expect(changeProxyAuthentication(raw, parts.username, parts.password)).toBe(raw);
|
||||
});
|
||||
|
||||
it("preserves unchanged credential escapes while changing host", () => {
|
||||
expect(changeProxyAddress("http://u%73er:p%61ss@old:8080", "https://new:8443"))
|
||||
.toBe("https://u%73er:p%61ss@new:8443");
|
||||
});
|
||||
|
||||
it("encodes typed separators, whitespace, percent, plus and Unicode once", () => {
|
||||
const raw = changeProxyAuthentication("http://proxy:8080", "u:@ /%+名", "p:@ /%+密");
|
||||
expect(raw).toBe("http://u%3A%40%20%2F%25%2B%E5%90%8D:p%3A%40%20%2F%25%2B%E5%AF%86@proxy:8080");
|
||||
expect(splitProxyUrl(raw).password).toBe("p:@ /%+密");
|
||||
});
|
||||
|
||||
it("updates only the edited credential and supports username-only authentication", () => {
|
||||
const raw = changeProxyAuthentication("http://user@proxy:8080", "user", "");
|
||||
expect(raw).toBe("http://user@proxy:8080");
|
||||
expect(changeProxyAuthentication(raw, "user", "password")).toBe("http://user:password@proxy:8080");
|
||||
expect(changeProxyAuthentication("http://u:p%61ss@proxy", "new", "pass")).toBe("http://new:p%61ss@proxy");
|
||||
});
|
||||
|
||||
it("preserves raw environment references rather than encoding or resolving them", () => {
|
||||
expect(changeProxyAuthentication("${SCHEME}://${USER}:${PASSWORD}@proxy:8080", "${USER}", "new:@"))
|
||||
.toBe("${SCHEME}://${USER}:new%3A%40@proxy:8080");
|
||||
expect(changeProxyAddress("http://${PROXY_AUTH}@old:8080", "http://new:8080"))
|
||||
.toBe("http://${PROXY_AUTH}@new:8080");
|
||||
expect(splitProxyUrl("${FULL_PROXY}").address).toBe("${FULL_PROXY}");
|
||||
expect(changeProxyAddress("http://u:p@old", "${FULL_PROXY}")).toBe("${FULL_PROXY}");
|
||||
});
|
||||
|
||||
it("uses pasted URL authentication and removes it only on explicit clearing", () => {
|
||||
expect(changeProxyAddress("http://old:pw@proxy", "http://new:secret@next"))
|
||||
.toBe("http://new:secret@next");
|
||||
expect(changeProxyAuthentication("http://u:p@proxy", "", "")).toBe("http://proxy");
|
||||
expect(changeProxyAddress("http://u:p@proxy", "")).toBe("");
|
||||
});
|
||||
|
||||
it("does not throw or rewrite an existing malformed percent escape on an address edit", () => {
|
||||
expect(splitProxyUrl("http://u:p%invalid@old").password).toBe("p%invalid");
|
||||
expect(changeProxyAddress("http://u:p%invalid@old", "http://new")).toBe("http://u:p%invalid@new");
|
||||
});
|
||||
});
|
||||
@@ -18,6 +18,7 @@ const xmindMcpPreset = {
|
||||
docs_url: "https://xmind.com/user-guide/xmind-mcp",
|
||||
transport: "streamableHttp",
|
||||
auth: "oauth" as const,
|
||||
use_proxy: false,
|
||||
requires: "Xmind account",
|
||||
note: "Connects securely in your browser with Xmind OAuth.",
|
||||
install_supported: true,
|
||||
@@ -33,9 +34,46 @@ const xmindMcpPreset = {
|
||||
source: "preset",
|
||||
};
|
||||
|
||||
async function connectXmind() {
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Connect Xmind" }));
|
||||
const dialog = await screen.findByRole("dialog", { name: "Xmind" });
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Connect" }));
|
||||
}
|
||||
|
||||
describe("SettingsView Apps catalog", () => {
|
||||
installSettingsViewTestHooks();
|
||||
|
||||
it.each([null, "", " ", "http://127.0.0.1:8080"])("offers inline proxy setup for missing shared proxy %j", async (proxy) => {
|
||||
const settings = { ...settingsPayload(), runtime_config: { "network.proxy": proxy } };
|
||||
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/settings") return jsonResponse(settings);
|
||||
if (url === "/api/settings/cli-apps") return jsonResponse({ apps: [], installed_count: 0 });
|
||||
if (url === "/api/settings/mcp-presets") return jsonResponse({ presets: [xmindMcpPreset], installed_count: 0 });
|
||||
return { ok: false, status: 404, text: async () => "Not found" } as Response;
|
||||
}));
|
||||
renderSettingsView({ initialSection: "apps" });
|
||||
fireEvent.click(await screen.findByRole("button", { name: "MCP" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Connect Xmind" }));
|
||||
const dialog = await screen.findByRole("dialog", { name: "Xmind" });
|
||||
const configure = within(dialog).queryByRole("button", { name: "Configure proxy" });
|
||||
if (proxy?.trim()) {
|
||||
expect(configure).not.toBeInTheDocument();
|
||||
expect(within(dialog).getByRole("switch", { name: "Use proxy" })).toBeInTheDocument();
|
||||
} else {
|
||||
expect(configure).toBeInTheDocument();
|
||||
expect(within(dialog).queryByRole("switch", { name: "Use proxy" })).not.toBeInTheDocument();
|
||||
fireEvent.click(configure!);
|
||||
const setup = await screen.findByRole("dialog", { name: "Shared proxy" });
|
||||
expect(dialog).toBeInTheDocument();
|
||||
const input = within(setup).getByRole("textbox", { name: "Shared proxy" });
|
||||
await waitFor(() => expect(input).toHaveFocus());
|
||||
fireEvent.click(within(setup).getByRole("button", { name: "Cancel" }));
|
||||
expect(await screen.findByRole("dialog", { name: "Xmind" })).toBe(dialog);
|
||||
}
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("collects an instance MCP URL before starting browser authorization", async () => {
|
||||
const metabasePreset = {
|
||||
...xmindMcpPreset,
|
||||
@@ -85,14 +123,14 @@ describe("SettingsView Apps catalog", () => {
|
||||
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.mcp.oauth_start",
|
||||
{ name: "metabase", mcp_url: "https://analytics.example.com/api/metabase-mcp" },
|
||||
{ name: "metabase", mcp_url: "https://analytics.example.com/api/metabase-mcp", use_proxy: "false" },
|
||||
expect.any(Number),
|
||||
));
|
||||
});
|
||||
|
||||
|
||||
|
||||
it("connects an OAuth MCP from the Apps catalog without manual callback input", async () => {
|
||||
it("sets the proxy flag before the first OAuth request, even with no credential fields", async () => {
|
||||
let connected = false;
|
||||
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
@@ -110,6 +148,7 @@ describe("SettingsView Apps catalog", () => {
|
||||
available: true,
|
||||
status: "configured",
|
||||
connection_summary: "https://app.xmind.com/api/mcp",
|
||||
use_proxy: true,
|
||||
}
|
||||
: xmindMcpPreset],
|
||||
installed_count: connected ? 1 : 0,
|
||||
@@ -164,6 +203,17 @@ describe("SettingsView Apps catalog", () => {
|
||||
const connectButton = await screen.findByRole("button", { name: "Connect Xmind" });
|
||||
expect(connectButton).toHaveTextContent("Connect");
|
||||
fireEvent.click(connectButton);
|
||||
const dialog = await screen.findByRole("dialog", { name: "Xmind" });
|
||||
expect(open).not.toHaveBeenCalled();
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
const useProxy = within(dialog).getByRole("switch", { name: "Use proxy" });
|
||||
expect(useProxy).not.toBeChecked();
|
||||
expect(within(dialog).queryByRole("textbox", { name: /proxy/i })).not.toBeInTheDocument();
|
||||
fireEvent.click(useProxy);
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Connect" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.mcp.oauth_start", { name: "xmind", use_proxy: "true" }, 30_000,
|
||||
));
|
||||
|
||||
expect(open).toHaveBeenCalledWith(
|
||||
"about:blank",
|
||||
@@ -185,6 +235,9 @@ describe("SettingsView Apps catalog", () => {
|
||||
expect(await screen.findByRole("button", { name: "Manage Xmind" }, { timeout: 2500 }))
|
||||
.toHaveTextContent("Manage");
|
||||
expect(popup.close).toHaveBeenCalledTimes(1);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Manage Xmind" }));
|
||||
fireEvent.click(screen.getByRole("tab", { name: "Connection" }));
|
||||
expect(screen.getByRole("switch", { name: "Use proxy" })).toBeChecked();
|
||||
expect(replace).toHaveBeenCalledTimes(1);
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
"/api/settings/mcp-oauth/status?flow_id=flow-123",
|
||||
@@ -250,7 +303,7 @@ describe("SettingsView Apps catalog", () => {
|
||||
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.mcp.oauth_start",
|
||||
{ name: "xmind", reset: true },
|
||||
{ name: "xmind", reset: true, use_proxy: "false" },
|
||||
30_000,
|
||||
));
|
||||
await act(() => i18n.changeLanguage("en"));
|
||||
@@ -405,6 +458,7 @@ describe("SettingsView Apps catalog", () => {
|
||||
display_name: "team-mcp",
|
||||
source: "custom",
|
||||
installed: true,
|
||||
use_proxy: true,
|
||||
status: "authorization_required",
|
||||
connection_summary: "https://mcp.example.com/mcp",
|
||||
};
|
||||
@@ -464,6 +518,7 @@ describe("SettingsView Apps catalog", () => {
|
||||
screen.getByText("Save the server, then select Connect to sign in."),
|
||||
).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Use proxy" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save MCP server" }));
|
||||
|
||||
await waitFor(() => {
|
||||
@@ -477,12 +532,15 @@ describe("SettingsView Apps catalog", () => {
|
||||
transport: "streamableHttp",
|
||||
url: "https://mcp.example.com/mcp",
|
||||
auth: "oauth",
|
||||
use_proxy: "true",
|
||||
});
|
||||
expect(values).not.toHaveProperty("headers");
|
||||
expect(saveCall?.[2]).toBe(20_000);
|
||||
});
|
||||
expect(await screen.findByRole("button", { name: "Connect team-mcp" }))
|
||||
.toBeInTheDocument();
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Connect team-mcp" }));
|
||||
const connection = await screen.findByRole("dialog", { name: "team-mcp" });
|
||||
expect(within(connection).getByRole("switch", { name: "Use proxy" })).toBeChecked();
|
||||
expect(requestMutationMock).not.toHaveBeenCalledWith("settings.mcp.oauth_start", expect.anything(), expect.anything());
|
||||
});
|
||||
|
||||
it("offers a pasted callback flow when the remote WebUI uses HTTP", async () => {
|
||||
@@ -561,7 +619,7 @@ describe("SettingsView Apps catalog", () => {
|
||||
|
||||
renderSettingsView({ initialSection: "apps" });
|
||||
fireEvent.click(await screen.findByRole("button", { name: "MCP" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Connect Xmind" }));
|
||||
await connectXmind();
|
||||
|
||||
const callbackInput = await screen.findByRole("textbox", { name: "Callback URL" });
|
||||
expect(screen.getByText(/localhost page will not load/i)).toBeInTheDocument();
|
||||
@@ -628,7 +686,7 @@ describe("SettingsView Apps catalog", () => {
|
||||
|
||||
renderSettingsView({ initialSection: "apps" });
|
||||
fireEvent.click(await screen.findByRole("button", { name: "MCP" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Connect Xmind" }));
|
||||
await connectXmind();
|
||||
|
||||
const cancelButton = await screen.findByRole("button", { name: "Cancel" });
|
||||
expect(screen.getByRole("button", { name: "Connecting Xmind" })).toBeInTheDocument();
|
||||
@@ -734,7 +792,7 @@ describe("SettingsView Apps catalog", () => {
|
||||
|
||||
renderSettingsView({ initialSection: "apps" });
|
||||
fireEvent.click(await screen.findByRole("button", { name: "MCP" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Connect Xmind" }));
|
||||
await connectXmind();
|
||||
|
||||
const continueButton = await screen.findByRole("button", { name: "Continue sign-in" });
|
||||
expect(screen.getByRole("status")).toHaveTextContent("Open the sign-in page to continue.");
|
||||
@@ -804,7 +862,7 @@ describe("SettingsView Apps catalog", () => {
|
||||
|
||||
renderSettingsView({ initialSection: "apps" });
|
||||
fireEvent.click(await screen.findByRole("button", { name: "MCP" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Connect Xmind" }));
|
||||
await connectXmind();
|
||||
|
||||
await waitFor(() => expect(statusCalls).toBe(1), { timeout: 2000 });
|
||||
expect(screen.getByRole("status")).toHaveTextContent(
|
||||
|
||||
@@ -317,9 +317,10 @@ describe("Settings capabilities", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("edits the existing web proxy in web access even while disabled, without a duplicate advanced editor", async () => {
|
||||
it("saves the web proxy switch separately from the shared address in Advanced", async () => {
|
||||
let payload = { ...settingsPayload(), runtime_config: {
|
||||
"tools.web.enable": false, "tools.web.proxy": "http://old-proxy.example:8080", "tools.web.user_agent": null,
|
||||
"tools.web.enable": false, "tools.web.use_proxy": false,
|
||||
"network.proxy": "http://old-proxy.example:8080", "tools.web.user_agent": null,
|
||||
} } as SettingsPayload;
|
||||
requestMutationMock.mockImplementation(async (_method, update) => {
|
||||
payload = { ...payload, runtime_config: { ...payload.runtime_config, ...update.values },
|
||||
@@ -329,21 +330,41 @@ 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" });
|
||||
expect(proxy).toHaveValue("http://old-proxy.example:8080");
|
||||
fireEvent.change(proxy, { target: { value: "http://new-proxy.example:7890" } });
|
||||
const useProxy = screen.getByRole("switch", { name: "Use proxy" });
|
||||
expect(useProxy).not.toBeChecked();
|
||||
expect(screen.queryByRole("textbox", { name: /proxy/i })).not.toBeInTheDocument();
|
||||
expect(screen.queryByLabelText("Shared proxy")).not.toBeInTheDocument();
|
||||
fireEvent.click(useProxy);
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.runtime_config.update", { values: { "tools.web.proxy": "http://new-proxy.example:7890" } }, 20_000,
|
||||
"settings.runtime_config.update", { values: { "tools.web.use_proxy": true } }, 20_000,
|
||||
));
|
||||
expect(await screen.findByText("Saved. Restart to apply changes.")).toBeVisible();
|
||||
fireEvent.change(proxy, { target: { value: "" } });
|
||||
await waitFor(() => expect(useProxy).toBeEnabled());
|
||||
expect(useProxy).toBeChecked();
|
||||
fireEvent.click(useProxy);
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
|
||||
"settings.runtime_config.update", { values: { "tools.web.proxy": null } }, 20_000,
|
||||
"settings.runtime_config.update", { values: { "tools.web.use_proxy": false } }, 20_000,
|
||||
));
|
||||
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" }));
|
||||
expect(screen.queryByRole("textbox", { name: "Web proxy" })).not.toBeInTheDocument();
|
||||
const proxy = screen.getByRole("textbox", { name: "Shared proxy" });
|
||||
expect(proxy).toHaveAttribute("type", "text");
|
||||
expect(proxy).toHaveValue("http://old-proxy.example:8080");
|
||||
expect(screen.queryByRole("switch", { name: "Use proxy" })).not.toBeInTheDocument();
|
||||
const address = "http://user:secret@new-proxy.example:7890";
|
||||
fireEvent.change(proxy, { target: { value: address } });
|
||||
expect(proxy).toHaveValue("http://new-proxy.example:7890");
|
||||
expect(screen.getByLabelText("Password")).toHaveAttribute("type", "password");
|
||||
fireEvent.click(within(screen.getByRole("region", { name: "Shared proxy" })).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
|
||||
"settings.runtime_config.update", { values: { "network.proxy": address } }, 20_000,
|
||||
));
|
||||
fireEvent.click(screen.getByRole("button", { name: "System" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced" }));
|
||||
expect(screen.getByLabelText("Shared proxy", { selector: "input" })).toHaveValue("http://new-proxy.example:7890");
|
||||
expect(screen.getByLabelText("Username")).toHaveValue("user");
|
||||
expect(screen.getByLabelText("Password")).toHaveValue("secret");
|
||||
expect(document.body).not.toHaveTextContent(address);
|
||||
});
|
||||
|
||||
it("saves optional-key web search providers without an API key", async () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { fireEvent, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { expect, it, vi } from "vitest";
|
||||
import type { SettingsPayload } from "@/lib/types";
|
||||
import type { ProviderCreationUpdate, SettingsPayload } from "@/lib/types";
|
||||
import { requestMutationMock, jsonResponse, settingsPayload, renderSettingsView, installSettingsViewTestHooks } from "@/tests/settings-test-utils";
|
||||
|
||||
|
||||
@@ -711,7 +711,7 @@ describe("Settings providers", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("saves scoped proxies for xAI and OpenAI Codex OAuth providers", async () => {
|
||||
it("saves proxy switches for xAI and OpenAI Codex OAuth providers before sign-in", async () => {
|
||||
const base = settingsPayload();
|
||||
const providers: SettingsPayload["providers"] = [
|
||||
{
|
||||
@@ -727,8 +727,8 @@ describe("Settings providers", () => {
|
||||
oauth_account: null,
|
||||
oauth_expires_at: null,
|
||||
oauth_login_supported: true,
|
||||
proxy: "http://127.0.0.1:7000",
|
||||
advanced_fields: ["extra_body", "proxy"],
|
||||
use_proxy: true,
|
||||
advanced_fields: ["extra_body", "use_proxy"],
|
||||
extra_body: null,
|
||||
},
|
||||
{
|
||||
@@ -744,8 +744,8 @@ describe("Settings providers", () => {
|
||||
oauth_account: null,
|
||||
oauth_expires_at: null,
|
||||
oauth_login_supported: true,
|
||||
proxy: null,
|
||||
advanced_fields: ["extra_body", "proxy"],
|
||||
use_proxy: false,
|
||||
advanced_fields: ["extra_body", "use_proxy"],
|
||||
extra_body: null,
|
||||
},
|
||||
];
|
||||
@@ -764,7 +764,7 @@ describe("Settings providers", () => {
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
requestMutationMock.mockImplementation(async (
|
||||
_action: string,
|
||||
values: { provider?: string; proxy?: string; extraBody?: string },
|
||||
values: { provider?: string; use_proxy?: boolean; extraBody?: string },
|
||||
) => {
|
||||
payload = {
|
||||
...payload,
|
||||
@@ -772,7 +772,7 @@ describe("Settings providers", () => {
|
||||
provider.name === values.provider
|
||||
? {
|
||||
...provider,
|
||||
proxy: values.proxy || null,
|
||||
use_proxy: values.use_proxy,
|
||||
extra_body: values.extraBody ? JSON.parse(values.extraBody) : null,
|
||||
}
|
||||
: provider,
|
||||
@@ -785,9 +785,10 @@ describe("Settings providers", () => {
|
||||
|
||||
await chooseProviderToConfigure("xAI Grok");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
const xaiProxy = screen.getByLabelText("Network proxy");
|
||||
expect(xaiProxy).toHaveValue("http://127.0.0.1:7000");
|
||||
fireEvent.change(xaiProxy, { target: { value: "http://127.0.0.1:7890" } });
|
||||
const xaiProxy = screen.getByRole("switch", { name: "Use proxy" });
|
||||
expect(xaiProxy).toBeChecked();
|
||||
expect(screen.queryByPlaceholderText("http://127.0.0.1:7890")).not.toBeInTheDocument();
|
||||
fireEvent.click(xaiProxy);
|
||||
expect(screen.getByRole("button", { name: "Sign in" })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "Sign in" })).toHaveAttribute(
|
||||
"title",
|
||||
@@ -801,7 +802,7 @@ describe("Settings providers", () => {
|
||||
{
|
||||
provider: "xai_grok",
|
||||
extraBody: "",
|
||||
proxy: "http://127.0.0.1:7890",
|
||||
use_proxy: false,
|
||||
},
|
||||
20_000,
|
||||
),
|
||||
@@ -812,9 +813,9 @@ describe("Settings providers", () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back to providers" }));
|
||||
await chooseProviderToConfigure("OpenAI Codex");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
const codexProxy = screen.getByLabelText("Network proxy");
|
||||
expect(codexProxy).toHaveValue("");
|
||||
fireEvent.change(codexProxy, { target: { value: "http://proxy.example:8080" } });
|
||||
const codexProxy = screen.getByRole("switch", { name: "Use proxy" });
|
||||
expect(codexProxy).not.toBeChecked();
|
||||
fireEvent.click(codexProxy);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save provider" }));
|
||||
|
||||
await waitFor(() =>
|
||||
@@ -823,13 +824,41 @@ describe("Settings providers", () => {
|
||||
{
|
||||
provider: "openai_codex",
|
||||
extraBody: "",
|
||||
proxy: "http://proxy.example:8080",
|
||||
use_proxy: true,
|
||||
},
|
||||
20_000,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it("persists a disabled proxy switch on an API-key provider without changing credentials", async () => {
|
||||
const base = settingsPayload();
|
||||
let payload: SettingsPayload = { ...base, providers: [{
|
||||
name: "openrouter", label: "OpenRouter", configured: true,
|
||||
api_key_hint: "sk-••••test", api_base: "https://openrouter.ai/api/v1",
|
||||
use_proxy: true, advanced_fields: ["use_proxy"],
|
||||
}] };
|
||||
requestMutationMock.mockImplementation(async (_action, values) => {
|
||||
payload = { ...payload, providers: payload.providers.map((provider) => ({ ...provider, use_proxy: values.use_proxy })) };
|
||||
return payload;
|
||||
});
|
||||
renderProviderManager({ initialSection: "models", initialSettings: payload });
|
||||
fireEvent.click(screen.getByRole("button", { name: "OpenRouter" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
const useProxy = screen.getByRole("switch", { name: "Use proxy" });
|
||||
expect(useProxy).toBeChecked();
|
||||
fireEvent.click(useProxy);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save provider" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.provider.update",
|
||||
{ provider: "openrouter", apiBase: "https://openrouter.ai/api/v1", apiKey: undefined, use_proxy: false },
|
||||
20_000,
|
||||
));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "OpenRouter" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
expect(screen.getByRole("switch", { name: "Use proxy" })).not.toBeChecked();
|
||||
});
|
||||
|
||||
it("maps provider request switches to raw extraBody fields", async () => {
|
||||
const base = settingsPayload();
|
||||
const providers: SettingsPayload["providers"] = [
|
||||
@@ -841,7 +870,7 @@ describe("Settings providers", () => {
|
||||
api_key_required: false,
|
||||
oauth_account: "grok@example.com",
|
||||
oauth_login_supported: true,
|
||||
advanced_fields: ["extra_body", "proxy"],
|
||||
advanced_fields: ["extra_body", "use_proxy"],
|
||||
extra_body: null,
|
||||
},
|
||||
{
|
||||
@@ -852,7 +881,7 @@ describe("Settings providers", () => {
|
||||
api_key_required: false,
|
||||
oauth_account: "codex@example.com",
|
||||
oauth_login_supported: true,
|
||||
advanced_fields: ["extra_body", "proxy"],
|
||||
advanced_fields: ["extra_body", "use_proxy"],
|
||||
extra_body: null,
|
||||
},
|
||||
{
|
||||
@@ -1056,7 +1085,7 @@ describe("Settings providers", () => {
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
requestMutationMock.mockImplementationOnce(async (
|
||||
_action: string,
|
||||
values: Record<string, string>,
|
||||
values: ProviderCreationUpdate,
|
||||
) => {
|
||||
payload = {
|
||||
...payload,
|
||||
@@ -1076,13 +1105,13 @@ describe("Settings providers", () => {
|
||||
"extra_headers",
|
||||
"extra_body",
|
||||
"extra_query",
|
||||
"proxy",
|
||||
"use_proxy",
|
||||
"thinking_style",
|
||||
],
|
||||
extra_headers: JSON.parse(values.extraHeaders),
|
||||
extra_body: JSON.parse(values.extraBody),
|
||||
extra_query: JSON.parse(values.extraQuery),
|
||||
proxy: values.proxy,
|
||||
extra_headers: JSON.parse(values.extraHeaders ?? "{}"),
|
||||
extra_body: JSON.parse(values.extraBody ?? "{}"),
|
||||
extra_query: JSON.parse(values.extraQuery ?? "{}"),
|
||||
use_proxy: values.use_proxy,
|
||||
thinking_style: values.thinkingStyle,
|
||||
},
|
||||
],
|
||||
@@ -1123,9 +1152,7 @@ describe("Settings providers", () => {
|
||||
fireEvent.click(within(editor).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog", { name: title })).not.toBeInTheDocument());
|
||||
}
|
||||
fireEvent.change(screen.getByLabelText("Network proxy"), {
|
||||
target: { value: "http://127.0.0.1:7890" },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Use proxy" }));
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Reasoning format" }));
|
||||
fireEvent.click(await screen.findByRole("menuitem", { name: "enable_thinking" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
@@ -1139,7 +1166,7 @@ describe("Settings providers", () => {
|
||||
name: "Company Gateway",
|
||||
apiKey: "sk-company",
|
||||
apiBase: "https://gateway.example/v1",
|
||||
proxy: "http://127.0.0.1:7890",
|
||||
use_proxy: true,
|
||||
extraHeaders: '{"X-Tenant":"engineering"}',
|
||||
extraBody: '{"service_tier":"priority"}',
|
||||
extraQuery: '{"api-version":"2026-01-01"}',
|
||||
|
||||
@@ -26,7 +26,8 @@ function runtimeSettings() {
|
||||
"tools.exec.sandbox_ro_binds": [],
|
||||
"tools.exec.sandbox_rw_binds": [],
|
||||
"agents.defaults.max_tool_iterations": 200,
|
||||
"tools.web.proxy": "http://localhost:8080",
|
||||
"network.proxy": "http://localhost:8080",
|
||||
"tools.web.use_proxy": false,
|
||||
};
|
||||
return { ...payload, advanced: { ...payload.advanced, exec_max_runtime_limit: 86400 }, runtime_config: runtimeConfig };
|
||||
}
|
||||
@@ -301,22 +302,47 @@ describe("Runtime configuration settings", () => {
|
||||
});
|
||||
|
||||
it("preserves drafts when navigating away and supports explicit clearing", async () => {
|
||||
renderSettingsView({ initialSection: "capabilities", initialSettings: runtimeSettings() });
|
||||
const openWebSettings = () => {
|
||||
fireEvent.click(within(screen.getByRole("region", { name: "Web access" })).getByRole("button", { name: "Configure" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
};
|
||||
openWebSettings();
|
||||
const proxy = screen.getByRole("textbox", { name: "Web proxy" });
|
||||
let payload = runtimeSettings();
|
||||
requestMutationMock.mockImplementation(async (_method, update) => {
|
||||
payload = { ...payload, runtime_config: { ...payload.runtime_config, ...update.values } };
|
||||
return payload;
|
||||
});
|
||||
renderSettingsView({ initialSection: "advanced", initialSettings: payload });
|
||||
const proxy = screen.getByRole("textbox", { name: "Shared proxy" });
|
||||
expect(proxy).toHaveAttribute("type", "text");
|
||||
expect(proxy).toHaveValue("http://localhost:8080");
|
||||
fireEvent.change(proxy, { target: { value: "" } });
|
||||
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();
|
||||
expect(screen.getByRole("textbox", { name: "Web proxy" })).toHaveValue("");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced" }));
|
||||
expect(screen.getByLabelText("Shared proxy", { selector: "input" })).toHaveValue("");
|
||||
fireEvent.click(within(screen.getByRole("region", { name: "Shared proxy" })).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.runtime_config.update", { values: { "tools.web.proxy": null } }, 20_000,
|
||||
"settings.runtime_config.update", { values: { "network.proxy": null } }, 20_000,
|
||||
));
|
||||
fireEvent.click(screen.getByRole("button", { name: "System" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced" }));
|
||||
expect(screen.getByLabelText("Shared proxy", { selector: "input" })).toHaveValue("");
|
||||
});
|
||||
|
||||
it("saves proxy address and authentication together without exposing the password in the address", async () => {
|
||||
const payload = runtimeSettings();
|
||||
payload.runtime_config!["network.proxy"] = "http://old:p%40ss@proxy:8080";
|
||||
requestMutationMock.mockImplementation(async (_method, update) => ({
|
||||
...payload, runtime_config: { ...payload.runtime_config, ...update.values }, requires_restart: true,
|
||||
}));
|
||||
renderSettingsView({ initialSection: "advanced", initialSettings: payload });
|
||||
const group = within(screen.getByRole("region", { name: "Shared proxy" }));
|
||||
expect(group.getByRole("textbox", { name: "Shared proxy" })).toHaveValue("http://proxy:8080");
|
||||
expect(group.getByLabelText("Password")).toHaveAttribute("type", "password");
|
||||
expect(group.getByLabelText("Password")).toHaveValue("p@ss");
|
||||
fireEvent.change(group.getByLabelText("Username"), { target: { value: "new@user" } });
|
||||
fireEvent.change(group.getByLabelText("Password"), { target: { value: "p:@ %密" } });
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
fireEvent.click(group.getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.runtime_config.update", { values: { "network.proxy": "http://new%40user:p%3A%40%20%25%E5%AF%86@proxy:8080" } }, 20_000,
|
||||
));
|
||||
expect(group.getByRole("textbox", { name: "Shared proxy" })).toHaveValue("http://proxy:8080");
|
||||
});
|
||||
|
||||
it("keeps an existing timezone alias selectable and accepts only listed search results", () => {
|
||||
|
||||
@@ -59,7 +59,7 @@ export function settingsPayload(): SettingsPayload {
|
||||
},
|
||||
web: {
|
||||
enable: true,
|
||||
proxy: null,
|
||||
use_proxy: false,
|
||||
user_agent: null,
|
||||
search: { max_results: 5, timeout: 30 },
|
||||
fetch: { use_jina_reader: true },
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { useState } from "react";
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { SharedProxyEditor } from "@/components/settings/shared/SharedProxyEditor";
|
||||
import i18n from "@/i18n";
|
||||
|
||||
function editor(initial: string) {
|
||||
let current = initial;
|
||||
function Harness() {
|
||||
const [value, setValue] = useState(initial);
|
||||
return <SharedProxyEditor value={value} onChange={(next) => { current = next; setValue(next); }} />;
|
||||
}
|
||||
render(<Harness />);
|
||||
return () => current;
|
||||
}
|
||||
|
||||
describe("Shared proxy editor", () => {
|
||||
beforeEach(async () => { await i18n.changeLanguage("en"); });
|
||||
|
||||
it("shows an existing URL password only in a masked password field", () => {
|
||||
const value = editor("http://user:p%40ss@proxy:8080");
|
||||
expect(screen.getByRole("textbox", { name: "Shared proxy" })).toHaveValue("http://proxy:8080");
|
||||
expect(screen.getByRole("textbox", { name: "Username" })).toHaveValue("user");
|
||||
expect(screen.getByLabelText("Password")).toHaveAttribute("type", "password");
|
||||
expect(screen.getByLabelText("Password")).toHaveValue("p@ss");
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "Shared proxy" }), { target: { value: "http://new:8080" } });
|
||||
expect(value()).toBe("http://user:p%40ss@new:8080");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Authentication (optional)" }));
|
||||
expect(value()).toBe("http://user:p%40ss@new:8080");
|
||||
expect(screen.queryByLabelText("Password")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps pasted authentication out of the plain address and encodes credential edits", () => {
|
||||
const value = editor("");
|
||||
const address = screen.getByRole("textbox", { name: "Shared proxy" });
|
||||
fireEvent.change(address, { target: { value: "http://user:secret@proxy:8080" } });
|
||||
expect(address).toHaveValue("http://proxy:8080");
|
||||
expect(screen.getByLabelText("Password")).toHaveAttribute("type", "password");
|
||||
fireEvent.change(screen.getByLabelText("Username"), { target: { value: "new@user" } });
|
||||
fireEvent.change(screen.getByLabelText("Password"), { target: { value: "p:@ %密" } });
|
||||
expect(value()).toBe("http://new%40user:p%3A%40%20%25%E5%AF%86@proxy:8080");
|
||||
expect(address).toHaveValue("http://proxy:8080");
|
||||
});
|
||||
|
||||
it("preserves whole-URL environment references and explains where authentication is set", () => {
|
||||
const value = editor("${FULL_PROXY}");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Authentication (optional)" }));
|
||||
expect(screen.getByText("Set authentication in the referenced proxy URL.")).toBeVisible();
|
||||
expect(screen.queryByLabelText("Password")).not.toBeInTheDocument();
|
||||
expect(value()).toBe("${FULL_PROXY}");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,142 @@
|
||||
import { act, fireEvent, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { McpPresetInfo } from "@/lib/types";
|
||||
import { installSettingsViewTestHooks, jsonResponse, renderSettingsView, requestMutationMock, settingsPayload } from "@/tests/settings-test-utils";
|
||||
|
||||
const preset: McpPresetInfo = {
|
||||
name: "docs", display_name: "Docs MCP", category: "productivity", description: "Docs",
|
||||
docs_url: "https://example.com", transport: "streamableHttp", auth: null, requires: "", note: "",
|
||||
install_supported: true, installed: true, configured: true, available: true, status: "configured",
|
||||
runtime_status: "connected", required_fields: [], connection_summary: "https://example.com/mcp",
|
||||
tool_count: 2, tool_names: ["search_docs", "write_note"], enabled_tools: ["*"], source: "custom",
|
||||
};
|
||||
|
||||
function installProxySettings() {
|
||||
const settings = { ...settingsPayload(), runtime_config: { "network.proxy": null } };
|
||||
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/settings") return jsonResponse(settings);
|
||||
if (url === "/api/settings/cli-apps") return jsonResponse({ apps: [], installed_count: 0 });
|
||||
if (url === "/api/settings/mcp-presets") return jsonResponse({ presets: [preset], installed_count: 1 });
|
||||
return jsonResponse({});
|
||||
}));
|
||||
return { settings, saved: { ...settings, runtime_config: { "network.proxy": "http://127.0.0.1:7890" }, requires_restart: true } };
|
||||
}
|
||||
|
||||
async function openMcpSetup() {
|
||||
fireEvent.click(await screen.findByRole("button", { name: "MCP" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Manage Docs MCP" }));
|
||||
const parent = await screen.findByRole("dialog", { name: "Docs MCP" });
|
||||
fireEvent.click(within(parent).getByRole("tab", { name: "Connection" }));
|
||||
fireEvent.click(within(parent).getByRole("button", { name: "Configure proxy" }));
|
||||
return { parent, setup: await screen.findByRole("dialog", { name: "Shared proxy" }) };
|
||||
}
|
||||
|
||||
describe("Inline shared proxy setup", () => {
|
||||
installSettingsViewTestHooks();
|
||||
|
||||
it("keeps custom Provider fields across cancel and successful setup without enabling proxy", async () => {
|
||||
const user = userEvent.setup();
|
||||
const { settings, saved } = installProxySettings();
|
||||
renderSettingsView({ initialSection: "models", initialSettings: settings });
|
||||
await user.click(await screen.findByRole("button", { name: "Manage providers" }));
|
||||
await user.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
await user.click(await screen.findByRole("button", { name: "Custom" }));
|
||||
const parent = screen.getByRole("dialog", { name: "Custom" });
|
||||
const name = within(parent).getByPlaceholderText("My model provider");
|
||||
const url = within(parent).getByPlaceholderText("https://api.example.com/v1");
|
||||
const key = within(parent).getByPlaceholderText("Enter API key");
|
||||
await user.type(name, "Keep this draft");
|
||||
await user.type(url, "https://gateway.example/v1");
|
||||
await user.type(key, "draft-key");
|
||||
await user.click(within(parent).getByRole("button", { name: "Advanced options" }));
|
||||
await user.click(within(parent).getByRole("button", { name: "Configure proxy" }));
|
||||
let setup = await screen.findByRole("dialog", { name: "Shared proxy" });
|
||||
await user.type(within(setup).getByRole("textbox"), "http://127.0.0.1:7890");
|
||||
await user.click(within(setup).getByRole("button", { name: "Cancel" }));
|
||||
expect(name).toHaveValue("Keep this draft");
|
||||
expect(url).toHaveValue("https://gateway.example/v1");
|
||||
expect(key).toHaveValue("draft-key");
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
await user.click(within(parent).getByRole("button", { name: "Configure proxy" }));
|
||||
setup = await screen.findByRole("dialog", { name: "Shared proxy" });
|
||||
expect(within(setup).getByRole("textbox")).toHaveValue("");
|
||||
await user.type(within(setup).getByRole("textbox"), "http://127.0.0.1:7890");
|
||||
requestMutationMock.mockResolvedValueOnce(saved);
|
||||
await user.click(within(setup).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog", { name: "Shared proxy" })).not.toBeInTheDocument());
|
||||
expect(await screen.findByRole("dialog", { name: "Custom" })).toBe(parent);
|
||||
expect(name).toHaveValue("Keep this draft");
|
||||
expect(url).toHaveValue("https://gateway.example/v1");
|
||||
expect(key).toHaveValue("draft-key");
|
||||
expect(within(parent).getByRole("switch", { name: "Use proxy" })).not.toBeChecked();
|
||||
expect(requestMutationMock).toHaveBeenCalledTimes(1);
|
||||
expect(requestMutationMock).toHaveBeenCalledWith("settings.runtime_config.update", { values: { "network.proxy": "http://127.0.0.1:7890" } }, 20_000);
|
||||
});
|
||||
|
||||
it("saves optional credentials from inline setup without enabling the consumer", async () => {
|
||||
const { settings, saved } = installProxySettings();
|
||||
renderSettingsView({ initialSection: "apps", initialSettings: settings });
|
||||
const { parent, setup } = await openMcpSetup();
|
||||
fireEvent.change(within(setup).getByRole("textbox", { name: "Shared proxy" }), { target: { value: "socks5://proxy:1080" } });
|
||||
fireEvent.click(within(setup).getByRole("button", { name: "Authentication (optional)" }));
|
||||
fireEvent.change(within(setup).getByLabelText("Username"), { target: { value: "user@org" } });
|
||||
fireEvent.change(within(setup).getByLabelText("Password"), { target: { value: "p:a@ss" } });
|
||||
expect(within(setup).getByLabelText("Password")).toHaveAttribute("type", "password");
|
||||
const encoded = "socks5://user%40org:p%3Aa%40ss@proxy:1080";
|
||||
requestMutationMock.mockResolvedValueOnce({ ...saved, runtime_config: { "network.proxy": encoded } });
|
||||
fireEvent.click(within(setup).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog", { name: "Shared proxy" })).not.toBeInTheDocument());
|
||||
expect(requestMutationMock).toHaveBeenCalledWith("settings.runtime_config.update", { values: { "network.proxy": encoded } }, 20_000);
|
||||
expect(within(parent).getByRole("switch", { name: "Use proxy" })).not.toBeChecked();
|
||||
});
|
||||
|
||||
it("retains MCP tool selections when setup is cancelled", async () => {
|
||||
const { settings } = installProxySettings();
|
||||
renderSettingsView({ initialSection: "apps", initialSettings: settings });
|
||||
fireEvent.click(await screen.findByRole("button", { name: "MCP" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Manage Docs MCP" }));
|
||||
const parent = await screen.findByRole("dialog", { name: "Docs MCP" });
|
||||
fireEvent.click(within(parent).getByRole("tab", { name: "Tools" }));
|
||||
fireEvent.click(within(parent).getByRole("checkbox", { name: "write_note" }));
|
||||
expect(within(parent).getByRole("checkbox", { name: "write_note" })).not.toBeChecked();
|
||||
fireEvent.click(within(parent).getByRole("tab", { name: "Connection" }));
|
||||
fireEvent.click(within(parent).getByRole("button", { name: "Configure proxy" }));
|
||||
const setup = await screen.findByRole("dialog", { name: "Shared proxy" });
|
||||
fireEvent.click(within(setup).getByRole("button", { name: "Cancel" }));
|
||||
fireEvent.click(within(parent).getByRole("tab", { name: "Tools" }));
|
||||
expect(within(parent).getByRole("checkbox", { name: "write_note" })).not.toBeChecked();
|
||||
expect(within(parent).getByRole("button", { name: "Save changes" })).toBeEnabled();
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps failed input and inline errors, blocks dismissal while saving and retries", async () => {
|
||||
const { settings, saved } = installProxySettings();
|
||||
renderSettingsView({ initialSection: "apps", initialSettings: settings });
|
||||
const { parent, setup } = await openMcpSetup();
|
||||
const input = within(setup).getByRole("textbox");
|
||||
const save = within(setup).getByRole("button", { name: "Save" });
|
||||
expect(save).toBeDisabled();
|
||||
fireEvent.change(input, { target: { value: "bad-address" } });
|
||||
requestMutationMock.mockRejectedValueOnce(new Error("Unsupported proxy scheme"));
|
||||
fireEvent.click(save);
|
||||
expect(await within(setup).findByRole("alert")).toHaveTextContent("Unsupported proxy scheme");
|
||||
expect(input).toHaveValue("bad-address");
|
||||
await waitFor(() => expect(input).toHaveFocus());
|
||||
fireEvent.change(input, { target: { value: "http://127.0.0.1:7890" } });
|
||||
let resolveSave!: (value: typeof saved) => void;
|
||||
requestMutationMock.mockImplementationOnce(() => new Promise((resolve) => { resolveSave = resolve; }));
|
||||
fireEvent.click(save);
|
||||
expect(within(setup).getByRole("button", { name: "Cancel" })).toBeDisabled();
|
||||
expect(input).toBeDisabled();
|
||||
fireEvent.keyDown(setup, { key: "Escape" });
|
||||
expect(setup).toBeInTheDocument();
|
||||
await act(async () => { resolveSave(saved); });
|
||||
await waitFor(() => expect(screen.queryByRole("dialog", { name: "Shared proxy" })).not.toBeInTheDocument());
|
||||
expect(screen.getByRole("dialog", { name: "Docs MCP" })).toBe(parent);
|
||||
expect(within(parent).getByRole("switch", { name: "Use proxy" })).not.toBeChecked();
|
||||
expect(requestMutationMock).toHaveBeenLastCalledWith("settings.runtime_config.update", { values: { "network.proxy": "http://127.0.0.1:7890" } }, 20_000);
|
||||
});
|
||||
});
|
||||
@@ -522,7 +522,7 @@ function modelSettings(model: string, provider: string): SettingsPayload {
|
||||
},
|
||||
web: {
|
||||
enable: true,
|
||||
proxy: null,
|
||||
use_proxy: false,
|
||||
user_agent: null,
|
||||
search: { max_results: 5, timeout: 30 },
|
||||
fetch: { use_jina_reader: true },
|
||||
|
||||
Reference in new issue
Block a user