mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
chore: chore: Fix types in tests 19/N.
This commit is contained in:
@@ -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