mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 02:52:15 +00:00
fix: expose CLI runtime env diagnostics
This commit is contained in:
@@ -3623,11 +3623,13 @@ ${JSON.stringify({
|
||||
it("formats CLI auth env diagnostics as key names without secret values", () => {
|
||||
vi.stubEnv("ANTHROPIC_API_KEY", "sk-ant-host");
|
||||
vi.stubEnv("ANTHROPIC_API_TOKEN", "token-host");
|
||||
vi.stubEnv("GEMINI_CLI_SYSTEM_SETTINGS_PATH", "/tmp/host-gemini-settings.json");
|
||||
vi.stubEnv("OPENAI_API_KEY", "sk-openai-host");
|
||||
|
||||
const log = buildCliEnvAuthLog({
|
||||
ANTHROPIC_API_TOKEN: "token-child",
|
||||
CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST: "1",
|
||||
GEMINI_CLI_HOME: "/tmp/child-gemini-home",
|
||||
OPENAI_API_KEY: "sk-openai-child",
|
||||
});
|
||||
|
||||
@@ -3638,8 +3640,12 @@ ${JSON.stringify({
|
||||
expect(log).toMatch(/child=.*CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST/);
|
||||
expect(log).toMatch(/child=.*OPENAI_API_KEY/);
|
||||
expect(log).toMatch(/cleared=.*ANTHROPIC_API_KEY/);
|
||||
expect(log).toMatch(/runtimeHost=.*GEMINI_CLI_SYSTEM_SETTINGS_PATH/);
|
||||
expect(log).toMatch(/runtimeChild=.*GEMINI_CLI_HOME/);
|
||||
expect(log).toMatch(/runtimeCleared=.*GEMINI_CLI_SYSTEM_SETTINGS_PATH/);
|
||||
expect(log).not.toContain("sk-ant-host");
|
||||
expect(log).not.toContain("token-child");
|
||||
expect(log).not.toContain("/tmp/child-gemini-home");
|
||||
expect(log).not.toContain("sk-openai-child");
|
||||
});
|
||||
|
||||
|
||||
@@ -312,6 +312,8 @@ const CLI_ENV_AUTH_LOG_KEYS = [
|
||||
"OPENROUTER_API_KEY",
|
||||
] as const;
|
||||
|
||||
const CLI_ENV_RUNTIME_LOG_KEYS = ["GEMINI_CLI_HOME", "GEMINI_CLI_SYSTEM_SETTINGS_PATH"] as const;
|
||||
|
||||
const CLI_BACKEND_PRESERVE_ENV = "OPENCLAW_LIVE_CLI_BACKEND_PRESERVE_ENV";
|
||||
|
||||
function parseCliBackendPreserveEnv(raw: string | undefined): Set<string> {
|
||||
@@ -346,6 +348,13 @@ function listPresentCliAuthEnvKeys(env: Record<string, string | undefined>): str
|
||||
});
|
||||
}
|
||||
|
||||
function listPresentCliRuntimeEnvKeys(env: Record<string, string | undefined>): string[] {
|
||||
return CLI_ENV_RUNTIME_LOG_KEYS.filter((key) => {
|
||||
const value = env[key];
|
||||
return typeof value === "string" && value.length > 0;
|
||||
});
|
||||
}
|
||||
|
||||
function formatCliEnvKeyList(keys: readonly string[]): string {
|
||||
return keys.length > 0 ? keys.join(",") : "none";
|
||||
}
|
||||
@@ -405,10 +414,17 @@ export function buildCliEnvAuthLog(childEnv: Record<string, string>): string {
|
||||
const childKeys = listPresentCliAuthEnvKeys(childEnv);
|
||||
const childKeySet = new Set(childKeys);
|
||||
const clearedKeys = hostKeys.filter((key) => !childKeySet.has(key));
|
||||
const runtimeHostKeys = listPresentCliRuntimeEnvKeys(process.env);
|
||||
const runtimeChildKeys = listPresentCliRuntimeEnvKeys(childEnv);
|
||||
const runtimeChildKeySet = new Set(runtimeChildKeys);
|
||||
const runtimeClearedKeys = runtimeHostKeys.filter((key) => !runtimeChildKeySet.has(key));
|
||||
return [
|
||||
`host=${formatCliEnvKeyList(hostKeys)}`,
|
||||
`child=${formatCliEnvKeyList(childKeys)}`,
|
||||
`cleared=${formatCliEnvKeyList(clearedKeys)}`,
|
||||
`runtimeHost=${formatCliEnvKeyList(runtimeHostKeys)}`,
|
||||
`runtimeChild=${formatCliEnvKeyList(runtimeChildKeys)}`,
|
||||
`runtimeCleared=${formatCliEnvKeyList(runtimeClearedKeys)}`,
|
||||
].join(" ");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user