Repository navigation
fix(process): preserve nested path identities during normalization - #2468
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@greptileai review |
|
| const paths = [...aliases.keys()].sort( | ||
| (left, right) => right.length - left.length, | ||
| ); | ||
| if (paths.length === 0) return value; | ||
| const pattern = paths | ||
| .map((path) => path.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")) | ||
| .join("|"); | ||
| return value.replace( | ||
| new RegExp(pattern, "gu"), |
There was a problem hiding this comment.
normalizePathTokens rebuilds the alias map, sorts paths, and escapes them on every call. TerminalRenderer calls it for every visible row and again for the saved terminal state, for each output chunk. With many observed roots or terminal rows, this repeats avoidable work even though the paths stay unchanged during a capture. Build the matcher once per scenario and temporary root, then reuse it.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/process/capture/ProcessNormalization.ts
Line: 56-64
Comment:
**Path setup repeats per row**
`normalizePathTokens` rebuilds the alias map, sorts paths, and escapes them on every call. `TerminalRenderer` calls it for every visible row and again for the saved terminal state, for each output chunk. With many observed roots or terminal rows, this repeats avoidable work even though the paths stay unchanged during a capture. Build the matcher once per scenario and temporary root, then reuse it.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| it("normalizes nested paths once using the most specific selected identity", () => { | ||
| const declared = parseProcessScenario({ | ||
| executable: "/workspace/project/bin/program", | ||
| working_directory: "/workspace/project", | ||
| filesystem_observation_paths: [ | ||
| "/workspace/project/data", | ||
| "/workspace/project/data/cache", | ||
| ], | ||
| normalization: { paths: true, pids: false, ports: false, patterns: [] }, |
There was a problem hiding this comment.
The new tests cover nested paths and punctuation, but not equal-path priority or keeping inserted aliases untouched. A sequential longest-first rewrite could pass both tests while changing inserted aliases. Overwriting duplicate map keys could also change priority unnoticed. Add two cases:
temporaryRoot === scenario.working_directoryto check which alias wins.- A relative observed root named
working-directoryto check that it cannot rewrite an inserted alias.
These guard two promised behaviors that a later rewrite could otherwise break unnoticed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/process/capture/ProcessNormalization.test.ts
Line: 270-278
Comment:
**Alias edge cases lack tests**
The new tests cover nested paths and punctuation, but not equal-path priority or keeping inserted aliases untouched. A sequential longest-first rewrite could pass both tests while changing inserted aliases. Overwriting duplicate map keys could also change priority unnoticed. Add two cases:
- `temporaryRoot === scenario.working_directory` to check which alias wins.
- A relative observed root named `working-directory` to check that it cannot rewrite an inserted alias.
These guard two promised behaviors that a later rewrite could otherwise break unnoticed.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
When a selected executable or filesystem root is inside the working directory, path normalization replaces the parent first. Captures then lose the more specific identities:
selected-nodebecomes<working-directory>/selected-nodeinstead of<executable>, and an observed data root loses its own alias. Match original literal paths once, longest first, while retaining the existing tie priority. Version path-normalized comparison contracts so older semantics are rejected rather than compared silently.Validation: two module regressions and one real local PTY capture fail on the original implementation. The fix passes 25 module/scenario tests, five native PTY tests (two Linux-only cases skipped on macOS), and
npm run checkwith Node 24.18.0/npm 11.16.0. The capture checks original bytes, normalized identities, legacy-contract rejection and verified owned-process cleanup. An independent Codex review checked alias ties, regexp punctuation and replacement non-cascading on commit 807f4cc.AI assistance: OpenAI Codex authored the analysis, code, tests and this description, with independent automated review. No human maintainer review is claimed.