fix(javascript): preserve semantic query identity and source coverage

This commit is contained in:
morluto
2026-10-24 02:52:47 +08:00
parent 34552ff0df
commit cf5e4f6fa3
16 changed files with 362 additions and 51 deletions
@@ -48,8 +48,17 @@ export const resolveJavaScriptSemanticQuerySeeds = (
.map(({ function_node_id }) => function_node_id)
: [],
);
const unresolvedAccesses = new Set(
input.seed.kind === "property"
? graph.unknowns.flatMap(({ family, node_id }) =>
family === "object-flow" && node_id !== null ? [node_id] : [],
)
: [],
);
return graph.nodes
.filter((node) => seedMatches(node, input, fingerprintFunctions))
.filter((node) =>
seedMatches(node, input, fingerprintFunctions, unresolvedAccesses),
)
.map(({ node_id }) => node_id)
.sort(compareUnicodeCodePoints);
};
@@ -58,6 +67,7 @@ const seedMatches = (
node: JavaScriptSemanticGraphNode,
input: JavaScriptSemanticQueryInput,
fingerprintFunctions: ReadonlySet<string>,
unresolvedAccesses: ReadonlySet<string>,
): boolean => {
const seed = input.seed;
if (seed.kind === "semantic-node") return node.node_id === seed.node_id;
@@ -66,8 +76,20 @@ const seedMatches = (
if (seed.kind === "function") return fingerprintFunctions.has(node.node_id);
if (seed.kind === "literal")
return node.kind === "literal" && node.properties.value === seed.value;
if (seed.kind === "property")
return node.kind === "property-slot" && node.properties.name === seed.name;
if (seed.kind === "property") {
if (node.kind === "property-slot")
return node.properties.name === seed.name;
if (node.kind !== "expression") return false;
const path = node.properties.property_path;
// Older retained graphs did not record slot resolution. Their existing
// source-bound unknown establishes an unresolved access without guessing
// from an absent or resource-omitted relation.
const slotless =
node.properties.property_slot_resolution === "unresolved" ||
(node.properties.property_slot_resolution === undefined &&
unresolvedAccesses.has(node.node_id));
return slotless && Array.isArray(path) && path.at(-1) === seed.name;
}
if (seed.kind === "endpoint")
return (
(node.kind === "request" || node.kind === "response") &&