test: guard thread ownership mock calls · openclaw/openclaw@f078d90
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -39,6 +39,14 @@ describe("thread-ownership plugin", () => {
|
39 | 39 | expect(init?.body).toBe(JSON.stringify({ agent_id: agentId })); |
40 | 40 | } |
41 | 41 | |
| 42 | +function requireFirstLogMessage(mock: ReturnType<typeof vi.fn>, label: string): string { |
| 43 | +const [call] = mock.mock.calls; |
| 44 | +if (!call || typeof call[0] !== "string") { |
| 45 | +throw new Error(`expected ${label}`); |
| 46 | +} |
| 47 | +return call[0]; |
| 48 | +} |
| 49 | + |
42 | 50 | beforeEach(() => { |
43 | 51 | vi.clearAllMocks(); |
44 | 52 | for (const key of Object.keys(hooks)) { |
@@ -256,8 +264,7 @@ describe("thread-ownership plugin", () => {
|
256 | 264 | const result = await sendSlackThreadMessage(); |
257 | 265 | |
258 | 266 | expect(result).toEqual({ cancel: true }); |
259 | | -const infoMessage = vi.mocked(api.logger.info).mock.calls[0]?.[0]; |
260 | | -expect(typeof infoMessage).toBe("string"); |
| 267 | +const infoMessage = requireFirstLogMessage(api.logger.info, "ownership cancel info log"); |
261 | 268 | expect(infoMessage).toContain("cancelled send"); |
262 | 269 | }); |
263 | 270 | |
@@ -267,8 +274,7 @@ describe("thread-ownership plugin", () => {
|
267 | 274 | const result = await sendSlackThreadMessage(); |
268 | 275 | |
269 | 276 | expect(result).toBeUndefined(); |
270 | | -const warningMessage = vi.mocked(api.logger.warn).mock.calls[0]?.[0]; |
271 | | -expect(typeof warningMessage).toBe("string"); |
| 277 | +const warningMessage = requireFirstLogMessage(api.logger.warn, "ownership check warning log"); |
272 | 278 | expect(warningMessage).toContain("ownership check failed"); |
273 | 279 | }); |
274 | 280 | }); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。