Files
OmniRoute/tests/unit/9551-proxyfetch-no-proxy-context-bypass.test.ts
Markus Hartung 04dba0460e fix(responses-continuation): recover a real id/output for passthrough and translate-mode replies (#11434)
Retargetado para release/v3.8.51 (release/v3.8.50 está congelada — freeze issue #11439). Validado em lote combinado (batch-0824h2, junto de #11435/#11436/#11437) contra o tip de release/v3.8.51: typecheck:core limpo, gates estáticos OK, 127/127 testes focados passando.

Investigação sólida com repro real via container isolado, três causas independentes identificadas e corrigidas com testes de regressão dedicados para cada uma. Obrigado pela contribuição!
2026-08-24 19:57:12 -03:00

76 lines
2.2 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import {
runWithDirectFetchContext,
runWithProxyContext,
resolveProxyForRequest,
} from "../../open-sse/utils/proxyFetch.ts";
async function withEnv(
overrides: Record<string, string | undefined>,
fn: () => unknown
): Promise<unknown> {
const previous = new Map<string, string | undefined>();
for (const [key, value] of Object.entries(overrides)) {
previous.set(key, process.env[key]);
if (value === undefined) {
delete process.env[key];
} else {
process.env[key] = value;
}
}
try {
return await fn();
} finally {
for (const [key, value] of previous.entries()) {
if (value === undefined) {
delete process.env[key];
} else {
process.env[key] = value;
}
}
}
}
test("[9551] BUG: context-proxy ignores NO_PROXY for non-local domains", async () => {
await withEnv(
{
NO_PROXY: "ark.cn-beijing.volces.com",
HTTP_PROXY: undefined,
},
async () => {
await runWithProxyContext({ type: "http", host: "127.0.0.1", port: 7897 }, () => {
const resolved = resolveProxyForRequest("https://ark.cn-beijing.volces.com/api/v3/models");
assert.equal(resolved.source, "direct", "NO_PROXY should bypass context proxy");
});
}
);
});
test("[9551] resolveProxyForRequest: context-proxy respects NO_PROXY=*", async () => {
await withEnv(
{
NO_PROXY: "*",
HTTP_PROXY: undefined,
},
async () => {
await runWithProxyContext({ type: "http", host: "127.0.0.1", port: 7897 }, () => {
const resolved = resolveProxyForRequest("https://api.openai.com/v1/chat/completions");
assert.equal(resolved.source, "direct", "NO_PROXY=* should bypass context proxy");
});
}
);
});
test("direct fetch context overrides an inherited proxy context", async () => {
await runWithProxyContext({ type: "http", host: "127.0.0.1", port: 7897 }, () =>
runWithDirectFetchContext(() => {
const resolved = resolveProxyForRequest("https://api.commandcode.ai/alpha/generate");
assert.equal(resolved.source, "direct");
assert.equal(resolved.proxyUrl, null);
})
);
});