From 058eb857629f5208c280e555cdb08c0a2f4cf74c Mon Sep 17 00:00:00 2001 From: cpojer Date: Tue, 17 Feb 2026 11:17:14 +0900 Subject: [PATCH] chore: Fix types in tests 10/N. --- ...s-non-default-telegram-account.e2e.test.ts | 2 +- src/commands/doctor-memory-search.ts | 2 +- src/commands/test-runtime-config-helpers.ts | 16 ++++++---- ...runs-one-shot-main-job-disables-it.test.ts | 32 +++++++++++++------ src/discord/accounts.ts | 2 +- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/commands/channels.adds-non-default-telegram-account.e2e.test.ts b/src/commands/channels.adds-non-default-telegram-account.e2e.test.ts index 5f276d2807..b3d0acbbb2 100644 --- a/src/commands/channels.adds-non-default-telegram-account.e2e.test.ts +++ b/src/commands/channels.adds-non-default-telegram-account.e2e.test.ts @@ -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) ?? []; diff --git a/src/commands/doctor-memory-search.ts b/src/commands/doctor-memory-search.ts index 5ceefd4205..c06876b234 100644 --- a/src/commands/doctor-memory-search.ts +++ b/src/commands/doctor-memory-search.ts @@ -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"; diff --git a/src/commands/test-runtime-config-helpers.ts b/src/commands/test-runtime-config-helpers.ts index 4890ea999d..e8bb67c352 100644 --- a/src/commands/test-runtime-config-helpers.ts +++ b/src/commands/test-runtime-config-helpers.ts @@ -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; + error: MockFn; + exit: MockFn; }; export function createTestRuntime(): TestRuntime { + const log = vi.fn() as MockFn; + const error = vi.fn() as MockFn; + const exit = vi.fn((_: number) => undefined) as MockFn; return { - log: vi.fn(), - error: vi.fn(), - exit: vi.fn(), + log, + error, + exit, }; } diff --git a/src/cron/service.runs-one-shot-main-job-disables-it.test.ts b/src/cron/service.runs-one-shot-main-job-disables-it.test.ts index d970979b77..7d2a2a0b57 100644 --- a/src/cron/service.runs-one-shot-main-job-disables-it.test.ts +++ b/src/cron/service.runs-one-shot-main-job-disables-it.test.ts @@ -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; - runHeartbeatOnce?: ReturnType; + runIsolatedAgentJob?: CronServiceDeps["runIsolatedAgentJob"]; + runHeartbeatOnce?: NonNullable; 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) { +async function createIsolatedAnnounceHarness( + runIsolatedAgentJob: CronServiceDeps["runIsolatedAgentJob"], +) { const harness = await createCronHarness({ runIsolatedAgentJob, }); @@ -295,7 +301,7 @@ async function createIsolatedAnnounceHarness(runIsolatedAgentJob: ReturnType number; - runHeartbeatOnce: ReturnType; + runHeartbeatOnce: NonNullable; 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, }); diff --git a/src/discord/accounts.ts b/src/discord/accounts.ts index 81b8d11481..2f5729114c 100644 --- a/src/discord/accounts.ts +++ b/src/discord/accounts.ts @@ -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";