test: reuse application analysis across comparison directions

Reuse immutable source graphs for both export comparison orientations and obtain rest-argument seeds from the existing public CLI Evidence. Retain all direction-specific assertions while removing nine repeated application analyses.

Validation: 75 focused tests; covered locations and hit status unchanged across all 1137 source files in controlled before/after coverage runs. Comparison file execution fell from 19.2s to 15.3s locally. Static and generated-document checks passed.
This commit is contained in:
morluto
2026-10-11 18:15:57 +08:00
parent e90acaea67
commit 044c0a92d5
2 changed files with 48 additions and 41 deletions
@@ -694,11 +694,9 @@ describe("rest parameter semantic trace CLI", () => {
root,
"--json",
]);
const analyzed = await analyzeJavaScriptApplication({ input_path: root });
if (!analyzed.ok) throw analyzed.error;
const graph = javascriptApplicationAnalysisResultSchema.parse(
analyzed.value.normalized_result,
).semantic_graph;
const graph = z
.object({ normalized_result: javascriptApplicationAnalysisResultSchema })
.parse(application).normalized_result.semantic_graph;
for (const index of [1, 2]) {
const argument = graph.nodes.find(
({ kind, label }) =>
@@ -260,36 +260,52 @@ describe("JavaScript export return-shape pairing limits", () => {
});
describe("JavaScript export return-shape uncertain presence", () => {
it.each([false, true])(
"keeps deleted property presence unknown (reversed: %s)",
async (reversed) => {
const plain = 'export default () => ({ kind: "result" });';
const mutated = `export default function make() {
it("keeps deleted property presence unknown in both comparison directions", async () => {
const plain = 'export default () => ({ kind: "result" });';
const mutated = `export default function make() {
const result = { kind: "result", count: 1 };
delete result.count;
return result;
}`;
const graphs = await analyzeSources({
left: reversed ? mutated : plain,
right: reversed ? plain : mutated,
});
const result = compare(...graphs);
expect(result.changes).toContainEqual(
const graphs = await analyzeSources({ left: plain, right: mutated });
for (const direction of [
{
name: "plain to deleted-property source",
result: compare(...graphs),
presence: { left: "absent", right: "unknown-coverage" },
inventorySide: "right" as const,
},
{
name: "deleted-property to plain source",
result: compare(graphs[1], graphs[0]),
presence: { left: "unknown-coverage", right: "absent" },
inventorySide: "left" as const,
},
]) {
expect(
direction.result.changes,
`${direction.name}: /count change`,
).toContainEqual(
expect.objectContaining({
path: "/count",
status: "unknown",
presence: reversed
? { left: "unknown-coverage", right: "absent" }
: { left: "absent", right: "unknown-coverage" },
presence: direction.presence,
}),
);
expect(
inventoryProperties(result, reversed ? "left" : "right", 0),
inventoryProperties(direction.result, direction.inventorySide, 0),
`${direction.name}: uncertain count inventory`,
).not.toContain("/count");
expect(result.summary.added + result.summary.removed).toBe(0);
expect(result.coverage.status).toBe("partial");
},
);
expect(
direction.result.summary.added + direction.result.summary.removed,
`${direction.name}: added/removed summary`,
).toBe(0);
expect(
direction.result.coverage.status,
`${direction.name}: coverage`,
).toBe("partial");
}
});
it("excludes array holes while preserving observed unknown elements", async () => {
const holes = 'export default () => ({ kind: "result", items: [,] });';
@@ -750,35 +766,28 @@ describe("JavaScript export return-shape property presence", () => {
describe("JavaScript export return-shape container presence", () => {
it.each(["{}", "[]", "{ nested: 1 }"])(
"does not report a retained %s container property as removed",
"does not report a retained %s container property as added or removed",
async (container) => {
const graphs = await analyzeSources({
left: 'export default () => ({ type: "item", options: false });',
right: `export default () => ({ type: "item", options: ${container} });`,
});
const result = compare(...graphs);
const change = result.changes.find(({ path }) => path === "/options");
expect(change).toMatchObject({
const forward = compare(...graphs);
const reverse = compare(graphs[1], graphs[0]);
expect(
forward.changes.find(({ path }) => path === "/options"),
`${container}: primitive to container`,
).toMatchObject({
status: "unknown",
left: { availability: "literal", value: false },
right: { availability: "unknown" },
});
expect(() =>
javaScriptExportShapeComparisonResultSchema.parse(result),
javaScriptExportShapeComparisonResultSchema.parse(forward),
).not.toThrow();
},
);
it.each(["{}", "[]", "{ nested: 1 }"])(
"does not report a retained %s container becoming a primitive as added",
async (container) => {
const graphs = await analyzeSources({
left: `export default () => ({ type: "item", options: ${container} });`,
right: 'export default () => ({ type: "item", options: false });',
});
const result = compare(...graphs);
expect(
result.changes.find(({ path }) => path === "/options"),
reverse.changes.find(({ path }) => path === "/options"),
`${container}: container to primitive`,
).toMatchObject({
status: "unknown",
left: { availability: "unknown" },