test(javascript): consolidate semantic graph coverage

This commit is contained in:
morluto committed 2026-11-17 21:02:58 -05:00
1 parent e2e3881c0e
commit c77d4261a1
17 files changed
+684 -1098

No files matched your search

@@ -9,25 +9,21 @@ import { resolveJavaScriptSemanticEvidence } from "../../../tests/support/javasc
const SHA256 = "a".repeat(64);
const GRAPH_ID = `jag_${"b".repeat(64)}`;
it("projects literal events and exact timer cancellation", () => {
it("keeps literal event links and dynamic event uncertainty", () => {
const graph = graphFor(`
function run(bus, dynamicName) {
const handle = setInterval(tick, 10);
bus.on("ready", handler);
bus.once(dynamicName, handler);
bus.emit("ready");
bus.removeListener("ready", handler);
clearInterval(handle);
}
`);
const relations = new Set(graph.relations.map(({ relation }) => relation));
for (const expected of [
"cancels-timer",
"dispatches-candidate",
"registers-listener",
"removes-listener",
"schedules-timer",
] as const)
expect(relations.has(expected)).toBe(true);
expect(
@@ -45,9 +41,6 @@ it("projects literal events and exact timer cancellation", () => {
expect(
graph.coverage.families.find(({ family }) => family === "event"),
).toMatchObject({ status: "partial" });
expect(
graph.coverage.families.find(({ family }) => family === "timer"),
).toMatchObject({ status: "partial" });
});
it("projects child-process creation, I/O, listeners, and signals", () => {
@@ -65,32 +58,41 @@ it("projects child-process creation, I/O, listeners, and signals", () => {
}
`);
const relations = new Set(graph.relations.map(({ relation }) => relation));
for (const expected of [
"connects-stdio",
"forwards-signal",
"listens-error",
"listens-exit",
"spawns",
"supplies-argv",
"supplies-env",
] as const)
expect(relations.has(expected)).toBe(true);
const child = graph.nodes.find(({ kind }) => kind === "child-process");
if (child === undefined) throw new Error("Expected the spawned child");
expect(child.properties).toMatchObject({
method: "spawn",
command: null,
argv_count: 2,
environment_supplied: true,
stdio_mode: "pipe",
});
expect(
graph.nodes.find(
({ kind, properties }) =>
kind === "child-process" &&
properties.method === "spawn" &&
properties.command === null,
),
).toBeDefined();
graph.relations
.filter(({ target_node_id }) => target_node_id === child.node_id)
.map(({ relation }) => relation),
).toEqual(
expect.arrayContaining([
"forwards-signal",
"spawns",
"supplies-argv",
"supplies-env",
]),
);
expect(
graph.unknowns.some(
({ family, detail }) =>
family === "child-process" &&
detail.includes("command remains unresolved"),
),
).toBe(true);
graph.relations
.filter(({ source_node_id }) => source_node_id === child.node_id)
.map(({ relation }) => relation),
).toEqual(
expect.arrayContaining(["connects-stdio", "listens-error", "listens-exit"]),
);
expect(graph.unknowns).toContainEqual(
expect.objectContaining({
node_id: child.node_id,
family: "child-process",
detail: expect.stringContaining("command remains unresolved"),
}),
);
expect(
graph.coverage.families.find(({ family }) => family === "child-process"),
).toMatchObject({ status: "partial" });
@@ -231,18 +233,48 @@ it("projects built-in resource acquisition and release", () => {
).toMatchObject({ status: "partial" });
});
it.each(["+= 1", "++"])(
"projects both property dependencies for %s",
(operator) => {
const graph = graphFor(`
const source = { count: 1 };
source.count ${operator};
`);
const relations = graph.relations.map(({ relation }) => relation);
expect(relations).toContain("reads-property");
expect(relations).toContain("writes-property");
},
);
it("links the read and write of each update to the same property slot", () => {
const graph = graphFor(`
const source = { count: 1, total: 2 };
source.count += 1;
source.total++;
`);
for (const path of ["count", "total"]) {
const slot = graph.nodes.find(
({ kind, properties }) =>
kind === "property-slot" && properties.property_pointer === `/${path}`,
);
if (slot === undefined) throw new Error(`Expected the ${path} slot`);
const updates = graph.nodes.filter(
({ properties }) =>
Array.isArray(properties.property_path) &&
properties.property_path[0] === path,
);
const read = updates.find(
({ properties }) => properties.operation_kind === "read",
);
const write = updates.find(
({ properties }) => properties.operation_kind === "write",
);
if (read === undefined || write === undefined)
throw new Error(`Expected both operations for ${path}`);
expect(graph.relations).toEqual(
expect.arrayContaining([
expect.objectContaining({
relation: "reads-property",
source_node_id: slot.node_id,
target_node_id: read.node_id,
}),
expect.objectContaining({
relation: "writes-property",
source_node_id: write.node_id,
target_node_id: slot.node_id,
}),
]),
);
}
});
it("does not project a literal property slot for dynamic destructuring", () => {
const graph = graphFor(`
const source = { token: "TOKEN" };