mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:11:23 +00:00
chore: Fix types in tests 10/N.
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user