fix(replay): keep __proto__ own properties and reject symbol-keyed results (#540)

This commit is contained in:
morluto
2026-10-05 16:54:06 +08:00
committed by GitHub
parent 5b51fa01e2
commit 05bb630a00
2 changed files with 65 additions and 1 deletions
@@ -497,6 +497,53 @@ describe("deterministic replay Date compatibility", () => {
});
});
it("rejects results the JSON projection cannot represent faithfully", async () => {
const workerRequest = await request("parser.mjs", "esm", "default", []);
workerRequest.left.modules[0] = {
alias: "entry",
format: "esm",
dependencies: {},
source: "export default function () { return { a: 1, [Symbol('s')]: 2 }; }",
};
const result = await runWorker(workerRequest);
expect(JSON.parse(result.stdout)).toMatchObject({
left: [
{
outcome: "serialization_error",
exception: {
message: "Symbol-keyed replay results are unavailable",
},
},
],
});
});
it("keeps an own __proto__ property instead of mutating the output", async () => {
const workerRequest = await request("parser.mjs", "esm", "default", []);
workerRequest.left.modules[0] = {
alias: "entry",
format: "esm",
dependencies: {},
source: `export default function () {
const value = {};
Object.defineProperty(value, "__proto__", {
value: { injected: true },
enumerable: true,
});
return value;
}`,
};
const result = await runWorker(workerRequest);
expect(JSON.parse(result.stdout)).toMatchObject({
left: [
{
outcome: "return",
value: { __proto__: { injected: true } },
},
],
});
});
describe("replay determinism and builtin identity", () => {
const evaluate = async (
expression: string,