From d6d73d0ed97712d91a705abc9e804f110e91b42b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 22 Feb 2026 08:12:55 +0000 Subject: [PATCH] test(core): trim redundant test resets and use mockClear --- ...ilters-final-suppresses-output-without-start-tag.e2e.test.ts | 2 +- ...handling.stages-inbound-media-into-sandbox-workspace.test.ts | 2 +- .../get-reply-inline-actions.skip-when-config-empty.test.ts | 2 -- src/commands/doctor-session-locks.test.ts | 2 +- src/commands/doctor-state-integrity.test.ts | 2 +- src/discord/send.webhook-activity.test.ts | 2 +- src/gateway/startup-auth.test.ts | 2 +- src/imessage/targets.test.ts | 2 +- src/infra/ports.test.ts | 2 +- src/infra/process-respawn.test.ts | 2 +- src/line/probe.test.ts | 2 +- src/plugins/tools.optional.test.ts | 2 +- src/process/kill-tree.test.ts | 2 +- src/process/supervisor/supervisor.pty-command.test.ts | 2 +- src/telegram/accounts.test.ts | 2 +- 15 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.filters-final-suppresses-output-without-start-tag.e2e.test.ts b/src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.filters-final-suppresses-output-without-start-tag.e2e.test.ts index 9ccb78605a6..79a8cf50a5c 100644 --- a/src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.filters-final-suppresses-output-without-start-tag.e2e.test.ts +++ b/src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.filters-final-suppresses-output-without-start-tag.e2e.test.ts @@ -30,7 +30,7 @@ describe("subscribeEmbeddedPiSession", () => { const firstPayload = onPartialReply.mock.calls[0][0]; expect(firstPayload.text).toBe("Hi there"); - onPartialReply.mockReset(); + onPartialReply.mockClear(); emit({ type: "message_start", message: { role: "assistant" } }); emitAssistantTextDelta({ emit, delta: "Oops no start" }); diff --git a/src/auto-reply/reply.triggers.trigger-handling.stages-inbound-media-into-sandbox-workspace.test.ts b/src/auto-reply/reply.triggers.trigger-handling.stages-inbound-media-into-sandbox-workspace.test.ts index 671c94bb105..4dfddded047 100644 --- a/src/auto-reply/reply.triggers.trigger-handling.stages-inbound-media-into-sandbox-workspace.test.ts +++ b/src/auto-reply/reply.triggers.trigger-handling.stages-inbound-media-into-sandbox-workspace.test.ts @@ -22,7 +22,7 @@ import { stageSandboxMedia } from "./reply/stage-sandbox-media.js"; afterEach(() => { vi.restoreAllMocks(); - childProcessMocks.spawn.mockReset(); + childProcessMocks.spawn.mockClear(); }); describe("stageSandboxMedia", () => { diff --git a/src/auto-reply/reply/get-reply-inline-actions.skip-when-config-empty.test.ts b/src/auto-reply/reply/get-reply-inline-actions.skip-when-config-empty.test.ts index c04140f63df..7ecead2d596 100644 --- a/src/auto-reply/reply/get-reply-inline-actions.skip-when-config-empty.test.ts +++ b/src/auto-reply/reply/get-reply-inline-actions.skip-when-config-empty.test.ts @@ -17,8 +17,6 @@ const { handleInlineActions } = await import("./get-reply-inline-actions.js"); describe("handleInlineActions", () => { it("skips whatsapp replies when config is empty and From !== To", async () => { - handleCommandsMock.mockReset(); - const typing: TypingController = { onReplyStart: async () => {}, startTypingLoop: async () => {}, diff --git a/src/commands/doctor-session-locks.test.ts b/src/commands/doctor-session-locks.test.ts index 7a89b9437bf..daa5ce0eedc 100644 --- a/src/commands/doctor-session-locks.test.ts +++ b/src/commands/doctor-session-locks.test.ts @@ -17,7 +17,7 @@ describe("noteSessionLockHealth", () => { let envSnapshot: ReturnType; beforeEach(async () => { - note.mockReset(); + note.mockClear(); envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]); root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-doctor-locks-")); process.env.OPENCLAW_STATE_DIR = root; diff --git a/src/commands/doctor-state-integrity.test.ts b/src/commands/doctor-state-integrity.test.ts index a72eb2cce99..50dd5c89114 100644 --- a/src/commands/doctor-state-integrity.test.ts +++ b/src/commands/doctor-state-integrity.test.ts @@ -77,7 +77,7 @@ describe("doctor state integrity oauth dir checks", () => { process.env.OPENCLAW_STATE_DIR = path.join(tempHome, ".openclaw"); delete process.env.OPENCLAW_OAUTH_DIR; fs.mkdirSync(process.env.OPENCLAW_STATE_DIR, { recursive: true, mode: 0o700 }); - vi.mocked(note).mockReset(); + vi.mocked(note).mockClear(); }); afterEach(() => { diff --git a/src/discord/send.webhook-activity.test.ts b/src/discord/send.webhook-activity.test.ts index 9a05ee28b08..0d92e16de3f 100644 --- a/src/discord/send.webhook-activity.test.ts +++ b/src/discord/send.webhook-activity.test.ts @@ -13,7 +13,7 @@ vi.mock("../infra/channel-activity.js", async (importOriginal) => { describe("sendWebhookMessageDiscord activity", () => { beforeEach(() => { - recordChannelActivityMock.mockReset(); + recordChannelActivityMock.mockClear(); vi.stubGlobal( "fetch", vi.fn(async () => { diff --git a/src/gateway/startup-auth.test.ts b/src/gateway/startup-auth.test.ts index 07cd724e91c..d09e97554b2 100644 --- a/src/gateway/startup-auth.test.ts +++ b/src/gateway/startup-auth.test.ts @@ -36,7 +36,7 @@ describe("ensureGatewayStartupAuth", () => { beforeEach(() => { vi.restoreAllMocks(); - mocks.writeConfigFile.mockReset(); + mocks.writeConfigFile.mockClear(); }); async function expectNoTokenGeneration(cfg: OpenClawConfig, mode: string) { diff --git a/src/imessage/targets.test.ts b/src/imessage/targets.test.ts index afafb6d8260..252c397399d 100644 --- a/src/imessage/targets.test.ts +++ b/src/imessage/targets.test.ts @@ -87,7 +87,7 @@ describe("imessage targets", () => { describe("createIMessageRpcClient", () => { beforeEach(() => { - spawnMock.mockReset(); + spawnMock.mockClear(); vi.stubEnv("VITEST", "true"); }); diff --git a/src/infra/ports.test.ts b/src/infra/ports.test.ts index 10027e24520..c02834bbbf2 100644 --- a/src/infra/ports.test.ts +++ b/src/infra/ports.test.ts @@ -91,7 +91,7 @@ describe("ports helpers", () => { describeUnix("inspectPortUsage", () => { beforeEach(() => { - runCommandWithTimeoutMock.mockReset(); + runCommandWithTimeoutMock.mockClear(); }); it("reports busy when lsof is missing but loopback listener exists", async () => { diff --git a/src/infra/process-respawn.test.ts b/src/infra/process-respawn.test.ts index 324282ec990..90e9b5a9c57 100644 --- a/src/infra/process-respawn.test.ts +++ b/src/infra/process-respawn.test.ts @@ -17,7 +17,7 @@ afterEach(() => { envSnapshot.restore(); process.argv = [...originalArgv]; process.execArgv = [...originalExecArgv]; - spawnMock.mockReset(); + spawnMock.mockClear(); }); function clearSupervisorHints() { diff --git a/src/line/probe.test.ts b/src/line/probe.test.ts index 688c754b1ef..737a2d8f892 100644 --- a/src/line/probe.test.ts +++ b/src/line/probe.test.ts @@ -15,7 +15,7 @@ let probeLineBot: typeof import("./probe.js").probeLineBot; afterEach(() => { vi.useRealTimers(); - getBotInfoMock.mockReset(); + getBotInfoMock.mockClear(); }); describe("probeLineBot", () => { diff --git a/src/plugins/tools.optional.test.ts b/src/plugins/tools.optional.test.ts index 7d68c06d7df..85c2a101928 100644 --- a/src/plugins/tools.optional.test.ts +++ b/src/plugins/tools.optional.test.ts @@ -54,7 +54,7 @@ function setRegistry(entries: MockRegistryToolEntry[]) { describe("resolvePluginTools optional tools", () => { beforeEach(() => { - loadOpenClawPluginsMock.mockReset(); + loadOpenClawPluginsMock.mockClear(); }); it("skips optional tools without explicit allowlist", () => { diff --git a/src/process/kill-tree.test.ts b/src/process/kill-tree.test.ts index b566248c67a..a506442aed4 100644 --- a/src/process/kill-tree.test.ts +++ b/src/process/kill-tree.test.ts @@ -25,7 +25,7 @@ describe("killProcessTree", () => { let killSpy: ReturnType; beforeEach(() => { - spawnMock.mockReset(); + spawnMock.mockClear(); killSpy = vi.spyOn(process, "kill"); vi.useFakeTimers(); }); diff --git a/src/process/supervisor/supervisor.pty-command.test.ts b/src/process/supervisor/supervisor.pty-command.test.ts index 582179e130e..daee348944d 100644 --- a/src/process/supervisor/supervisor.pty-command.test.ts +++ b/src/process/supervisor/supervisor.pty-command.test.ts @@ -40,7 +40,7 @@ describe("process supervisor PTY command contract", () => { }); beforeEach(() => { - createPtyAdapterMock.mockReset(); + createPtyAdapterMock.mockClear(); }); it("passes PTY command verbatim to shell args", async () => { diff --git a/src/telegram/accounts.test.ts b/src/telegram/accounts.test.ts index c254ced27c0..3eaee29819b 100644 --- a/src/telegram/accounts.test.ts +++ b/src/telegram/accounts.test.ts @@ -19,7 +19,7 @@ vi.mock("../logging/subsystem.js", () => ({ describe("resolveTelegramAccount", () => { afterEach(() => { - warnMock.mockReset(); + warnMock.mockClear(); }); it("falls back to the first configured account when accountId is omitted", () => {