mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
chore: chore: Fix types in tests 19/N.
This commit is contained in:
@@ -46,7 +46,6 @@ function stubMinimaxOkFetch() {
|
||||
base_resp: { status_code: 0, status_msg: "" },
|
||||
}),
|
||||
});
|
||||
// @ts-expect-error partial global
|
||||
global.fetch = fetch;
|
||||
vi.stubEnv("MINIMAX_API_KEY", "minimax-test");
|
||||
return fetch;
|
||||
@@ -116,7 +115,6 @@ describe("image tool implicit imageModel config", () => {
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
// @ts-expect-error global fetch cleanup
|
||||
global.fetch = priorFetch;
|
||||
});
|
||||
|
||||
@@ -401,7 +399,6 @@ describe("image tool implicit imageModel config", () => {
|
||||
base_resp: { status_code: 0, status_msg: "" },
|
||||
}),
|
||||
});
|
||||
// @ts-expect-error partial global
|
||||
global.fetch = fetch;
|
||||
vi.stubEnv("MINIMAX_API_KEY", "minimax-test");
|
||||
|
||||
@@ -461,7 +458,6 @@ describe("image tool MiniMax VLM routing", () => {
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
// @ts-expect-error global fetch cleanup
|
||||
global.fetch = priorFetch;
|
||||
});
|
||||
|
||||
@@ -476,7 +472,6 @@ describe("image tool MiniMax VLM routing", () => {
|
||||
base_resp: baseResp,
|
||||
}),
|
||||
});
|
||||
// @ts-expect-error partial global
|
||||
global.fetch = fetch;
|
||||
|
||||
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-minimax-vlm-"));
|
||||
|
||||
@@ -12,7 +12,6 @@ describe("web_fetch firecrawl apiKey normalization", () => {
|
||||
const priorFetch = global.fetch;
|
||||
|
||||
afterEach(() => {
|
||||
// @ts-expect-error restore
|
||||
global.fetch = priorFetch;
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
@@ -34,7 +33,6 @@ describe("web_fetch firecrawl apiKey normalization", () => {
|
||||
);
|
||||
});
|
||||
|
||||
// @ts-expect-error mock fetch
|
||||
global.fetch = fetchSpy;
|
||||
|
||||
const { createWebFetchTool } = await import("./web-tools.js");
|
||||
|
||||
@@ -23,7 +23,6 @@ describe("web_fetch response size limits", () => {
|
||||
});
|
||||
|
||||
const fetchSpy = vi.fn().mockResolvedValue(response);
|
||||
// @ts-expect-error mock fetch
|
||||
global.fetch = fetchSpy;
|
||||
|
||||
const tool = createWebFetchTool(baseToolConfig);
|
||||
|
||||
@@ -62,7 +62,6 @@ describe("web_fetch SSRF protection", () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// @ts-expect-error restore
|
||||
global.fetch = priorFetch;
|
||||
lookupMock.mockReset();
|
||||
vi.restoreAllMocks();
|
||||
|
||||
@@ -92,7 +92,6 @@ function requestUrl(input: RequestInfo): string {
|
||||
|
||||
function installMockFetch(impl: (input: RequestInfo) => Promise<Response>) {
|
||||
const mockFetch = vi.fn(impl);
|
||||
// @ts-expect-error mock fetch
|
||||
global.fetch = mockFetch;
|
||||
return mockFetch;
|
||||
}
|
||||
@@ -141,7 +140,6 @@ describe("web_fetch extraction fallbacks", () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// @ts-expect-error restore
|
||||
global.fetch = priorFetch;
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
@@ -2,19 +2,29 @@ import { Command } from "commander";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { withEnvOverride } from "../config/test-helpers.js";
|
||||
|
||||
const callGateway = vi.fn(async () => ({ ok: true }));
|
||||
const startGatewayServer = vi.fn(async () => ({
|
||||
type DiscoveredBeacon = Awaited<
|
||||
ReturnType<typeof import("../infra/bonjour-discovery.js").discoverGatewayBeacons>
|
||||
>[number];
|
||||
|
||||
const callGateway = vi.fn<(opts: unknown) => Promise<{ ok: true }>>(async () => ({ ok: true }));
|
||||
const startGatewayServer = vi.fn<
|
||||
(port: number, opts?: unknown) => Promise<{ close: () => Promise<void> }>
|
||||
>(async () => ({
|
||||
close: vi.fn(async () => {}),
|
||||
}));
|
||||
const setVerbose = vi.fn();
|
||||
const forceFreePortAndWait = vi.fn(async () => ({
|
||||
const forceFreePortAndWait = vi.fn<
|
||||
(port: number) => Promise<{ killed: unknown[]; waitedMs: number; escalatedToSigkill: boolean }>
|
||||
>(async () => ({
|
||||
killed: [],
|
||||
waitedMs: 0,
|
||||
escalatedToSigkill: false,
|
||||
}));
|
||||
const serviceIsLoaded = vi.fn().mockResolvedValue(true);
|
||||
const discoverGatewayBeacons = vi.fn(async () => []);
|
||||
const gatewayStatusCommand = vi.fn(async () => {});
|
||||
const discoverGatewayBeacons = vi.fn<(opts: unknown) => Promise<DiscoveredBeacon[]>>(
|
||||
async () => [],
|
||||
);
|
||||
const gatewayStatusCommand = vi.fn<(opts: unknown) => Promise<void>>(async () => {});
|
||||
|
||||
const runtimeLogs: string[] = [];
|
||||
const runtimeErrors: string[] = [];
|
||||
|
||||
@@ -19,7 +19,9 @@ import { parseTimeoutMs } from "../nodes-run.js";
|
||||
* least approvalTimeoutMs + 10_000.
|
||||
*/
|
||||
|
||||
const callGatewaySpy = vi.fn(async () => ({ decision: "allow-once" }));
|
||||
const callGatewaySpy = vi.fn<
|
||||
(opts: Record<string, unknown>) => Promise<{ decision: "allow-once" }>
|
||||
>(async () => ({ decision: "allow-once" }));
|
||||
|
||||
vi.mock("../../gateway/call.js", () => ({
|
||||
callGateway: callGatewaySpy,
|
||||
@@ -44,7 +46,7 @@ describe("nodes run: approval transport timeout (#12098)", () => {
|
||||
});
|
||||
|
||||
expect(callGatewaySpy).toHaveBeenCalledTimes(1);
|
||||
const callOpts = callGatewaySpy.mock.calls[0][0] as Record<string, unknown>;
|
||||
const callOpts = callGatewaySpy.mock.calls[0][0];
|
||||
expect(callOpts.method).toBe("exec.approval.request");
|
||||
expect(callOpts.timeoutMs).toBe(35_000);
|
||||
});
|
||||
@@ -65,7 +67,7 @@ describe("nodes run: approval transport timeout (#12098)", () => {
|
||||
);
|
||||
|
||||
expect(callGatewaySpy).toHaveBeenCalledTimes(1);
|
||||
const callOpts = callGatewaySpy.mock.calls[0][0] as Record<string, unknown>;
|
||||
const callOpts = callGatewaySpy.mock.calls[0][0];
|
||||
expect(callOpts.timeoutMs).toBeGreaterThanOrEqual(approvalTimeoutMs);
|
||||
expect(callOpts.timeoutMs).toBe(130_000);
|
||||
});
|
||||
@@ -89,7 +91,7 @@ describe("nodes run: approval transport timeout (#12098)", () => {
|
||||
{ transportTimeoutMs },
|
||||
);
|
||||
|
||||
const callOpts = callGatewaySpy.mock.calls[0][0] as Record<string, unknown>;
|
||||
const callOpts = callGatewaySpy.mock.calls[0][0];
|
||||
expect(callOpts.timeoutMs).toBe(200_000);
|
||||
});
|
||||
|
||||
@@ -109,7 +111,7 @@ describe("nodes run: approval transport timeout (#12098)", () => {
|
||||
{ transportTimeoutMs },
|
||||
);
|
||||
|
||||
const callOpts = callGatewaySpy.mock.calls[0][0] as Record<string, unknown>;
|
||||
const callOpts = callGatewaySpy.mock.calls[0][0];
|
||||
expect(callOpts.timeoutMs).toBe(130_000);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from "vitest";
|
||||
|
||||
vi.mock("node:child_process", async () => {
|
||||
const actual = await vi.importActual<typeof import("node:child_process")>("node:child_process");
|
||||
@@ -39,9 +39,8 @@ describe("gateway --force helpers", () => {
|
||||
});
|
||||
|
||||
it("returns empty list when lsof finds nothing", () => {
|
||||
(execFileSync as unknown as vi.Mock).mockImplementation(() => {
|
||||
const err = new Error("no matches");
|
||||
// @ts-expect-error partial
|
||||
(execFileSync as unknown as Mock).mockImplementation(() => {
|
||||
const err = new Error("no matches") as NodeJS.ErrnoException & { status?: number };
|
||||
err.status = 1; // lsof uses exit 1 for no matches
|
||||
throw err;
|
||||
});
|
||||
@@ -49,9 +48,8 @@ describe("gateway --force helpers", () => {
|
||||
});
|
||||
|
||||
it("throws when lsof missing", () => {
|
||||
(execFileSync as unknown as vi.Mock).mockImplementation(() => {
|
||||
const err = new Error("not found");
|
||||
// @ts-expect-error partial
|
||||
(execFileSync as unknown as Mock).mockImplementation(() => {
|
||||
const err = new Error("not found") as NodeJS.ErrnoException;
|
||||
err.code = "ENOENT";
|
||||
throw err;
|
||||
});
|
||||
@@ -59,11 +57,10 @@ describe("gateway --force helpers", () => {
|
||||
});
|
||||
|
||||
it("kills each listener and returns metadata", () => {
|
||||
(execFileSync as unknown as vi.Mock).mockReturnValue(
|
||||
(execFileSync as unknown as Mock).mockReturnValue(
|
||||
["p42", "cnode", "p99", "cssh", ""].join("\n"),
|
||||
);
|
||||
const killMock = vi.fn();
|
||||
// @ts-expect-error override for test
|
||||
process.kill = killMock;
|
||||
|
||||
const killed = forceFreePort(18789);
|
||||
@@ -81,7 +78,7 @@ describe("gateway --force helpers", () => {
|
||||
it("retries until the port is free", async () => {
|
||||
vi.useFakeTimers();
|
||||
let call = 0;
|
||||
(execFileSync as unknown as vi.Mock).mockImplementation(() => {
|
||||
(execFileSync as unknown as Mock).mockImplementation(() => {
|
||||
call += 1;
|
||||
// 1st call: initial listeners to kill; 2nd call: still listed; 3rd call: gone.
|
||||
if (call === 1) {
|
||||
@@ -94,7 +91,6 @@ describe("gateway --force helpers", () => {
|
||||
});
|
||||
|
||||
const killMock = vi.fn();
|
||||
// @ts-expect-error override for test
|
||||
process.kill = killMock;
|
||||
|
||||
const promise = forceFreePortAndWait(18789, {
|
||||
@@ -117,7 +113,7 @@ describe("gateway --force helpers", () => {
|
||||
it("escalates to SIGKILL if SIGTERM doesn't free the port", async () => {
|
||||
vi.useFakeTimers();
|
||||
let call = 0;
|
||||
(execFileSync as unknown as vi.Mock).mockImplementation(() => {
|
||||
(execFileSync as unknown as Mock).mockImplementation(() => {
|
||||
call += 1;
|
||||
// 1st call: initial kill list; then keep showing until after SIGKILL.
|
||||
if (call <= 6) {
|
||||
@@ -127,7 +123,6 @@ describe("gateway --force helpers", () => {
|
||||
});
|
||||
|
||||
const killMock = vi.fn();
|
||||
// @ts-expect-error override for test
|
||||
process.kill = killMock;
|
||||
|
||||
const promise = forceFreePortAndWait(18789, {
|
||||
|
||||
Reference in New Issue
Block a user