test: guard gateway shutdown mock calls · openclaw/openclaw@74d7c32
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -54,6 +54,14 @@ const { clearActiveSessionsForShutdownTracker, listActiveSessionsForShutdown } =
|
54 | 54 | |
55 | 55 | const cfg: OpenClawConfig = {}; |
56 | 56 | |
| 57 | +const requireSessionEndHookEvent = (index: number): SessionEndHookEvent => { |
| 58 | +const call = runSessionEndMock.mock.calls.at(index); |
| 59 | +if (!call) { |
| 60 | +throw new Error(`Expected session_end hook call ${index}`); |
| 61 | +} |
| 62 | +return call[0]; |
| 63 | +}; |
| 64 | + |
57 | 65 | beforeEach(() => { |
58 | 66 | clearActiveSessionsForShutdownTracker(); |
59 | 67 | runSessionEndMock.mockClear(); |
@@ -113,7 +121,7 @@ describe("drainActiveSessionsForShutdown", () => {
|
113 | 121 | await drainActiveSessionsForShutdown({ reason: "restart" }); |
114 | 122 | |
115 | 123 | expect(runSessionEndMock).toHaveBeenCalledTimes(1); |
116 | | -expect((runSessionEndMock.mock.calls[0][0] as { reason?: string }).reason).toBe("restart"); |
| 124 | +expect(requireSessionEndHookEvent(0).reason).toBe("restart"); |
117 | 125 | }); |
118 | 126 | |
119 | 127 | it("does not double-fire for a session already finalized by reset/delete/compaction", async () => { |
@@ -144,7 +152,7 @@ describe("drainActiveSessionsForShutdown", () => {
|
144 | 152 | await drainActiveSessionsForShutdown({ reason: "shutdown" }); |
145 | 153 | |
146 | 154 | expect(runSessionEndMock).toHaveBeenCalledTimes(1); |
147 | | -expect((runSessionEndMock.mock.calls[0][0] as { sessionId?: string }).sessionId).toBe("sess-B"); |
| 155 | +expect(requireSessionEndHookEvent(0).sessionId).toBe("sess-B"); |
148 | 156 | }); |
149 | 157 | |
150 | 158 | it("awaits each session_end handler so the bounded timeout actually races real plugin work", async () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。