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

推荐订阅源

WordPress大学
WordPress大学
博客园 - 司徒正美
I
InfoQ
宝玉的分享
宝玉的分享
G
Google Developers Blog
J
Java Code Geeks
Martin Fowler
Martin Fowler
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
罗磊的独立博客
腾讯CDC
F
Fortinet All Blogs
A
About on SuperTechFans
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
B
Blog RSS Feed
博客园 - 聂微东
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
L
LangChain Blog
Microsoft Azure Blog
Microsoft Azure 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
test: tighten compact command assertions · openclaw/openc...
steipete · 2026-05-11 · via Recent Commits to openclaw:main

@@ -50,6 +50,40 @@ function buildCompactParams(

5050

} as unknown as HandleCommandsParams;

5151

}

525253+

function requireCompactEmbeddedPiSessionCall(index = 0) {

54+

const call = vi.mocked(compactEmbeddedPiSession).mock.calls[index]?.[0];

55+

if (!call) {

56+

throw new Error(`compactEmbeddedPiSession call ${index} missing`);

57+

}

58+

return call;

59+

}

60+61+

function requireResolveSessionAgentIdCall(index = 0) {

62+

const call = (

63+

resolveSessionAgentIdMock.mock.calls[index] as unknown as [unknown] | undefined

64+

)?.[0] as { sessionKey?: string; config?: OpenClawConfig } | undefined;

65+

if (!call) {

66+

throw new Error(`resolveSessionAgentId call ${index} missing`);

67+

}

68+

return call;

69+

}

70+71+

function requireResolveAgentDirCall(index = 0) {

72+

const call = resolveAgentDirMock.mock.calls[index] as [OpenClawConfig, string] | undefined;

73+

if (!call) {

74+

throw new Error(`resolveAgentDir call ${index} missing`);

75+

}

76+

return call;

77+

}

78+79+

function requireIncrementCompactionCountCall(index = 0) {

80+

const call = vi.mocked(incrementCompactionCount).mock.calls[index]?.[0];

81+

if (!call) {

82+

throw new Error(`incrementCompactionCount call ${index} missing`);

83+

}

84+

return call;

85+

}

86+5387

describe("handleCompactCommand", () => {

5488

beforeEach(() => {

5589

vi.clearAllMocks();

@@ -134,25 +168,22 @@ describe("handleCompactCommand", () => {

134168135169

expect(result?.shouldContinue).toBe(false);

136170

expect(vi.mocked(compactEmbeddedPiSession)).toHaveBeenCalledOnce();

137-

expect(vi.mocked(compactEmbeddedPiSession)).toHaveBeenCalledWith(

138-

expect.objectContaining({

139-

sessionId: "session-1",

140-

sessionKey: "agent:main:main",

141-

allowGatewaySubagentBinding: true,

142-

trigger: "manual",

143-

customInstructions: "focus on decisions",

144-

messageChannel: "whatsapp",

145-

groupId: "group-1",

146-

groupChannel: "#general",

147-

groupSpace: "workspace-1",

148-

spawnedBy: "agent:main:parent",

149-

senderId: "owner",

150-

senderName: "Alice",

151-

senderUsername: "alice_u",

152-

senderE164: "+15551234567",

153-

agentDir: "/tmp/openclaw-agent-compact",

154-

}),

155-

);

171+

const call = requireCompactEmbeddedPiSessionCall();

172+

expect(call.sessionId).toBe("session-1");

173+

expect(call.sessionKey).toBe("agent:main:main");

174+

expect(call.allowGatewaySubagentBinding).toBe(true);

175+

expect(call.trigger).toBe("manual");

176+

expect(call.customInstructions).toBe("focus on decisions");

177+

expect(call.messageChannel).toBe("whatsapp");

178+

expect(call.groupId).toBe("group-1");

179+

expect(call.groupChannel).toBe("#general");

180+

expect(call.groupSpace).toBe("workspace-1");

181+

expect(call.spawnedBy).toBe("agent:main:parent");

182+

expect(call.senderId).toBe("owner");

183+

expect(call.senderName).toBe("Alice");

184+

expect(call.senderUsername).toBe("alice_u");

185+

expect(call.senderE164).toBe("+15551234567");

186+

expect(call.agentDir).toBe("/tmp/openclaw-agent-compact");

156187

});

157188158189

it("uses the canonical session agent when resolving the compaction session file", async () => {

@@ -161,14 +192,15 @@ describe("handleCompactCommand", () => {

161192

compacted: false,

162193

});

163194

resolveSessionAgentIdMock.mockReturnValue("target");

195+

const cfg = {

196+

commands: { text: true },

197+

channels: { whatsapp: { allowFrom: ["*"] } },

198+

session: { store: "/tmp/openclaw-session-store.json" },

199+

} as OpenClawConfig;

164200165201

await handleCompactCommand(

166202

{

167-

...buildCompactParams("/compact", {

168-

commands: { text: true },

169-

channels: { whatsapp: { allowFrom: ["*"] } },

170-

session: { store: "/tmp/openclaw-session-store.json" },

171-

} as OpenClawConfig),

203+

...buildCompactParams("/compact", cfg),

172204

agentId: "main",

173205

sessionKey: "agent:target:whatsapp:direct:12345",

174206

sessionEntry: {

@@ -179,10 +211,10 @@ describe("handleCompactCommand", () => {

179211

true,

180212

);

181213182-

expect(resolveSessionAgentIdMock).toHaveBeenCalledWith({

183-

sessionKey: "agent:target:whatsapp:direct:12345",

184-

config: expect.any(Object),

185-

});

214+

expect(resolveSessionAgentIdMock).toHaveBeenCalledOnce();

215+

const resolveCall = requireResolveSessionAgentIdCall();

216+

expect(resolveCall.sessionKey).toBe("agent:target:whatsapp:direct:12345");

217+

expect(resolveCall.config).toBe(cfg);

186218

expect(vi.mocked(resolveSessionFilePathOptions)).toHaveBeenCalledWith({

187219

agentId: "target",

188220

storePath: undefined,

@@ -196,13 +228,14 @@ describe("handleCompactCommand", () => {

196228

});

197229

resolveSessionAgentIdMock.mockReturnValue("target");

198230

resolveAgentDirMock.mockReturnValue("/tmp/target-agent");

231+

const cfg = {

232+

commands: { text: true },

233+

channels: { whatsapp: { allowFrom: ["*"] } },

234+

} as OpenClawConfig;

199235200236

await handleCompactCommand(

201237

{

202-

...buildCompactParams("/compact", {

203-

commands: { text: true },

204-

channels: { whatsapp: { allowFrom: ["*"] } },

205-

} as OpenClawConfig),

238+

...buildCompactParams("/compact", cfg),

206239

agentId: "main",

207240

agentDir: "/tmp/main-agent",

208241

sessionKey: "agent:target:whatsapp:direct:12345",

@@ -214,12 +247,11 @@ describe("handleCompactCommand", () => {

214247

true,

215248

);

216249217-

expect(vi.mocked(compactEmbeddedPiSession)).toHaveBeenCalledWith(

218-

expect.objectContaining({

219-

agentDir: "/tmp/target-agent",

220-

}),

221-

);

222-

expect(resolveAgentDirMock).toHaveBeenCalledWith(expect.any(Object), "target");

250+

expect(requireCompactEmbeddedPiSessionCall().agentDir).toBe("/tmp/target-agent");

251+

expect(resolveAgentDirMock).toHaveBeenCalledOnce();

252+

const [configArg, agentIdArg] = requireResolveAgentDirCall();

253+

expect(configArg).toBe(cfg);

254+

expect(agentIdArg).toBe("target");

223255

});

224256225257

it("prefers the target session entry for compaction runtime metadata", async () => {

@@ -261,16 +293,13 @@ describe("handleCompactCommand", () => {

261293

true,

262294

);

263295264-

expect(vi.mocked(compactEmbeddedPiSession)).toHaveBeenCalledWith(

265-

expect.objectContaining({

266-

sessionId: "target-session",

267-

groupId: "target-group",

268-

groupChannel: "#target",

269-

groupSpace: "target-space",

270-

spawnedBy: "agent:target-parent",

271-

skillsSnapshot: { prompt: "target", skills: [] },

272-

}),

273-

);

296+

const call = requireCompactEmbeddedPiSessionCall();

297+

expect(call.sessionId).toBe("target-session");

298+

expect(call.groupId).toBe("target-group");

299+

expect(call.groupChannel).toBe("#target");

300+

expect(call.groupSpace).toBe("target-space");

301+

expect(call.spawnedBy).toBe("agent:target-parent");

302+

expect(call.skillsSnapshot).toEqual({ prompt: "target", skills: [] });

274303

});

275304276305

it("prefers the target session entry when incrementing compaction count", async () => {

@@ -306,13 +335,11 @@ describe("handleCompactCommand", () => {

306335

true,

307336

);

308337309-

expect(vi.mocked(incrementCompactionCount)).toHaveBeenCalledWith(

310-

expect.objectContaining({

311-

sessionEntry: expect.objectContaining({

312-

sessionId: "target-session",

313-

}),

314-

tokensAfter: 321,

315-

}),

316-

);

338+

const call = requireIncrementCompactionCountCall();

339+

if (!call.sessionEntry) {

340+

throw new Error("incrementCompactionCount sessionEntry missing");

341+

}

342+

expect(call.sessionEntry.sessionId).toBe("target-session");

343+

expect(call.tokensAfter).toBe(321);

317344

});

318345

});