From 7b53b00009417e68c3eeb66faaf588589f74cdb7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 7 Apr 2026 08:59:21 +0100 Subject: [PATCH] perf(test): skip live config normalization by default --- test/test-env.ts | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/test/test-env.ts b/test/test-env.ts index 232316967ff..a19f4b4cc7f 100644 --- a/test/test-env.ts +++ b/test/test-env.ts @@ -1,15 +1,23 @@ import { execFileSync } from "node:child_process"; import fs from "node:fs"; +import { createRequire } from "node:module"; import os from "node:os"; import path from "node:path"; import JSON5 from "json5"; -import { applyLegacyDoctorMigrations } from "../src/commands/doctor/shared/legacy-config-migrate.js"; -import { validateConfigObjectWithPlugins } from "../src/config/validation.js"; type RestoreEntry = { key: string; value: string | undefined }; const LIVE_EXTERNAL_AUTH_DIRS = [".claude", ".codex", ".minimax"] as const; const LIVE_EXTERNAL_AUTH_FILES = [".claude.json"] as const; +const requireFromHere = createRequire(import.meta.url); + +type LegacyConfigCompatApi = typeof import( + "../src/commands/doctor/shared/legacy-config-migrate.js" +); +type ConfigValidationApi = typeof import("../src/config/validation.js"); + +let cachedLegacyConfigCompatApi: LegacyConfigCompatApi | undefined; +let cachedConfigValidationApi: ConfigValidationApi | undefined; function isTruthyEnvValue(value: string | undefined): boolean { if (!value) { @@ -37,6 +45,18 @@ function restoreEnv(entries: RestoreEntry[]): void { } } +function loadLegacyConfigCompatApi(): LegacyConfigCompatApi { + cachedLegacyConfigCompatApi ??= requireFromHere( + "../src/commands/doctor/shared/legacy-config-migrate.js", + ) as LegacyConfigCompatApi; + return cachedLegacyConfigCompatApi; +} + +function loadConfigValidationApi(): ConfigValidationApi { + cachedConfigValidationApi ??= requireFromHere("../src/config/validation.js") as ConfigValidationApi; + return cachedConfigValidationApi; +} + function resolveHomeRelativePath(input: string, homeDir: string): string { const trimmed = input.trim(); if (trimmed === "~") { @@ -128,6 +148,10 @@ function resolveRestoreEntries(): RestoreEntry[] { key: "OPENCLAW_ALLOW_SLOW_REPLY_TESTS", value: process.env.OPENCLAW_ALLOW_SLOW_REPLY_TESTS, }, + { + key: "OPENCLAW_LIVE_TEST_NORMALIZE_CONFIG", + value: process.env.OPENCLAW_LIVE_TEST_NORMALIZE_CONFIG, + }, { key: "HOME", value: process.env.HOME }, { key: "USERPROFILE", value: process.env.USERPROFILE }, { key: "XDG_CONFIG_HOME", value: process.env.XDG_CONFIG_HOME }, @@ -288,11 +312,17 @@ function sanitizeLiveConfig(raw: string): string { }); } + if (!isTruthyEnvValue(process.env.OPENCLAW_LIVE_TEST_NORMALIZE_CONFIG)) { + return `${JSON.stringify(parsed, null, 2)}\n`; + } + + const { applyLegacyDoctorMigrations } = loadLegacyConfigCompatApi(); const migrated = applyLegacyDoctorMigrations(parsed); if (!migrated.next) { return `${JSON.stringify(parsed, null, 2)}\n`; } + const { validateConfigObjectWithPlugins } = loadConfigValidationApi(); const validated = validateConfigObjectWithPlugins(migrated.next); return `${JSON.stringify(validated.ok ? validated.config : migrated.next, null, 2)}\n`; } catch {