fix(javascript): qualify response consumers with uncertain receivers

This commit is contained in:
RRFZ authored and Ysopwnable committed 2026-11-21 21:10:51 +01:00
1 parent 286d599e9f
commit a8d714f0e3
3 files changed
+35 -4

No files matched your search

@@ -0,0 +1,29 @@
import { expect, it } from "vitest";
import { analyzeJavaScriptSemantics } from "./javascriptSemanticAnalysis.js";
const consumers = (source: string) =>
analyzeJavaScriptSemantics(source).requestOperations.filter(
({ kind }) => kind === "response-consumer",
);
it.each([
'let response = await fetch("data:text/plain,original"); response = {text: () => "replacement"}; response.text();',
'async function load(response) { response.text(); response = await fetch("data:text/plain,original"); }',
])(
"qualifies a response candidate when its request does not prove the receiver: %s",
(source) => {
const result = consumers(source);
expect(result).toMatchObject([{ endpoint: null, resolution: "partial" }]);
expect(result[0]?.linkedRequestIds).toHaveLength(1);
},
);
it("keeps a response whose request definitely reaches the read complete", () => {
expect(
consumers(
'async function load(response) { response = await fetch("data:text/plain,original"); response.text(); }',
),
).toMatchObject([
{ endpoint: "data:text/plain,original", resolution: "complete" },
]);
});