























@@ -79,6 +79,14 @@ describe("runBootOnce", () => {
7979});
8080};
818182+const requireAgentCall = () => {
83+const [call] = agentCommand.mock.calls[0] ?? [];
84+if (!call || typeof call !== "object") {
85+throw new Error("expected agent command call");
86+}
87+return call as Record<string, unknown>;
88+};
89+8290const expectMainSessionRestored = (params: {
8391storePath: string;
8492sessionKey: string;
@@ -135,12 +143,12 @@ describe("runBootOnce", () => {
135143});
136144137145expect(agentCommand).toHaveBeenCalledTimes(1);
138-const call = agentCommand.mock.calls.at(0)?.[0];
139-expect(call?.deliver).toBe(false);
140-expect(call?.sessionKey).toBe(resolveMainSessionKey({}));
141-expect(call?.message).toContain("BOOT.md:");
142-expect(call?.message).toContain(content);
143-expect(call?.message).toContain("NO_REPLY");
146+const call = requireAgentCall();
147+expect(call.deliver).toBe(false);
148+expect(call.sessionKey).toBe(resolveMainSessionKey({}));
149+expect(call.message).toContain("BOOT.md:");
150+expect(call.message).toContain(content);
151+expect(call.message).toContain("NO_REPLY");
144152});
145153});
146154@@ -165,8 +173,7 @@ describe("runBootOnce", () => {
165173});
166174167175expect(agentCommand).toHaveBeenCalledTimes(1);
168-const perAgentCall = agentCommand.mock.calls.at(0)?.[0];
169-expect(perAgentCall?.sessionKey).toBe(resolveAgentMainSessionKey({ cfg, agentId }));
176+expect(requireAgentCall().sessionKey).toBe(resolveAgentMainSessionKey({ cfg, agentId }));
170177});
171178});
172179@@ -180,10 +187,10 @@ describe("runBootOnce", () => {
180187});
181188182189expect(agentCommand).toHaveBeenCalledTimes(1);
183-const call = agentCommand.mock.calls.at(0)?.[0];
190+const call = requireAgentCall();
184191185192// Verify a boot-style session ID was generated (format: boot-YYYY-MM-DD_HH-MM-SS-xxx-xxxxxxxx)
186-expect(call?.sessionId).toMatch(
193+expect(call.sessionId).toMatch(
187194/^boot-\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}-\d{3}-[0-9a-f]{8}$/,
188195);
189196});
@@ -209,13 +216,13 @@ describe("runBootOnce", () => {
209216});
210217211218expect(agentCommand).toHaveBeenCalledTimes(1);
212-const call = agentCommand.mock.calls.at(0)?.[0];
219+const call = requireAgentCall();
213220214-expect(call?.sessionId).not.toBe(existingSessionId);
215-expect(call?.sessionId).toMatch(
221+expect(call.sessionId).not.toBe(existingSessionId);
222+expect(call.sessionId).toMatch(
216223/^boot-\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}-\d{3}-[0-9a-f]{8}$/,
217224);
218-expect(call?.sessionKey).toBe(sessionKey);
225+expect(call.sessionKey).toBe(sessionKey);
219226});
220227});
221228此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。