mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:01:36 +00:00
chore: Fix types in tests 30/N.
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import { Command } from "commander";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const callGatewayFromCli = vi.fn(async (method: string, _opts: unknown, params?: unknown) => {
|
||||
if (method === "cron.status") {
|
||||
return { enabled: true };
|
||||
}
|
||||
return { ok: true, params };
|
||||
});
|
||||
const callGatewayFromCli = vi.fn(
|
||||
async (method: string, _opts: unknown, params?: unknown, _timeoutMs?: number) => {
|
||||
if (method === "cron.status") {
|
||||
return { enabled: true };
|
||||
}
|
||||
return { ok: true, params };
|
||||
},
|
||||
);
|
||||
|
||||
vi.mock("./gateway-rpc.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./gateway-rpc.js")>("./gateway-rpc.js");
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Command } from "commander";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const callGateway = vi.fn(async () => ({ ok: true }));
|
||||
const resolveGatewayProgramArguments = vi.fn(async () => ({
|
||||
const callGateway = vi.fn(async (..._args: unknown[]) => ({ ok: true }));
|
||||
const resolveGatewayProgramArguments = vi.fn(async (_opts?: unknown) => ({
|
||||
programArguments: ["/bin/node", "cli", "gateway", "--port", "18789"],
|
||||
}));
|
||||
const serviceInstall = vi.fn().mockResolvedValue(undefined);
|
||||
@@ -12,7 +12,7 @@ const serviceRestart = vi.fn().mockResolvedValue(undefined);
|
||||
const serviceIsLoaded = vi.fn().mockResolvedValue(false);
|
||||
const serviceReadCommand = vi.fn().mockResolvedValue(null);
|
||||
const serviceReadRuntime = vi.fn().mockResolvedValue({ status: "running" });
|
||||
const findExtraGatewayServices = vi.fn(async () => []);
|
||||
const findExtraGatewayServices = vi.fn(async (_env: unknown, _opts?: unknown) => []);
|
||||
const inspectPortUsage = vi.fn(async (port: number) => ({
|
||||
port,
|
||||
status: "free",
|
||||
|
||||
@@ -9,7 +9,7 @@ const consumeGatewaySigusr1RestartAuthorization = vi.fn(() => true);
|
||||
const isGatewaySigusr1RestartExternallyAllowed = vi.fn(() => false);
|
||||
const markGatewaySigusr1RestartHandled = vi.fn();
|
||||
const getActiveTaskCount = vi.fn(() => 0);
|
||||
const waitForActiveTasks = vi.fn(async () => ({ drained: true }));
|
||||
const waitForActiveTasks = vi.fn(async (_timeoutMs: number) => ({ drained: true }));
|
||||
const resetAllLanes = vi.fn();
|
||||
const DRAIN_TIMEOUT_LOG = "drain timeout reached; proceeding with restart";
|
||||
const gatewayLog = {
|
||||
@@ -103,7 +103,7 @@ describe("runGatewayLoop", () => {
|
||||
start,
|
||||
runtime: {
|
||||
exit: vi.fn(),
|
||||
} as { exit: (code: number) => never },
|
||||
} as unknown as { exit: (code: number) => never },
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
@@ -14,8 +14,10 @@ vi.mock("../../plugin-registry.js", () => ({
|
||||
ensurePluginRegistryLoaded: vi.fn(),
|
||||
}));
|
||||
|
||||
const hasHooksMock = vi.fn(() => false);
|
||||
const runGatewayStopMock = vi.fn(async () => {});
|
||||
const hasHooksMock = vi.fn((_hookName: string) => false);
|
||||
const runGatewayStopMock = vi.fn(
|
||||
async (_event: { reason?: string }, _ctx: Record<string, unknown>) => {},
|
||||
);
|
||||
const runGlobalGatewayStopSafelyMock = vi.fn(
|
||||
async (params: {
|
||||
event: { reason?: string };
|
||||
@@ -201,7 +203,13 @@ describe("runMessageAction", () => {
|
||||
expect.anything(),
|
||||
);
|
||||
// account key should be stripped in favor of accountId
|
||||
const passedOpts = messageCommandMock.mock.calls[0][0] as Record<string, unknown>;
|
||||
const passedOpts = (
|
||||
messageCommandMock.mock.calls as unknown as Array<[Record<string, unknown>]>
|
||||
)?.[0]?.[0];
|
||||
expect(passedOpts).toBeTruthy();
|
||||
if (!passedOpts) {
|
||||
throw new Error("expected message command call");
|
||||
}
|
||||
expect(passedOpts).not.toHaveProperty("account");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { isYes, setVerbose, setYes } from "../globals.js";
|
||||
|
||||
vi.mock("node:readline/promises", () => {
|
||||
const question = vi.fn<[], Promise<string>>();
|
||||
const question = vi.fn(async () => "");
|
||||
const close = vi.fn();
|
||||
const createInterface = vi.fn(() => ({ question, close }));
|
||||
return { default: { createInterface } };
|
||||
@@ -11,14 +11,14 @@ vi.mock("node:readline/promises", () => {
|
||||
type ReadlineMock = {
|
||||
default: {
|
||||
createInterface: () => {
|
||||
question: ReturnType<typeof vi.fn<[], Promise<string>>>;
|
||||
question: ReturnType<typeof vi.fn>;
|
||||
close: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
const { promptYesNo } = await import("./prompt.js");
|
||||
const readline = (await import("node:readline/promises")) as ReadlineMock;
|
||||
const readline = (await import("node:readline/promises")) as unknown as ReadlineMock;
|
||||
|
||||
describe("promptYesNo", () => {
|
||||
it("returns true when global --yes is set", async () => {
|
||||
|
||||
Reference in New Issue
Block a user