Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(process): preserve replay event causality

morlutod895e4914522
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<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));
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 });
}