Skip to content

armgit / rea

Public Imported from GitHub
0

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

fix(replay): preserve sparse array positions in result projection (#522)

Rudy Mizrahi Celekli9d1c3631b8de
diff --git a/src/replay/JavaScriptReplayWorker.ts b/src/replay/JavaScriptReplayWorker.ts
index e0056b7eb..2af759e8d 100644
--- a/src/replay/JavaScriptReplayWorker.ts
+++ b/src/replay/JavaScriptReplayWorker.ts
@@ -434,6 +434,17 @@ const projectComplexValue = (
);
}
}
+ if (Array.isArray(candidate) && Array.isArray(output)) {
+ for (let index = 0; index < candidate.length; index += 1) {
+ if (Object.hasOwn(descriptors, String(index))) continue;
+ output[index] = projectValueRecursive(
+ null,
+ depth + 1,
+ ancestors,
+ context,
+ );
+ }
+ }
return output;
};
diff --git a/tests/boundary/providers/replay/javascriptReplayWorker.test.ts b/tests/boundary/providers/replay/javascriptReplayWorker.test.ts
index ee7263fe8..dce65a6d3 100644
--- a/tests/boundary/providers/replay/javascriptReplayWorker.test.ts
+++ b/tests/boundary/providers/replay/javascriptReplayWorker.test.ts
@@ -225,3 +225,48 @@ describe("disposable JavaScript replay worker", () => {
});
});
});
+
+describe("replay array projection", () => {
+ it.each([
+ ["Array(3)", [null, null, null]],
+ [
+ "(() => { const value = Array(3); value[1] = 42; return value; })()",
+ [null, 42, null],
+ ],
+ ["[1, null, 3]", [1, null, 3]],
+ ["[]", []],
+ ])("preserves JSON array positions for %s", async (expression, expected) => {
+ const workerRequest = await request("parser.mjs", "esm", "default", []);
+ workerRequest.left.modules[0] = {
+ alias: "entry",
+ format: "esm",
+ dependencies: {},
+ source: `export default function () { return ${expression}; }`,
+ };
+ const result = await runWorker(workerRequest);
+ expect(result.code).toBe(0);
+ expect(JSON.parse(result.stdout)).toMatchObject({
+ left: [{ outcome: "return", value: expected }],
+ });
+ });
+
+ it("accounts for holes in the existing result node budget", async () => {
+ const workerRequest = await request("parser.mjs", "esm", "default", []);
+ workerRequest.left.modules[0] = {
+ alias: "entry",
+ format: "esm",
+ dependencies: {},
+ source: "export default function () { return Array(4); }",
+ };
+ workerRequest.limits.resultNodes = 3;
+ const result = await runWorker(workerRequest);
+ expect(JSON.parse(result.stdout)).toMatchObject({
+ left: [
+ {
+ outcome: "serialization_error",
+ exception: { message: "Replay result projection limit exceeded" },
+ },
+ ],
+ });
+ });
+});