mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 05:22:17 +00:00
fix(grok): compare worktree roots with native realpath on Windows
GitHub Windows runners use an 8.3 short path for os.tmpdir() (C:\Users\RUNNER~1\...). git rev-parse --show-toplevel returns the long path, but JS fs.realpathSync does not expand 8.3 short names, so isGitWorkTreeRoot compared unequal for a valid worktree and source preparation fell through to the registry branch and threw. Prefer fs.realpathSync.native (falling back to realpathSync for injected fakes) in isGitWorkTreeRoot and findRegistrySource. Fail-closed behavior is unchanged. Adds cross-platform and Windows-only regression tests. Fixes the windows npm/full lane on #3882.
This commit is contained in:
2 files changed
+50
-3
No files matched your search
@@ -16,13 +16,20 @@ process.once('exit', () => {
|
||||
}
|
||||
});
|
||||
|
||||
// Prefer the native realpath: JS fs.realpathSync does not expand Windows 8.3
|
||||
// short names (e.g. RUNNER~1), so it can disagree with git's long-path output.
|
||||
function realpath(fsModule, value) {
|
||||
const resolve = fsModule.realpathSync.native || fsModule.realpathSync;
|
||||
return resolve.call(fsModule, value);
|
||||
}
|
||||
|
||||
function isGitWorkTreeRoot(dir, fsModule = fs, execute = execFileSync) {
|
||||
try {
|
||||
const top = execute('git', ['-C', dir, 'rev-parse', '--show-toplevel'], {
|
||||
encoding: 'utf8',
|
||||
stdio: ['ignore', 'pipe', 'ignore'],
|
||||
}).trim();
|
||||
return fsModule.realpathSync(top) === fsModule.realpathSync(dir);
|
||||
return realpath(fsModule, top) === realpath(fsModule, dir);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
@@ -101,11 +108,11 @@ function findRegistrySource(sourceRoot, homeDir, pathModule = path) {
|
||||
if (error.code === 'ENOENT') return null;
|
||||
throw new Error(`Failed to read Grok plugin registry at ${registryPath}: ${error.message}`);
|
||||
}
|
||||
const expectedPath = fs.realpathSync(sourceRoot);
|
||||
const expectedPath = realpath(fs, sourceRoot);
|
||||
for (const record of Object.values(registry.repos || {})) {
|
||||
let recordPath;
|
||||
try {
|
||||
recordPath = fs.realpathSync(record.path);
|
||||
recordPath = realpath(fs, record.path);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -363,6 +363,46 @@ function runTests() {
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('Git worktree roots prefer native realpath so Windows 8.3 aliases resolve', () => {
|
||||
const canonicalPath = path.join(os.tmpdir(), 'ecc-grok-long-name', 'repo');
|
||||
const shortAliasPath = path.join(os.tmpdir(), 'ECC-GR~1', 'repo');
|
||||
const fakeFs = {
|
||||
realpathSync: Object.assign(
|
||||
// Mimics JS realpath: it leaves the short-name alias unexpanded.
|
||||
value => path.resolve(value),
|
||||
{
|
||||
native: value => (path.resolve(value) === shortAliasPath ? canonicalPath : path.resolve(value)),
|
||||
}
|
||||
),
|
||||
};
|
||||
const fakeGit = () => `${canonicalPath}\n`;
|
||||
assert.strictEqual(isGitWorkTreeRoot(shortAliasPath, fakeFs, fakeGit), true);
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (process.platform !== 'win32') {
|
||||
console.log(' - skipped: Git worktree roots accept Windows 8.3 short-name aliases (not Windows)');
|
||||
} else if (test('Git worktree roots accept Windows 8.3 short-name aliases', () => {
|
||||
const parent = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-grok-long-name-alias-'));
|
||||
try {
|
||||
const sourceRoot = path.join(parent, 'source-with-a-long-directory-name');
|
||||
fs.mkdirSync(sourceRoot);
|
||||
git(sourceRoot, ['init', '--quiet']);
|
||||
assert.strictEqual(isGitWorkTreeRoot(sourceRoot), true);
|
||||
const aliasRoot = execFileSync(
|
||||
'cmd',
|
||||
['/d', '/s', '/c', `for %I in ("${sourceRoot}") do @echo %~sI`],
|
||||
{ encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], windowsVerbatimArguments: true }
|
||||
).trim();
|
||||
if (!aliasRoot || aliasRoot.toLowerCase() === sourceRoot.toLowerCase()) {
|
||||
console.log(' (volume has no 8.3 alias for the test directory; alias assertion skipped)');
|
||||
return;
|
||||
}
|
||||
assert.strictEqual(isGitWorkTreeRoot(aliasRoot), true);
|
||||
} finally {
|
||||
fs.rmSync(parent, { recursive: true, force: true });
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('source identity rejects a marketplace version that does not match the pinned plugin', () => {
|
||||
const fixture = createPinnedFixture();
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user