fix(workflows): preserve punctuation in filesystem source paths (#521)

* fix(workflows): preserve punctuation in filesystem source paths

Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>

* fix(workflows): share scheme URL pattern in path normalization

---------

Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-05 15:01:12 +08:00
committed by GitHub
co-authored by morluto
parent 056c123759
commit 5b28a8b331
3 changed files with 149 additions and 2 deletions
@@ -136,6 +136,86 @@ 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([
"https://example.test/src/modified.ts?revision=2#section",
"webpack://fixture/./src/modified.ts?revision=2#section",
])("still strips URL query and fragment from %s", (path) => {
const node = moduleNode("url", { 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", ["src/modified.ts"]),
application: {
evidenceId: EVIDENCE_ID,
rootArtifactSha256: HASH.artifact,
graph,
},
});
expect(item(result, "src/modified.ts")).toMatchObject({
status: "unknown",
current_node_ids: [node.node_id],
candidates: [
expect.objectContaining({
signals: expect.arrayContaining([
expect.objectContaining({ kind: "current-path-suffix" }),
]),
}),
],
});
});
});
describe("source to bundle complete metadata", () => {
it("accepts long source metadata and all reported limitations", () => {
const result = compareSourceToBundle({
+9 -2
View File
@@ -268,9 +268,16 @@ const addPath = (
if (value !== null) paths.push({ kind, value });
};
/** Matches a `scheme://...` URL prefix; bare filesystem paths keep `?`/`#`. */
const SCHEME_URL = /^[a-z][a-z0-9+.-]*:\/\//iu;
/** Matches a `scheme://...` URL prefix with any run of slashes, for stripping. */
const SCHEME_URL_PREFIX = /^[a-z][a-z0-9+.-]*:\/\/+/iu;
const normalizeCurrentPath = (raw: string): string | null => {
const withoutQuery = raw.split(/[?#]/u, 1)[0] ?? "";
const withoutScheme = withoutQuery.replace(/^[a-z][a-z0-9+.-]*:\/\/+/iu, "");
const withoutQuery = SCHEME_URL.test(raw)
? (raw.split(/[?#]/u, 1)[0] ?? "")
: raw;
const withoutScheme = withoutQuery.replace(SCHEME_URL_PREFIX, "");
const parts = withoutScheme
.replaceAll("\\", "/")
.split("/")