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 { withFetchPreconnect } from "../../test-utils/fetch-mock.js";
import { createWebFetchTool, createWebSearchTool } from "./web-tools.js";
@@ -143,6 +144,19 @@ describe("web_search country and language parameters", () => {
expect(mockFetch).not.toHaveBeenCalled();
expect(result?.details).toMatchObject({ error: "invalid_freshness" });
});
it("uses proxy-aware dispatcher when HTTP_PROXY is configured", async () => {
vi.stubEnv("HTTP_PROXY", "http://127.0.0.1:7890");
const mockFetch = installMockFetch({ web: { results: [] } });
const tool = createWebSearchTool({ config: undefined, sandboxed: true });
await tool?.execute?.("call-1", { query: "proxy-test" });
const requestInit = mockFetch.mock.calls[0]?.[1] as
| (RequestInit & { dispatcher?: unknown })
| undefined;
expect(requestInit?.dispatcher).toBeInstanceOf(EnvHttpProxyAgent);
});
});
describe("web_search perplexity baseUrl defaults", () => {