Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/testing/ci-retry-list.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
{
"file": "server/post-to-room.test.ts",
"test": "limits counted per turn on a bearer that outlives the turn > stops a turn at its third room post, and the next turn may post again",
"test": "limits counted per turn on a bearer that outlives the turn > stops a turn at its eighth room post by default, takes the configured cap, and the next turn may post again",
"owner": "siddharth",
"reason": "Failed once in the 0.2.33 release CI (run 45993068105, ubuntu shard 5 or parallel-threads, a different test each attempt); passes locally on a quiet machine.",
"since": "2026-11-27"
Expand Down
6 changes: 3 additions & 3 deletions server/system-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe("installSystemProxy", () => {
it("sends the harness's own fetch through the proxy the computer's settings name", async () => {
const proxy = await fakeProxy();
const parent = fakeParent(() => `PROXY 127.0.0.1:${proxy.port}; DIRECT`);
installSystemProxy(parent, {});
await installSystemProxy(parent, {});

const response = await fetch("http://models.example.test/api.json");
expect(await response.text()).toBe("via proxy");
Expand All @@ -122,7 +122,7 @@ describe("installSystemProxy", () => {
const proxy = await fakeProxy();
const target = await listen((_request, response) => response.end("direct"));
const parent = fakeParent((request) => (request.url.includes("bypassed") ? "DIRECT" : `PROXY 127.0.0.1:${proxy.port}`));
installSystemProxy(parent, {});
await installSystemProxy(parent, {});

await fetch("http://models.example.test/a").then((response) => response.text());
await fetch("http://models.example.test/b").then((response) => response.text());
Expand All @@ -143,7 +143,7 @@ describe("installSystemProxy", () => {
const own = await fakeProxy();
const target = await listen((_request, response) => response.end("direct"));
const parent = fakeParent(() => `PROXY 127.0.0.1:${system.port}`);
installSystemProxy(parent, { HTTP_PROXY: `http://127.0.0.1:${own.port}` });
await installSystemProxy(parent, { HTTP_PROXY: `http://127.0.0.1:${own.port}` });

expect(await (await fetch("http://models.example.test/")).text()).toBe("via proxy");
expect(await (await fetch(`http://127.0.0.1:${target.port}/`)).text()).toBe("direct");
Expand Down
15 changes: 10 additions & 5 deletions server/system-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { randomUUID } from "node:crypto";
import { Agent, EnvHttpProxyAgent, ProxyAgent, Socks5ProxyAgent, setGlobalDispatcher, type Dispatcher } from "undici";
import { isIP } from "node:net";
import type { Dispatcher } from "undici";
import { addressClass } from "../electron/egress-addresses.mjs";

type Undici = typeof import("undici");

/** asked of the desktop main process: `rule` is Chromium's `session.resolveProxy` answer for `url` (PAC syntax,
* "PROXY host:port; DIRECT"), so the computer's own proxy settings, PAC script and WPAD apply; null when it has none */
export type ProxyResolveRequest = { type: "duskbot:resolve-proxy"; requestId: string; url: string };
Expand Down Expand Up @@ -63,12 +65,14 @@ export const envProxySet = (env: NodeJS.ProcessEnv) => PROXY_ENV.some((name) =>
* environment wins, otherwise each origin goes where Chromium's resolver says (cached for `ttlMs`). Engines, MCP
* servers and the bot box are separate processes and keep their own env.
*/
export function systemProxyDispatcher({ resolve, env = process.env, ttlMs = 60_000, now = Date.now }: {
export function systemProxyDispatcher({ resolve, env = process.env, ttlMs = 60_000, now = Date.now, undici }: {
resolve: (url: string) => Promise<string | null>;
env?: NodeJS.ProcessEnv;
ttlMs?: number;
now?: () => number;
undici: Undici;
}): Dispatcher {
const { Agent, EnvHttpProxyAgent, ProxyAgent, Socks5ProxyAgent } = undici;
const direct = new Agent();
const fromEnv = envProxySet(env) ? new EnvHttpProxyAgent({
httpProxy: env.http_proxy || env.HTTP_PROXY || "",
Expand Down Expand Up @@ -107,14 +111,15 @@ export function systemProxyDispatcher({ resolve, env = process.env, ttlMs = 60_0

type ParentPort = { on(event: "message", listener: (event: { data?: unknown }) => void): void; postMessage(message: object): void };

export function installSystemProxy(port: ParentPort, env: NodeJS.ProcessEnv = process.env): void {
export async function installSystemProxy(port: ParentPort, env: NodeJS.ProcessEnv = process.env): Promise<void> {
const undici = await import("undici");
const resolver = createProxyResolver((message) => {
try { port.postMessage(message); return true; } catch { return false; }
});
port.on("message", ({ data }) => { resolver.receive(data); });
setGlobalDispatcher(systemProxyDispatcher({ resolve: resolver.resolve, env }));
undici.setGlobalDispatcher(systemProxyDispatcher({ resolve: resolver.resolve, env, undici }));
}

// Only Electron's utility process supplies parentPort (the desktop app's harness); plain Node leaves it absent.
const parentPort = (process as NodeJS.Process & { parentPort?: ParentPort }).parentPort;
if (parentPort) installSystemProxy(parentPort);
if (parentPort) await installSystemProxy(parentPort);
22 changes: 22 additions & 0 deletions src/components/BotSettingsDialog.simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,20 @@ describe("the Where it works page", () => {
(warning.props.onConfirm as () => void)();
expect(fixture.dispatch).toHaveBeenLastCalledWith({ type: "updateBot", botId: "scout", patch: { computer: "local", acknowledgeLocalAuto: true } });
});

it("on Windows offers the bot's own server field even when no default server is set up", () => {
fixture.capabilities = { host: { platform: "win32" } };
fixture.storeState = { ...fixture.storeState, config: { vps: { configured: false, sshAlias: "" } } };
try {
const rendered = where(makeBot({ computer: "local" }));
expect(rendered.html).toContain('aria-label="Server (SSH alias)"');
expect(rendered.html).toContain('placeholder="My-vps"');
expect(rendered.html).toContain("Type an SSH alias from your SSH config. Only this bot uses it.");
expect(where(makeBot({ vpsAlias: "studio-vps" })).html).toContain('value="studio-vps"');
} finally {
fixture.capabilities = undefined;
}
});
});


Expand All @@ -1058,6 +1072,14 @@ describe("the Where it works sheet", () => {
expect(patch).toHaveBeenLastCalledWith({ computer: "vm" });
expect(find(sheet(makeBot({ computer: "vm" })), "data-panel-choice", "vm").props.checked).toBe(true);
});

it("carries the same per-bot server field on the bot panel's Computer tab", () => {
fixture.storeState = { ...fixture.storeState, config: { vps: { configured: false, sshAlias: "" } } };
const rendered = sheet(makeBot({ computer: "local", vpsAlias: "studio-vps" }));
expect(rendered.html).toContain('aria-label="Server (SSH alias)"');
expect(rendered.html).toContain('value="studio-vps"');
expect(rendered.html).toContain("Type an SSH alias from your SSH config. Only this bot uses it.");
});
});
describe("the drill-in pages", () => {
const PAGE = {
Expand Down
Loading