test: guard label generator mock calls · openclaw/openclaw@21a80ce
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -39,6 +39,14 @@ vi.mock("../../plugins/runtime/runtime-model-auth.runtime.js", () => ({
|
39 | 39 | |
40 | 40 | import { generateConversationLabel } from "./conversation-label-generator.js"; |
41 | 41 | |
| 42 | +function requireFirstMockCall<T>(mock: { mock: { calls: T[][] } }, label: string): T[] { |
| 43 | +const call = mock.mock.calls.at(0); |
| 44 | +if (!call) { |
| 45 | +throw new Error(`expected ${label} call`); |
| 46 | +} |
| 47 | +return call; |
| 48 | +} |
| 49 | + |
42 | 50 | describe("generateConversationLabel", () => { |
43 | 51 | beforeEach(() => { |
44 | 52 | completeSimple.mockReset(); |
@@ -108,10 +116,7 @@ describe("generateConversationLabel", () => {
|
108 | 116 | }); |
109 | 117 | |
110 | 118 | expect(completeSimple).toHaveBeenCalledOnce(); |
111 | | -const call = completeSimple.mock.calls[0]; |
112 | | -if (!call) { |
113 | | -throw new Error("expected simple completion call"); |
114 | | -} |
| 119 | +const call = requireFirstMockCall(completeSimple, "simple completion"); |
115 | 120 | expect(call[0]).toStrictEqual({ provider: "openai" }); |
116 | 121 | expect(call[1]).toStrictEqual({ |
117 | 122 | systemPrompt: "Generate a label", |
@@ -144,7 +149,7 @@ describe("generateConversationLabel", () => {
|
144 | 149 | }); |
145 | 150 | |
146 | 151 | expect(completeSimple).toHaveBeenCalledOnce(); |
147 | | -const options = completeSimple.mock.calls[0]?.[2]; |
| 152 | +const options = requireFirstMockCall(completeSimple, "simple completion")[2]; |
148 | 153 | if (!options) { |
149 | 154 | throw new Error("expected simple completion options"); |
150 | 155 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。