
























@@ -21,6 +21,17 @@ afterEach(() => {
2121resetSystemEventsForTest();
2222});
232324+type HeartbeatReplyContext = {
25+Body?: string;
26+ForceSenderIsOwnerFalse?: boolean;
27+Provider?: string;
28+SessionKey?: string;
29+};
30+31+function replyCall(replySpy: { mock: { calls: unknown[][] } }, index = 0): HeartbeatReplyContext {
32+return (replySpy.mock.calls.at(index)?.at(0) ?? {}) as HeartbeatReplyContext;
33+}
34+2435describe("runHeartbeatOnce – isolated session key stability (#59493)", () => {
2536/**
2637 * Simulates the wake-request feedback loop:
@@ -58,7 +69,7 @@ describe("runHeartbeatOnce – isolated session key stability (#59493)", () => {
5869});
59706071expect(replySpy).toHaveBeenCalledTimes(1);
61-return replySpy.mock.calls[0]?.[0];
72+return replyCall(replySpy);
6273}
63746475function makeIsolatedHeartbeatConfig(tmpDir: string, storePath: string): OpenClawConfig {
@@ -134,7 +145,7 @@ describe("runHeartbeatOnce – isolated session key stability (#59493)", () => {
134145});
135146136147// Key must remain stable — no double :heartbeat suffix.
137-expect(replySpy.mock.calls[0]?.[0]?.SessionKey).toBe(`${baseSessionKey}:heartbeat`);
148+expect(replyCall(replySpy).SessionKey).toBe(`${baseSessionKey}:heartbeat`);
138149});
139150});
140151@@ -239,16 +250,8 @@ describe("runHeartbeatOnce – isolated session key stability (#59493)", () => {
239250});
240251241252expect(replySpy).toHaveBeenCalledTimes(2);
242-const firstCtx = replySpy.mock.calls[0]?.[0] as {
243-Body?: string;
244-Provider?: string;
245-SessionKey?: string;
246-};
247-const secondCtx = replySpy.mock.calls[1]?.[0] as {
248-Body?: string;
249-Provider?: string;
250-SessionKey?: string;
251-};
253+const firstCtx = replyCall(replySpy);
254+const secondCtx = replyCall(replySpy, 1);
252255253256expect(firstCtx.SessionKey).toBe(`${baseSessionKey}:heartbeat`);
254257expect(firstCtx.Provider).toBe("cron-event");
@@ -289,7 +292,7 @@ describe("runHeartbeatOnce – isolated session key stability (#59493)", () => {
289292},
290293});
291294292-expect(replySpy.mock.calls[0]?.[0]?.SessionKey).toBe(alreadyIsolatedKey);
295+expect(replyCall(replySpy).SessionKey).toBe(alreadyIsolatedKey);
293296});
294297});
295298@@ -327,11 +330,7 @@ describe("runHeartbeatOnce – isolated session key stability (#59493)", () => {
327330});
328331329332expect(result.status).toBe("ran");
330-const calledCtx = replySpy.mock.calls[0]?.[0] as {
331-SessionKey?: string;
332-Provider?: string;
333-ForceSenderIsOwnerFalse?: boolean;
334-};
333+const calledCtx = replyCall(replySpy);
335334expect(calledCtx.SessionKey).toBe(isolatedSessionKey);
336335expect(calledCtx.Provider).toBe("exec-event");
337336expect(calledCtx.ForceSenderIsOwnerFalse).toBe(true);
@@ -388,7 +387,7 @@ describe("runHeartbeatOnce – isolated session key stability (#59493)", () => {
388387});
389388390389expect(replySpy).toHaveBeenCalledTimes(1);
391-expect(replySpy.mock.calls[0]?.[0]?.SessionKey).toBe(isolatedSessionKey);
390+expect(replyCall(replySpy).SessionKey).toBe(isolatedSessionKey);
392391});
393392});
394393@@ -494,7 +493,7 @@ describe("runHeartbeatOnce – isolated session key stability (#59493)", () => {
494493});
495494496495// Must converge to the same canonical isolated key, not produce :heartbeat:heartbeat.
497-expect(replySpy.mock.calls[0]?.[0]?.SessionKey).toBe(legacyIsolatedKey);
496+expect(replyCall(replySpy).SessionKey).toBe(legacyIsolatedKey);
498497});
499498});
500499});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。