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

推荐订阅源

量子位
Stack Overflow Blog
Stack Overflow Blog
人人都是产品经理
人人都是产品经理
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
博客园 - 司徒正美
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog

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(whatsapp): recover stale listener after auth conflict...
vincentkoc · 2026-04-28 · via Recent Commits to openclaw:main

@@ -18,6 +18,7 @@ const hoisted = vi.hoisted(() => ({

1818

waitForCredsSaveQueueWithTimeout: vi.fn<() => Promise<CredsQueueWaitResult>>(

1919

async () => "drained",

2020

),

21+

oauthDir: "/tmp/openclaw-wa-auth-store-test-oauth",

2122

}));

22232324

vi.mock("./creds-persistence.js", async () => {

@@ -29,12 +30,31 @@ vi.mock("./creds-persistence.js", async () => {

2930

};

3031

});

313233+

vi.mock("./auth-store.runtime.js", () => ({

34+

resolveOAuthDir: () => hoisted.oauthDir,

35+

}));

36+3237

function createTempAuthDir(prefix: string) {

3338

return fsSync.mkdtempSync(

3439

path.join((process.env.TMPDIR ?? "/tmp").replace(/\/+$/, ""), `${prefix}-`),

3540

);

3641

}

374243+

function withOwnedOAuthAuthDir<T>(

44+

prefix: string,

45+

run: (authDir: string) => Promise<T>,

46+

): Promise<T> {

47+

const previousOAuthDir = hoisted.oauthDir;

48+

const oauthDir = createTempAuthDir(`${prefix}-oauth`);

49+

const authDir = path.join(oauthDir, "whatsapp", "default");

50+

fsSync.mkdirSync(authDir, { recursive: true });

51+

hoisted.oauthDir = oauthDir;

52+

return run(authDir).finally(() => {

53+

hoisted.oauthDir = previousOAuthDir;

54+

fsSync.rmSync(oauthDir, { recursive: true, force: true });

55+

});

56+

}

57+3858

describe("auth-store", () => {

3959

beforeEach(() => {

4060

hoisted.waitForCredsSaveQueueWithTimeout.mockReset().mockResolvedValue("drained");

@@ -115,29 +135,32 @@ describe("auth-store", () => {

115135

});

116136117137

it("clears unreadable auth state on explicit logout", async () => {

118-

const authDir = createTempAuthDir("openclaw-wa-auth-logout");

119-

fsSync.writeFileSync(path.join(authDir, "creds.json"), "{", "utf-8");

120-

fsSync.writeFileSync(

121-

path.join(authDir, "creds.json.bak"),

122-

JSON.stringify({ me: { id: "123@s.whatsapp.net" } }),

123-

"utf-8",

124-

);

138+

await withOwnedOAuthAuthDir("openclaw-wa-auth-logout", async (authDir) => {

139+

fsSync.writeFileSync(path.join(authDir, "creds.json"), "{", "utf-8");

140+

fsSync.writeFileSync(

141+

path.join(authDir, "creds.json.bak"),

142+

JSON.stringify({ me: { id: "123@s.whatsapp.net" } }),

143+

"utf-8",

144+

);

125145126-

const runtime = {

127-

log: vi.fn(),

128-

error: vi.fn(),

129-

exit: vi.fn(),

130-

};

146+

const runtime = {

147+

log: vi.fn(),

148+

error: vi.fn(),

149+

exit: vi.fn(),

150+

};

131151132-

await expect(logoutWeb({ authDir, runtime: runtime as never })).resolves.toBe(true);

133-

expect(fsSync.existsSync(authDir)).toBe(false);

152+

await expect(logoutWeb({ authDir, runtime: runtime as never })).resolves.toBe(true);

153+

expect(fsSync.existsSync(authDir)).toBe(false);

154+

});

134155

});

135156136157

it("does not delete the whole legacy auth root when targeted cleanup fails", async () => {

137158

const authDir = createTempAuthDir("openclaw-wa-auth-legacy-failure");

159+

const previousOAuthDir = hoisted.oauthDir;

138160

fsSync.writeFileSync(path.join(authDir, "creds.json"), "{}", "utf-8");

139161

fsSync.writeFileSync(path.join(authDir, "oauth.json"), '{"token":true}', "utf-8");

140162

fsSync.writeFileSync(path.join(authDir, "session-abc.json"), "{}", "utf-8");

163+

hoisted.oauthDir = authDir;

141164

const originalRm = fs.rm;

142165

const rmSpy = vi.spyOn(fs, "rm").mockImplementation(async (target, options) => {

143166

if (String(target).endsWith("creds.json")) {

@@ -151,29 +174,114 @@ describe("auth-store", () => {

151174

exit: vi.fn(),

152175

};

153176154-

await expect(

155-

logoutWeb({ authDir, isLegacyAuthDir: true, runtime: runtime as never }),

156-

).rejects.toThrow("EACCES");

157-

expect(fsSync.existsSync(authDir)).toBe(true);

158-

expect(fsSync.existsSync(path.join(authDir, "oauth.json"))).toBe(true);

159-

rmSpy.mockRestore();

177+

try {

178+

await expect(

179+

logoutWeb({ authDir, isLegacyAuthDir: true, runtime: runtime as never }),

180+

).rejects.toThrow("EACCES");

181+

expect(fsSync.existsSync(authDir)).toBe(true);

182+

expect(fsSync.existsSync(path.join(authDir, "oauth.json"))).toBe(true);

183+

} finally {

184+

hoisted.oauthDir = previousOAuthDir;

185+

rmSpy.mockRestore();

186+

fsSync.rmSync(authDir, { recursive: true, force: true });

187+

}

160188

});

161189162190

it("clears auth state even when directory enumeration fails", async () => {

163-

const authDir = createTempAuthDir("openclaw-wa-auth-readdir");

191+

await withOwnedOAuthAuthDir("openclaw-wa-auth-readdir", async (authDir) => {

192+

fsSync.writeFileSync(path.join(authDir, "creds.json"), "{}", "utf-8");

193+

const readdirSpy = vi

194+

.spyOn(fs, "readdir")

195+

.mockRejectedValueOnce(Object.assign(new Error("EACCES"), { code: "EACCES" }));

196+

const runtime = {

197+

log: vi.fn(),

198+

error: vi.fn(),

199+

exit: vi.fn(),

200+

};

201+202+

await expect(logoutWeb({ authDir, runtime: runtime as never })).resolves.toBe(true);

203+

expect(fsSync.existsSync(authDir)).toBe(false);

204+

readdirSpy.mockRestore();

205+

});

206+

});

207+208+

it("does not delete custom auth directories outside the OpenClaw auth root", async () => {

209+

const authDir = createTempAuthDir("openclaw-wa-auth-custom");

210+

const nestedDir = path.join(authDir, "nested");

211+

fsSync.mkdirSync(nestedDir);

164212

fsSync.writeFileSync(path.join(authDir, "creds.json"), "{}", "utf-8");

165-

const readdirSpy = vi

166-

.spyOn(fs, "readdir")

167-

.mockRejectedValueOnce(Object.assign(new Error("EACCES"), { code: "EACCES" }));

213+

fsSync.writeFileSync(path.join(authDir, "notes.txt"), "keep me", "utf-8");

214+

fsSync.writeFileSync(path.join(nestedDir, "session-abc.json"), "keep me", "utf-8");

168215

const runtime = {

169216

log: vi.fn(),

170217

error: vi.fn(),

171218

exit: vi.fn(),

172219

};

173220174-

await expect(logoutWeb({ authDir, runtime: runtime as never })).resolves.toBe(true);

175-

expect(fsSync.existsSync(authDir)).toBe(false);

176-

readdirSpy.mockRestore();

221+

await expect(logoutWeb({ authDir, runtime: runtime as never })).resolves.toBe(false);

222+

expect(fsSync.existsSync(authDir)).toBe(true);

223+

expect(fsSync.existsSync(path.join(authDir, "creds.json"))).toBe(true);

224+

expect(fsSync.existsSync(path.join(authDir, "notes.txt"))).toBe(true);

225+

expect(fsSync.existsSync(path.join(nestedDir, "session-abc.json"))).toBe(true);

226+

});

227+228+

it("does not clear auth files through a symlinked owned auth directory", async () => {

229+

const previousOAuthDir = hoisted.oauthDir;

230+

const oauthDir = createTempAuthDir("openclaw-wa-auth-symlink-oauth");

231+

const externalDir = createTempAuthDir("openclaw-wa-auth-symlink-target");

232+

const authDir = path.join(oauthDir, "whatsapp", "default");

233+

try {

234+

fsSync.mkdirSync(path.dirname(authDir), { recursive: true });

235+

fsSync.writeFileSync(path.join(externalDir, "creds.json"), "{}", "utf-8");

236+

fsSync.writeFileSync(path.join(externalDir, "notes.txt"), "keep me", "utf-8");

237+

fsSync.symlinkSync(externalDir, authDir, "dir");

238+

hoisted.oauthDir = oauthDir;

239+

const runtime = {

240+

log: vi.fn(),

241+

error: vi.fn(),

242+

exit: vi.fn(),

243+

};

244+245+

await expect(logoutWeb({ authDir, runtime: runtime as never })).resolves.toBe(false);

246+

expect(fsSync.existsSync(authDir)).toBe(true);

247+

expect(fsSync.existsSync(path.join(externalDir, "creds.json"))).toBe(true);

248+

expect(fsSync.existsSync(path.join(externalDir, "notes.txt"))).toBe(true);

249+

} finally {

250+

hoisted.oauthDir = previousOAuthDir;

251+

fsSync.rmSync(oauthDir, { recursive: true, force: true });

252+

fsSync.rmSync(externalDir, { recursive: true, force: true });

253+

}

254+

});

255+256+

it("does not clear auth files through an intermediate symlink in the owned auth tree", async () => {

257+

const previousOAuthDir = hoisted.oauthDir;

258+

const oauthDir = createTempAuthDir("openclaw-wa-auth-symlink-parent-oauth");

259+

const externalRoot = createTempAuthDir("openclaw-wa-auth-symlink-parent-target");

260+

const externalAuthDir = path.join(externalRoot, "default");

261+

const linkedParent = path.join(oauthDir, "whatsapp", "linked");

262+

const authDir = path.join(linkedParent, "default");

263+

try {

264+

fsSync.mkdirSync(path.dirname(linkedParent), { recursive: true });

265+

fsSync.mkdirSync(externalAuthDir, { recursive: true });

266+

fsSync.writeFileSync(path.join(externalAuthDir, "creds.json"), "{}", "utf-8");

267+

fsSync.writeFileSync(path.join(externalAuthDir, "notes.txt"), "keep me", "utf-8");

268+

fsSync.symlinkSync(externalRoot, linkedParent, "dir");

269+

hoisted.oauthDir = oauthDir;

270+

const runtime = {

271+

log: vi.fn(),

272+

error: vi.fn(),

273+

exit: vi.fn(),

274+

};

275+276+

await expect(logoutWeb({ authDir, runtime: runtime as never })).resolves.toBe(false);

277+

expect(fsSync.existsSync(authDir)).toBe(true);

278+

expect(fsSync.existsSync(path.join(externalAuthDir, "creds.json"))).toBe(true);

279+

expect(fsSync.existsSync(path.join(externalAuthDir, "notes.txt"))).toBe(true);

280+

} finally {

281+

hoisted.oauthDir = previousOAuthDir;

282+

fsSync.rmSync(oauthDir, { recursive: true, force: true });

283+

fsSync.rmSync(externalRoot, { recursive: true, force: true });

284+

}

177285

});

178286179287

it("does not delete unrelated non-empty directories on logout", async () => {