From 1b470fb34856a5e0646461fed7942d64b631ce61 Mon Sep 17 00:00:00 2001 From: kridaydave Date: Thu, 3 Dec 2026 17:02:10 +0530 Subject: [PATCH 1/2] harness: load undici at first use so the server bundle and its source guard stay lazy --- scripts/testing/ci-retry-list.json | 2 +- server/system-proxy.test.ts | 6 +++--- server/system-proxy.ts | 15 ++++++++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/scripts/testing/ci-retry-list.json b/scripts/testing/ci-retry-list.json index 90b819f616..77bccfc0dc 100644 --- a/scripts/testing/ci-retry-list.json +++ b/scripts/testing/ci-retry-list.json @@ -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" diff --git a/server/system-proxy.test.ts b/server/system-proxy.test.ts index 86dd4ab1b0..37dfdecfa1 100644 --- a/server/system-proxy.test.ts +++ b/server/system-proxy.test.ts @@ -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"); @@ -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()); @@ -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"); diff --git a/server/system-proxy.ts b/server/system-proxy.ts index b3c328c6eb..45f5cbe623 100644 --- a/server/system-proxy.ts +++ b/server/system-proxy.ts @@ -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 }; @@ -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; 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 || "", @@ -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 { + 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); From c6aaefc8c1c48ff857c8ebf2b14325b5516e312a Mon Sep 17 00:00:00 2001 From: kridaydave Date: Thu, 3 Dec 2026 17:06:06 +0530 Subject: [PATCH 2/2] tests: a routine test run wraps its custom command server in the dry-run MCP (#491) --- server/drivers/codex.test.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/server/drivers/codex.test.ts b/server/drivers/codex.test.ts index 718d1ab9de..00e6a919f3 100644 --- a/server/drivers/codex.test.ts +++ b/server/drivers/codex.test.ts @@ -29,10 +29,11 @@ import { unsupportedCallsNotice } from "./codex-unsupported-calls.ts"; import { rebuiltSessionNotice } from "../resume-recovery.ts"; import { startFakeHttpMcp, type FakeHttpMcp } from "../testing/fake-http-mcp-server.ts"; import { MCP_RESTART_ENV } from "../mcp-app-catalog.ts"; +import { DRY_RUN_NAME_ENV, DRY_RUN_UPSTREAM_ENV } from "../dry-run-mcp.ts"; +import { testRunMounts } from "../dry-run-mounts.ts"; import * as procs from "../procs.ts"; import { autoVerdict } from "../auto-approve.ts"; import { formatQuestionAnswers } from "../../shared/ask-question.ts"; -import { testRunMounts } from "../dry-run-mounts.ts"; vi.mock("./codex-release.ts", async (importOriginal) => ({ ...await importOriginal(), @@ -1297,6 +1298,26 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`) })).rejects.toThrow("cannot set reserved environment variable “DUSK_COMMS_TOKEN”"); }); + it("runs a routine test run's own dry-run wrapper around a custom command server", async () => { + await create(); + const dump = join(scratch, "dry-run-mcp.json"); + process.env.FAKE_CODEX_DUMP = dump; + const mounted = testRunMounts({ notes: { command: "npx", args: ["-y", "@x/notes-mcp"], env: { NOTES_TOKEN: "tok-notes" } } }); + expect(mounted.notes).toMatchObject({ env: { [DRY_RUN_NAME_ENV]: "notes", [DRY_RUN_UPSTREAM_ENV]: expect.any(String) } }); + + await instance.adapter.sendTurn({ + threadId: "t-dry-run-mcp", + text: "go", + integrations: { custom: mounted }, + }); + const done = await recorder.until((event) => event.type === "turn.completed"); + expect(recorder.events.filter((event) => event.type === "runtime.error")).toEqual([]); + expect(done).toMatchObject({ ok: true }); + const seen = JSON.parse(readFileSync(dump, "utf8")); + expect(seen.argv.join(" ")).toContain("mcp_servers.notes.command"); + expect(seen.env[DRY_RUN_NAME_ENV]).toBe("notes"); + }); + it("mounts a custom server under its own name when the user's config.toml already has one by that name", async () => { const codexHome = join(scratch, "collision-codex-home"); mkdirSync(codexHome, { recursive: true });