mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
chore: Fix types in tests 40/N.
This commit is contained in:
@@ -25,6 +25,7 @@ describe("runCronIsolatedAgentTurn", () => {
|
||||
lastTo: "123",
|
||||
});
|
||||
const deps: CliDeps = {
|
||||
sendMessageSlack: vi.fn(),
|
||||
sendMessageWhatsApp: vi.fn(),
|
||||
sendMessageTelegram: vi.fn().mockResolvedValue({
|
||||
messageId: "t1",
|
||||
|
||||
@@ -15,6 +15,7 @@ import { setupIsolatedAgentTurnMocks } from "./isolated-agent.test-setup.js";
|
||||
|
||||
function createCliDeps(overrides: Partial<CliDeps> = {}): CliDeps {
|
||||
return {
|
||||
sendMessageSlack: vi.fn(),
|
||||
sendMessageWhatsApp: vi.fn(),
|
||||
sendMessageTelegram: vi.fn(),
|
||||
sendMessageDiscord: vi.fn(),
|
||||
|
||||
@@ -21,6 +21,7 @@ const withTempHome = withTempCronHome;
|
||||
|
||||
function makeDeps(): CliDeps {
|
||||
return {
|
||||
sendMessageSlack: vi.fn(),
|
||||
sendMessageWhatsApp: vi.fn(),
|
||||
sendMessageTelegram: vi.fn(),
|
||||
sendMessageDiscord: vi.fn(),
|
||||
|
||||
@@ -2,7 +2,8 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { CronService } from "./service.js";
|
||||
import type { ChannelId } from "../channels/plugins/types.js";
|
||||
import { CronService, type CronServiceDeps } from "./service.js";
|
||||
|
||||
const noopLogger = {
|
||||
debug: vi.fn(),
|
||||
@@ -25,13 +26,13 @@ type DeliveryMode = "none" | "announce";
|
||||
|
||||
type DeliveryOverride = {
|
||||
mode: DeliveryMode;
|
||||
channel?: string;
|
||||
channel?: ChannelId | "last";
|
||||
to?: string;
|
||||
};
|
||||
|
||||
async function withCronService(
|
||||
params: {
|
||||
runIsolatedAgentJob?: () => Promise<{ status: "ok"; summary: string; delivered?: boolean }>;
|
||||
runIsolatedAgentJob?: CronServiceDeps["runIsolatedAgentJob"];
|
||||
},
|
||||
run: (context: {
|
||||
cron: CronService;
|
||||
@@ -50,7 +51,7 @@ async function withCronService(
|
||||
requestHeartbeatNow,
|
||||
runIsolatedAgentJob:
|
||||
params.runIsolatedAgentJob ??
|
||||
(vi.fn(async () => ({ status: "ok", summary: "done" })) as never),
|
||||
(vi.fn(async () => ({ status: "ok" as const, summary: "done" })) as never),
|
||||
});
|
||||
|
||||
await cron.start();
|
||||
@@ -73,6 +74,7 @@ async function addIsolatedAgentTurnJob(
|
||||
) {
|
||||
return cron.add({
|
||||
name: params.name,
|
||||
enabled: true,
|
||||
schedule: { kind: "every", everyMs: 60_000, anchorMs: Date.now() },
|
||||
sessionTarget: "isolated",
|
||||
wakeMode: params.wakeMode,
|
||||
@@ -80,7 +82,7 @@ async function addIsolatedAgentTurnJob(
|
||||
kind: "agentTurn",
|
||||
message: "hello",
|
||||
...params.payload,
|
||||
},
|
||||
} as unknown as { kind: "agentTurn"; message: string },
|
||||
...(params.delivery
|
||||
? {
|
||||
delivery: params.delivery as unknown as {
|
||||
@@ -129,7 +131,7 @@ describe("CronService delivery plan consistency", () => {
|
||||
await withCronService(
|
||||
{
|
||||
runIsolatedAgentJob: vi.fn(async () => ({
|
||||
status: "ok",
|
||||
status: "ok" as const,
|
||||
summary: "done",
|
||||
delivered: true,
|
||||
})),
|
||||
|
||||
@@ -147,7 +147,7 @@ describe("CronService interval/cron jobs fire on time", () => {
|
||||
log: noopLogger,
|
||||
enqueueSystemEvent,
|
||||
requestHeartbeatNow,
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" })),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" as const })),
|
||||
});
|
||||
|
||||
await cron.start();
|
||||
|
||||
@@ -17,7 +17,7 @@ function createCronService(storePath: string) {
|
||||
log: logger,
|
||||
enqueueSystemEvent: vi.fn(),
|
||||
requestHeartbeatNow: vi.fn(),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" })),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" as const })),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ function createCronFromStorePath(storePath: string) {
|
||||
log: noopLogger,
|
||||
enqueueSystemEvent: vi.fn(),
|
||||
requestHeartbeatNow: vi.fn(),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" })),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" as const })),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ describe("CronService", () => {
|
||||
const store = await makeStorePath();
|
||||
const enqueueSystemEvent = vi.fn();
|
||||
const requestHeartbeatNow = vi.fn();
|
||||
const runIsolatedAgentJob = vi.fn(async () => ({ status: "ok" }));
|
||||
const runIsolatedAgentJob = vi.fn(async () => ({ status: "ok" as const }));
|
||||
|
||||
const cronA = new CronService({
|
||||
storePath: store.storePath,
|
||||
|
||||
@@ -30,9 +30,9 @@ describe("CronService restart catch-up", () => {
|
||||
storePath: params.storePath,
|
||||
cronEnabled: true,
|
||||
log: noopLogger,
|
||||
enqueueSystemEvent: params.enqueueSystemEvent,
|
||||
requestHeartbeatNow: params.requestHeartbeatNow,
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" })),
|
||||
enqueueSystemEvent: params.enqueueSystemEvent as never,
|
||||
requestHeartbeatNow: params.requestHeartbeatNow as never,
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" as const })) as never,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -394,7 +394,7 @@ async function loadLegacyDeliveryMigration(rawJob: Record<string, unknown>) {
|
||||
log: noopLogger,
|
||||
enqueueSystemEvent: vi.fn(),
|
||||
requestHeartbeatNow: vi.fn(),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" })),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" as const })),
|
||||
});
|
||||
await cron.start();
|
||||
const jobs = await cron.list({ includeDisabled: true });
|
||||
@@ -506,7 +506,7 @@ describe("CronService", () => {
|
||||
expect(job.state.runningAtMs).toBeTypeOf("number");
|
||||
|
||||
if (typeof resolveHeartbeat === "function") {
|
||||
resolveHeartbeat({ status: "ran", durationMs: 123 });
|
||||
(resolveHeartbeat as (res: HeartbeatRunResult) => void)({ status: "ran", durationMs: 123 });
|
||||
}
|
||||
await runPromise;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ async function withCronService(
|
||||
log: noopLogger,
|
||||
enqueueSystemEvent,
|
||||
requestHeartbeatNow,
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" })),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" as const })),
|
||||
});
|
||||
|
||||
await cron.start();
|
||||
|
||||
@@ -58,7 +58,7 @@ describe("CronService store migrations", () => {
|
||||
log: noopLogger,
|
||||
enqueueSystemEvent: vi.fn(),
|
||||
requestHeartbeatNow: vi.fn(),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok", summary: "ok" })),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" as const, summary: "ok" })),
|
||||
});
|
||||
|
||||
await cron.start();
|
||||
|
||||
@@ -30,7 +30,7 @@ async function migrateAndLoadFirstJob(storePath: string): Promise<Record<string,
|
||||
log: noopLogger,
|
||||
enqueueSystemEvent: vi.fn(),
|
||||
requestHeartbeatNow: vi.fn(),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" })),
|
||||
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" as const })),
|
||||
});
|
||||
|
||||
await cron.start();
|
||||
|
||||
Reference in New Issue
Block a user