From 8604af0337c34e1282f3b6c0f5d8245070ec9d55 Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Mon, 31 Aug 2026 14:04:39 -0700 Subject: [PATCH 1/4] fix(e2e): publish fake APIs on ephemeral ports Signed-off-by: Prekshi Vyas --- test/e2e/live/messaging-providers-helpers.ts | 23 +++++++++++++------ ...messaging-providers-runtime-proofs.test.ts | 12 ++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/test/e2e/live/messaging-providers-helpers.ts b/test/e2e/live/messaging-providers-helpers.ts index 78489f03336..bde62c60df2 100644 --- a/test/e2e/live/messaging-providers-helpers.ts +++ b/test/e2e/live/messaging-providers-helpers.ts @@ -112,8 +112,15 @@ export function assertDiscordGatewayCapture(captureFile: string, expectedToken: expect(identify?.tokenLooksPlaceholder, "Discord placeholder leaked").toBe(false); } +export type FakeDockerApiKind = + | "slack" + | "telegram" + | "wechat" + | "discord-gateway" + | "discord-message"; + export type FakeDockerApi = { - kind: string; + kind: FakeDockerApiKind; port: string; alternatePort?: string; dir: string; @@ -121,6 +128,11 @@ export type FakeDockerApi = { container: string; }; +export function fakeDockerApiPublishArgs(kind: FakeDockerApiKind): string[] { + const containerPorts = kind === "slack" ? [8080, 8081] : [8080]; + return containerPorts.flatMap((port) => ["-p", `127.0.0.1::${port}`]); +} + export function outputText(result: CommandOutput): string { return [result.stdout, result.stderr].filter(Boolean).join("\n"); } @@ -600,7 +612,7 @@ export async function startFakeDockerApi( host: HostCliClient, cleanup: (name: string, run: () => Promise) => void, options: { - kind: "slack" | "telegram" | "wechat" | "discord-gateway" | "discord-message"; + kind: FakeDockerApiKind; imageScript: string; nodeArgs?: readonly string[]; containerPrefix: string; @@ -657,8 +669,7 @@ export async function startFakeDockerApi( container, "--network", network, - "-p", - "0:8080", + ...fakeDockerApiPublishArgs(options.kind), "-e", `${options.portEnv}=8080`, "-e", @@ -666,9 +677,7 @@ export async function startFakeDockerApi( "-e", `${options.captureFileEnv}=/tmp/fake/capture.jsonl`, ]; - if (options.kind === "slack") { - dockerArgs.push("-p", "0:8081", "-e", "FAKE_SLACK_API_WEBSOCKET_PORT=8081"); - } + if (options.kind === "slack") dockerArgs.push("-e", "FAKE_SLACK_API_WEBSOCKET_PORT=8081"); for (const [key, value] of Object.entries(options.expectedEnv)) { dockerArgs.push("-e", `${key}=${value}`); } diff --git a/test/e2e/support/messaging-providers-runtime-proofs.test.ts b/test/e2e/support/messaging-providers-runtime-proofs.test.ts index 11a67a618c9..034ef56f639 100644 --- a/test/e2e/support/messaging-providers-runtime-proofs.test.ts +++ b/test/e2e/support/messaging-providers-runtime-proofs.test.ts @@ -12,6 +12,7 @@ import { buildProcessTokenProbe } from "../fixtures/process-token-probe.ts"; import { buildSandboxNodeInvocation, buildSandboxShellInvocation, + fakeDockerApiPublishArgs, isNvidiaEndpointRateLimitFailure, messagingEnv, OPENSHELL_EXEC_ARGUMENT_LIMIT_BYTES, @@ -38,6 +39,17 @@ async function waitFor(predicate: () => boolean, message: string): Promise } describe("messaging provider installed-runtime proofs", () => { + it.each([ + ["discord-gateway", ["-p", "127.0.0.1::8080"]], + ["slack", ["-p", "127.0.0.1::8080", "-p", "127.0.0.1::8081"]], + ] as const)("publishes the fake %s API on loopback ephemeral ports", (kind, expected) => { + const args = fakeDockerApiPublishArgs(kind); + + expect(args).toEqual(expected); + expect(args).not.toContain("0:8080"); + expect(args).not.toContain("0:8081"); + }); + it("uses a synthetic WeChat token even when the host exports one", () => { const previousToken = process.env.WECHAT_BOT_TOKEN; process.env.WECHAT_BOT_TOKEN = "host-wechat-token-must-not-reach-the-fake-api"; From 929be7dae786d94b3406f35d13b5cc98f18374d8 Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Mon, 31 Aug 2026 14:39:28 -0700 Subject: [PATCH 2/4] fix(e2e): proxy isolated fake APIs through host ports Signed-off-by: Prekshi Vyas --- test/e2e/live/messaging-providers-helpers.ts | 168 ++++++++++++++---- ...messaging-providers-runtime-proofs.test.ts | 25 ++- 2 files changed, 152 insertions(+), 41 deletions(-) diff --git a/test/e2e/live/messaging-providers-helpers.ts b/test/e2e/live/messaging-providers-helpers.ts index bde62c60df2..38ae512019f 100644 --- a/test/e2e/live/messaging-providers-helpers.ts +++ b/test/e2e/live/messaging-providers-helpers.ts @@ -41,6 +41,33 @@ export const LIVE_TIMEOUT_MS = 90 * 60_000; export const OPENSHELL_EXEC_ARGUMENT_LIMIT_BYTES = 32_768; const FAKE_API_IMAGE = "node:22-trixie-slim@sha256:db8a96a63e5264607ada2d206758876ebbed6a12be2ada7517793cbfb0c2a29c"; +const FAKE_API_PROXY_SOURCE = String.raw` +const net = require("node:net"); +const upstream = process.env.NEMOCLAW_FAKE_API_UPSTREAM; +const ports = (process.env.NEMOCLAW_FAKE_API_PROXY_PORTS || "") + .split(",") + .filter(Boolean) + .map(Number); + +if (!upstream || ports.length === 0 || ports.some((port) => !Number.isInteger(port))) { + process.exit(2); +} + +for (const port of ports) { + const server = net.createServer((client) => { + const backend = net.connect(port, upstream); + const close = () => { + client.destroy(); + backend.destroy(); + }; + client.on("error", close); + backend.on("error", close); + client.pipe(backend).pipe(client); + }); + server.on("error", () => process.exit(3)); + server.listen(port, "0.0.0.0"); +} +`; // Leave ample headroom beneath OpenShell's strict per-argument ceiling. const SANDBOX_SOURCE_CHUNK_BYTES = 16_384; @@ -128,9 +155,23 @@ export type FakeDockerApi = { container: string; }; -export function fakeDockerApiPublishArgs(kind: FakeDockerApiKind): string[] { +export function fakeDockerApiNetworkPlan( + kind: FakeDockerApiKind, + internalNetwork: string, + proxyContainer: string, +): { + apiRunNetworkArgs: string[]; + proxyRunNetworkArgs: string[]; + proxyPublishArgs: string[]; + proxyConnectArgs: string[]; +} { const containerPorts = kind === "slack" ? [8080, 8081] : [8080]; - return containerPorts.flatMap((port) => ["-p", `127.0.0.1::${port}`]); + return { + apiRunNetworkArgs: ["--network", internalNetwork], + proxyRunNetworkArgs: ["--network", "bridge"], + proxyPublishArgs: containerPorts.flatMap((port) => ["-p", String(port)]), + proxyConnectArgs: ["network", "connect", internalNetwork, proxyContainer], + }; } export function outputText(result: CommandOutput): string { @@ -629,7 +670,9 @@ export async function startFakeDockerApi( const portFile = path.join(dir, "port"); const captureFile = path.join(dir, "capture.jsonl"); const container = uniqueContainerName(options.containerPrefix); + const proxyContainer = uniqueContainerName(`${options.containerPrefix}-proxy`); const network = uniqueContainerName("nemoclaw-fake-api-network"); + const networkPlan = fakeDockerApiNetworkPlan(options.kind, network, proxyContainer); fs.writeFileSync(captureFile, ""); const networkCreate = await runHost( @@ -667,9 +710,7 @@ export async function startFakeDockerApi( "--rm", "--name", container, - "--network", - network, - ...fakeDockerApiPublishArgs(options.kind), + ...networkPlan.apiRunNetworkArgs, "-e", `${options.portEnv}=8080`, "-e", @@ -716,40 +757,103 @@ export async function startFakeDockerApi( }); expectExitZero(start, `start fake ${options.kind} API`); + let apiReady = false; for (let attempt = 0; attempt < 100; attempt += 1) { if (fs.existsSync(portFile) && fs.statSync(portFile).size > 0) { - const restPort = await runHost(host, "docker", ["port", container, "8080/tcp"], { - artifactName: `port-fake-${options.kind}-api`, + apiReady = true; + break; + } + await sleep(100); + } + if (!apiReady) throw new Error(`fake ${options.kind} API did not become ready`); + + cleanup(`remove ${proxyContainer}`, async () => { + const remove = await runHost(host, "docker", ["rm", "-f", proxyContainer], { + artifactName: `cleanup-${proxyContainer}`, + env: options.env, + redactionValues: options.redactionValues, + timeoutMs: 60_000, + }); + if (remove.exitCode !== 0 && !/No such container:/iu.test(resultText(remove))) { + expectExitZero(remove, `remove fake ${options.kind} API proxy ${proxyContainer}`); + } + }); + + const proxyStart = await runHost( + host, + "docker", + [ + "run", + "-d", + "--rm", + "--name", + proxyContainer, + ...networkPlan.proxyRunNetworkArgs, + ...networkPlan.proxyPublishArgs, + "--read-only", + "--cap-drop", + "ALL", + "--security-opt", + "no-new-privileges", + "--pids-limit", + "32", + "-e", + `NEMOCLAW_FAKE_API_UPSTREAM=${container}`, + "-e", + `NEMOCLAW_FAKE_API_PROXY_PORTS=${options.kind === "slack" ? "8080,8081" : "8080"}`, + FAKE_API_IMAGE, + "node", + "-e", + FAKE_API_PROXY_SOURCE, + ], + { + artifactName: `start-fake-${options.kind}-api-proxy`, + env: options.env, + redactionValues: options.redactionValues, + timeoutMs: 120_000, + }, + ); + expectExitZero(proxyStart, `start fake ${options.kind} API proxy`); + + const proxyConnect = await runHost(host, "docker", networkPlan.proxyConnectArgs, { + artifactName: `connect-fake-${options.kind}-api-proxy`, + env: options.env, + redactionValues: options.redactionValues, + timeoutMs: 30_000, + }); + expectExitZero(proxyConnect, `connect fake ${options.kind} API proxy`); + + const publishedPort = async (containerPort: number, artifactName: string): Promise => { + const result = await runHost( + host, + "docker", + ["port", proxyContainer, `${String(containerPort)}/tcp`], + { + artifactName, env: options.env, redactionValues: options.redactionValues, timeoutMs: 30_000, - }); - const publishedRestPort = restPort.stdout.trim().split(":").at(-1)?.trim() ?? ""; - let publishedWebsocketPort = ""; - if (options.kind === "slack") { - const websocketPort = await runHost(host, "docker", ["port", container, "8081/tcp"], { - artifactName: "port-fake-slack-websocket-api", - env: options.env, - redactionValues: options.redactionValues, - timeoutMs: 30_000, - }); - publishedWebsocketPort = websocketPort.stdout.trim().split(":").at(-1)?.trim() ?? ""; - } - if (publishedRestPort && (options.kind !== "slack" || publishedWebsocketPort)) { - return { - kind: options.kind, - port: publishedRestPort, - ...(options.kind === "slack" ? { alternatePort: publishedWebsocketPort } : {}), - dir, - captureFile, - container, - }; - } - } - await sleep(100); + }, + ); + expectExitZero(result, `read fake ${options.kind} API proxy port`); + return result.stdout.match(/:(\d+)\s*$/mu)?.[1] ?? ""; + }; + + const publishedRestPort = await publishedPort(8080, `port-fake-${options.kind}-api`); + const publishedWebsocketPort = + options.kind === "slack" ? await publishedPort(8081, "port-fake-slack-websocket-api") : ""; + if (!publishedRestPort || (options.kind === "slack" && !publishedWebsocketPort)) { + throw new Error(`fake ${options.kind} API proxy did not publish a port`); } - throw new Error(`fake ${options.kind} API did not publish a port`); + return { + kind: options.kind, + port: publishedRestPort, + ...(options.kind === "slack" ? { alternatePort: publishedWebsocketPort } : {}), + dir, + captureFile, + container, + }; } export async function applyRestRewritePolicy( diff --git a/test/e2e/support/messaging-providers-runtime-proofs.test.ts b/test/e2e/support/messaging-providers-runtime-proofs.test.ts index 034ef56f639..6203f6d02bd 100644 --- a/test/e2e/support/messaging-providers-runtime-proofs.test.ts +++ b/test/e2e/support/messaging-providers-runtime-proofs.test.ts @@ -12,7 +12,7 @@ import { buildProcessTokenProbe } from "../fixtures/process-token-probe.ts"; import { buildSandboxNodeInvocation, buildSandboxShellInvocation, - fakeDockerApiPublishArgs, + fakeDockerApiNetworkPlan, isNvidiaEndpointRateLimitFailure, messagingEnv, OPENSHELL_EXEC_ARGUMENT_LIMIT_BYTES, @@ -40,14 +40,21 @@ async function waitFor(predicate: () => boolean, message: string): Promise describe("messaging provider installed-runtime proofs", () => { it.each([ - ["discord-gateway", ["-p", "127.0.0.1::8080"]], - ["slack", ["-p", "127.0.0.1::8080", "-p", "127.0.0.1::8081"]], - ] as const)("publishes the fake %s API on loopback ephemeral ports", (kind, expected) => { - const args = fakeDockerApiPublishArgs(kind); - - expect(args).toEqual(expected); - expect(args).not.toContain("0:8080"); - expect(args).not.toContain("0:8081"); + ["discord-gateway", ["-p", "8080"]], + ["slack", ["-p", "8080", "-p", "8081"]], + ] as const)("proxies the isolated fake %s API through ephemeral host ports", (kind, expected) => { + const plan = fakeDockerApiNetworkPlan(kind, "internal-fixture", "fixture-proxy"); + + expect(plan).toEqual({ + apiRunNetworkArgs: ["--network", "internal-fixture"], + proxyRunNetworkArgs: ["--network", "bridge"], + proxyPublishArgs: expected, + proxyConnectArgs: ["network", "connect", "internal-fixture", "fixture-proxy"], + }); + expect(plan.apiRunNetworkArgs).not.toContain("bridge"); + expect(plan.apiRunNetworkArgs).not.toContain("-p"); + expect(plan.proxyPublishArgs).not.toContain("0:8080"); + expect(plan.proxyPublishArgs).not.toContain("0:8081"); }); it("uses a synthetic WeChat token even when the host exports one", () => { From 3bf8e4591ba4e12f8bfdb5594c46698c1cbc5d67 Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Mon, 31 Aug 2026 15:10:33 -0700 Subject: [PATCH 3/4] fix(e2e): bind fake API proxy to loopback Signed-off-by: Prekshi Vyas --- test/e2e/live/messaging-providers-helpers.ts | 57 +++----- ...messaging-providers-runtime-proofs.test.ts | 134 +++++++++++++++--- 2 files changed, 141 insertions(+), 50 deletions(-) diff --git a/test/e2e/live/messaging-providers-helpers.ts b/test/e2e/live/messaging-providers-helpers.ts index 38ae512019f..28d19278ab4 100644 --- a/test/e2e/live/messaging-providers-helpers.ts +++ b/test/e2e/live/messaging-providers-helpers.ts @@ -155,25 +155,6 @@ export type FakeDockerApi = { container: string; }; -export function fakeDockerApiNetworkPlan( - kind: FakeDockerApiKind, - internalNetwork: string, - proxyContainer: string, -): { - apiRunNetworkArgs: string[]; - proxyRunNetworkArgs: string[]; - proxyPublishArgs: string[]; - proxyConnectArgs: string[]; -} { - const containerPorts = kind === "slack" ? [8080, 8081] : [8080]; - return { - apiRunNetworkArgs: ["--network", internalNetwork], - proxyRunNetworkArgs: ["--network", "bridge"], - proxyPublishArgs: containerPorts.flatMap((port) => ["-p", String(port)]), - proxyConnectArgs: ["network", "connect", internalNetwork, proxyContainer], - }; -} - export function outputText(result: CommandOutput): string { return [result.stdout, result.stderr].filter(Boolean).join("\n"); } @@ -672,7 +653,7 @@ export async function startFakeDockerApi( const container = uniqueContainerName(options.containerPrefix); const proxyContainer = uniqueContainerName(`${options.containerPrefix}-proxy`); const network = uniqueContainerName("nemoclaw-fake-api-network"); - const networkPlan = fakeDockerApiNetworkPlan(options.kind, network, proxyContainer); + const containerPorts = options.kind === "slack" ? [8080, 8081] : [8080]; fs.writeFileSync(captureFile, ""); const networkCreate = await runHost( @@ -710,7 +691,8 @@ export async function startFakeDockerApi( "--rm", "--name", container, - ...networkPlan.apiRunNetworkArgs, + "--network", + network, "-e", `${options.portEnv}=8080`, "-e", @@ -788,8 +770,9 @@ export async function startFakeDockerApi( "--rm", "--name", proxyContainer, - ...networkPlan.proxyRunNetworkArgs, - ...networkPlan.proxyPublishArgs, + "--network", + "bridge", + ...containerPorts.flatMap((port) => ["-p", `127.0.0.1::${String(port)}`]), "--read-only", "--cap-drop", "ALL", @@ -800,7 +783,7 @@ export async function startFakeDockerApi( "-e", `NEMOCLAW_FAKE_API_UPSTREAM=${container}`, "-e", - `NEMOCLAW_FAKE_API_PROXY_PORTS=${options.kind === "slack" ? "8080,8081" : "8080"}`, + `NEMOCLAW_FAKE_API_PROXY_PORTS=${containerPorts.join(",")}`, FAKE_API_IMAGE, "node", "-e", @@ -815,12 +798,17 @@ export async function startFakeDockerApi( ); expectExitZero(proxyStart, `start fake ${options.kind} API proxy`); - const proxyConnect = await runHost(host, "docker", networkPlan.proxyConnectArgs, { - artifactName: `connect-fake-${options.kind}-api-proxy`, - env: options.env, - redactionValues: options.redactionValues, - timeoutMs: 30_000, - }); + const proxyConnect = await runHost( + host, + "docker", + ["network", "connect", network, proxyContainer], + { + artifactName: `connect-fake-${options.kind}-api-proxy`, + env: options.env, + redactionValues: options.redactionValues, + timeoutMs: 30_000, + }, + ); expectExitZero(proxyConnect, `connect fake ${options.kind} API proxy`); const publishedPort = async (containerPort: number, artifactName: string): Promise => { @@ -836,15 +824,16 @@ export async function startFakeDockerApi( }, ); expectExitZero(result, `read fake ${options.kind} API proxy port`); - return result.stdout.match(/:(\d+)\s*$/mu)?.[1] ?? ""; + const hostPort = result.stdout.trim().match(/^127\.0\.0\.1:(\d+)$/u)?.[1]; + if (!hostPort) { + throw new Error(`fake ${options.kind} API proxy port did not bind only to 127.0.0.1`); + } + return hostPort; }; const publishedRestPort = await publishedPort(8080, `port-fake-${options.kind}-api`); const publishedWebsocketPort = options.kind === "slack" ? await publishedPort(8081, "port-fake-slack-websocket-api") : ""; - if (!publishedRestPort || (options.kind === "slack" && !publishedWebsocketPort)) { - throw new Error(`fake ${options.kind} API proxy did not publish a port`); - } return { kind: options.kind, diff --git a/test/e2e/support/messaging-providers-runtime-proofs.test.ts b/test/e2e/support/messaging-providers-runtime-proofs.test.ts index 6203f6d02bd..eb7121f0f22 100644 --- a/test/e2e/support/messaging-providers-runtime-proofs.test.ts +++ b/test/e2e/support/messaging-providers-runtime-proofs.test.ts @@ -9,14 +9,15 @@ import path from "node:path"; import { describe, expect, it } from "vitest"; import { buildProcessTokenProbe } from "../fixtures/process-token-probe.ts"; +import type { HostCliClient } from "../fixtures/clients/host.ts"; import { buildSandboxNodeInvocation, buildSandboxShellInvocation, - fakeDockerApiNetworkPlan, isNvidiaEndpointRateLimitFailure, messagingEnv, OPENSHELL_EXEC_ARGUMENT_LIMIT_BYTES, parseRuntimeProofPort, + startFakeDockerApi, } from "../live/messaging-providers-helpers.ts"; import { parseInstalledSlackProof, @@ -38,23 +39,124 @@ async function waitFor(predicate: () => boolean, message: string): Promise expect(matched, message).toBe(true); } +type CleanupAction = { + name: string; + run: () => Promise; +}; + +function successfulCommand(stdout = "") { + return { + artifacts: { result: "", stderr: "", stdout: "" }, + command: [], + exitCode: 0, + signal: null, + stderr: "", + stdout, + timedOut: false, + }; +} + +function fakeDockerHost(publishedAddress = "127.0.0.1"): { + calls: string[][]; + host: HostCliClient; +} { + const calls: string[][] = []; + const host = { + command: async (command: string, args: string[]) => { + expect(command).toBe("docker"); + calls.push([...args]); + args + .filter((argument) => args[0] === "run" && argument.endsWith(":/tmp/fake")) + .forEach((fakeApiMount) => { + const fixtureDir = fakeApiMount.slice(0, -":/tmp/fake".length); + fs.writeFileSync(path.join(fixtureDir, "port"), "8080"); + }); + return args[0] === "port" + ? successfulCommand(`${publishedAddress}:${args[2] === "8081/tcp" ? "32101" : "32100"}\n`) + : successfulCommand(); + }, + } as unknown as HostCliClient; + return { calls, host }; +} + +async function runCleanup(actions: CleanupAction[]): Promise { + for (const action of actions.toReversed()) await action.run(); +} + describe("messaging provider installed-runtime proofs", () => { it.each([ - ["discord-gateway", ["-p", "8080"]], - ["slack", ["-p", "8080", "-p", "8081"]], - ] as const)("proxies the isolated fake %s API through ephemeral host ports", (kind, expected) => { - const plan = fakeDockerApiNetworkPlan(kind, "internal-fixture", "fixture-proxy"); - - expect(plan).toEqual({ - apiRunNetworkArgs: ["--network", "internal-fixture"], - proxyRunNetworkArgs: ["--network", "bridge"], - proxyPublishArgs: expected, - proxyConnectArgs: ["network", "connect", "internal-fixture", "fixture-proxy"], - }); - expect(plan.apiRunNetworkArgs).not.toContain("bridge"); - expect(plan.apiRunNetworkArgs).not.toContain("-p"); - expect(plan.proxyPublishArgs).not.toContain("0:8080"); - expect(plan.proxyPublishArgs).not.toContain("0:8081"); + ["discord-gateway", ["127.0.0.1::8080"], ["8080/tcp"]], + ["slack", ["127.0.0.1::8080", "127.0.0.1::8081"], ["8080/tcp", "8081/tcp"]], + ] as const)( + "proxies the isolated fake %s API through loopback-only ephemeral ports", + async (kind, expectedPublications, expectedPortQueries) => { + const { calls, host } = fakeDockerHost(); + const cleanup: CleanupAction[] = []; + + try { + const api = await startFakeDockerApi(host, (name, run) => cleanup.push({ name, run }), { + kind, + imageScript: `fake-${kind}-api.cjs`, + containerPrefix: `fake-${kind}`, + portEnv: "FAKE_API_PORT", + portFileEnv: "FAKE_API_PORT_FILE", + captureFileEnv: "FAKE_API_CAPTURE_FILE", + expectedEnv: {}, + redactionValues: [], + env: {}, + }); + const networkCreate = calls.find((args) => args[0] === "network" && args[1] === "create"); + const runCalls = calls.filter((args) => args[0] === "run"); + expect(networkCreate).toBeDefined(); + expect(runCalls).toHaveLength(2); + const [apiRun, proxyRun] = runCalls as [string[], string[]]; + const network = networkCreate!.at(-1); + const apiContainer = apiRun[apiRun.indexOf("--name") + 1]; + const proxyContainer = proxyRun[proxyRun.indexOf("--name") + 1]; + const publications = proxyRun.flatMap((argument, index) => + argument === "-p" ? [proxyRun[index + 1]] : [], + ); + + expect(networkCreate.slice(0, -1)).toEqual(["network", "create", "--internal"]); + expect(apiRun).toEqual(expect.arrayContaining(["--network", network])); + expect(apiRun).not.toContain("-p"); + expect(apiRun).not.toContain("bridge"); + expect(publications).toEqual(expectedPublications); + expect(proxyRun).toEqual(expect.arrayContaining(["--network", "bridge"])); + expect(calls).toContainEqual(["network", "connect", network, proxyContainer]); + expect( + calls.filter((args) => args[0] === "port").map((args) => [args[1], args[2]]), + ).toEqual(expectedPortQueries.map((port) => [proxyContainer, port])); + expect(proxyContainer).not.toBe(apiContainer); + expect(api.port).toBe("32100"); + expect(api.alternatePort).toBe(kind === "slack" ? "32101" : undefined); + } finally { + await runCleanup(cleanup); + } + }, + ); + + it("rejects a fake API proxy port that Docker publishes beyond loopback", async () => { + const { host } = fakeDockerHost("0.0.0.0"); + const cleanup: CleanupAction[] = []; + + try { + await expect( + startFakeDockerApi(host, (name, run) => cleanup.push({ name, run }), { + kind: "discord-gateway", + imageScript: "fake-discord-gateway-api.cjs", + containerPrefix: "fake-discord-gateway", + portEnv: "FAKE_API_PORT", + portFileEnv: "FAKE_API_PORT_FILE", + captureFileEnv: "FAKE_API_CAPTURE_FILE", + expectedEnv: {}, + redactionValues: [], + env: {}, + }), + ).rejects.toThrow(/did not bind only to 127\.0\.0\.1/u); + } finally { + await runCleanup(cleanup); + } }); it("uses a synthetic WeChat token even when the host exports one", () => { From c68773605fd0023e35b866c3d3b6f72b797a9b3b Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Mon, 31 Aug 2026 15:18:35 -0700 Subject: [PATCH 4/4] test(e2e): keep proxy proof target compatible Signed-off-by: Prekshi Vyas --- .../e2e/support/messaging-providers-runtime-proofs.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/e2e/support/messaging-providers-runtime-proofs.test.ts b/test/e2e/support/messaging-providers-runtime-proofs.test.ts index eb7121f0f22..620feec9c1c 100644 --- a/test/e2e/support/messaging-providers-runtime-proofs.test.ts +++ b/test/e2e/support/messaging-providers-runtime-proofs.test.ts @@ -80,7 +80,7 @@ function fakeDockerHost(publishedAddress = "127.0.0.1"): { } async function runCleanup(actions: CleanupAction[]): Promise { - for (const action of actions.toReversed()) await action.run(); + for (let index = actions.length - 1; index >= 0; index -= 1) await actions[index]!.run(); } describe("messaging provider installed-runtime proofs", () => { @@ -109,15 +109,16 @@ describe("messaging provider installed-runtime proofs", () => { const runCalls = calls.filter((args) => args[0] === "run"); expect(networkCreate).toBeDefined(); expect(runCalls).toHaveLength(2); + const createdNetwork = networkCreate!; const [apiRun, proxyRun] = runCalls as [string[], string[]]; - const network = networkCreate!.at(-1); + const network = createdNetwork.at(-1); const apiContainer = apiRun[apiRun.indexOf("--name") + 1]; const proxyContainer = proxyRun[proxyRun.indexOf("--name") + 1]; const publications = proxyRun.flatMap((argument, index) => argument === "-p" ? [proxyRun[index + 1]] : [], ); - expect(networkCreate.slice(0, -1)).toEqual(["network", "create", "--internal"]); + expect(createdNetwork.slice(0, -1)).toEqual(["network", "create", "--internal"]); expect(apiRun).toEqual(expect.arrayContaining(["--network", network])); expect(apiRun).not.toContain("-p"); expect(apiRun).not.toContain("bridge");