mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
perf(test): skip live config normalization by default
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user