From d895e49145222eb02eb34cd7de93c5212884f5cc Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Wed, 22 Jul 2026 20:42:57 +0000 Subject: [PATCH] fix(process): preserve replay event causality --- src/application/LoopbackReplayRecorder.ts | 10 +++++++--- tests/processCapture.test.ts | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/application/LoopbackReplayRecorder.ts b/src/application/LoopbackReplayRecorder.ts index d676ab434..74736cba9 100644 --- a/src/application/LoopbackReplayRecorder.ts +++ b/src/application/LoopbackReplayRecorder.ts @@ -70,10 +70,12 @@ export class ReplayRecorder { ): ReplayMachineDecision { if (this.machine === undefined) throw new Error("replay machine is not configured"); - const decision = this.machine.dispatch(event); + return this.machine.dispatch(event); + } + + recordTransition(decision: ReplayMachineDecision): void { if (decision.transition !== null) this.recordEvent("replay_transitions", decision.transition.sequence); - return decision; } record(event: Omit): void { @@ -117,12 +119,14 @@ export const recordMachineEvent = ( recorder: ReplayRecorder, event: Omit, decision: ReplayMachineDecision, -): void => +): void => { recorder.record({ ...event, data: recorder.machine?.redact(event.data) ?? event.data, outcome: decision.outcome, }); + recorder.recordTransition(decision); +}; export const waitForReplayDelay = (durationMs: number): Promise => new Promise((resolveDelay) => setTimeout(resolveDelay, durationMs)); diff --git a/tests/processCapture.test.ts b/tests/processCapture.test.ts index f67eaa5de..f3f2b2db2 100644 --- a/tests/processCapture.test.ts +++ b/tests/processCapture.test.ts @@ -1400,6 +1400,13 @@ describe("process capture adapter", () => { ({ collection }) => collection === "replay_transitions", ), ).toHaveLength(capture.value.replay_transitions.length); + for (const [index, entry] of ( + capture.value.event_journal ?? [] + ).entries()) + if (entry.collection === "replay_transitions") + expect(capture.value.event_journal?.[index - 1]?.collection).toBe( + "protocol_events", + ); } finally { await rm(root, { recursive: true, force: true }); }