diff --git a/src/application/javascript/JavaScriptArtifactPathResolution.test.ts b/src/application/javascript/JavaScriptArtifactPathResolution.test.ts index b8f3a9f3dd6..2b7f4c1b115 100644 --- a/src/application/javascript/JavaScriptArtifactPathResolution.test.ts +++ b/src/application/javascript/JavaScriptArtifactPathResolution.test.ts @@ -15,6 +15,10 @@ const completeInventoryCoverage = { status: "complete", } as const; +const unresolvedPath = ( + status: "not-found" | "unavailable" | "external" | "rejected", +) => ({ resolution_status: status, resolved_path: null }); + describe("incomplete inventory lookups", () => { it.each(["complete", "unknown"] as const)( "qualifies missing candidates before extension fallbacks under %s traversal", @@ -68,10 +72,9 @@ describe("incomplete inventory lookups", () => { files, unanalyzedFiles, }), - ).toMatchObject({ - resolution_status: status === "complete" ? "not-found" : "unavailable", - resolved_path: null, - }); + ).toMatchObject( + unresolvedPath(status === "complete" ? "not-found" : "unavailable"), + ); }, ); }); @@ -290,7 +293,7 @@ describe("literal POSIX inventory base segments", () => { moduleKind: "import", files: fileMap([file("literal\\dir/b.js", "container")]), }), - ).toMatchObject({ resolution_status: "rejected", resolved_path: null }); + ).toMatchObject(unresolvedPath("rejected")); }, ); @@ -310,10 +313,7 @@ describe("literal POSIX inventory base segments", () => { moduleKind: "import", files: fileMap([file("literal\\dir/b.js", "container")]), }), - ).toMatchObject({ - resolution_status: "rejected", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("rejected")); }, ); }); @@ -335,10 +335,7 @@ describe("runtime host path classification", () => { moduleKind: "import", files: new Map(), }), - ).toMatchObject({ - resolution_status: "unavailable", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("unavailable")); }, ); it("retains unknown URL identity for an unpaired source directory segment", () => { @@ -350,7 +347,7 @@ describe("runtime host path classification", () => { moduleKind: "import", files: new Map(), }), - ).toMatchObject({ resolution_status: "unavailable", resolved_path: null }); + ).toMatchObject(unresolvedPath("unavailable")); }); it.each([ "/shared%2Fwindow.mjs", @@ -368,7 +365,7 @@ describe("runtime host path classification", () => { moduleKind: "import", files: new Map(), }), - ).toMatchObject({ resolution_status: "rejected", resolved_path: null }); + ).toMatchObject(unresolvedPath("rejected")); expect( resolve({ declaredPath, @@ -377,10 +374,7 @@ describe("runtime host path classification", () => { moduleKind: "require", files: new Map(), }), - ).toMatchObject({ - resolution_status: "unavailable", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("unavailable")); }, ); it("keeps encoded query bytes outside ESM pathname admission", () => { @@ -392,7 +386,7 @@ describe("runtime host path classification", () => { moduleKind: "import", files: new Map(), }), - ).toMatchObject({ resolution_status: "unavailable", resolved_path: null }); + ).toMatchObject(unresolvedPath("unavailable")); }); it.each(["exact-file", "application-file", "node-entrypoint"] as const)( "keeps POSIX and Windows absolute %s paths unavailable before canonical admission", @@ -429,7 +423,7 @@ describe("runtime host path classification", () => { runtimePathKind, files: new Map(), }), - ).toMatchObject({ resolution_status: "rejected", resolved_path: null }); + ).toMatchObject(unresolvedPath("rejected")); }, ); }); @@ -463,7 +457,7 @@ describe("artifact URI scheme classification", () => { moduleKind: "require", files, }), - ).toMatchObject({ resolution_status: "external", resolved_path: null }); + ).toMatchObject(unresolvedPath("external")); expect( resolve({ declaredPath, @@ -521,7 +515,7 @@ describe("artifact URI scheme classification", () => { context, files, }), - ).toMatchObject({ resolution_status: "external", resolved_path: null }); + ).toMatchObject(unresolvedPath("external")); }, ); @@ -538,7 +532,7 @@ describe("artifact URI scheme classification", () => { htmlBaseHref: "web3:assets/", files, }), - ).toMatchObject({ resolution_status: "external", resolved_path: null }); + ).toMatchObject(unresolvedPath("external")); }); }); @@ -634,7 +628,7 @@ describe("loader-specific module suffix lookup", () => { moduleKind: "import", files, }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); } expect( resolve({ @@ -660,7 +654,7 @@ describe("loader-specific module suffix lookup", () => { moduleKind: "require", files, }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); expect( resolve({ declaredPath: "./feature.cjs", @@ -717,7 +711,7 @@ describe("loader-specific module suffix lookup", () => { files, unanalyzedFiles, }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); expect( resolve({ declaredPath: "./core.jsc", @@ -736,7 +730,7 @@ describe("loader-specific module suffix lookup", () => { : undefined, }, }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); }); }); @@ -822,7 +816,7 @@ describe("unavailable package metadata", () => { files, unanalyzedFiles: lookup, }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); const restoredFiles = fileMap([ ...files.values(), @@ -930,7 +924,7 @@ describe("bare package root file lookup", () => { moduleKind: "import", files: packageDirectory, }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); expect( resolve({ declaredPath: "fixture", @@ -968,7 +962,7 @@ describe("legacy package main lookup", () => { moduleKind, files, }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); }, ); }); @@ -1017,7 +1011,7 @@ describe("legacy package main metadata validation and fallback", () => { file("app/package/index.js", "root"), ]), }), - ).toMatchObject({ resolution_status: "unavailable", resolved_path: null }); + ).toMatchObject(unresolvedPath("unavailable")); }); }); @@ -1052,10 +1046,9 @@ describe("CommonJS bare package ancestor lookup", () => { resolution_status: "resolved", resolved_path: "app/node_modules/fixture/index.js", }); - expect(resolve({ ...input, moduleKind: "import" })).toMatchObject({ - resolution_status: "not-found", - resolved_path: null, - }); + expect(resolve({ ...input, moduleKind: "import" })).toMatchObject( + unresolvedPath("not-found"), + ); }, ); }); @@ -1135,7 +1128,7 @@ describe("CommonJS bare package exhausted lookup", () => { moduleKind: "require", files, }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); }, ); }); @@ -1166,7 +1159,7 @@ describe("logical path identity", () => { context: "module-specifier", files, }), - ).toMatchObject({ resolution_status: "rejected", resolved_path: null }); + ).toMatchObject(unresolvedPath("rejected")); }); }); @@ -1219,10 +1212,9 @@ describe("contextual JavaScript artifact path resolution", () => { resolution_status: "resolved", resolved_path: "app/preload.js", }); - expect(resolve({ ...base, context: "module-specifier" })).toMatchObject({ - resolution_status: "external", - resolved_path: null, - }); + expect(resolve({ ...base, context: "module-specifier" })).toMatchObject( + unresolvedPath("external"), + ); }); it.each(["node:fs", "electron", "../../escape.js", "%2e%2e/escape.js"])( @@ -1253,7 +1245,7 @@ describe("contextual JavaScript artifact path resolution", () => { context: "filesystem-expression", files, }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); }); it("resolves an inventoried path of more than 5,000 characters", () => { @@ -1361,7 +1353,7 @@ describe("JavaScript file URL resolution", () => { moduleKind: "import", files, }), - ).toMatchObject({ resolution_status: "rejected", resolved_path: null }); + ).toMatchObject(unresolvedPath("rejected")); } expect( @@ -1372,7 +1364,7 @@ describe("JavaScript file URL resolution", () => { moduleKind: "import", files, }), - ).toMatchObject({ resolution_status: "unavailable", resolved_path: null }); + ).toMatchObject(unresolvedPath("unavailable")); }); }); @@ -1502,7 +1494,7 @@ describe("contextual JavaScript package path resolution", () => { moduleKind: "require", files, }), - ).toMatchObject({ resolution_status: "external", resolved_path: null }); + ).toMatchObject(unresolvedPath("external")); expect( resolve({ declaredPath: "fixture/hidden.js", @@ -1626,10 +1618,7 @@ describe("scoped package directory and specifier resolution", () => { moduleKind: "require", files, }), - ).toMatchObject({ - resolution_status: "external", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("external")); // ESM import "@scope" without trailing slash is an invalid module specifier expect( @@ -1640,10 +1629,7 @@ describe("scoped package directory and specifier resolution", () => { moduleKind: "import", files, }), - ).toMatchObject({ - resolution_status: "external", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("external")); // ESM import "@scope/" with trailing slash resolves root exports expect( @@ -1668,10 +1654,7 @@ describe("scoped package directory and specifier resolution", () => { moduleKind: "require", files, }), - ).toMatchObject({ - resolution_status: "external", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("external")); expect( resolve({ @@ -1681,10 +1664,7 @@ describe("scoped package directory and specifier resolution", () => { moduleKind: "require", files, }), - ).toMatchObject({ - resolution_status: "external", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("external")); }); }); @@ -1954,10 +1934,7 @@ describe("package subpath directory ownership", () => { moduleKind: "require", files, }), - ).toMatchObject({ - resolution_status: "not-found", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("not-found")); }); }); @@ -2098,10 +2075,7 @@ describe("package exports exact targets", () => { moduleKind, files, }); - expect(resolution).toMatchObject({ - resolution_status: "not-found", - resolved_path: null, - }); + expect(resolution).toMatchObject(unresolvedPath("not-found")); expect(resolution.limitations.join(" ")).toContain( "exports targets are exact files", ); @@ -2172,10 +2146,7 @@ describe("package import alias resolution", () => { moduleKind: "require", files, }); - expect(outcome).toMatchObject({ - resolution_status: "external", - resolved_path: null, - }); + expect(outcome).toMatchObject(unresolvedPath("external")); expect(outcome.limitations.join(" ")).toContain( "node_modules/fixture/package.json", ); @@ -2259,10 +2230,7 @@ describe("package import alias refusals", () => { moduleKind: "import", files, }); - expect(outcome).toMatchObject({ - resolution_status: "unavailable", - resolved_path: null, - }); + expect(outcome).toMatchObject(unresolvedPath("unavailable")); expect(outcome.limitations.join(" ")).toMatch(/wildcard/i); }); @@ -2288,15 +2256,9 @@ describe("package import alias refusals", () => { moduleKind: "require", files, }); - expect(recursive).toMatchObject({ - resolution_status: "unavailable", - resolved_path: null, - }); + expect(recursive).toMatchObject(unresolvedPath("unavailable")); expect(recursive.limitations.join(" ")).toMatch(/recursive/i); - expect(external).toMatchObject({ - resolution_status: "unavailable", - resolved_path: null, - }); + expect(external).toMatchObject(unresolvedPath("unavailable")); expect(external.limitations.join(" ")).toMatch(/external-package/i); }); @@ -2316,7 +2278,7 @@ describe("package import alias refusals", () => { moduleKind: "import", files, }), - ).toMatchObject({ resolution_status: "rejected", resolved_path: null }); + ).toMatchObject(unresolvedPath("rejected")); }); it("does not use a foreign-container enclosing package.json", () => { @@ -2336,10 +2298,7 @@ describe("package import alias refusals", () => { moduleKind: "require", files, }); - expect(outcome).toMatchObject({ - resolution_status: "unavailable", - resolved_path: null, - }); + expect(outcome).toMatchObject(unresolvedPath("unavailable")); expect(outcome.limitations.join(" ")).toContain("container boundary"); }); }); @@ -2412,10 +2371,7 @@ describe("directory package entrypoint precedence", () => { moduleKind: "require", files, }), - ).toMatchObject({ - resolution_status: "unavailable", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("unavailable")); }, ); @@ -2437,10 +2393,7 @@ describe("directory package entrypoint precedence", () => { moduleKind: "require", files, }), - ).toMatchObject({ - resolution_status: "not-found", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("not-found")); }); it("keeps direct files ahead of a relative directory package", () => { @@ -2546,7 +2499,7 @@ describe("TypeScript declaration fallback ownership", () => { file("src/dep.ts", container), ]), }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); }); it("does not apply the mapping to URL resources or package export targets", () => { @@ -2561,7 +2514,7 @@ describe("TypeScript declaration fallback ownership", () => { context: "url-reference", files: urlFiles, }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); const packageFiles = fileMap([ file("src/main.ts", container), @@ -2580,7 +2533,7 @@ describe("TypeScript declaration fallback ownership", () => { moduleKind: "import", files: packageFiles, }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); }); it("does not substitute source counterparts for directory or index resolution", () => { @@ -2596,7 +2549,7 @@ describe("TypeScript declaration fallback ownership", () => { moduleKind: "import", files, }), - ).toMatchObject({ resolution_status: "not-found", resolved_path: null }); + ).toMatchObject(unresolvedPath("not-found")); }); it("resolves an emitted dotfile name within its own directory", () => { @@ -2860,10 +2813,7 @@ describe("url-reference JavaScript artifact path resolution", () => { context: "url-reference", files, }), - ).toMatchObject({ - resolution_status: "external", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("external")); expect( resolve({ declaredPath: "https://cdn.example.com/app.js.map", @@ -2871,10 +2821,7 @@ describe("url-reference JavaScript artifact path resolution", () => { context: "url-reference", files, }), - ).toMatchObject({ - resolution_status: "external", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("external")); }); }); @@ -2989,7 +2936,7 @@ describe("module-backed package main host paths", () => { file("app/node_modules/fixture/index.js", "root"), ]), }), - ).toMatchObject({ resolution_status: "rejected", resolved_path: null }); + ).toMatchObject(unresolvedPath("rejected")); }, ); }); @@ -3090,7 +3037,7 @@ it.each(["require", "import"] as const)( moduleKind, files, }), - ).toMatchObject({ resolution_status: "unavailable", resolved_path: null }); + ).toMatchObject(unresolvedPath("unavailable")); }, ); @@ -3201,10 +3148,7 @@ describe("literal-percent runtime path resolution", () => { file("app/preload/name.cjs", "root"), ]), }), - ).toMatchObject({ - resolution_status: "rejected", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("rejected")); }, ); }); @@ -3416,10 +3360,7 @@ describe("exact Electron runtime entrypoint resolution", () => { files, runtimePathKind: "exact-file", }), - ).toMatchObject({ - resolution_status: "not-found", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("not-found")); }); it("accepts an exact extensionless file but not a directory index", () => { @@ -3449,10 +3390,7 @@ describe("exact Electron runtime entrypoint resolution", () => { files, runtimePathKind: "exact-file", }), - ).toMatchObject({ - resolution_status: "not-found", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("not-found")); }); }); @@ -3642,7 +3580,7 @@ describe("Node launch package main ownership", () => { file("app/declared.cjs", "foreign"), ]), }), - ).toMatchObject({ resolution_status: status, resolved_path: null }); + ).toMatchObject(unresolvedPath(status)); }); }); @@ -3720,10 +3658,7 @@ describe("package metadata at archive module boundaries", () => { file(`${directory}/window.cjs`, "foreign"), ]), }), - ).toMatchObject({ - resolution_status: "unavailable", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("unavailable")); }); it.each([ ["resources/app.asar/main.cjs", "../pkg", "resources/pkg"], @@ -3784,10 +3719,7 @@ describe("package metadata at archive module boundaries", () => { hasDirectory: () => false, }, }), - ).toMatchObject({ - resolution_status: "unavailable", - resolved_path: null, - }); + ).toMatchObject(unresolvedPath("unavailable")); } }, );