diff --git a/src/commands/doctor-config-flow.ts b/src/commands/doctor-config-flow.ts index 2b02cf45b5d..84d2f9e4307 100644 --- a/src/commands/doctor-config-flow.ts +++ b/src/commands/doctor-config-flow.ts @@ -9,15 +9,11 @@ import { import { fetchTelegramChatId } from "../channels/telegram/api.js"; import { formatCliCommand } from "../cli/command-format.js"; import type { OpenClawConfig } from "../config/config.js"; -import { - OpenClawSchema, - CONFIG_PATH, - migrateLegacyConfig, - readConfigFileSnapshot, -} from "../config/config.js"; +import { CONFIG_PATH, migrateLegacyConfig, readConfigFileSnapshot } from "../config/config.js"; import { collectProviderDangerousNameMatchingScopes } from "../config/dangerous-name-matching.js"; import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js"; import { parseToolsBySenderTypedKey } from "../config/types.tools.js"; +import { OpenClawSchema } from "../config/zod-schema.js"; import { resolveCommandResolutionFromArgv } from "../infra/exec-command-resolution.js"; import { listInterpreterLikeSafeBins, diff --git a/src/config/config.ts b/src/config/config.ts index df667d498b1..dfe47d82f87 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -21,4 +21,3 @@ export { validateConfigObjectRawWithPlugins, validateConfigObjectWithPlugins, } from "./validation.js"; -export { OpenClawSchema } from "./zod-schema.js"; diff --git a/src/config/paths.ts b/src/config/paths.ts index b60f41f3362..5f9afc85a46 100644 --- a/src/config/paths.ts +++ b/src/config/paths.ts @@ -67,6 +67,9 @@ export function resolveStateDir( return resolveUserPath(override, env, effectiveHomedir); } const newDir = newStateDir(effectiveHomedir); + if (env.OPENCLAW_TEST_FAST === "1") { + return newDir; + } const legacyDirs = legacyStateDirs(effectiveHomedir); const hasNew = fs.existsSync(newDir); if (hasNew) { @@ -131,6 +134,9 @@ export function resolveConfigPathCandidate( env: NodeJS.ProcessEnv = process.env, homedir: () => string = envHomedir(env), ): string { + if (env.OPENCLAW_TEST_FAST === "1") { + return resolveCanonicalConfigPath(env, resolveStateDir(env, homedir)); + } const candidates = resolveDefaultConfigCandidates(env, homedir); const existing = candidates.find((candidate) => { try { @@ -157,6 +163,9 @@ export function resolveConfigPath( if (override) { return resolveUserPath(override, env, homedir); } + if (env.OPENCLAW_TEST_FAST === "1") { + return path.join(stateDir, CONFIG_FILENAME); + } const stateOverride = env.OPENCLAW_STATE_DIR?.trim(); const candidates = [ path.join(stateDir, CONFIG_FILENAME), diff --git a/test/setup.ts b/test/setup.ts index 4e008ff1881..03b46c2d75b 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -1,4 +1,4 @@ -import { afterAll, afterEach, beforeEach, vi } from "vitest"; +import { afterAll, afterEach, beforeAll, vi } from "vitest"; // Ensure Vitest environment is properly set process.env.VITEST = "true"; @@ -25,12 +25,15 @@ import { withIsolatedTestHome } from "./test-env.js"; const testEnv = withIsolatedTestHome(); afterAll(() => testEnv.cleanup()); -const [{ installProcessWarningFilter }, { setActivePluginRegistry }, { createTestRegistry }] = - await Promise.all([ - import("../src/infra/warning-filter.js"), - import("../src/plugins/runtime.js"), - import("../src/test-utils/channel-plugins.js"), - ]); +const [ + { installProcessWarningFilter }, + { getActivePluginRegistry, setActivePluginRegistry }, + { createTestRegistry }, +] = await Promise.all([ + import("../src/infra/warning-filter.js"), + import("../src/plugins/runtime.js"), + import("../src/test-utils/channel-plugins.js"), +]); installProcessWarningFilter(); @@ -172,16 +175,18 @@ const createDefaultRegistry = () => }, ]); -// Creating a fresh registry before every single test was measurable overhead. -// The registry is treated as immutable by production code; tests that need a -// custom registry set it explicitly. +// Creating a fresh registry before every test is measurable overhead. +// The registry is immutable by default; tests that override it are restored in afterEach. const DEFAULT_PLUGIN_REGISTRY = createDefaultRegistry(); -beforeEach(() => { +beforeAll(() => { setActivePluginRegistry(DEFAULT_PLUGIN_REGISTRY); }); afterEach(() => { + if (getActivePluginRegistry() !== DEFAULT_PLUGIN_REGISTRY) { + setActivePluginRegistry(DEFAULT_PLUGIN_REGISTRY); + } // Guard against leaked fake timers across test files/workers. if (vi.isFakeTimers()) { vi.useRealTimers();