fix: address comments

This commit is contained in:
Drew Ballance 2026-04-28 12:58:52 -05:00
parent 8461cead75
commit 70f5fe34bd
No known key found for this signature in database
GPG Key ID: FFF2E6A4496D5858

View File

@ -22,6 +22,11 @@ let settings: IGitSourceSettings
let sshPath: string let sshPath: string
let githubServerUrl: string let githubServerUrl: string
// Helper function to normalize path separators to forward slashes
function convertBackslashes(file: string): string {
return file.replace(/\\/g, '/')
}
describe('git-auth-helper tests', () => { describe('git-auth-helper tests', () => {
beforeAll(async () => { beforeAll(async () => {
// SSH // SSH
@ -261,7 +266,8 @@ describe('git-auth-helper tests', () => {
await fs.promises.symlink(workspace, symlinkPath) await fs.promises.symlink(workspace, symlinkPath)
// Make git appear to be operating from the symlink path // Make git appear to be operating from the symlink path
;(git.getWorkingDirectory as jest.Mock).mockReturnValue(symlinkPath) const mockGetWorkingDirectory = git.getWorkingDirectory as jest.Mock
mockGetWorkingDirectory.mockReturnValue(symlinkPath)
process.env['GITHUB_WORKSPACE'] = symlinkPath process.env['GITHUB_WORKSPACE'] = symlinkPath
const authHelper = gitAuthHelper.createAuthHelper(git, settings) const authHelper = gitAuthHelper.createAuthHelper(git, settings)
@ -273,10 +279,10 @@ describe('git-auth-helper tests', () => {
const localConfigContent = ( const localConfigContent = (
await fs.promises.readFile(localGitConfigPath) await fs.promises.readFile(localGitConfigPath)
).toString() ).toString()
const realGitDir = ( const realGitDir = convertBackslashes(
await fs.promises.realpath(path.join(symlinkPath, '.git')) await fs.promises.realpath(path.join(symlinkPath, '.git'))
).replace(/\\/g, '/') )
const symlinkGitDir = path.join(symlinkPath, '.git').replace(/\\/g, '/') const symlinkGitDir = convertBackslashes(path.join(symlinkPath, '.git'))
expect(realGitDir).not.toBe(symlinkGitDir) // sanity check: paths differ expect(realGitDir).not.toBe(symlinkGitDir) // sanity check: paths differ
expect( expect(
@ -295,10 +301,11 @@ describe('git-auth-helper tests', () => {
// Arrange // Arrange
await setup(configureAuth_fallsBackWhenRealpathSyncFails) await setup(configureAuth_fallsBackWhenRealpathSyncFails)
// Use a non-existent path so realpathSync throws ENOENT naturally, // Use a nonexistent path so realpathSync throws ENOENT naturally,
// exercising the catch fallback in configureToken() // exercising the catch fallback in configureToken()
const nonexistentPath = path.join(runnerTemp, 'does-not-exist') const nonexistentPath = path.join(runnerTemp, 'does-not-exist')
;(git.getWorkingDirectory as jest.Mock).mockReturnValue(nonexistentPath) const mockGetWorkingDirectory = git.getWorkingDirectory as jest.Mock
mockGetWorkingDirectory.mockReturnValue(nonexistentPath)
const authHelper = gitAuthHelper.createAuthHelper(git, settings) const authHelper = gitAuthHelper.createAuthHelper(git, settings)
@ -309,9 +316,9 @@ describe('git-auth-helper tests', () => {
const localConfigContent = ( const localConfigContent = (
await fs.promises.readFile(localGitConfigPath) await fs.promises.readFile(localGitConfigPath)
).toString() ).toString()
const fallbackGitDir = path const fallbackGitDir = convertBackslashes(
.join(nonexistentPath, '.git') path.join(nonexistentPath, '.git')
.replace(/\\/g, '/') )
expect( expect(
localConfigContent.indexOf(`includeIf.gitdir:${fallbackGitDir}.path`) localConfigContent.indexOf(`includeIf.gitdir:${fallbackGitDir}.path`)
).toBeGreaterThanOrEqual(0) ).toBeGreaterThanOrEqual(0)