From cefc90628800100e2415c41b6a8a88a254f98a99 Mon Sep 17 00:00:00 2001 From: montjeffrey Date: Mon, 9 Nov 2026 21:40:51 -0500 Subject: [PATCH 1/2] 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. --- scripts/lib/grok-source-identity.js | 13 ++++++-- tests/lib/grok-canonical-install.test.js | 40 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/scripts/lib/grok-source-identity.js b/scripts/lib/grok-source-identity.js index 242254b0d..e9f11f76b 100644 --- a/scripts/lib/grok-source-identity.js +++ b/scripts/lib/grok-source-identity.js @@ -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; } diff --git a/tests/lib/grok-canonical-install.test.js b/tests/lib/grok-canonical-install.test.js index bb59fc1a3..aafa43200 100644 --- a/tests/lib/grok-canonical-install.test.js +++ b/tests/lib/grok-canonical-install.test.js @@ -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 { From bf7f495a5307caf85a41b05c82757b2a3a8fcf20 Mon Sep 17 00:00:00 2001 From: montjeffrey Date: Tue, 10 Nov 2026 01:11:31 -0500 Subject: [PATCH 2/2] fix(harness): canonicalize source_doc containment with native realpath Resolve both sides of the source_doc containment check with fs.realpathSync.native (falling back to fs.realpathSync). With the JS realpath, a repo root reached through a Windows 8.3 short name stays in short form while an in-repo symlink whose target uses the long-path form resolves to the long form, so a legitimate in-repo doc was reported as "resolves outside repository root". Escapes outside the repo are still rejected. Adds a cross-platform regression test that models differing JS and native realpath results: in-repo docs are accepted through a short-form root and an outside target is still rejected. It fails on the previous implementation. Not required for the #3882 Windows CI fix; kept as a separate commit so it can be taken or dropped on its own. --- scripts/lib/harness-adapter-compliance.js | 11 +++- tests/docs/harness-adapter-compliance.test.js | 50 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/scripts/lib/harness-adapter-compliance.js b/scripts/lib/harness-adapter-compliance.js index abcbfa045..2303058ca 100644 --- a/scripts/lib/harness-adapter-compliance.js +++ b/scripts/lib/harness-adapter-compliance.js @@ -688,6 +688,13 @@ function isSafeRelativeSourceDocPath(trimmedEntry, normalizedEntry) { && !segments.includes('.'); } +// Canonicalize both sides of the containment check the same way. The native +// realpath also expands Windows 8.3 short names (e.g. RUNNER~1), which the JS +// realpath leaves as-is. +function nativeRealpath(value) { + return (fs.realpathSync.native || fs.realpathSync)(value); +} + function validateSingleSourceDoc(label, docEntry, repoRoot, canonicalRepoRoot) { if (typeof docEntry !== 'string' || !docEntry.trim()) { return null; @@ -706,7 +713,7 @@ function validateSingleSourceDoc(label, docEntry, repoRoot, canonicalRepoRoot) { let canonicalResolved; try { - canonicalResolved = fs.realpathSync(resolved); + canonicalResolved = nativeRealpath(resolved); } catch (_error) { return `${label}: missing source_doc ${trimmedEntry}`; } @@ -720,7 +727,7 @@ function validateSingleSourceDoc(label, docEntry, repoRoot, canonicalRepoRoot) { function validateSourceDocs(records = ADAPTER_RECORDS, options = {}) { const repoRoot = path.resolve(options.repoRoot || path.resolve(__dirname, '..', '..')); - const canonicalRepoRoot = fs.existsSync(repoRoot) ? fs.realpathSync(repoRoot) : repoRoot; + const canonicalRepoRoot = fs.existsSync(repoRoot) ? nativeRealpath(repoRoot) : repoRoot; const errors = []; for (const record of records) { diff --git a/tests/docs/harness-adapter-compliance.test.js b/tests/docs/harness-adapter-compliance.test.js index 76d026c55..ea09b2a18 100644 --- a/tests/docs/harness-adapter-compliance.test.js +++ b/tests/docs/harness-adapter-compliance.test.js @@ -287,6 +287,56 @@ test('validateSourceDocs rejects a symlinked source_doc escaping the repository } }); +test('validateSourceDocs canonicalizes the root and source_docs with the native realpath', () => { + // Models Windows 8.3 aliasing without needing symlink privileges: the JS + // realpath keeps the root's short form (e.g. RUNNER~1) while an in-repo + // link resolves to a long-form target; the native realpath returns the + // long form for both. Before the fix, both in-repo docs were reported as + // outside the repository root. + const tempRoot = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-adapter-native-'))); + const outsideRoot = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-adapter-native-outside-'))); + const shortRoot = path.join(path.dirname(tempRoot), 'ECC-AD~1'); + const realDoc = path.join(tempRoot, 'docs', 'real.md'); + const linkDoc = path.join(tempRoot, 'docs', 'link.md'); + const outsideDoc = path.join(tempRoot, 'docs', 'outside.md'); + const outsideFile = path.join(outsideRoot, 'secret.md'); + const originalRealpathSync = fs.realpathSync; + + try { + fs.mkdirSync(path.join(tempRoot, 'docs'), { recursive: true }); + for (const file of [realDoc, linkDoc, outsideDoc, outsideFile]) { + fs.writeFileSync(file, 'doc\n'); + } + const linkTargets = new Map([[linkDoc, realDoc], [outsideDoc, outsideFile]]); + const nativeRealpath = value => linkTargets.get(path.resolve(value)) || path.resolve(value); + const jsRealpath = value => (path.resolve(value) === tempRoot ? shortRoot : nativeRealpath(value)); + fs.realpathSync = Object.assign(jsRealpath, { native: nativeRealpath }); + + const errors = validateSourceDocs( + [{ + id: 'sample', + harness: 'Sample', + state: 'Adapter-backed', + supported_assets: ['skills'], + unsupported_surfaces: ['hooks'], + install_or_onramp: ['`./install.sh --target sample`'], + verification_commands: ['`npm test`'], + risk_notes: ['None'], + last_verified_at: '2026-10-30', + owner: 'ECC maintainers', + source_docs: ['docs/real.md', 'docs/link.md', 'docs/outside.md'], + }], + { repoRoot: tempRoot } + ); + assert.strictEqual(errors.length, 1, errors.join('\n')); + assert.match(errors[0], /docs\/outside\.md resolves outside repository root/); + } finally { + fs.realpathSync = originalRealpathSync; + fs.rmSync(tempRoot, { recursive: true, force: true }); + fs.rmSync(outsideRoot, { recursive: true, force: true }); + } +}); + if (failed > 0) { console.log(`\nFailed: ${failed}`); process.exit(1);