mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
chore: Fix types in tests 10/N.
This commit is contained in:
@@ -245,7 +245,7 @@ describe("channels command", () => {
|
||||
});
|
||||
|
||||
await channelsListCommand({ json: true, usage: false }, runtime);
|
||||
const payload = JSON.parse(String(runtime.log.mock.calls[0]?.[0] ?? "{}")) as {
|
||||
const payload = JSON.parse(runtime.log.mock.calls[0]?.[0] as string) as {
|
||||
auth?: Array<{ id: string }>;
|
||||
};
|
||||
const ids = payload.auth?.map((entry) => entry.id) ?? [];
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import fsSync from "node:fs";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolveAgentDir, resolveDefaultAgentId } from "../agents/agent-scope.js";
|
||||
import { resolveMemorySearchConfig } from "../agents/memory-search.js";
|
||||
import { resolveApiKeyForProvider } from "../agents/model-auth.js";
|
||||
import { formatCliCommand } from "../cli/command-format.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { note } from "../terminal/note.js";
|
||||
import { resolveUserPath } from "../utils.js";
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { vi } from "vitest";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import type { MockFn } from "../test-utils/vitest-mock-fn.js";
|
||||
|
||||
export const baseConfigSnapshot = {
|
||||
@@ -13,15 +14,18 @@ export const baseConfigSnapshot = {
|
||||
};
|
||||
|
||||
export type TestRuntime = {
|
||||
log: MockFn;
|
||||
error: MockFn;
|
||||
exit: MockFn;
|
||||
log: MockFn<RuntimeEnv["log"]>;
|
||||
error: MockFn<RuntimeEnv["error"]>;
|
||||
exit: MockFn<RuntimeEnv["exit"]>;
|
||||
};
|
||||
|
||||
export function createTestRuntime(): TestRuntime {
|
||||
const log = vi.fn() as MockFn<RuntimeEnv["log"]>;
|
||||
const error = vi.fn() as MockFn<RuntimeEnv["error"]>;
|
||||
const exit = vi.fn((_: number) => undefined) as MockFn<RuntimeEnv["exit"]>;
|
||||
return {
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn(),
|
||||
log,
|
||||
error,
|
||||
exit,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import path from "node:path";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { HeartbeatRunResult } from "../infra/heartbeat-wake.js";
|
||||
import type { CronEvent } from "./service.js";
|
||||
import type { CronEvent, CronServiceDeps } from "./service.js";
|
||||
import { CronService } from "./service.js";
|
||||
import { createNoopLogger, installCronTestHooks } from "./service.test-harness.js";
|
||||
|
||||
@@ -161,7 +161,7 @@ vi.mock("node:fs", async (importOriginal) => {
|
||||
}
|
||||
fsState.entries.delete(absInMock(p));
|
||||
},
|
||||
} satisfies typeof actual.promises;
|
||||
} as unknown as typeof actual.promises;
|
||||
|
||||
const wrapped = { ...actual, promises };
|
||||
return { ...wrapped, default: wrapped };
|
||||
@@ -239,8 +239,8 @@ function createCronEventHarness() {
|
||||
}
|
||||
|
||||
type CronHarnessOptions = {
|
||||
runIsolatedAgentJob?: ReturnType<typeof vi.fn>;
|
||||
runHeartbeatOnce?: ReturnType<typeof vi.fn>;
|
||||
runIsolatedAgentJob?: CronServiceDeps["runIsolatedAgentJob"];
|
||||
runHeartbeatOnce?: NonNullable<CronServiceDeps["runHeartbeatOnce"]>;
|
||||
nowMs?: () => number;
|
||||
wakeNowHeartbeatBusyMaxWaitMs?: number;
|
||||
wakeNowHeartbeatBusyRetryDelayMs?: number;
|
||||
@@ -268,7 +268,11 @@ async function createCronHarness(options: CronHarnessOptions = {}) {
|
||||
enqueueSystemEvent,
|
||||
requestHeartbeatNow,
|
||||
...(options.runHeartbeatOnce ? { runHeartbeatOnce: options.runHeartbeatOnce } : {}),
|
||||
runIsolatedAgentJob: options.runIsolatedAgentJob ?? vi.fn(async () => ({ status: "ok" })),
|
||||
runIsolatedAgentJob:
|
||||
options.runIsolatedAgentJob ??
|
||||
(vi.fn(async (_params: { job: unknown; message: string }) => ({
|
||||
status: "ok",
|
||||
})) as unknown as CronServiceDeps["runIsolatedAgentJob"]),
|
||||
...(events ? { onEvent: events.onEvent } : {}),
|
||||
});
|
||||
await cron.start();
|
||||
@@ -283,7 +287,9 @@ async function createMainOneShotHarness() {
|
||||
return { ...harness, events: harness.events };
|
||||
}
|
||||
|
||||
async function createIsolatedAnnounceHarness(runIsolatedAgentJob: ReturnType<typeof vi.fn>) {
|
||||
async function createIsolatedAnnounceHarness(
|
||||
runIsolatedAgentJob: CronServiceDeps["runIsolatedAgentJob"],
|
||||
) {
|
||||
const harness = await createCronHarness({
|
||||
runIsolatedAgentJob,
|
||||
});
|
||||
@@ -295,7 +301,7 @@ async function createIsolatedAnnounceHarness(runIsolatedAgentJob: ReturnType<typ
|
||||
|
||||
async function createWakeModeNowMainHarness(options: {
|
||||
nowMs?: () => number;
|
||||
runHeartbeatOnce: ReturnType<typeof vi.fn>;
|
||||
runHeartbeatOnce: NonNullable<CronServiceDeps["runHeartbeatOnce"]>;
|
||||
wakeNowHeartbeatBusyMaxWaitMs?: number;
|
||||
wakeNowHeartbeatBusyRetryDelayMs?: number;
|
||||
}) {
|
||||
@@ -499,7 +505,9 @@ describe("CronService", () => {
|
||||
);
|
||||
expect(job.state.runningAtMs).toBeTypeOf("number");
|
||||
|
||||
resolveHeartbeat?.({ status: "ran", durationMs: 123 });
|
||||
if (typeof resolveHeartbeat === "function") {
|
||||
resolveHeartbeat({ status: "ran", durationMs: 123 });
|
||||
}
|
||||
await runPromise;
|
||||
|
||||
expect(job.state.lastStatus).toBe("ok");
|
||||
@@ -690,7 +698,9 @@ describe("CronService", () => {
|
||||
log: noopLogger,
|
||||
enqueueSystemEvent: vi.fn(),
|
||||
requestHeartbeatNow: vi.fn(),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" })),
|
||||
runIsolatedAgentJob: vi.fn(async (_params: { job: unknown; message: string }) => ({
|
||||
status: "ok",
|
||||
})) as unknown as CronServiceDeps["runIsolatedAgentJob"],
|
||||
});
|
||||
|
||||
await cron.start();
|
||||
@@ -752,7 +762,9 @@ describe("CronService", () => {
|
||||
log: noopLogger,
|
||||
enqueueSystemEvent,
|
||||
requestHeartbeatNow,
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" })),
|
||||
runIsolatedAgentJob: vi.fn(async (_params: { job: unknown; message: string }) => ({
|
||||
status: "ok",
|
||||
})) as unknown as CronServiceDeps["runIsolatedAgentJob"],
|
||||
onEvent: events.onEvent,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { DiscordAccountConfig, DiscordActionConfig } from "../config/types.js";
|
||||
import { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||
import { normalizeAccountId } from "../routing/session-key.js";
|
||||
import { resolveDiscordToken } from "./token.js";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user