mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 07:00:22 +00:00
fix(telegram): add dnsResultOrder=ipv4first default on Node 22+ to fix fetch failures (#5405)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 71366e9532
Co-authored-by: Glucksberg <80581902+Glucksberg@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
@@ -3,6 +3,7 @@ import { resolveFetch } from "../infra/fetch.js";
|
||||
import { resetTelegramFetchStateForTests, resolveTelegramFetch } from "./fetch.js";
|
||||
|
||||
const setDefaultAutoSelectFamily = vi.hoisted(() => vi.fn());
|
||||
const setDefaultResultOrder = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("node:net", async () => {
|
||||
const actual = await vi.importActual<typeof import("node:net")>("node:net");
|
||||
@@ -12,11 +13,20 @@ vi.mock("node:net", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("node:dns", async () => {
|
||||
const actual = await vi.importActual<typeof import("node:dns")>("node:dns");
|
||||
return {
|
||||
...actual,
|
||||
setDefaultResultOrder,
|
||||
};
|
||||
});
|
||||
|
||||
const originalFetch = globalThis.fetch;
|
||||
|
||||
afterEach(() => {
|
||||
resetTelegramFetchStateForTests();
|
||||
setDefaultAutoSelectFamily.mockClear();
|
||||
setDefaultAutoSelectFamily.mockReset();
|
||||
setDefaultResultOrder.mockReset();
|
||||
vi.unstubAllEnvs();
|
||||
vi.clearAllMocks();
|
||||
if (originalFetch) {
|
||||
@@ -105,4 +115,22 @@ describe("resolveTelegramFetch", () => {
|
||||
resolveTelegramFetch(undefined, { network: { autoSelectFamily: true } });
|
||||
expect(setDefaultAutoSelectFamily).toHaveBeenCalledWith(false);
|
||||
});
|
||||
|
||||
it("applies dns result order from config", async () => {
|
||||
globalThis.fetch = vi.fn(async () => ({})) as unknown as typeof fetch;
|
||||
resolveTelegramFetch(undefined, { network: { dnsResultOrder: "verbatim" } });
|
||||
expect(setDefaultResultOrder).toHaveBeenCalledWith("verbatim");
|
||||
});
|
||||
|
||||
it("retries dns setter on next call when previous attempt threw", async () => {
|
||||
setDefaultResultOrder.mockImplementationOnce(() => {
|
||||
throw new Error("dns setter failed once");
|
||||
});
|
||||
globalThis.fetch = vi.fn(async () => ({})) as unknown as typeof fetch;
|
||||
|
||||
resolveTelegramFetch(undefined, { network: { dnsResultOrder: "ipv4first" } });
|
||||
resolveTelegramFetch(undefined, { network: { dnsResultOrder: "ipv4first" } });
|
||||
|
||||
expect(setDefaultResultOrder).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user