fix(platform-integrations): skip copy when src and dst are same file#104
Conversation
Add _safe_copy2 helper to avoid errors on hardlink/APFS clone scenarios. Also remove .bob symlink and add it to .gitignore.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRemoved a bob-related file/entry, added Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
platform-integrations/install.sh (1)
226-227: Add a regression test for same-inode copies with content assertions.Given this behavior change, please add a platform integration test that creates a samefile scenario (e.g., hardlink) and validates file contents after reinstall, not just path existence.
Based on learnings: Tests for
platform-integrations/install.shmust NEVER overwrite or corrupt existing user skills, commands, modes, or configurations - detect existing user content, preserve it completely during installation, and add Kaizen content alongside (not replacing) user content.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@platform-integrations/install.sh` around lines 226 - 227, Add a regression test that simulates the same-inode copy case (create a hardlink/duplicate inode for a source file), runs the install flow that triggers shutil.copytree(..., copy_function=_safe_copy2) and then asserts not only that target paths exist but that file contents match originals (both for pre-existing user files and newly added Kaizen files); ensure the test first creates sentinel user content (skills/commands/modes/configs), verifies the installer preserves those files verbatim (no truncation or corruption) and only adds new Kaizen files alongside, and fail the test if any user file content changes or is overwritten.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@platform-integrations/install.sh`:
- Around line 207-213: The _safe_copy2 helper currently checks os.path.samefile
before calling shutil.copy2 but can still race; wrap the shutil.copy2(src, dst)
call in a try/except that catches shutil.SameFileError and treats it the same as
the pre-check (log via debug like "Skipping (same file): {src} → {dst}" and
return) so any TOCTOU where src and dst become the same inode at copy time is
handled safely; keep the existing pre-check and only add the SameFileError
handling around the call to shutil.copy2 in _safe_copy2.
---
Nitpick comments:
In `@platform-integrations/install.sh`:
- Around line 226-227: Add a regression test that simulates the same-inode copy
case (create a hardlink/duplicate inode for a source file), runs the install
flow that triggers shutil.copytree(..., copy_function=_safe_copy2) and then
asserts not only that target paths exist but that file contents match originals
(both for pre-existing user files and newly added Kaizen files); ensure the test
first creates sentinel user content (skills/commands/modes/configs), verifies
the installer preserves those files verbatim (no truncation or corruption) and
only adds new Kaizen files alongside, and fail the test if any user file content
changes or is overwritten.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4d3936d7-5ba4-400d-9a2d-471d0f666d2c
📒 Files selected for processing (3)
.bob.gitignoreplatform-integrations/install.sh
💤 Files with no reviewable changes (1)
- .bob
Addresses CodeRabbit review finding: Handle same-file races at copy time, not only pre-check time Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add _safe_copy2 helper to avoid errors on hardlink/APFS clone scenarios. Also remove .bob symlink and add it to .gitignore.
For #103
Summary by CodeRabbit
Bug Fixes
Chores