fix(test): type CDP DNS lookup mocks (#122607)

Amp-Thread-ID: https://ampcode.com/threads/T-019ff3db-c467-70ad-8ed3-81f2ba94b0c0

Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Peter Steinberger
2026-08-12 04:45:15 -07:00
committed by GitHub
parent 3e6aec1d55
commit 79ac476b0f
@@ -1,6 +1,7 @@
// Browser tests cover cdp.helpers plugin behavior.
import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { LookupFn } from "../infra/net/ssrf.js";
import {
assertChromeMcpCdpTransportAllowed,
resolveCdpReachabilityPolicy,
@@ -13,6 +14,11 @@ const PROFILE_HTTP_REACHABILITY_TIMEOUT_MS = 300;
const PROFILE_WS_REACHABILITY_MIN_TIMEOUT_MS = 200;
const PROFILE_WS_REACHABILITY_MAX_TIMEOUT_MS = 2000;
function createLookupFn(address: string): LookupFn {
const family = address.includes(":") ? 6 : 4;
return vi.fn(async () => [{ address, family }]) as unknown as LookupFn;
}
const fetchWithSsrFGuardMock = vi.hoisted(() => vi.fn());
vi.mock("openclaw/plugin-sdk/ssrf-runtime", async (importOriginal) => {
@@ -167,7 +173,7 @@ describe("cdp helpers", () => {
await expect(
resolvePinnedHostnameWithPolicy("browser.example", {
policy: scoped,
lookupFn: async () => [{ address: "10.0.0.8", family: 4 }],
lookupFn: createLookupFn("10.0.0.8"),
}),
).rejects.toThrow(/private\/internal\/special-use ip address/i);
});
@@ -188,7 +194,7 @@ describe("cdp helpers", () => {
await expect(
resolvePinnedHostnameWithPolicy("browser.example", {
policy: scoped,
lookupFn: async () => [{ address: "10.0.0.8", family: 4 }],
lookupFn: createLookupFn("10.0.0.8"),
}),
).resolves.toEqual(expect.objectContaining({ addresses: ["10.0.0.8"] }));
});