mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-18 17:16:46 +03:00
refactor: share the containment gate with hook-before-edit
hook-before-edit.mjs kept its own string-based isInsideProject; it now uses the shared isScanTargetInsideProject so all three hook passes apply one containment semantic, symlink canonicalization included. Because the before-edit hook gates proposed Writes whose target does not exist yet, canonicalPath now resolves the nearest existing ancestor and re-appends the remainder instead of falling back to the raw resolved path — a new file under a symlinked root compares equal to its canonical project. Written with AI assistance (Claude Code). Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Code
parent
ae03e9e09c
commit
febce52e8d
@@ -195,6 +195,19 @@ describe('isScanTargetInsideProject()', () => {
|
||||
assert.equal(isScanTargetInsideProject(file, link), true);
|
||||
assert.equal(isScanTargetInsideProject(path.join(link, 'src', 'Card.tsx'), real), true);
|
||||
});
|
||||
|
||||
it('classifies not-yet-written files by their nearest existing ancestor', () => {
|
||||
// The before-edit hook gates proposed Writes, so the target often does
|
||||
// not exist. Canonicalization must climb to an existing ancestor rather
|
||||
// than bail, or a new file under a symlinked root would read as outside.
|
||||
const real = path.join(root, 'real');
|
||||
const link = path.join(root, 'link');
|
||||
fs.mkdirSync(real, { recursive: true });
|
||||
fs.symlinkSync(real, link);
|
||||
assert.equal(isScanTargetInsideProject(path.join(link, 'src', 'New.tsx'), real), true);
|
||||
assert.equal(isScanTargetInsideProject(path.join(real, 'deep', 'New.tsx'), link), true);
|
||||
assert.equal(isScanTargetInsideProject(path.join(root, 'elsewhere', 'New.tsx'), real), false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('readConfig()', () => {
|
||||
|
||||
Reference in New Issue
Block a user