fix(path-extender-posix): greedy regex causes data loss when duplicate config blocks exist#29
fix(path-extender-posix): greedy regex causes data loss when duplicate config blocks exist#29Zelys-DFKH wants to merge 2 commits into
Conversation
…e config blocks exist
|
Warning Review limit reached
More reviews will be available in 51 minutes and 10 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughFixes a greedy regex bug in ChangesDuplicate pnpm block handling fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoFix greedy regex replacement to avoid data loss with duplicate pnpm blocks Description
Diagram
High-Level Assessment
Files changed (2)
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
os/env/path-extender-posix/path-extender-posix.spec.ts (1)
270-294: ⚡ Quick winAssert marker de-duplication explicitly in overwrite test.
This test checks content preservation/removal, but it doesn’t verify there is exactly one
# pnpm ... # pnpm endsection left. Adding that assertion will better lock the contract.🧪 Suggested test hardening
expect(configContent).toContain('# content between blocks that must not be deleted') expect(configContent).toContain(`export PNPM_HOME="${pnpmHomeDir}"`) expect(configContent).not.toContain('duplicate_block') + expect(configContent.match(/^# pnpm$/gm) ?? []).toHaveLength(1) + expect(configContent.match(/^# pnpm end$/gm) ?? []).toHaveLength(1)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@os/env/path-extender-posix/path-extender-posix.spec.ts` around lines 270 - 294, The test `should update first pnpm block and remove duplicate blocks, preserving content between them` currently verifies content preservation and variable values, but does not explicitly assert that exactly one pnpm configuration block remains after deduplication. Add assertions after reading configContent to verify that the string `# pnpm` and `# pnpm end` each appear exactly once in the final config file, ensuring the marker de-duplication contract is properly tested and locked in.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@os/env/path-extender-posix/path-extender-posix.spec.ts`:
- Around line 270-294: The test `should update first pnpm block and remove
duplicate blocks, preserving content between them` currently verifies content
preservation and variable values, but does not explicitly assert that exactly
one pnpm configuration block remains after deduplication. Add assertions after
reading configContent to verify that the string `# pnpm` and `# pnpm end` each
appear exactly once in the final config file, ensuring the marker de-duplication
contract is properly tested and locked in.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 160775fb-6bda-4780-b511-18a65fa3c143
📒 Files selected for processing (2)
os/env/path-extender-posix/path-extender-posix.spec.tsos/env/path-extender-posix/path-extender-posix.ts
📜 Review details
🧰 Additional context used
🪛 OpenGrep (1.22.0)
os/env/path-extender-posix/path-extender-posix.ts
[ERROR] 224-224: Dynamic command passed to child_process.exec/execSync. Use child_process.execFile or spawn with an argument array instead.
(coderabbit.command-injection.exec-js)
🔇 Additional comments (2)
os/env/path-extender-posix/path-extender-posix.ts (1)
224-224: LGTM!Also applies to: 256-261
os/env/path-extender-posix/path-extender-posix.spec.ts (1)
295-314: LGTM!
|
Good catch. Added both assertions. |
Both
updateShellConfigandreplaceSectionused[\s\S]*(greedy) to locate the pnpm-managed config block. When a shell config contains two# pnpmsections — from runningpnpm setuptwice or a manual duplicate — the greedy match spans from the first# pnpmto the last# pnpm end, treating the entire range as one section. On the nextpnpm setup --forcerun, that whole span is replaced with a single updated block, silently destroying anything between the two markers.Two changes address this:
updateShellConfig:[\s\S]*→[\s\S]*?(non-greedy), and the vestigial'g'flag removed. The regex now stops at the first# pnpm endand reads only that block's content.replaceSection: also non-greedy, and updated to use a replace callback that writes the new content into the first match and removes any subsequent duplicate blocks, leaving exactly one# pnpmsection in the config.Reported by @Dzhuneyt in pnpm/pnpm#12282.
Fixes pnpm/pnpm#12282.
Summary by CodeRabbit
Bug Fixes
Tests