Skip to content
Merged
Prev Previous commit
Next Next commit
fix(javascript): preserve filesystem names during URI classification
  • Loading branch information
morluto committed Oct 9, 2026
commit 3c3188263d07102ac5432521c5ed20a6a66dbb91
82 changes: 43 additions & 39 deletions src/domain/javascript/sourceToBundleComparison.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createJavaScriptApplicationNode,
} from "./javascriptApplicationGraph.js";
import { createHistoricalSourceGraph } from "../referenceSourceGraph.js";
import { compareCodePoints } from "../canonicalOrdering.js";
import { compareSourceToBundle } from "./sourceToBundleComparison.js";
import {
SOURCE_TO_BUNDLE_SIGNAL_WEIGHTS,
Expand Down Expand Up @@ -137,44 +138,47 @@ describe("historical source to bundle comparison", () => {
});

describe("source to bundle path syntax", () => {
it.each(["src/modified#part.ts", "src/modified?part.ts"])(
"preserves literal filesystem punctuation in %s",
(path) => {
const node = moduleNode("punctuated", { path });
const graph = createJavaScriptApplicationGraph({
schema: "JavaScriptApplicationGraph",
root_node_ids: [node.node_id],
nodes: [node],
edges: [],
coverage: {
status: "complete",
truncated: false,
omitted_count: 0,
limits: [],
},
limitations: [],
});
const result = compareSourceToBundle({
reference: historicalGraph("complete", [path]),
application: {
evidenceId: EVIDENCE_ID,
rootArtifactSha256: HASH.artifact,
graph,
},
});
expect(item(result, path)).toMatchObject({
status: "unknown",
current_node_ids: [node.node_id],
candidates: [
expect.objectContaining({
signals: expect.arrayContaining([
expect.objectContaining({ kind: "current-path-exact" }),
]),
}),
],
});
},
);
it.each([
"src/modified#part.ts",
"src/modified?part.ts",
"pkg:app/src/modified#part.ts",
"pkg:app/src/modified?part.ts",
"data:/src/modified.ts",
])("preserves literal filesystem punctuation in %s", (path) => {
const node = moduleNode("punctuated", { path });
const graph = createJavaScriptApplicationGraph({
schema: "JavaScriptApplicationGraph",
root_node_ids: [node.node_id],
nodes: [node],
edges: [],
coverage: {
status: "complete",
truncated: false,
omitted_count: 0,
limits: [],
},
limitations: [],
});
const result = compareSourceToBundle({
reference: historicalGraph("complete", [path]),
application: {
evidenceId: EVIDENCE_ID,
rootArtifactSha256: HASH.artifact,
graph,
},
});
expect(item(result, path)).toMatchObject({
status: "unknown",
current_node_ids: [node.node_id],
candidates: [
expect.objectContaining({
signals: expect.arrayContaining([
expect.objectContaining({ kind: "current-path-exact" }),
]),
}),
],
});
});

it.each([
"https://example.test/src/modified.ts?revision=2#section",
Expand Down Expand Up @@ -297,7 +301,7 @@ const historicalGraph = (
content_state: "hashed" as const,
limitations: [],
})),
],
].sort((left, right) => compareCodePoints(left.path, right.path)),
relationships: [],
parse_failures: [],
exclusions: [],
Expand Down
16 changes: 11 additions & 5 deletions src/domain/javascript/sourceToBundleSignals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,18 @@ const addPath = (
): void => {
const portable = raw.replaceAll("\\", "/");
const windowsPath = /^[a-z]:\//iu.test(portable);
const scheme = windowsPath ? undefined : URI_SCHEME.exec(portable)?.[0];
const sourceMapReference =
kind === "source-map-original" || mapPath !== undefined;
const scheme = windowsPath
? undefined
: (sourceMapReference ? URI_SCHEME : AUTHORITY_URI_SCHEME).exec(
portable,
)?.[0];
// Opaque URI payloads do not establish a filesystem path, even with slash text.
if (scheme !== undefined && !portable.slice(scheme.length).startsWith("/"))
if (scheme !== undefined && !raw.slice(scheme.length).startsWith("/"))
return;
const reference =
scheme !== undefined ||
kind === "source-map-original" ||
mapPath !== undefined
scheme !== undefined || sourceMapReference
? (portable.split(/[?#]/u, 1)[0] ?? "")
: portable;
if (
Expand Down Expand Up @@ -345,6 +349,8 @@ const addPath = (

/** Recognize URI schemes even when the URI has no authority component. */
const URI_SCHEME = /^[a-z][a-z0-9+.-]*:/iu;
/** Outside source maps, only an explicit authority distinguishes URLs from paths. */
const AUTHORITY_URI_SCHEME = /^[a-z][a-z0-9+.-]*:(?=\/\/)/iu;

const normalizeCurrentPath = (raw: string): string | null => {
const parts: string[] = [];
Expand Down
1 change: 1 addition & 0 deletions tests/boundary/filesystem/sourceToBundlePaths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ it.each([
{ source: "node:internal/src/a.js", hasPath: false },
{ source: "data:text/javascript,virtual/src/a.js", hasPath: false },
{ source: "data:text/javascript,virtual/../src/a.js", hasPath: false },
{ source: "data:\\src\\a.js", hasPath: false },
])(
"projects a filesystem path from $source only when it is hierarchical",
async ({ source, hasPath }) => {
Expand Down
Loading