From 044c0a92d5c86faa9965669680935d4f552977b1 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sun, 11 Oct 2026 18:15:57 +0800 Subject: [PATCH] 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. --- .../applicationWorkflowCli.test.ts | 8 +- .../javascriptExportShapeComparison.test.ts | 81 ++++++++++--------- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/tests/acceptance/applications/applicationWorkflowCli.test.ts b/tests/acceptance/applications/applicationWorkflowCli.test.ts index 9cf63147a..065101ed8 100644 --- a/tests/acceptance/applications/applicationWorkflowCli.test.ts +++ b/tests/acceptance/applications/applicationWorkflowCli.test.ts @@ -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 }) => diff --git a/tests/boundary/filesystem/javascriptExportShapeComparison.test.ts b/tests/boundary/filesystem/javascriptExportShapeComparison.test.ts index e4cbfcc30..97090c029 100644 --- a/tests/boundary/filesystem/javascriptExportShapeComparison.test.ts +++ b/tests/boundary/filesystem/javascriptExportShapeComparison.test.ts @@ -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" },