fix: unify web tool proxy path (#27430) (thanks @kevinWangSheng)

This commit is contained in:
Peter Steinberger
2026-02-26 12:32:30 +01:00
parent d8e2030d47
commit 46003e85bf
6 changed files with 298 additions and 191 deletions

View File

@@ -1,3 +1,4 @@
import { EnvHttpProxyAgent } from "undici";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import * as ssrf from "../../infra/net/ssrf.js";
import { withFetchPreconnect } from "../../test-utils/fetch-mock.js";
@@ -146,6 +147,7 @@ describe("web_fetch extraction fallbacks", () => {
afterEach(() => {
global.fetch = priorFetch;
vi.unstubAllEnvs();
vi.restoreAllMocks();
});
@@ -256,6 +258,27 @@ describe("web_fetch extraction fallbacks", () => {
expect(details?.warning).toContain("Response body truncated");
});
it("uses proxy-aware dispatcher when HTTP_PROXY is configured", async () => {
vi.stubEnv("HTTP_PROXY", "http://127.0.0.1:7890");
const mockFetch = installMockFetch((input: RequestInfo | URL) =>
Promise.resolve({
ok: true,
status: 200,
headers: makeHeaders({ "content-type": "text/plain" }),
text: async () => "proxy body",
url: requestUrl(input),
} as Response),
);
const tool = createFetchTool({ firecrawl: { enabled: false } });
await tool?.execute?.("call", { url: "https://example.com/proxy" });
const requestInit = mockFetch.mock.calls[0]?.[1] as
| (RequestInit & { dispatcher?: unknown })
| undefined;
expect(requestInit?.dispatcher).toBeInstanceOf(EnvHttpProxyAgent);
});
// NOTE: Test for wrapping url/finalUrl/warning fields requires DNS mocking.
// The sanitization of these fields is verified by external-content.test.ts tests.