fix(process): normalize scenario replacements literally

capture_process_scenario declares normalization patterns as literal text, but\nreplaceAll expands \$&\, \$\`, and \$1\ in the replacement as a replacement\npattern. A caller normalizing text that contains a dollar sign silently gets\nduplicated, spliced, or dropped content in the recorded Evidence instead of\nthe requested literal replacement.\n\nUse split/join, which is literal on both sides and is already the idiom used\nfor exact-literal scenario rules in browserScenarioNormalization.ts.
This commit is contained in:
openhands
2026-10-10 16:57:06 +08:00
committed by Ysopwnable
parent 2bf812772d
commit f51503ef1c
2 changed files with 28 additions and 1 deletions
@@ -71,6 +71,30 @@ const scenario = (normalization: {
},
});
it("replaces caller-declared patterns literally, without expanding replacement patterns", () => {
const declared = parseProcessScenario({
executable: "/usr/bin/node",
working_directory: "/workspace",
normalization: {
paths: false,
time_bucket_ms: 10,
patterns: [
{ pattern: "8080", replacement: "$&$&" },
{ pattern: "READY", replacement: "$$" },
{ pattern: "NAME", replacement: "$1" },
],
},
});
expect(
normalizeProcessText(
"listening on 8080; READY; NAME=alpha; tail NAME",
declared,
"/temporary",
rootPid,
),
).toBe("listening on $&$&; $$; $1=alpha; tail $1");
});
it("preserves compact JSON, counters, line numbers, and ambiguous endpoint spellings", () => {
const input = [
'{"pid":32,"size":108,"height":480,"width":640,"score":20}',