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

推荐订阅源

SecWiki News
SecWiki News
Vercel News
Vercel News
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
N
News and Events Feed by Topic
Application and Cybersecurity Blog
Application and Cybersecurity Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 【当耐特】
WordPress大学
WordPress大学
Google Online Security Blog
Google Online Security Blog
博客园 - Franky
Attack and Defense Labs
Attack and Defense Labs
Help Net Security
Help Net Security
V
Visual Studio Blog
Jina AI
Jina AI
H
Heimdal Security Blog
小众软件
小众软件
O
OpenAI News
腾讯CDC
The Last Watchdog
The Last Watchdog
雷峰网
雷峰网
Cloudbric
Cloudbric
量子位
博客园_首页
The GitHub Blog
The GitHub Blog
L
LangChain Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
The Blog of Author Tim Ferriss
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Last Week in AI
Last Week in AI
V2EX - 技术
V2EX - 技术
Security Archives - TechRepublic
Security Archives - TechRepublic
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 司徒正美
M
MIT News - Artificial intelligence
大猫的无限游戏
大猫的无限游戏
T
Tor Project blog
C
CERT Recently Published Vulnerability Notes
W
WeLiveSecurity
B
Blog
C
Check Point Blog
TaoSecurity Blog
TaoSecurity Blog
T
Threatpost
Hugging Face - Blog
Hugging Face - Blog
Recent Announcements
Recent Announcements
Project Zero
Project Zero
Hacker News: Ask HN
Hacker News: Ask HN
U
Unit 42
Simon Willison's Weblog
Simon Willison's Weblog

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 test: trim doctor command hotspots · openclaw/openclaw@c66f16a test: isolate agent auth and spawn hotspots · openclaw/openclaw@9285935 test: stabilize MCP startup disposal race · openclaw/openclaw@dd9d2eb test: merge browser contract server suites · openclaw/openclaw@5817a76 test: narrow ollama provider discovery setup · openclaw/openclaw@a0d9598 build: declare qa-lab aimock runtime dependency · openclaw/openclaw@24431e5 test: speed up safe-bins exec harness · openclaw/openclaw@ee856ab test: preserve tool helpers in embedded runner mocks · openclaw/openclaw@acd86a0 refactor: move memory embeddings into provider plugins · openclaw/openclaw@77e6e4c test: reuse system-run temp fixtures · openclaw/openclaw@7e9ff0f test: trim hotspot wait overhead · openclaw/openclaw@12a59b0 Check: avoid duplicate boundary prep · openclaw/openclaw@baf11b8 test: reduce hotspot fixture overhead · openclaw/openclaw@3a59edd feat(ui): overhaul settings and slash command UX (#67819) thanks @Bun… · openclaw/openclaw@2cfb660 QA Matrix: exit cleanly on failure · openclaw/openclaw@42805d2 QA Matrix: isolate scenario coverage · openclaw/openclaw@7e659e1 Matrix: refresh crypto bootstrap state · openclaw/openclaw@94081d8 QA Lab: add provider registry · openclaw/openclaw@bb7e982 Matrix: add plugin changelog · openclaw/openclaw@4acab55 test: trim more hotspot overhead · openclaw/openclaw@f485311 test: trim remaining hotspot tests · openclaw/openclaw@6ba8626 test: narrow hotspot mocks · openclaw/openclaw@dbc8179 test: isolate gemini embedding request helpers · openclaw/openclaw@cd330f5 test: trim memory and mcp hotspots · openclaw/openclaw@fd48dfa test: slim provider registry mocks · openclaw/openclaw@2e08c77 test: harden Parallels update smoke · openclaw/openclaw@1a98090 feat: default Anthropic to Opus 4.7 · openclaw/openclaw@628b454 fix: harden node-host shell payload mutability checks · openclaw/openclaw@75c551e fix: land node-host approval binding for native binaries (#66731) (th… · openclaw/openclaw@29919bb CI: add daily schedule to CodeQL workflow (#67645) · openclaw/openclaw@69d25f5 fix(gateway): capture config hash after plugin auto-enable to prevent… · openclaw/openclaw@8c11210 fix: repair sanitized replay tool results before send (#67620) (thank… · openclaw/openclaw@c3c7a99 fix: restrict HTML timeout short-circuit to transient statuses · openclaw/openclaw@de129a6 fix: keep TUI watchdog bound to active run (#67401) (thanks @xantorres) · openclaw/openclaw@3525273 Gateway/skills: dedupe skills prefix-match + drop dead fallback on log · openclaw/openclaw@d7f489f Extensions/lmstudio: back off inference preload after consecutive fai… · openclaw/openclaw@b555214 TUI/streaming: add watchdog that resets the activity indicator after … · openclaw/openclaw@f44ab20 Agents/tool-loop: enable unknown-tool stream guard by default · openclaw/openclaw@36ed367 Gateway/skills: invalidate session skills snapshot on config write · openclaw/openclaw@b23d59a fix: classify HTML provider error pages correctly (#67642) (thanks @s… · openclaw/openclaw@e588e90 fix(skills): remove unused model-usage import (#67641) · openclaw/openclaw@55f05df docs(changelog): credit codex fix superseded PRs · openclaw/openclaw@e485f24 fix(openai-codex): normalize stale transport metadata in resolution a… · openclaw/openclaw@90801ba CI: pin Docker-related GitHub Actions (#67632) · openclaw/openclaw@f697b01 Android: modernize WebView and discovery API usage (#67627) · openclaw/openclaw@44a6e50 fix(deps): bump hono to 4.12.14 and @hono/node-server to 1.19.14 (GHS… · openclaw/openclaw@fbccc18 fix(deps): bump dompurify to 3.4.0 (#67614) · openclaw/openclaw@2c2dc00 CI: add explicit permissions to all workflow jobs (fixes code-scannin… · openclaw/openclaw@01b7516 fix: register bundled TTS providers and route overrides correctly (#6… · openclaw/openclaw@6ea3cdd fix: align host tilde paths with OS home (#62804) (thanks @stainlu) · openclaw/openclaw@ecfaf64 fix: flush creds queue before reconnect socket open (#67464) (thanks … · openclaw/openclaw@405c63f fix: strip standalone <function> tool call tags from visible text (#6… · openclaw/openclaw@78df859 fix(agents): preserve cli session metadata before transcript persist … · openclaw/openclaw@898fd04 docs(changelog): move cli transcript entry · openclaw/openclaw@c1817c6 fix(agents): normalize cli transcript api field · openclaw/openclaw@3a3fae0 docs(changelog): note cli transcript persistence · openclaw/openclaw@6c343f1 fix(agents): persist cli transcript turns · openclaw/openclaw@b8ef507 fix(msteams): harden security-sensitive flows (#65841) · openclaw/openclaw@c56b56e [Dashboard] Fix exec approval modal overflow for long command content… · openclaw/openclaw@053c5b0 Docs: remove QA changelog entry · openclaw/openclaw@7fd5771 QA: fix private runtime source loading (#67428) · openclaw/openclaw@d5933af docs(gateway): correct protocol.md schema path, hello-ok example, aut… · openclaw/openclaw@489404d CI: pin Node 22 runners to 22.18.0 · openclaw/openclaw@4ffa621 models.authStatus: normalize provider ids + tighten env-backed escape… · openclaw/openclaw@f2fdb9d Update CHANGELOG.md · openclaw/openclaw@7694a92 test(parallels): clean up npm update guard jobs · openclaw/openclaw@045ea7b Plugins: prefer scanDir override paths · openclaw/openclaw@b2974da fix(dreaming): default storage.mode to "separate" so phase blocks sto… · openclaw/openclaw@8c392f0 fix(memory-core): skip dreaming transcript ingestion via session stor… · openclaw/openclaw@a1b01f0 fix: dedupe replayed exec.finished node events (#67281) · openclaw/openclaw@5dcf526
fix(feishu): repair stale channel state · openclaw/openclaw@b7c461a
steipete · 2026-05-27 · via Recent Commits to openclaw:main

@@ -0,0 +1,381 @@

1+

import fs from "node:fs";

2+

import os from "node:os";

3+

import path from "node:path";

4+

import { loadSessionStore } from "openclaw/plugin-sdk/session-store-runtime";

5+

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

6+

import type { OpenClawConfig } from "../runtime-api.js";

7+

import { isFeishuSessionStoreKey, runFeishuDoctorSequence } from "./doctor.js";

8+9+

type EnvSnapshot = {

10+

HOME?: string;

11+

OPENCLAW_HOME?: string;

12+

OPENCLAW_STATE_DIR?: string;

13+

};

14+15+

function captureEnv(): EnvSnapshot {

16+

return {

17+

HOME: process.env.HOME,

18+

OPENCLAW_HOME: process.env.OPENCLAW_HOME,

19+

OPENCLAW_STATE_DIR: process.env.OPENCLAW_STATE_DIR,

20+

};

21+

}

22+23+

function restoreEnv(snapshot: EnvSnapshot) {

24+

for (const key of Object.keys(snapshot) as Array<keyof EnvSnapshot>) {

25+

const value = snapshot[key];

26+

if (value === undefined) {

27+

delete process.env[key];

28+

} else {

29+

process.env[key] = value;

30+

}

31+

}

32+

}

33+34+

function feishuConfig(): OpenClawConfig {

35+

return {

36+

channels: {

37+

feishu: {

38+

appId: "cli_xxx",

39+

appSecret: "secret_xxx",

40+

},

41+

},

42+

} as OpenClawConfig;

43+

}

44+45+

function stateDir(): string {

46+

const dir = process.env.OPENCLAW_STATE_DIR;

47+

if (!dir) {

48+

throw new Error("OPENCLAW_STATE_DIR is not set");

49+

}

50+

return dir;

51+

}

52+53+

function sessionsDir(agentId = "main"): string {

54+

return path.join(stateDir(), "agents", agentId, "sessions");

55+

}

56+57+

function storePath(agentId = "main"): string {

58+

return path.join(sessionsDir(agentId), "sessions.json");

59+

}

60+61+

function writeStore(entries: Record<string, unknown>, agentId = "main"): string {

62+

const target = storePath(agentId);

63+

fs.mkdirSync(path.dirname(target), { recursive: true });

64+

fs.writeFileSync(target, JSON.stringify(entries, null, 2));

65+

return target;

66+

}

67+68+

function writeTranscript(sessionId: string, lines: unknown[], agentId = "main"): string {

69+

const target = path.join(sessionsDir(agentId), `${sessionId}.jsonl`);

70+

fs.mkdirSync(path.dirname(target), { recursive: true });

71+

fs.writeFileSync(target, `${lines.map((line) => JSON.stringify(line)).join("\n")}\n`);

72+

return target;

73+

}

74+75+

function sessionHeader(sessionId: string) {

76+

return {

77+

type: "session",

78+

id: sessionId,

79+

version: 7,

80+

timestamp: new Date(0).toISOString(),

81+

cwd: "/tmp",

82+

};

83+

}

84+85+

function userMessage(content: string) {

86+

return {

87+

type: "message",

88+

id: `msg-${content || "blank"}-${Math.random().toString(36).slice(2)}`,

89+

parentId: null,

90+

timestamp: new Date(0).toISOString(),

91+

message: { role: "user", content },

92+

};

93+

}

94+95+

function listBackupDirs(): string[] {

96+

const backupsDir = path.join(stateDir(), "backups");

97+

return fs.existsSync(backupsDir)

98+

? fs.readdirSync(backupsDir).filter((name) => name.startsWith("feishu-state-repair-"))

99+

: [];

100+

}

101+102+

describe("Feishu doctor state repair", () => {

103+

let envSnapshot: EnvSnapshot;

104+

let tempHome = "";

105+106+

beforeEach(() => {

107+

envSnapshot = captureEnv();

108+

tempHome = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-feishu-doctor-"));

109+

process.env.HOME = tempHome;

110+

process.env.OPENCLAW_HOME = tempHome;

111+

process.env.OPENCLAW_STATE_DIR = path.join(tempHome, ".openclaw");

112+

fs.mkdirSync(process.env.OPENCLAW_STATE_DIR, { recursive: true, mode: 0o700 });

113+

});

114+115+

afterEach(() => {

116+

restoreEnv(envSnapshot);

117+

fs.rmSync(tempHome, { recursive: true, force: true });

118+

});

119+120+

it("matches only Feishu channel session keys", () => {

121+

expect(isFeishuSessionStoreKey("agent:main:feishu:direct:ou_user")).toBe(true);

122+

expect(isFeishuSessionStoreKey("feishu:direct:ou_user")).toBe(true);

123+

expect(isFeishuSessionStoreKey("agent:codex:acp:binding:feishu:default:abc123")).toBe(false);

124+

expect(isFeishuSessionStoreKey("agent:main:discord:direct:user")).toBe(false);

125+

});

126+127+

it("stays quiet for healthy Feishu state and transcripts", async () => {

128+

const feishuDedupDir = path.join(stateDir(), "feishu", "dedup");

129+

fs.mkdirSync(feishuDedupDir, { recursive: true });

130+

fs.writeFileSync(path.join(feishuDedupDir, "default.json"), JSON.stringify({ msg1: 1 }));

131+132+

writeTranscript("sess-ok", [sessionHeader("sess-ok"), userMessage("hello")]);

133+

writeStore({

134+

"agent:main:feishu:direct:ou_user": {

135+

sessionId: "sess-ok",

136+

sessionFile: "sess-ok.jsonl",

137+

updatedAt: Date.now(),

138+

},

139+

});

140+141+

const result = await runFeishuDoctorSequence({

142+

cfg: feishuConfig(),

143+

env: process.env,

144+

shouldRepair: false,

145+

});

146+147+

expect(result).toEqual({ changeNotes: [], warningNotes: [] });

148+

});

149+150+

it("keeps custom-store sessions with canonical absolute transcripts", async () => {

151+

const transcriptPath = writeTranscript("sess-abs", [

152+

sessionHeader("sess-abs"),

153+

userMessage("hello"),

154+

]);

155+

const customStorePath = path.join(stateDir(), "custom-sessions", "sessions.json");

156+

fs.mkdirSync(path.dirname(customStorePath), { recursive: true });

157+

fs.writeFileSync(

158+

customStorePath,

159+

JSON.stringify({

160+

"agent:main:feishu:direct:ou_user": {

161+

sessionId: "sess-abs",

162+

sessionFile: transcriptPath,

163+

updatedAt: Date.now(),

164+

},

165+

}),

166+

);

167+168+

const result = await runFeishuDoctorSequence({

169+

cfg: {

170+

...feishuConfig(),

171+

session: { store: customStorePath },

172+

} as OpenClawConfig,

173+

env: process.env,

174+

shouldRepair: false,

175+

});

176+177+

expect(result).toEqual({ changeNotes: [], warningNotes: [] });

178+

});

179+180+

it("keeps Feishu sessions with separated blank user messages", async () => {

181+

writeTranscript("sess-separated-blanks", [

182+

sessionHeader("sess-separated-blanks"),

183+

userMessage(""),

184+

userMessage("hello"),

185+

userMessage(""),

186+

userMessage("world"),

187+

userMessage(""),

188+

]);

189+

writeStore({

190+

"agent:main:feishu:direct:ou_user": {

191+

sessionId: "sess-separated-blanks",

192+

sessionFile: "sess-separated-blanks.jsonl",

193+

updatedAt: Date.now(),

194+

},

195+

});

196+197+

const result = await runFeishuDoctorSequence({

198+

cfg: feishuConfig(),

199+

env: process.env,

200+

shouldRepair: false,

201+

});

202+203+

expect(result).toEqual({ changeNotes: [], warningNotes: [] });

204+

});

205+206+

it("warns before repair when Feishu local state is corrupt", async () => {

207+

const feishuDedupDir = path.join(stateDir(), "feishu", "dedup");

208+

fs.mkdirSync(feishuDedupDir, { recursive: true });

209+

fs.writeFileSync(path.join(feishuDedupDir, "default.json"), "{");

210+211+

const result = await runFeishuDoctorSequence({

212+

cfg: feishuConfig(),

213+

env: process.env,

214+

shouldRepair: false,

215+

});

216+217+

expect(result.changeNotes).toEqual([]);

218+

expect(result.warningNotes.join("\n")).toContain("Feishu local channel state may need repair");

219+

expect(result.warningNotes.join("\n")).toContain("preserving Feishu App ID/secret config");

220+

expect(result.warningNotes.join("\n")).toContain("openclaw doctor --fix");

221+

});

222+223+

it("rebuilds corrupt Feishu state without deleting healthy Feishu sessions", async () => {

224+

const feishuDedupDir = path.join(stateDir(), "feishu", "dedup");

225+

fs.mkdirSync(feishuDedupDir, { recursive: true });

226+

fs.writeFileSync(path.join(feishuDedupDir, "default.json"), "{");

227+228+

const transcriptPath = writeTranscript("sess-ok", [

229+

sessionHeader("sess-ok"),

230+

userMessage("hello"),

231+

]);

232+

const targetStorePath = writeStore({

233+

"agent:main:feishu:direct:ou_user": {

234+

sessionId: "sess-ok",

235+

sessionFile: "sess-ok.jsonl",

236+

updatedAt: Date.now(),

237+

},

238+

});

239+240+

const result = await runFeishuDoctorSequence({

241+

cfg: feishuConfig(),

242+

env: process.env,

243+

shouldRepair: true,

244+

});

245+246+

expect(result.warningNotes).toEqual([]);

247+

expect(result.changeNotes.join("\n")).toContain("Rebuilt Feishu runtime state: yes");

248+

expect(result.changeNotes.join("\n")).toContain("Removed 0 Feishu-scoped session entries");

249+250+

const store = loadSessionStore(targetStorePath, { skipCache: true });

251+

expect(store["agent:main:feishu:direct:ou_user"]).toBeDefined();

252+

expect(fs.existsSync(transcriptPath)).toBe(true);

253+254+

expect(fs.existsSync(path.join(stateDir(), "feishu"))).toBe(true);

255+

expect(fs.existsSync(path.join(stateDir(), "feishu", "dedup", "default.json"))).toBe(false);

256+257+

const backups = listBackupDirs();

258+

expect(backups).toHaveLength(1);

259+

const backupDir = path.join(stateDir(), "backups", backups[0] ?? "");

260+

expect(fs.existsSync(path.join(backupDir, "feishu", "dedup", "default.json"))).toBe(true);

261+

expect(fs.existsSync(path.join(backupDir, "session-stores", "main", "sessions.json"))).toBe(

262+

false,

263+

);

264+

});

265+266+

it("archives only unhealthy Feishu direct sessions while preserving state, config, and other sessions", async () => {

267+

const feishuDedupDir = path.join(stateDir(), "feishu", "dedup");

268+

fs.mkdirSync(feishuDedupDir, { recursive: true });

269+

fs.writeFileSync(path.join(feishuDedupDir, "default.json"), JSON.stringify({ msg1: 1 }));

270+271+

const transcriptPath = writeTranscript("sess-bad", [

272+

sessionHeader("sess-bad"),

273+

userMessage(""),

274+

userMessage(""),

275+

userMessage(""),

276+

]);

277+

const trajectoryPath = path.join(sessionsDir(), "sess-bad.trajectory.jsonl");

278+

const trajectoryIndexPath = path.join(sessionsDir(), "sess-bad.trajectory-path.json");

279+

fs.writeFileSync(trajectoryPath, "{}\n");

280+

fs.writeFileSync(trajectoryIndexPath, "{}\n");

281+

const acpTranscriptPath = writeTranscript("sess-acp-bad", [

282+

sessionHeader("sess-acp-bad"),

283+

userMessage(""),

284+

userMessage(""),

285+

userMessage(""),

286+

]);

287+288+

const targetStorePath = writeStore({

289+

"agent:main:feishu:direct:ou_user": {

290+

sessionId: "sess-bad",

291+

sessionFile: "sess-bad.jsonl",

292+

updatedAt: Date.now(),

293+

},

294+

"agent:codex:acp:binding:feishu:default:abc123": {

295+

sessionId: "sess-acp-bad",

296+

sessionFile: "sess-acp-bad.jsonl",

297+

updatedAt: Date.now(),

298+

route: { channel: "feishu", target: { to: "ou_user", chatType: "direct" } },

299+

},

300+

"agent:main:discord:direct:user": {

301+

sessionId: "sess-discord",

302+

updatedAt: Date.now(),

303+

},

304+

});

305+306+

const result = await runFeishuDoctorSequence({

307+

cfg: feishuConfig(),

308+

env: process.env,

309+

shouldRepair: true,

310+

});

311+312+

expect(result.warningNotes).toEqual([]);

313+

expect(result.changeNotes.join("\n")).toContain("Feishu local state repaired");

314+

expect(result.changeNotes.join("\n")).toContain("Rebuilt Feishu runtime state: not needed");

315+

expect(result.changeNotes.join("\n")).toContain("Preserved Feishu App ID/secret config");

316+317+

expect(fs.existsSync(path.join(stateDir(), "feishu"))).toBe(true);

318+

expect(fs.existsSync(path.join(stateDir(), "feishu", "dedup", "default.json"))).toBe(true);

319+320+

const backups = listBackupDirs();

321+

expect(backups).toHaveLength(1);

322+

const backupDir = path.join(stateDir(), "backups", backups[0] ?? "");

323+

expect(fs.existsSync(path.join(backupDir, "feishu", "dedup", "default.json"))).toBe(false);

324+

expect(fs.existsSync(path.join(backupDir, "session-stores", "main", "sessions.json"))).toBe(

325+

true,

326+

);

327+328+

const store = loadSessionStore(targetStorePath, { skipCache: true });

329+

expect(store["agent:main:feishu:direct:ou_user"]).toBeUndefined();

330+

expect(store["agent:codex:acp:binding:feishu:default:abc123"]).toBeDefined();

331+

expect(store["agent:main:discord:direct:user"]).toBeDefined();

332+333+

expect(fs.existsSync(transcriptPath)).toBe(false);

334+

expect(fs.existsSync(acpTranscriptPath)).toBe(true);

335+

expect(fs.existsSync(trajectoryPath)).toBe(false);

336+

expect(fs.existsSync(trajectoryIndexPath)).toBe(false);

337+

const archivedNames = fs.readdirSync(sessionsDir());

338+

expect(archivedNames.some((name) => name.startsWith("sess-bad.jsonl.deleted."))).toBe(true);

339+

expect(

340+

archivedNames.some((name) => name.startsWith("sess-bad.trajectory.jsonl.deleted.")),

341+

).toBe(true);

342+

expect(

343+

archivedNames.some((name) => name.startsWith("sess-bad.trajectory-path.json.deleted.")),

344+

).toBe(true);

345+

});

346+347+

it("archives unhealthy default-scope sessions when metadata identifies Feishu", async () => {

348+

const transcriptPath = writeTranscript("sess-default-feishu-bad", [

349+

sessionHeader("sess-default-feishu-bad"),

350+

userMessage(""),

351+

userMessage(""),

352+

userMessage(""),

353+

]);

354+

const targetStorePath = writeStore({

355+

"agent:main:main": {

356+

sessionId: "sess-default-feishu-bad",

357+

sessionFile: "sess-default-feishu-bad.jsonl",

358+

updatedAt: Date.now(),

359+

origin: { provider: "feishu", from: "feishu:ou_user" },

360+

route: { channel: "feishu", target: { to: "ou_user", chatType: "direct" } },

361+

},

362+

"agent:main:main-non-feishu": {

363+

sessionId: "sess-other",

364+

updatedAt: Date.now(),

365+

origin: { provider: "discord" },

366+

},

367+

});

368+369+

const result = await runFeishuDoctorSequence({

370+

cfg: feishuConfig(),

371+

env: process.env,

372+

shouldRepair: true,

373+

});

374+375+

expect(result.warningNotes).toEqual([]);

376+

const store = loadSessionStore(targetStorePath, { skipCache: true });

377+

expect(store["agent:main:main"]).toBeUndefined();

378+

expect(store["agent:main:main-non-feishu"]).toBeDefined();

379+

expect(fs.existsSync(transcriptPath)).toBe(false);

380+

});

381+

});