test: guard transcript update mock call · openclaw/openclaw@c7d34ff
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -18,6 +18,11 @@ describe("appendAssistantMessageToSessionTranscript", () => {
|
18 | 18 | type ExactAssistantMessage = Parameters< |
19 | 19 | typeof appendExactAssistantMessageToSessionTranscript |
20 | 20 | >[0]["message"]; |
| 21 | +type TranscriptUpdateEmitterSpy = { |
| 22 | +mock: { |
| 23 | +calls: [string | SessionTranscriptUpdate][]; |
| 24 | +}; |
| 25 | +}; |
21 | 26 | |
22 | 27 | function writeTranscriptStore() { |
23 | 28 | fs.writeFileSync( |
@@ -58,6 +63,18 @@ describe("appendAssistantMessageToSessionTranscript", () => {
|
58 | 63 | }; |
59 | 64 | } |
60 | 65 | |
| 66 | +function requireTranscriptUpdateCall(spy: TranscriptUpdateEmitterSpy): SessionTranscriptUpdate { |
| 67 | +const call = spy.mock.calls.at(0); |
| 68 | +if (!call) { |
| 69 | +throw new Error("expected transcript update event"); |
| 70 | +} |
| 71 | +const event = call[0]; |
| 72 | +if (typeof event === "string") { |
| 73 | +throw new Error("expected structured transcript update event"); |
| 74 | +} |
| 75 | +return event; |
| 76 | +} |
| 77 | + |
61 | 78 | it("creates transcript file and appends message for valid session", async () => { |
62 | 79 | writeTranscriptStore(); |
63 | 80 | |
@@ -109,7 +126,7 @@ describe("appendAssistantMessageToSessionTranscript", () => {
|
109 | 126 | |
110 | 127 | const sessionFile = resolveSessionTranscriptPathInDir(sessionId, fixture.sessionsDir()); |
111 | 128 | expect(emitSpy).toHaveBeenCalledTimes(1); |
112 | | -const [event] = emitSpy.mock.calls[0] as [SessionTranscriptUpdate]; |
| 129 | +const event = requireTranscriptUpdateCall(emitSpy); |
113 | 130 | const message = event.message as |
114 | 131 | | { |
115 | 132 | role?: string; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。