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

推荐订阅源

J
Java Code Geeks
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
B
Blog RSS Feed
I
InfoQ
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
H
Help Net Security
L
LangChain Blog
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
aimingoo的专栏
aimingoo的专栏

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(doctor): surface GH_CONFIG_DIR hint when gh auth live...
tmimmanuel · 2026-05-11 · via Recent Commits to openclaw:main

@@ -0,0 +1,223 @@

1+

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

2+

import {

3+

detectGhConfigDirMismatch,

4+

formatGhConfigDirMismatchHint,

5+

type GhConfigDirMismatch,

6+

type GhConfigDiscoveryInput,

7+

} from "./gh-config-discovery.js";

8+9+

function makeInput(overrides: Partial<GhConfigDiscoveryInput>): GhConfigDiscoveryInput {

10+

return {

11+

platform: "linux",

12+

env: {},

13+

fileExists: () => false,

14+

...overrides,

15+

};

16+

}

17+18+

function fileSet(...paths: readonly string[]): (absolutePath: string) => boolean {

19+

const set = new Set(paths);

20+

return (absolutePath) => set.has(absolutePath);

21+

}

22+23+

describe("detectGhConfigDirMismatch", () => {

24+

it("returns 'explicit-gh-config-dir-set' when GH_CONFIG_DIR is already set", () => {

25+

const result = detectGhConfigDirMismatch(

26+

makeInput({

27+

env: { HOME: "/agent/home", GH_CONFIG_DIR: "/etc/openclaw/gh" },

28+

}),

29+

);

30+

expect(result).toEqual({ kind: "explicit-gh-config-dir-set", ghConfigDir: "/etc/openclaw/gh" });

31+

});

32+33+

it("returns 'no-process-home' when HOME and XDG and APPDATA are missing", () => {

34+

const result = detectGhConfigDirMismatch(makeInput({ env: {} }));

35+

expect(result).toEqual({ kind: "no-process-home" });

36+

});

37+38+

it("returns 'auth-discoverable' when the effective config dir already has hosts.yml", () => {

39+

const result = detectGhConfigDirMismatch(

40+

makeInput({

41+

env: { HOME: "/agent/home" },

42+

fileExists: fileSet("/agent/home/.config/gh/hosts.yml"),

43+

}),

44+

);

45+

expect(result).toEqual({

46+

kind: "auth-discoverable",

47+

effectiveConfigDir: "/agent/home/.config/gh",

48+

});

49+

});

50+51+

it("flags a mismatch when /root/.config/gh has hosts.yml but the agent HOME does not", () => {

52+

const result = detectGhConfigDirMismatch(

53+

makeInput({

54+

env: { HOME: "/root/.openclaw/agents/main/agent/codex-home/home" },

55+

fileExists: fileSet("/root/.config/gh/hosts.yml"),

56+

}),

57+

);

58+

expect(result).toMatchObject({

59+

kind: "mismatch",

60+

effectiveConfigDir: "/root/.openclaw/agents/main/agent/codex-home/home/.config/gh",

61+

alternateConfigDir: "/root/.config/gh",

62+

alternateHostsFile: "/root/.config/gh/hosts.yml",

63+

alternateHomeHint: "/root",

64+

suggestedEnvValue: "/root/.config/gh",

65+

});

66+

});

67+68+

it("uses SUDO_USER home as a candidate when set", () => {

69+

const result = detectGhConfigDirMismatch(

70+

makeInput({

71+

env: { HOME: "/var/lib/openclaw/agent", SUDO_USER: "alice" },

72+

fileExists: fileSet("/home/alice/.config/gh/hosts.yml"),

73+

}),

74+

);

75+

expect(result).toMatchObject({

76+

kind: "mismatch",

77+

alternateConfigDir: "/home/alice/.config/gh",

78+

alternateHomeHint: "/home/alice",

79+

});

80+

});

81+82+

it("uses USER home as a fallback candidate when SUDO_USER is missing", () => {

83+

const result = detectGhConfigDirMismatch(

84+

makeInput({

85+

env: { HOME: "/var/lib/openclaw/agent", USER: "ops" },

86+

fileExists: fileSet("/home/ops/.config/gh/hosts.yml"),

87+

}),

88+

);

89+

expect(result).toMatchObject({

90+

kind: "mismatch",

91+

alternateConfigDir: "/home/ops/.config/gh",

92+

alternateHomeHint: "/home/ops",

93+

});

94+

});

95+96+

it("ignores USER=root since /root is already part of the default candidate set", () => {

97+

const result = detectGhConfigDirMismatch(

98+

makeInput({

99+

env: { HOME: "/agent/home", USER: "root" },

100+

fileExists: fileSet("/root/.config/gh/hosts.yml"),

101+

}),

102+

);

103+

expect(result.kind).toBe("mismatch");

104+

});

105+106+

it("returns 'no-known-auth' when no candidate has hosts.yml", () => {

107+

const result = detectGhConfigDirMismatch(

108+

makeInput({

109+

env: { HOME: "/agent/home" },

110+

fileExists: () => false,

111+

}),

112+

);

113+

expect(result).toEqual({

114+

kind: "no-known-auth",

115+

effectiveConfigDir: "/agent/home/.config/gh",

116+

});

117+

});

118+119+

it("does not flag a mismatch when the agent HOME equals the operator HOME", () => {

120+

const result = detectGhConfigDirMismatch(

121+

makeInput({

122+

env: { HOME: "/root" },

123+

fileExists: fileSet("/root/.config/gh/hosts.yml"),

124+

}),

125+

);

126+

expect(result).toEqual({

127+

kind: "auth-discoverable",

128+

effectiveConfigDir: "/root/.config/gh",

129+

});

130+

});

131+132+

it("respects XDG_CONFIG_HOME for the effective config dir on Linux", () => {

133+

const result = detectGhConfigDirMismatch(

134+

makeInput({

135+

env: { HOME: "/agent/home", XDG_CONFIG_HOME: "/agent/xdg" },

136+

fileExists: fileSet("/agent/xdg/gh/hosts.yml"),

137+

}),

138+

);

139+

expect(result).toEqual({

140+

kind: "auth-discoverable",

141+

effectiveConfigDir: "/agent/xdg/gh",

142+

});

143+

});

144+145+

it("uses HOME/.config/gh on darwin (matches gh's documented macOS lookup)", () => {

146+

const result = detectGhConfigDirMismatch(

147+

makeInput({

148+

platform: "darwin",

149+

env: { HOME: "/Users/agent" },

150+

fileExists: fileSet("/Users/operator/.config/gh/hosts.yml"),

151+

candidateOperatorHomes: ["/Users/operator"],

152+

}),

153+

);

154+

expect(result).toMatchObject({

155+

kind: "mismatch",

156+

effectiveConfigDir: "/Users/agent/.config/gh",

157+

alternateConfigDir: "/Users/operator/.config/gh",

158+

alternateHomeHint: "/Users/operator",

159+

});

160+

});

161+162+

it("uses APPDATA/GitHub CLI on win32", () => {

163+

const result = detectGhConfigDirMismatch(

164+

makeInput({

165+

platform: "win32",

166+

env: { APPDATA: "C:\\Users\\agent\\AppData\\Roaming" },

167+

fileExists: fileSet("C:\\Users\\agent\\AppData\\Roaming\\GitHub CLI\\hosts.yml"),

168+

}),

169+

);

170+

expect(result).toMatchObject({

171+

kind: "auth-discoverable",

172+

effectiveConfigDir: "C:\\Users\\agent\\AppData\\Roaming\\GitHub CLI",

173+

});

174+

});

175+176+

it("respects an explicit candidateOperatorHomes list", () => {

177+

const result = detectGhConfigDirMismatch(

178+

makeInput({

179+

env: { HOME: "/agent/home" },

180+

fileExists: fileSet("/srv/automation/.config/gh/hosts.yml"),

181+

candidateOperatorHomes: ["/srv/automation"],

182+

}),

183+

);

184+

expect(result).toMatchObject({

185+

kind: "mismatch",

186+

alternateConfigDir: "/srv/automation/.config/gh",

187+

alternateHomeHint: "/srv/automation",

188+

});

189+

});

190+

});

191+192+

describe("formatGhConfigDirMismatchHint", () => {

193+

it("formats the mismatch into operator-actionable lines", () => {

194+

const mismatch: GhConfigDirMismatch = {

195+

effectiveConfigDir: "/agent/home/.config/gh",

196+

alternateConfigDir: "/root/.config/gh",

197+

alternateHostsFile: "/root/.config/gh/hosts.yml",

198+

alternateHomeHint: "/root",

199+

suggestedEnvValue: "/root/.config/gh",

200+

};

201+

expect(formatGhConfigDirMismatchHint(mismatch)).toEqual([

202+

"GitHub CLI auth was found at a different HOME than the one this OpenClaw process uses.",

203+

" Process gh config dir: /agent/home/.config/gh",

204+

" Authenticated config: /root/.config/gh (contains hosts.yml)",

205+

" Authenticated HOME: /root",

206+

" Fix: set GH_CONFIG_DIR=/root/.config/gh on the OpenClaw service environment, then restart the gateway.",

207+

]);

208+

});

209+210+

it("omits the home hint line when the alternate has no associated HOME", () => {

211+

const mismatch: GhConfigDirMismatch = {

212+

effectiveConfigDir: "/agent/home/.config/gh",

213+

alternateConfigDir: "/srv/automation/.config/gh",

214+

alternateHostsFile: "/srv/automation/.config/gh/hosts.yml",

215+

suggestedEnvValue: "/srv/automation/.config/gh",

216+

};

217+

const lines = formatGhConfigDirMismatchHint(mismatch);

218+

expect(lines.some((line) => line.includes("Authenticated HOME"))).toBe(false);

219+

expect(lines).toContain(

220+

" Fix: set GH_CONFIG_DIR=/srv/automation/.config/gh on the OpenClaw service environment, then restart the gateway.",

221+

);

222+

});

223+

});