mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 10:51:23 +00:00
fix: unify web tool proxy path (#27430) (thanks @kevinWangSheng)
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user