惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园 - 【当耐特】
月光博客
月光博客
Vercel News
Vercel News
D
Docker
I
InfoQ
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
有赞技术团队
有赞技术团队
雷峰网
雷峰网
博客园 - 聂微东
小众软件
小众软件
Y
Y Combinator Blog
腾讯CDC
L
LangChain Blog
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix: scope best effort config env · openclaw/openclaw@3e4...
shakkernerd · 2026-06-20 · via Recent Commits to openclaw:main
11

// Covers best-effort config IO reads and warning behavior.

22

import fs from "node:fs/promises";

33

import { describe, expect, it, vi } from "vitest";

4+

import { withEnvAsync } from "../test-utils/env.js";

45

import {

56

readBestEffortConfig,

67

readBestEffortConfigSnapshot,

@@ -30,9 +31,7 @@ describe("readBestEffortConfig", () => {

3031

it("can read snapshots without applying config env vars to the process", async () => {

3132

await withTempHome(async (home) => {

3233

const key = "OPENCLAW_ISOLATED_CONFIG_READ_TEST";

33-

const previous = process.env[key];

34-

delete process.env[key];

35-

try {

34+

await withEnvAsync({ [key]: undefined }, async () => {

3635

await writeOpenClawConfig(home, {

3736

env: { vars: { [key]: "from-config" } },

3837

gateway: { mode: "local" },

@@ -41,22 +40,14 @@ describe("readBestEffortConfig", () => {

4140

await readConfigFileSnapshot({ isolateEnv: true, observe: false });

42414342

expect(process.env[key]).toBeUndefined();

44-

} finally {

45-

if (previous === undefined) {

46-

delete process.env[key];

47-

} else {

48-

process.env[key] = previous;

49-

}

50-

}

43+

});

5144

});

5245

});

53465447

it("resolves config env above exact lower-precedence values in isolated snapshots", async () => {

5548

await withTempHome(async (home) => {

5649

const key = "OPENCLAW_GATEWAY_TOKEN";

57-

const previous = process.env[key];

58-

process.env[key] = "shell-token";

59-

try {

50+

await withEnvAsync({ [key]: "shell-token" }, async () => {

6051

await writeOpenClawConfig(home, {

6152

env: { vars: { [key]: "config-token" } },

6253

gateway: { auth: { mode: "token", token: `\${${key}}` }, mode: "local" },

@@ -70,23 +61,13 @@ describe("readBestEffortConfig", () => {

70617162

expect(snapshot.config.gateway?.auth?.token).toBe("config-token");

7263

expect(process.env[key]).toBe("shell-token");

73-

} finally {

74-

if (previous === undefined) {

75-

delete process.env[key];

76-

} else {

77-

process.env[key] = previous;

78-

}

79-

}

64+

});

8065

});

8166

});

82678368

it("resolves config env above normalized lower-precedence aliases in isolated snapshots", async () => {

8469

await withTempHome(async (home) => {

85-

const previousCanonical = process.env.ZAI_API_KEY;

86-

const previousLegacy = process.env.Z_AI_API_KEY;

87-

process.env.ZAI_API_KEY = "shell-token";

88-

delete process.env.Z_AI_API_KEY;

89-

try {

70+

await withEnvAsync({ ZAI_API_KEY: "shell-token", Z_AI_API_KEY: undefined }, async () => {

9071

await writeOpenClawConfig(home, {

9172

env: { vars: { Z_AI_API_KEY: "config-token" } },

9273

gateway: { auth: { mode: "token", token: "${ZAI_API_KEY}" }, mode: "local" },

@@ -101,28 +82,13 @@ describe("readBestEffortConfig", () => {

10182

expect(snapshot.config.gateway?.auth?.token).toBe("config-token");

10283

expect(process.env.ZAI_API_KEY).toBe("shell-token");

10384

expect(process.env.Z_AI_API_KEY).toBeUndefined();

104-

} finally {

105-

if (previousCanonical === undefined) {

106-

delete process.env.ZAI_API_KEY;

107-

} else {

108-

process.env.ZAI_API_KEY = previousCanonical;

109-

}

110-

if (previousLegacy === undefined) {

111-

delete process.env.Z_AI_API_KEY;

112-

} else {

113-

process.env.Z_AI_API_KEY = previousLegacy;

114-

}

115-

}

85+

});

11686

});

11787

});

1188811989

it("resolves config aliases from a higher-precedence canonical value in isolated snapshots", async () => {

12090

await withTempHome(async (home) => {

121-

const previousCanonical = process.env.ZAI_API_KEY;

122-

const previousLegacy = process.env.Z_AI_API_KEY;

123-

process.env.ZAI_API_KEY = "invocation-token";

124-

delete process.env.Z_AI_API_KEY;

125-

try {

91+

await withEnvAsync({ ZAI_API_KEY: "invocation-token", Z_AI_API_KEY: undefined }, async () => {

12692

await writeOpenClawConfig(home, {

12793

env: { vars: { Z_AI_API_KEY: "config-token" } },

12894

gateway: { auth: { mode: "token", token: "${Z_AI_API_KEY}" }, mode: "local" },

@@ -136,27 +102,14 @@ describe("readBestEffortConfig", () => {

136102

expect(snapshot.config.gateway?.auth?.token).toBe("invocation-token");

137103

expect(process.env.ZAI_API_KEY).toBe("invocation-token");

138104

expect(process.env.Z_AI_API_KEY).toBeUndefined();

139-

} finally {

140-

if (previousCanonical === undefined) {

141-

delete process.env.ZAI_API_KEY;

142-

} else {

143-

process.env.ZAI_API_KEY = previousCanonical;

144-

}

145-

if (previousLegacy === undefined) {

146-

delete process.env.Z_AI_API_KEY;

147-

} else {

148-

process.env.Z_AI_API_KEY = previousLegacy;

149-

}

150-

}

105+

});

151106

});

152107

});

153108154109

it("can read best-effort config without applying env vars or recording observation", async () => {

155110

await withTempHome(async (home) => {

156111

const key = "OPENCLAW_ISOLATED_BEST_EFFORT_CONFIG_TEST";

157-

const previous = process.env[key];

158-

delete process.env[key];

159-

try {

112+

await withEnvAsync({ [key]: undefined }, async () => {

160113

await writeOpenClawConfig(home, {

161114

env: { vars: { [key]: "from-config" } },

162115

gateway: { mode: "local" },

@@ -169,49 +122,33 @@ describe("readBestEffortConfig", () => {

169122

await expect(fs.stat(`${home}/.openclaw/logs/config-health.json`)).rejects.toMatchObject({

170123

code: "ENOENT",

171124

});

172-

} finally {

173-

if (previous === undefined) {

174-

delete process.env[key];

175-

} else {

176-

process.env[key] = previous;

177-

}

178-

}

125+

});

179126

});

180127

});

181128182129

it("preserves Windows case-insensitive env lookup in isolated reads", async () => {

183130

await withTempHome(async (home) => {

184131

const mixedCaseKey = "OpenClaw_Config_Path";

185132

const customConfigPath = `${home}/custom-openclaw.json`;

186-

const previousMixedCasePath = process.env[mixedCaseKey];

187-

const previousConfigPath = process.env.OPENCLAW_CONFIG_PATH;

188-

const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");

189-

delete process.env.OPENCLAW_CONFIG_PATH;

190-

process.env[mixedCaseKey] = customConfigPath;

191-

try {

192-

await fs.writeFile(

193-

customConfigPath,

194-

`${JSON.stringify({ gateway: { mode: "local" } }, null, 2)}\n`,

195-

"utf-8",

196-

);

197-198-

const snapshot = await readConfigFileSnapshot({ isolateEnv: true, observe: false });

199-200-

expect(snapshot.exists).toBe(true);

201-

expect(snapshot.path).toBe(customConfigPath);

202-

} finally {

203-

platformSpy.mockRestore();

204-

if (previousMixedCasePath === undefined) {

205-

delete process.env[mixedCaseKey];

206-

} else {

207-

process.env[mixedCaseKey] = previousMixedCasePath;

208-

}

209-

if (previousConfigPath === undefined) {

210-

delete process.env.OPENCLAW_CONFIG_PATH;

211-

} else {

212-

process.env.OPENCLAW_CONFIG_PATH = previousConfigPath;

213-

}

214-

}

133+

await withEnvAsync({ OPENCLAW_CONFIG_PATH: undefined }, async () => {

134+

await withEnvAsync({ [mixedCaseKey]: customConfigPath }, async () => {

135+

const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");

136+

try {

137+

await fs.writeFile(

138+

customConfigPath,

139+

`${JSON.stringify({ gateway: { mode: "local" } }, null, 2)}\n`,

140+

"utf-8",

141+

);

142+143+

const snapshot = await readConfigFileSnapshot({ isolateEnv: true, observe: false });

144+145+

expect(snapshot.exists).toBe(true);

146+

expect(snapshot.path).toBe(customConfigPath);

147+

} finally {

148+

platformSpy.mockRestore();

149+

}

150+

});

151+

});

215152

});

216153

});

217154