test: dedupe core test teardown paths

This commit is contained in:
Peter Steinberger 2026-04-03 07:14:44 +01:00
parent b66197f932
commit 051b5ddafe
No known key found for this signature in database
14 changed files with 8 additions and 49 deletions

View File

@ -42,7 +42,6 @@ describe("channel tools", () => {
afterEach(() => {
setActivePluginRegistry(createTestRegistry([]));
errorSpy.mockClear();
});
it("skips crashing plugins and logs once", () => {

View File

@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { importFreshModule } from "../../test/helpers/import-fresh.js";
const state = vi.hoisted(() => ({
@ -49,11 +49,6 @@ describe("live model switch", () => {
state.loadSessionStoreMock.mockReset().mockReturnValue({});
state.resolveStorePathMock.mockReset().mockReturnValue("/tmp/session-store.json");
});
afterEach(() => {
vi.clearAllMocks();
});
it("resolves persisted session overrides ahead of agent defaults", async () => {
state.loadSessionStoreMock.mockReturnValue({
main: {

View File

@ -115,9 +115,7 @@ describe("announce loop guard (#18264)", () => {
afterEach(() => {
vi.useRealTimers();
loadSubagentRegistryFromDisk.mockClear();
loadSubagentRegistryFromDisk.mockReturnValue(new Map());
saveSubagentRegistryToDisk.mockClear();
vi.clearAllMocks();
});

View File

@ -28,7 +28,6 @@ const {
listDevicePairing,
approveDevicePairing,
summarizeDeviceTokens,
withProgress,
} = mocks;
vi.mock("../gateway/call.js", () => ({
@ -337,20 +336,12 @@ beforeEach(() => {
});
afterEach(() => {
buildGatewayConnectionDetails.mockClear();
buildGatewayConnectionDetails.mockReturnValue({
url: "ws://127.0.0.1:18789",
urlSource: "local loopback",
message: "",
});
listDevicePairing.mockClear();
listDevicePairing.mockResolvedValue({ pending: [], paired: [] });
approveDevicePairing.mockClear();
approveDevicePairing.mockResolvedValue(undefined);
summarizeDeviceTokens.mockClear();
summarizeDeviceTokens.mockReturnValue(undefined);
withProgress.mockClear();
runtime.log.mockClear();
runtime.error.mockClear();
runtime.exit.mockClear();
});

View File

@ -887,7 +887,6 @@ describe("onboard (non-interactive): provider auth", () => {
resetFileLockStateForTest();
clearPluginDiscoveryCache();
clearPluginManifestRegistryCache();
ensureWorkspaceAndSessionsMock.mockClear();
});
it("stores MiniMax API key in the global auth profile", async () => {

View File

@ -1,4 +1,4 @@
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { createEmptyPluginRegistry } from "../plugins/registry.js";
const { resolveRuntimePluginRegistryMock } = vi.hoisted(() => ({
@ -20,7 +20,7 @@ describe("image-generation provider registry", () => {
await import("./provider-registry.js"));
});
afterEach(() => {
beforeEach(() => {
resolveRuntimePluginRegistryMock.mockReset();
resolveRuntimePluginRegistryMock.mockReturnValue(undefined);
});

View File

@ -28,13 +28,13 @@ describe("image-generation runtime helpers", () => {
({ generateImage, listRuntimeImageGenerationProviders } = await import("./runtime.js"));
});
afterEach(() => {
beforeEach(() => {
resolveRuntimePluginRegistryMock.mockReset();
resolveRuntimePluginRegistryMock.mockReturnValue(undefined);
resetPluginRuntimeStateForTest();
});
beforeEach(() => {
afterEach(() => {
resetPluginRuntimeStateForTest();
});

View File

@ -23,7 +23,6 @@ beforeEach(() => {
describe("gaxios fetch compat", () => {
afterEach(() => {
vi.doUnmock("undici");
Reflect.deleteProperty(globalThis as object, TEST_GAXIOS_CONSTRUCTOR_OVERRIDE);
__testing.resetGaxiosFetchCompatForTests();
vi.restoreAllMocks();

View File

@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, describe, expect, it, vi } from "vitest";
import * as replyModule from "../auto-reply/reply.js";
import type { OpenClawConfig } from "../config/config.js";
import { resolveAgentMainSessionKey, resolveMainSessionKey } from "../config/sessions.js";
@ -38,8 +38,6 @@ async function withHeartbeatFixture(
);
}
beforeEach(() => {});
afterEach(() => {
vi.restoreAllMocks();
});

View File

@ -31,9 +31,6 @@ function decodeCmdPathArg(value: string): string {
afterEach(() => {
envSnapshot.restore();
spawnMock.mockReset();
resolvePreferredOpenClawTmpDirMock.mockReset();
resolvePreferredOpenClawTmpDirMock.mockReturnValue(os.tmpdir());
for (const scriptPath of createdScriptPaths) {
try {
fs.unlinkSync(scriptPath);

View File

@ -18,13 +18,6 @@ describe("compaction hook wiring", () => {
let handleAutoCompactionEnd: typeof import("../agents/pi-embedded-subscribe.handlers.compaction.js").handleAutoCompactionEnd;
beforeAll(async () => {
hookMocks.runner.hasHooks.mockClear();
hookMocks.runner.hasHooks.mockReturnValue(false);
hookMocks.runner.runBeforeCompaction.mockClear();
hookMocks.runner.runBeforeCompaction.mockResolvedValue(undefined);
hookMocks.runner.runAfterCompaction.mockClear();
hookMocks.runner.runAfterCompaction.mockResolvedValue(undefined);
hookMocks.emitAgentEvent.mockClear();
vi.doMock("../plugins/hook-runner-global.js", () => ({
getGlobalHookRunner: () => hookMocks.runner,
}));

View File

@ -140,8 +140,6 @@ describe("secrets runtime snapshot", () => {
clearSecretsRuntimeSnapshot();
clearRuntimeConfigSnapshot();
clearConfigCache();
resolveBundledPluginWebSearchProvidersMock.mockReset();
resolvePluginWebSearchProvidersMock.mockReset();
});
it("resolves env refs for config and auth profiles", async () => {

View File

@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { beforeEach, describe, expect, it } from "vitest";
import {
findLatestTaskFlowForOwner,
getTaskFlowByIdForOwner,
@ -10,11 +10,6 @@ import { createManagedTaskFlow, resetTaskFlowRegistryForTests } from "./task-flo
beforeEach(() => {
resetTaskFlowRegistryForTests();
});
afterEach(() => {
resetTaskFlowRegistryForTests();
});
describe("task flow owner access", () => {
it("returns owner-scoped flows for direct and owner-key lookups", () => {
const older = createManagedTaskFlow({

View File

@ -1,4 +1,4 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { createEmptyPluginRegistry } from "../plugins/registry-empty.js";
import type { SpeechProviderPlugin } from "../plugins/types.js";
@ -44,9 +44,6 @@ describe("speech provider registry", () => {
resolveRuntimePluginRegistryMock.mockReset();
resolveRuntimePluginRegistryMock.mockReturnValue(undefined);
});
afterEach(() => {});
it("uses active plugin speech providers without reloading plugins", () => {
resolveRuntimePluginRegistryMock.mockReturnValue({
...createEmptyPluginRegistry(),