fix(process): preserve replay event causality
This commit is contained in:
parent
6d8ecd2b88
commit
d895e49145
|
|
@ -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<ProtocolEvent, "sequence">): void {
|
||||
|
|
@ -117,12 +119,14 @@ export const recordMachineEvent = (
|
|||
recorder: ReplayRecorder,
|
||||
event: Omit<ProtocolEvent, "sequence" | "outcome">,
|
||||
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<void> =>
|
||||
new Promise((resolveDelay) => setTimeout(resolveDelay, durationMs));
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue