From ddab6f11900a9225b1aac0e777234e45313d3d24 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Thu, 12 Mar 2026 14:51:14 -0700 Subject: [PATCH] fix: compare hook roots by file identity --- tests/hooks/hooks.test.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/hooks/hooks.test.js b/tests/hooks/hooks.test.js index ea5c696b..a9ca850b 100644 --- a/tests/hooks/hooks.test.js +++ b/tests/hooks/hooks.test.js @@ -120,6 +120,22 @@ function normalizeComparablePath(targetPath) { return path.normalize(normalizedPath).replace(/\\/g, '/').replace(/^([a-z]):/, (_, drive) => `${drive.toUpperCase()}:`); } +function pathsReferToSameLocation(leftPath, rightPath) { + const normalizedLeftPath = normalizeComparablePath(leftPath); + const normalizedRightPath = normalizeComparablePath(rightPath); + + if (!normalizedLeftPath || !normalizedRightPath) return false; + if (normalizedLeftPath === normalizedRightPath) return true; + + try { + const leftStats = fs.statSync(normalizedLeftPath); + const rightStats = fs.statSync(normalizedRightPath); + return leftStats.dev === rightStats.dev && leftStats.ino === rightStats.ino; + } catch { + return false; + } +} + function createCommandShim(binDir, baseName, logFile) { fs.mkdirSync(binDir, { recursive: true }); @@ -2268,7 +2284,10 @@ async function runTests() { const normalizedMetadataRoot = normalizeComparablePath(metadata.root); const normalizedRepoDir = normalizeComparablePath(repoDir); assert.ok(normalizedMetadataRoot, 'project.json should include a non-empty repo root'); - assert.strictEqual(normalizedMetadataRoot, normalizedRepoDir, 'project.json should include the repo root'); + assert.ok( + pathsReferToSameLocation(normalizedMetadataRoot, normalizedRepoDir), + `project.json should include the repo root (expected ${normalizedRepoDir}, got ${normalizedMetadataRoot})`, + ); assert.strictEqual(metadata.remote, 'https://github.com/example/ecc-test.git', 'project.json should include the sanitized remote'); assert.ok(metadata.created_at, 'project.json should include created_at'); assert.ok(metadata.last_seen, 'project.json should include last_seen');