mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-13 11:00:50 +00:00
* fix(telegram): preserve HTTP proxy env in global dispatcher workaround * telegram: document request-scoped proxy dispatcher constraint * telegram: assert proxy path never mutates global dispatcher * changelog: credit telegram proxy env regression fix --------- Co-authored-by: Rylen Anil <rylen.anil@gmail.com>
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => {
|
|
const undiciFetch = vi.fn();
|
|
const proxyAgentSpy = vi.fn();
|
|
const setGlobalDispatcher = vi.fn();
|
|
class ProxyAgent {
|
|
static lastCreated: ProxyAgent | undefined;
|
|
proxyUrl: string;
|
|
constructor(proxyUrl: string) {
|
|
this.proxyUrl = proxyUrl;
|
|
ProxyAgent.lastCreated = this;
|
|
proxyAgentSpy(proxyUrl);
|
|
}
|
|
}
|
|
|
|
return {
|
|
ProxyAgent,
|
|
undiciFetch,
|
|
proxyAgentSpy,
|
|
setGlobalDispatcher,
|
|
getLastAgent: () => ProxyAgent.lastCreated,
|
|
};
|
|
});
|
|
|
|
vi.mock("undici", () => ({
|
|
ProxyAgent: mocks.ProxyAgent,
|
|
fetch: mocks.undiciFetch,
|
|
setGlobalDispatcher: mocks.setGlobalDispatcher,
|
|
}));
|
|
|
|
import { makeProxyFetch } from "./proxy.js";
|
|
|
|
describe("makeProxyFetch", () => {
|
|
it("uses undici fetch with ProxyAgent dispatcher", async () => {
|
|
const proxyUrl = "http://proxy.test:8080";
|
|
mocks.undiciFetch.mockResolvedValue({ ok: true });
|
|
|
|
const proxyFetch = makeProxyFetch(proxyUrl);
|
|
await proxyFetch("https://api.telegram.org/bot123/getMe");
|
|
|
|
expect(mocks.proxyAgentSpy).toHaveBeenCalledWith(proxyUrl);
|
|
expect(mocks.undiciFetch).toHaveBeenCalledWith(
|
|
"https://api.telegram.org/bot123/getMe",
|
|
expect.objectContaining({ dispatcher: mocks.getLastAgent() }),
|
|
);
|
|
expect(mocks.setGlobalDispatcher).not.toHaveBeenCalled();
|
|
});
|
|
});
|