fix(process): preserve sibling path identities

Keep aliases on selected paths at clear text delimiters so a longer sibling filename is not rewritten as the executable. Version the normalization contract and cover source and actual PTY behavior.

Fixes #6586
This commit is contained in:
morluto committed 2026-10-23 18:07:45 +08:00
1 parent 65168f77fb
commit c74bc2108c
5 files changed
+80 -4

No files matched your search

+1 -1
View File
@@ -133,7 +133,7 @@ export const processComparisonContract = (
limits: scenario.limits,
normalization: scenario.normalization,
...(scenario.normalization.paths
? { path_normalization_version: "longest-original-paths-v1" }
? { path_normalization_version: "path-component-boundaries-v2" }
: {}),
...(scenario.normalization.ports
? { port_normalization_version: "contextual-endpoints-v2" }
@@ -520,3 +520,21 @@ it("treats path metacharacters literally while preferring nested observed roots"
"<executable> <filesystem-root-1>/item <filesystem-root-0>/file <working-directory>/log <working-directory>/toolll",
);
});
it("does not give a selected executable identity to a sibling filename", () => {
const declared = parseProcessScenario({
executable: "/tmp/process-paths/original/tool",
working_directory: "/tmp/process-paths",
normalization: { paths: true, pids: false, ports: false, patterns: [] },
});
expect(
normalizeProcessText(
"/tmp/process-paths/original/tool-helper /tmp/process-paths/original/tool, /tmp/process-paths/original/tool",
declared,
"/tmp/rea-private",
rootPid,
),
).toBe(
"<working-directory>/original/tool-helper <working-directory>/original/tool, <executable>",
);
});
+8 -2
View File
@@ -314,10 +314,16 @@ const createPathRule = (
const pattern = paths
.map((path) => path.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"))
.join("|");
const matcher = new RegExp(pattern, "gu");
// A selected path is an identity, not an arbitrary text prefix. Only match
// it at a clear text delimiter; keep the parent-directory case (`/root` in
// `/root/file`) while leaving punctuation-adjacent names untouched.
const matcher = new RegExp(
`(^|[\\s"'=:(\\[{<])(${pattern})(?=$|/|[\\s"'])`,
"gu",
);
return {
matcher,
replace: (path) => aliases.get(path) ?? path,
replace: (_match, prefix, path) => `${prefix}${aliases.get(path) ?? path}`,
};
};