fix: refuse a tracked file in any repo, not just the running package (0.7.1) - #42
Merged
Conversation
…(0.7.1) `insideCheckout` asked whether the *running package* had a `.git`. That is true from a checkout and false from an installed package, so a registered path pointing into a checkout was refused in dev mode and silently written in normal mode. Switching a machine from `npm install -g .` to the published package leaves exactly such a path behind. The next `compact` then wrote a machine-specific digest into a tracked `skills/recall/SKILL.md` — the same failure that shipped one machine's note count for twenty releases, reached from the other direction. Observed on a real install during the 0.7.0 upgrade, not hypothesised. The question was always about the target, never about where the code runs from, so ask git about the target: `git ls-files --error-unmatch`. A non-zero exit covers both "not tracked" and "not in a repository", and both mean writing publishes nothing. `realpathSync` first, because the path arrives as a symlink `setup` planted — asking about the link answers "not tracked" and then writes straight through it. Without git, fall back to the previous package-root heuristic. It is narrower than the real question, but a machine with no git also has no tracked file to damage. Zero dependencies; `node:child_process` was already in use elsewhere. 106 tests, up from 105. The new one fails against the old guard: it returns false for a tracked file in another repo, which is the write that happened. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014fSLBRUVVhAauWDuzJM4mc
|
Warning Review limit reachedNext included review available in 1 minute. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
insideCheckoutasked whether the running package had a.git. That is true from a checkout and false from an installed package — but a registered path can point into a checkout regardless of where the running code lives.Switching a machine from
npm install -g .to the published package leaves exactly such a path behind inskillPaths. The nextcompactwrote a machine-specific digest into a trackedskills/recall/SKILL.md.This is the same failure that shipped one machine's note count for twenty releases, reached from the other direction. Observed on a real install during the 0.7.0 upgrade, not hypothesised.
The fix
The question was always about the target, never about where the code runs from. So ask git about the target:
A non-zero exit covers both "not tracked" and "not in a repository", and both mean the same thing here: writing publishes nothing.
ENOENTmeans git is missing, which is not an answer — that falls back to the previous package-root heuristic. A machine with no git also has no tracked file to damage.realpathSyncruns first, because the path arrives as a symlinksetupplanted. Asking about the link answers "not tracked" and then writes straight through it into the repository.Results are cached per process — one process, one answer, so the cache cannot go stale.
Proof the test is not vacuous
Replicating the old guard and pointing it at a tracked file in another repo:
The new test also covers an untracked file in the same repository, which must still be written — the guard is about tracked-ness, not about being near a
.git.Verification
node:child_processwas already in use instaleness.js🤖 Generated with Claude Code
https://claude.ai/code/session_014fSLBRUVVhAauWDuzJM4mc