test: guard session store write mock call · openclaw/openclaw@e9d13cb
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -20,6 +20,19 @@ import { clearSessionStoreCacheForTest, loadSessionStore, updateSessionStore } f
|
20 | 20 | import { useTempSessionsFixture } from "./test-helpers.js"; |
21 | 21 | import { mergeSessionEntry, mergeSessionEntryWithPolicy, type SessionEntry } from "./types.js"; |
22 | 22 | |
| 23 | +type WriteTextAtomicCall = Parameters<typeof jsonFiles.writeTextAtomic>; |
| 24 | + |
| 25 | +function requireWriteTextAtomicCall( |
| 26 | +spy: { mock: { calls: WriteTextAtomicCall[] } }, |
| 27 | +callIndex = 0, |
| 28 | +): WriteTextAtomicCall { |
| 29 | +const call = spy.mock.calls.at(callIndex); |
| 30 | +if (!call) { |
| 31 | +throw new Error(`expected writeTextAtomic call ${callIndex}`); |
| 32 | +} |
| 33 | +return call; |
| 34 | +} |
| 35 | + |
23 | 36 | describe("session path safety", () => { |
24 | 37 | it("rejects unsafe session IDs", () => { |
25 | 38 | const unsafeSessionIds = [ |
@@ -346,7 +359,7 @@ describe("session store writer queue", () => {
|
346 | 359 | ); |
347 | 360 | |
348 | 361 | expect(writeSpy).toHaveBeenCalledTimes(1); |
349 | | -const [writtenPath, writtenText, writeOptions] = writeSpy.mock.calls[0] ?? []; |
| 362 | +const [writtenPath, writtenText, writeOptions] = requireWriteTextAtomicCall(writeSpy); |
350 | 363 | expect(writtenPath).toBe(storePath); |
351 | 364 | expect(writtenText).toBeTypeOf("string"); |
352 | 365 | expect(writeOptions?.durable).toBe(false); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。