fix: review nits

This commit is contained in:
Drew Ballance 2026-03-25 12:54:48 -05:00
parent 70525c3952
commit 8461cead75
No known key found for this signature in database
GPG Key ID: FFF2E6A4496D5858
3 changed files with 35 additions and 27 deletions

View File

@ -251,36 +251,42 @@ describe('git-auth-helper tests', () => {
// Arrange // Arrange
await setup(configureAuth_resolvesSymlinksInIncludeIfGitdir) await setup(configureAuth_resolvesSymlinksInIncludeIfGitdir)
// Create a symlink pointing to the real workspace directory
const symlinkPath = path.join(path.dirname(workspace), 'workspace-symlink') const symlinkPath = path.join(path.dirname(workspace), 'workspace-symlink')
await fs.promises.symlink(workspace, symlinkPath)
// Make git appear to be operating from the symlink path try {
;(git.getWorkingDirectory as jest.Mock).mockReturnValue(symlinkPath) // Ensure no pre-existing symlink or file remains at this path
process.env['GITHUB_WORKSPACE'] = symlinkPath await fs.promises.rm(symlinkPath, {force: true})
const authHelper = gitAuthHelper.createAuthHelper(git, settings) // Create a symlink pointing to the real workspace directory
await fs.promises.symlink(workspace, symlinkPath)
// Act // Make git appear to be operating from the symlink path
await authHelper.configureAuth() ;(git.getWorkingDirectory as jest.Mock).mockReturnValue(symlinkPath)
process.env['GITHUB_WORKSPACE'] = symlinkPath
// Assert the host includeIf uses the real resolved path, not the symlink path const authHelper = gitAuthHelper.createAuthHelper(git, settings)
const localConfigContent = (
await fs.promises.readFile(localGitConfigPath)
).toString()
const realGitDir = fs
.realpathSync(path.join(symlinkPath, '.git'))
.replace(/\\/g, '/')
const symlinkGitDir = path.join(symlinkPath, '.git').replace(/\\/g, '/')
expect(realGitDir).not.toBe(symlinkGitDir) // sanity check: paths differ // Act
expect( await authHelper.configureAuth()
localConfigContent.indexOf(`includeIf.gitdir:${realGitDir}.path`)
).toBeGreaterThanOrEqual(0)
expect(localConfigContent.indexOf(symlinkGitDir)).toBeLessThan(0)
// Clean up symlink // Assert the host includeIf uses the real resolved path, not the symlink path
await fs.promises.unlink(symlinkPath) const localConfigContent = (
await fs.promises.readFile(localGitConfigPath)
).toString()
const realGitDir = (
await fs.promises.realpath(path.join(symlinkPath, '.git'))
).replace(/\\/g, '/')
const symlinkGitDir = path.join(symlinkPath, '.git').replace(/\\/g, '/')
expect(realGitDir).not.toBe(symlinkGitDir) // sanity check: paths differ
expect(
localConfigContent.indexOf(`includeIf.gitdir:${realGitDir}.path`)
).toBeGreaterThanOrEqual(0)
expect(localConfigContent.indexOf(symlinkGitDir)).toBeLessThan(0)
} finally {
// Clean up symlink (or any file) at the symlink path
await fs.promises.rm(symlinkPath, {force: true})
}
}) })
const configureAuth_fallsBackWhenRealpathSyncFails = const configureAuth_fallsBackWhenRealpathSyncFails =

5
dist/index.js vendored
View File

@ -411,10 +411,11 @@ class GitAuthHelper {
let gitDir; let gitDir;
try { try {
const constructed = path.join(this.git.getWorkingDirectory(), '.git'); const constructed = path.join(this.git.getWorkingDirectory(), '.git');
gitDir = fs.realpathSync(constructed).replace(/\\/g, '/'); const resolved = yield fs.promises.realpath(constructed);
gitDir = resolved.replace(/\\/g, '/');
} }
catch (_a) { catch (_a) {
// Fall back to constructed path if realpathSync fails // Fall back to constructed path if realpath fails
gitDir = path.join(this.git.getWorkingDirectory(), '.git'); gitDir = path.join(this.git.getWorkingDirectory(), '.git');
gitDir = gitDir.replace(/\\/g, '/'); gitDir = gitDir.replace(/\\/g, '/');
} }

View File

@ -371,9 +371,10 @@ class GitAuthHelper {
let gitDir: string let gitDir: string
try { try {
const constructed = path.join(this.git.getWorkingDirectory(), '.git') const constructed = path.join(this.git.getWorkingDirectory(), '.git')
gitDir = fs.realpathSync(constructed).replace(/\\/g, '/') const resolved = await fs.promises.realpath(constructed)
gitDir = resolved.replace(/\\/g, '/')
} catch { } catch {
// Fall back to constructed path if realpathSync fails // Fall back to constructed path if realpath fails
gitDir = path.join(this.git.getWorkingDirectory(), '.git') gitDir = path.join(this.git.getWorkingDirectory(), '.git')
gitDir = gitDir.replace(/\\/g, '/') gitDir = gitDir.replace(/\\/g, '/')
} }