mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 23:56:07 +00:00
test: guard tooling mock call fallbacks
This commit is contained in:
@@ -46,7 +46,11 @@ describe("requireValidConfigSnapshot", () => {
|
||||
}
|
||||
|
||||
function requireFirstLog(runtime: ReturnType<typeof createRuntime>): string {
|
||||
const [message] = runtime.log.mock.calls[0] ?? [];
|
||||
const [call] = runtime.log.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error("expected runtime log message");
|
||||
}
|
||||
const [message] = call;
|
||||
if (message === undefined) {
|
||||
throw new Error("expected runtime log message");
|
||||
}
|
||||
|
||||
@@ -57,13 +57,29 @@ vi.mock("../gateway/call.js", () => ({
|
||||
}));
|
||||
|
||||
function requireFirstRuntimeLog(): string {
|
||||
const [message] = runtime.log.mock.calls[0] ?? [];
|
||||
const [call] = runtime.log.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error("expected health command log output");
|
||||
}
|
||||
const [message] = call;
|
||||
if (message === undefined) {
|
||||
throw new Error("expected health command log output");
|
||||
}
|
||||
return String(message);
|
||||
}
|
||||
|
||||
function requireFirstGatewayRequest(): Record<string, unknown> {
|
||||
const [call] = callGatewayMock.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error("expected gateway call");
|
||||
}
|
||||
const [request] = call;
|
||||
if (!request || typeof request !== "object" || Array.isArray(request)) {
|
||||
throw new Error("expected gateway request");
|
||||
}
|
||||
return request as Record<string, unknown>;
|
||||
}
|
||||
|
||||
describe("healthCommand", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -124,10 +140,10 @@ describe("healthCommand", () => {
|
||||
);
|
||||
|
||||
expect(callGatewayMock).toHaveBeenCalledOnce();
|
||||
const [gatewayRequest] = callGatewayMock.mock.calls[0] ?? [];
|
||||
expect(gatewayRequest?.method).toBe("health");
|
||||
expect(gatewayRequest?.token).toBe("setup-token");
|
||||
expect(gatewayRequest?.password).toBe("setup-password");
|
||||
const gatewayRequest = requireFirstGatewayRequest();
|
||||
expect(gatewayRequest.method).toBe("health");
|
||||
expect(gatewayRequest.token).toBe("setup-token");
|
||||
expect(gatewayRequest.password).toBe("setup-password");
|
||||
});
|
||||
|
||||
it("prints degraded model-pricing health without failing the command", async () => {
|
||||
|
||||
@@ -27,7 +27,11 @@ describe("image-ops temp dir", () => {
|
||||
await getImageMetadata(Buffer.from("image"));
|
||||
|
||||
expect(fs.mkdtemp).toHaveBeenCalledTimes(1);
|
||||
const [prefix] = vi.mocked(fs.mkdtemp).mock.calls[0] ?? [];
|
||||
const [mkdtempCall] = vi.mocked(fs.mkdtemp).mock.calls;
|
||||
if (!mkdtempCall) {
|
||||
throw new Error("expected mkdtemp call");
|
||||
}
|
||||
const [prefix] = mkdtempCall;
|
||||
expect(typeof prefix).toBe("string");
|
||||
const uuidPrefix = path.join(secureRoot, "openclaw-img-");
|
||||
expect(prefix?.startsWith(uuidPrefix)).toBe(true);
|
||||
|
||||
@@ -6,7 +6,11 @@ import {
|
||||
} from "../../scripts/preinstall-package-manager-warning.mjs";
|
||||
|
||||
function requireFirstWarning(warn: ReturnType<typeof vi.fn>): unknown {
|
||||
const [message] = warn.mock.calls[0] ?? [];
|
||||
const [call] = warn.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error("expected package manager warning");
|
||||
}
|
||||
const [message] = call;
|
||||
if (message === undefined) {
|
||||
throw new Error("expected package manager warning");
|
||||
}
|
||||
|
||||
@@ -35,7 +35,11 @@ function runScript(args: string[], cwd = process.cwd()) {
|
||||
}
|
||||
|
||||
function requireFirstMockArg<T>(mock: { mock: { calls: Array<[T, ...unknown[]]> } }): T {
|
||||
const [arg] = mock.mock.calls[0] ?? [];
|
||||
const [call] = mock.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error("expected first mock call argument");
|
||||
}
|
||||
const [arg] = call;
|
||||
if (arg === undefined) {
|
||||
throw new Error("expected first mock call argument");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user