mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 20:53:00 +00:00
fix(process)!: version literal scenario replacement semantics
Keep caller-selected replacement text literal with a callback, preserving empty-search positions instead of changing their split/join behavior. Commit the replacement interpretation for captures using custom patterns so legacy records cannot report this producer correction as a target change. BREAKING CHANGE: Captures with custom normalization patterns use literal-replacements-v1 and cannot be compared with legacy unversioned pattern captures. Capture both sides with the same replacement semantics; legacy captures remain readable and captures without patterns are unaffected.
This commit is contained in:
1 parent
f51503ef1c
commit
2b6f14f528
5 files changed
+121
-17
No files matched your search
@@ -59,31 +59,30 @@ const scenario = (normalization: {
|
||||
readonly pids?: boolean;
|
||||
readonly paths?: boolean;
|
||||
readonly ports?: boolean;
|
||||
readonly patterns?: readonly {
|
||||
readonly pattern: string;
|
||||
readonly replacement: string;
|
||||
}[];
|
||||
}) =>
|
||||
parseProcessScenario({
|
||||
executable: "/usr/bin/node",
|
||||
working_directory: "/workspace",
|
||||
normalization: {
|
||||
paths: true,
|
||||
...normalization,
|
||||
time_bucket_ms: 10,
|
||||
patterns: [{ pattern: "marker", replacement: "selected" }],
|
||||
...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" },
|
||||
],
|
||||
},
|
||||
const declared = scenario({
|
||||
paths: false,
|
||||
patterns: [
|
||||
{ pattern: "8080", replacement: "$&$&" },
|
||||
{ pattern: "READY", replacement: "$$" },
|
||||
{ pattern: "NAME", replacement: "$1" },
|
||||
],
|
||||
});
|
||||
expect(
|
||||
normalizeProcessText(
|
||||
@@ -95,6 +94,33 @@ it("replaces caller-declared patterns literally, without expanding replacement p
|
||||
).toBe("listening on $&$&; $$; $1=alpha; tail $1");
|
||||
});
|
||||
|
||||
it("preserves empty-pattern boundaries, including empty text", () => {
|
||||
const declared = scenario({
|
||||
patterns: [{ pattern: "", replacement: "$$" }],
|
||||
});
|
||||
expect(normalizeProcessText("ab", declared, "/temporary", rootPid)).toBe(
|
||||
"$$a$$b$$",
|
||||
);
|
||||
expect(normalizeProcessText("", declared, "/temporary", rootPid)).toBe("$$");
|
||||
});
|
||||
|
||||
it.each(["$`", "$'"])(
|
||||
"retains the selected replacement %s verbatim",
|
||||
(replacement) => {
|
||||
const declared = scenario({
|
||||
patterns: [{ pattern: "marker", replacement }],
|
||||
});
|
||||
expect(
|
||||
normalizeProcessText(
|
||||
"before marker after",
|
||||
declared,
|
||||
"/temporary",
|
||||
rootPid,
|
||||
),
|
||||
).toBe(`before ${replacement} after`);
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves compact JSON, counters, line numbers, and ambiguous endpoint spellings", () => {
|
||||
const input = [
|
||||
'{"pid":32,"size":108,"height":480,"width":640,"score":20}',
|
||||
|
||||
Reference in new issue
Block a user