From 79f4c4c584e08b67b98c8bd3ca8e511b0c8ac55e Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Feb 2026 15:04:43 +0000 Subject: [PATCH] perf(test): trim module resets in config suites --- .../config.agent-concurrency-defaults.test.ts | 5 +- src/config/config.compaction-settings.test.ts | 7 +- src/config/config.discord.test.ts | 5 +- ...tion.accepts-imessage-dmpolicy.e2e.test.ts | 56 ++------------- ...tion.rejects-routing-allowfrom.e2e.test.ts | 69 +------------------ ...ig.multi-agent-agentdir-validation.test.ts | 5 +- ...preservation-on-validation-failure.test.ts | 7 +- src/config/config.pruning-defaults.test.ts | 11 +-- src/config/normalize-paths.test.ts | 6 +- .../logger.import-side-effects.test.ts | 6 +- 10 files changed, 23 insertions(+), 154 deletions(-) diff --git a/src/config/config.agent-concurrency-defaults.test.ts b/src/config/config.agent-concurrency-defaults.test.ts index 461e77ba18..9ad565a969 100644 --- a/src/config/config.agent-concurrency-defaults.test.ts +++ b/src/config/config.agent-concurrency-defaults.test.ts @@ -1,12 +1,13 @@ import fs from "node:fs/promises"; import path from "node:path"; -import { describe, expect, it, vi } from "vitest"; +import { describe, expect, it } from "vitest"; import { DEFAULT_AGENT_MAX_CONCURRENT, DEFAULT_SUBAGENT_MAX_CONCURRENT, resolveAgentMaxConcurrent, resolveSubagentMaxConcurrent, } from "./agent-limits.js"; +import { loadConfig } from "./config.js"; import { withTempHome } from "./test-helpers.js"; describe("agent concurrency defaults", () => { @@ -51,8 +52,6 @@ describe("agent concurrency defaults", () => { "utf-8", ); - vi.resetModules(); - const { loadConfig } = await import("./config.js"); const cfg = loadConfig(); expect(cfg.agents?.defaults?.maxConcurrent).toBe(DEFAULT_AGENT_MAX_CONCURRENT); diff --git a/src/config/config.compaction-settings.test.ts b/src/config/config.compaction-settings.test.ts index e80d3a8769..b6eada3032 100644 --- a/src/config/config.compaction-settings.test.ts +++ b/src/config/config.compaction-settings.test.ts @@ -1,6 +1,7 @@ import fs from "node:fs/promises"; import path from "node:path"; -import { describe, expect, it, vi } from "vitest"; +import { describe, expect, it } from "vitest"; +import { loadConfig } from "./config.js"; import { withTempHome } from "./test-helpers.js"; describe("config compaction settings", () => { @@ -33,8 +34,6 @@ describe("config compaction settings", () => { "utf-8", ); - vi.resetModules(); - const { loadConfig } = await import("./config.js"); const cfg = loadConfig(); expect(cfg.agents?.defaults?.compaction?.reserveTokensFloor).toBe(12_345); @@ -68,8 +67,6 @@ describe("config compaction settings", () => { "utf-8", ); - vi.resetModules(); - const { loadConfig } = await import("./config.js"); const cfg = loadConfig(); expect(cfg.agents?.defaults?.compaction?.mode).toBe("safeguard"); diff --git a/src/config/config.discord.test.ts b/src/config/config.discord.test.ts index b5790f2a97..47c9e996fb 100644 --- a/src/config/config.discord.test.ts +++ b/src/config/config.discord.test.ts @@ -1,6 +1,7 @@ import fs from "node:fs/promises"; import path from "node:path"; -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, beforeEach, describe, expect, it } from "vitest"; +import { loadConfig } from "./config.js"; import { withTempHome } from "./test-helpers.js"; describe("config discord", () => { @@ -55,8 +56,6 @@ describe("config discord", () => { "utf-8", ); - vi.resetModules(); - const { loadConfig } = await import("./config.js"); const cfg = loadConfig(); expect(cfg.channels?.discord?.enabled).toBe(true); diff --git a/src/config/config.legacy-config-detection.accepts-imessage-dmpolicy.e2e.test.ts b/src/config/config.legacy-config-detection.accepts-imessage-dmpolicy.e2e.test.ts index 840f581476..ca5cb63b5e 100644 --- a/src/config/config.legacy-config-detection.accepts-imessage-dmpolicy.e2e.test.ts +++ b/src/config/config.legacy-config-detection.accepts-imessage-dmpolicy.e2e.test.ts @@ -1,12 +1,16 @@ import fs from "node:fs/promises"; import path from "node:path"; -import { describe, expect, it, vi } from "vitest"; +import { describe, expect, it } from "vitest"; +import { + loadConfig, + migrateLegacyConfig, + readConfigFileSnapshot, + validateConfigObject, +} from "./config.js"; import { withTempHome } from "./test-helpers.js"; describe("legacy config detection", () => { it('accepts imessage.dmPolicy="open" with allowFrom "*"', async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { imessage: { dmPolicy: "open", allowFrom: ["*"] } }, }); @@ -16,8 +20,6 @@ describe("legacy config detection", () => { } }); it("defaults imessage.dmPolicy to pairing when imessage section exists", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { imessage: {} } }); expect(res.ok).toBe(true); if (res.ok) { @@ -25,8 +27,6 @@ describe("legacy config detection", () => { } }); it("defaults imessage.groupPolicy to allowlist when imessage section exists", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { imessage: {} } }); expect(res.ok).toBe(true); if (res.ok) { @@ -34,8 +34,6 @@ describe("legacy config detection", () => { } }); it("defaults discord.groupPolicy to allowlist when discord section exists", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { discord: {} } }); expect(res.ok).toBe(true); if (res.ok) { @@ -43,8 +41,6 @@ describe("legacy config detection", () => { } }); it("defaults slack.groupPolicy to allowlist when slack section exists", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { slack: {} } }); expect(res.ok).toBe(true); if (res.ok) { @@ -52,8 +48,6 @@ describe("legacy config detection", () => { } }); it("defaults msteams.groupPolicy to allowlist when msteams section exists", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { msteams: {} } }); expect(res.ok).toBe(true); if (res.ok) { @@ -61,8 +55,6 @@ describe("legacy config detection", () => { } }); it("rejects unsafe executable config values", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { imessage: { cliPath: "imsg; rm -rf /" } }, audio: { transcription: { command: ["whisper", "--model", "base"] } }, @@ -73,16 +65,12 @@ describe("legacy config detection", () => { } }); it("accepts tools audio transcription without cli", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ audio: { transcription: { command: ["whisper", "--model", "base"] } }, }); expect(res.ok).toBe(true); }); it("accepts path-like executable values with spaces", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { imessage: { cliPath: "/Applications/Imsg Tools/imsg" } }, audio: { @@ -94,8 +82,6 @@ describe("legacy config detection", () => { expect(res.ok).toBe(true); }); it('rejects discord.dm.policy="open" without allowFrom "*"', async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { discord: { dm: { policy: "open", allowFrom: ["123"] } } }, }); @@ -105,8 +91,6 @@ describe("legacy config detection", () => { } }); it('rejects slack.dm.policy="open" without allowFrom "*"', async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { slack: { dm: { policy: "open", allowFrom: ["U123"] } } }, }); @@ -116,8 +100,6 @@ describe("legacy config detection", () => { } }); it("rejects legacy agent.model string", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ agent: { model: "anthropic/claude-opus-4-5" }, }); @@ -127,8 +109,6 @@ describe("legacy config detection", () => { } }); it("migrates telegram.requireMention to channels.telegram.groups.*.requireMention", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ telegram: { requireMention: false }, }); @@ -139,8 +119,6 @@ describe("legacy config detection", () => { expect(res.config?.channels?.telegram?.requireMention).toBeUndefined(); }); it("migrates messages.tts.enabled to messages.tts.auto", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ messages: { tts: { enabled: true } }, }); @@ -149,8 +127,6 @@ describe("legacy config detection", () => { expect(res.config?.messages?.tts?.enabled).toBeUndefined(); }); it("migrates legacy model config to agent.models + model lists", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ agent: { model: "anthropic/claude-opus-4-5", @@ -184,8 +160,6 @@ describe("legacy config detection", () => { "utf-8", ); - vi.resetModules(); - const { readConfigFileSnapshot } = await import("./config.js"); const snap = await readConfigFileSnapshot(); expect(snap.valid).toBe(false); @@ -210,8 +184,6 @@ describe("legacy config detection", () => { "utf-8", ); - vi.resetModules(); - const { readConfigFileSnapshot } = await import("./config.js"); const snap = await readConfigFileSnapshot(); expect(snap.valid).toBe(false); @@ -238,8 +210,6 @@ describe("legacy config detection", () => { "utf-8", ); - vi.resetModules(); - const { loadConfig } = await import("./config.js"); const cfg = loadConfig(); expect(cfg.auth?.profiles?.["anthropic:claude-cli"]?.mode).toBe("token"); @@ -260,8 +230,6 @@ describe("legacy config detection", () => { "utf-8", ); - vi.resetModules(); - const { readConfigFileSnapshot } = await import("./config.js"); const snap = await readConfigFileSnapshot(); expect(snap.valid).toBe(false); @@ -286,8 +254,6 @@ describe("legacy config detection", () => { "utf-8", ); - vi.resetModules(); - const { readConfigFileSnapshot } = await import("./config.js"); const snap = await readConfigFileSnapshot(); expect(snap.valid).toBe(false); @@ -318,8 +284,6 @@ describe("legacy config detection", () => { "utf-8", ); - vi.resetModules(); - const { readConfigFileSnapshot } = await import("./config.js"); const snap = await readConfigFileSnapshot(); expect(snap.valid).toBe(false); @@ -348,8 +312,6 @@ describe("legacy config detection", () => { "utf-8", ); - vi.resetModules(); - const { readConfigFileSnapshot } = await import("./config.js"); const snap = await readConfigFileSnapshot(); expect(snap.valid).toBe(false); @@ -382,8 +344,6 @@ describe("legacy config detection", () => { "utf-8", ); - vi.resetModules(); - const { readConfigFileSnapshot } = await import("./config.js"); const snap = await readConfigFileSnapshot(); expect(snap.valid).toBe(false); @@ -406,8 +366,6 @@ describe("legacy config detection", () => { "utf-8", ); - vi.resetModules(); - const { readConfigFileSnapshot } = await import("./config.js"); const snap = await readConfigFileSnapshot(); expect(snap.valid).toBe(false); diff --git a/src/config/config.legacy-config-detection.rejects-routing-allowfrom.e2e.test.ts b/src/config/config.legacy-config-detection.rejects-routing-allowfrom.e2e.test.ts index 695239cf8e..6b74d77676 100644 --- a/src/config/config.legacy-config-detection.rejects-routing-allowfrom.e2e.test.ts +++ b/src/config/config.legacy-config-detection.rejects-routing-allowfrom.e2e.test.ts @@ -1,9 +1,8 @@ -import { describe, expect, it, vi } from "vitest"; +import { describe, expect, it } from "vitest"; +import { migrateLegacyConfig, validateConfigObject } from "./config.js"; describe("legacy config detection", () => { it("rejects routing.allowFrom", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ routing: { allowFrom: ["+15555550123"] }, }); @@ -13,8 +12,6 @@ describe("legacy config detection", () => { } }); it("rejects routing.groupChat.requireMention", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ routing: { groupChat: { requireMention: false } }, }); @@ -24,8 +21,6 @@ describe("legacy config detection", () => { } }); it("migrates routing.allowFrom to channels.whatsapp.allowFrom when whatsapp configured", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ routing: { allowFrom: ["+15555550123"] }, channels: { whatsapp: {} }, @@ -35,8 +30,6 @@ describe("legacy config detection", () => { expect(res.config?.routing?.allowFrom).toBeUndefined(); }); it("drops routing.allowFrom when whatsapp missing", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ routing: { allowFrom: ["+15555550123"] }, }); @@ -45,8 +38,6 @@ describe("legacy config detection", () => { expect(res.config?.routing?.allowFrom).toBeUndefined(); }); it("migrates routing.groupChat.requireMention to channels whatsapp/telegram/imessage groups when whatsapp configured", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ routing: { groupChat: { requireMention: false } }, channels: { whatsapp: {} }, @@ -66,8 +57,6 @@ describe("legacy config detection", () => { expect(res.config?.routing?.groupChat?.requireMention).toBeUndefined(); }); it("migrates routing.groupChat.requireMention to telegram/imessage when whatsapp missing", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ routing: { groupChat: { requireMention: false } }, }); @@ -86,8 +75,6 @@ describe("legacy config detection", () => { expect(res.config?.routing?.groupChat?.requireMention).toBeUndefined(); }); it("migrates routing.groupChat.mentionPatterns to messages.groupChat.mentionPatterns", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ routing: { groupChat: { mentionPatterns: ["@openclaw"] } }, }); @@ -98,8 +85,6 @@ describe("legacy config detection", () => { expect(res.config?.routing?.groupChat?.mentionPatterns).toBeUndefined(); }); it("migrates routing agentToAgent/queue/transcribeAudio to tools/messages/media", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ routing: { agentToAgent: { enabled: true, allow: ["main"] }, @@ -174,8 +159,6 @@ describe("legacy config detection", () => { expect(res.config?.audio).toBeUndefined(); }); it("migrates agent config into agents.defaults and tools", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ agent: { model: "openai/gpt-5.2", @@ -213,8 +196,6 @@ describe("legacy config detection", () => { expect((res.config as { agent?: unknown }).agent).toBeUndefined(); }); it("migrates top-level memorySearch to agents.defaults.memorySearch", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ memorySearch: { provider: "local", @@ -231,8 +212,6 @@ describe("legacy config detection", () => { expect((res.config as { memorySearch?: unknown }).memorySearch).toBeUndefined(); }); it("merges top-level memorySearch into agents.defaults.memorySearch", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ memorySearch: { provider: "local", @@ -259,8 +238,6 @@ describe("legacy config detection", () => { }); }); it("keeps nested agents.defaults.memorySearch values when merging legacy defaults", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ memorySearch: { query: { @@ -290,8 +267,6 @@ describe("legacy config detection", () => { }); }); it("migrates tools.bash to tools.exec", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ tools: { bash: { timeoutSec: 12 }, @@ -302,8 +277,6 @@ describe("legacy config detection", () => { expect((res.config?.tools as { bash?: unknown } | undefined)?.bash).toBeUndefined(); }); it("accepts per-agent tools.elevated overrides", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ tools: { elevated: { @@ -334,8 +307,6 @@ describe("legacy config detection", () => { } }); it("rejects telegram.requireMention", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ telegram: { requireMention: true }, }); @@ -345,8 +316,6 @@ describe("legacy config detection", () => { } }); it("rejects gateway.token", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ gateway: { token: "legacy-token" }, }); @@ -356,8 +325,6 @@ describe("legacy config detection", () => { } }); it("migrates gateway.token to gateway.auth.token", async () => { - vi.resetModules(); - const { migrateLegacyConfig } = await import("./config.js"); const res = migrateLegacyConfig({ gateway: { token: "legacy-token" }, }); @@ -367,8 +334,6 @@ describe("legacy config detection", () => { expect((res.config?.gateway as { token?: string })?.token).toBeUndefined(); }); it("keeps gateway.bind tailnet", async () => { - vi.resetModules(); - const { migrateLegacyConfig, validateConfigObject } = await import("./config.js"); const res = migrateLegacyConfig({ gateway: { bind: "tailnet" as const }, }); @@ -382,8 +347,6 @@ describe("legacy config detection", () => { } }); it('rejects telegram.dmPolicy="open" without allowFrom "*"', async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { telegram: { dmPolicy: "open", allowFrom: ["123456789"] } }, }); @@ -393,8 +356,6 @@ describe("legacy config detection", () => { } }); it('accepts telegram.dmPolicy="open" with allowFrom "*"', async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { telegram: { dmPolicy: "open", allowFrom: ["*"] } }, }); @@ -404,8 +365,6 @@ describe("legacy config detection", () => { } }); it("defaults telegram.dmPolicy to pairing when telegram section exists", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { telegram: {} } }); expect(res.ok).toBe(true); if (res.ok) { @@ -413,8 +372,6 @@ describe("legacy config detection", () => { } }); it("defaults telegram.groupPolicy to allowlist when telegram section exists", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { telegram: {} } }); expect(res.ok).toBe(true); if (res.ok) { @@ -422,8 +379,6 @@ describe("legacy config detection", () => { } }); it("defaults telegram.streamMode to partial when telegram section exists", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { telegram: {} } }); expect(res.ok).toBe(true); if (res.ok) { @@ -431,8 +386,6 @@ describe("legacy config detection", () => { } }); it('rejects whatsapp.dmPolicy="open" without allowFrom "*"', async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { whatsapp: { dmPolicy: "open", allowFrom: ["+15555550123"] }, @@ -444,8 +397,6 @@ describe("legacy config detection", () => { } }); it('accepts whatsapp.dmPolicy="open" with allowFrom "*"', async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { whatsapp: { dmPolicy: "open", allowFrom: ["*"] } }, }); @@ -455,8 +406,6 @@ describe("legacy config detection", () => { } }); it("defaults whatsapp.dmPolicy to pairing when whatsapp section exists", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { whatsapp: {} } }); expect(res.ok).toBe(true); if (res.ok) { @@ -464,8 +413,6 @@ describe("legacy config detection", () => { } }); it("defaults whatsapp.groupPolicy to allowlist when whatsapp section exists", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { whatsapp: {} } }); expect(res.ok).toBe(true); if (res.ok) { @@ -473,8 +420,6 @@ describe("legacy config detection", () => { } }); it('rejects signal.dmPolicy="open" without allowFrom "*"', async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { signal: { dmPolicy: "open", allowFrom: ["+15555550123"] } }, }); @@ -484,8 +429,6 @@ describe("legacy config detection", () => { } }); it('accepts signal.dmPolicy="open" with allowFrom "*"', async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { signal: { dmPolicy: "open", allowFrom: ["*"] } }, }); @@ -495,8 +438,6 @@ describe("legacy config detection", () => { } }); it("defaults signal.dmPolicy to pairing when signal section exists", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { signal: {} } }); expect(res.ok).toBe(true); if (res.ok) { @@ -504,8 +445,6 @@ describe("legacy config detection", () => { } }); it("defaults signal.groupPolicy to allowlist when signal section exists", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { signal: {} } }); expect(res.ok).toBe(true); if (res.ok) { @@ -513,8 +452,6 @@ describe("legacy config detection", () => { } }); it("accepts historyLimit overrides per provider and account", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ messages: { groupChat: { historyLimit: 12 } }, channels: { @@ -542,8 +479,6 @@ describe("legacy config detection", () => { } }); it('rejects imessage.dmPolicy="open" without allowFrom "*"', async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ channels: { imessage: { dmPolicy: "open", allowFrom: ["+15555550123"] }, diff --git a/src/config/config.multi-agent-agentdir-validation.test.ts b/src/config/config.multi-agent-agentdir-validation.test.ts index f41236ae4c..5a49d1e285 100644 --- a/src/config/config.multi-agent-agentdir-validation.test.ts +++ b/src/config/config.multi-agent-agentdir-validation.test.ts @@ -2,12 +2,11 @@ import fs from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { describe, expect, it, vi } from "vitest"; +import { loadConfig, validateConfigObject } from "./config.js"; import { withTempHome } from "./test-helpers.js"; describe("multi-agent agentDir validation", () => { it("rejects shared agents.list agentDir", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const shared = path.join(tmpdir(), "openclaw-shared-agentdir"); const res = validateConfigObject({ agents: { @@ -46,9 +45,7 @@ describe("multi-agent agentDir validation", () => { "utf-8", ); - vi.resetModules(); const spy = vi.spyOn(console, "error").mockImplementation(() => {}); - const { loadConfig } = await import("./config.js"); expect(() => loadConfig()).toThrow(/duplicate agentDir/i); expect(spy.mock.calls.flat().join(" ")).toMatch(/Duplicate agentDir/i); spy.mockRestore(); diff --git a/src/config/config.preservation-on-validation-failure.test.ts b/src/config/config.preservation-on-validation-failure.test.ts index 27bac2d8e1..b82b861d28 100644 --- a/src/config/config.preservation-on-validation-failure.test.ts +++ b/src/config/config.preservation-on-validation-failure.test.ts @@ -1,12 +1,11 @@ import fs from "node:fs/promises"; import path from "node:path"; -import { describe, expect, it, vi } from "vitest"; +import { describe, expect, it } from "vitest"; +import { readConfigFileSnapshot, validateConfigObject } from "./config.js"; import { withTempHome } from "./test-helpers.js"; describe("config strict validation", () => { it("rejects unknown fields", async () => { - vi.resetModules(); - const { validateConfigObject } = await import("./config.js"); const res = validateConfigObject({ agents: { list: [{ id: "pi" }] }, customUnknownField: { nested: "value" }, @@ -27,8 +26,6 @@ describe("config strict validation", () => { "utf-8", ); - vi.resetModules(); - const { readConfigFileSnapshot } = await import("./config.js"); const snap = await readConfigFileSnapshot(); expect(snap.valid).toBe(false); diff --git a/src/config/config.pruning-defaults.test.ts b/src/config/config.pruning-defaults.test.ts index 3a63c227aa..00320e618c 100644 --- a/src/config/config.pruning-defaults.test.ts +++ b/src/config/config.pruning-defaults.test.ts @@ -1,6 +1,7 @@ import fs from "node:fs/promises"; import path from "node:path"; -import { describe, expect, it, vi } from "vitest"; +import { describe, expect, it } from "vitest"; +import { loadConfig } from "./config.js"; import { withTempHome } from "./test-helpers.js"; describe("config pruning defaults", () => { @@ -18,8 +19,6 @@ describe("config pruning defaults", () => { "utf-8", ); - vi.resetModules(); - const { loadConfig } = await import("./config.js"); const cfg = loadConfig(); expect(cfg.agents?.defaults?.contextPruning?.mode).toBeUndefined(); @@ -57,8 +56,6 @@ describe("config pruning defaults", () => { "utf-8", ); - vi.resetModules(); - const { loadConfig } = await import("./config.js"); const cfg = loadConfig(); expect(cfg.agents?.defaults?.contextPruning?.mode).toBe("cache-ttl"); @@ -92,8 +89,6 @@ describe("config pruning defaults", () => { "utf-8", ); - vi.resetModules(); - const { loadConfig } = await import("./config.js"); const cfg = loadConfig(); expect(cfg.agents?.defaults?.contextPruning?.mode).toBe("cache-ttl"); @@ -115,8 +110,6 @@ describe("config pruning defaults", () => { "utf-8", ); - vi.resetModules(); - const { loadConfig } = await import("./config.js"); const cfg = loadConfig(); expect(cfg.agents?.defaults?.contextPruning?.mode).toBe("off"); diff --git a/src/config/normalize-paths.test.ts b/src/config/normalize-paths.test.ts index c3059495b3..e0e0f0a014 100644 --- a/src/config/normalize-paths.test.ts +++ b/src/config/normalize-paths.test.ts @@ -1,13 +1,11 @@ import path from "node:path"; -import { describe, expect, it, vi } from "vitest"; +import { describe, expect, it } from "vitest"; import { withTempHome } from "../../test/helpers/temp-home.js"; +import { normalizeConfigPaths } from "./normalize-paths.js"; describe("normalizeConfigPaths", () => { it("expands tilde for path-ish keys only", async () => { await withTempHome(async (home) => { - vi.resetModules(); - const { normalizeConfigPaths } = await import("./normalize-paths.js"); - const cfg = normalizeConfigPaths({ tools: { exec: { pathPrepend: ["~/bin"] } }, plugins: { load: { paths: ["~/plugins/a"] } }, diff --git a/src/logging/logger.import-side-effects.test.ts b/src/logging/logger.import-side-effects.test.ts index 712892e8c1..b0e8c2b972 100644 --- a/src/logging/logger.import-side-effects.test.ts +++ b/src/logging/logger.import-side-effects.test.ts @@ -1,11 +1,7 @@ import fs from "node:fs"; -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; describe("logger import side effects", () => { - beforeEach(() => { - vi.resetModules(); - }); - afterEach(() => { vi.restoreAllMocks(); });