Compare commits

...

2 Commits

Author SHA1 Message Date
Drew Ballance
fbeb4a8af3
fix: formatting 2026-04-28 13:01:14 -05:00
Drew Ballance
70f5fe34bd
fix: address comments 2026-04-28 12:58:52 -05:00
2 changed files with 22 additions and 15 deletions

View File

@ -22,6 +22,11 @@ let settings: IGitSourceSettings
let sshPath: 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', () => {
beforeAll(async () => {
// SSH
@ -261,7 +266,8 @@ describe('git-auth-helper tests', () => {
await fs.promises.symlink(workspace, symlinkPath)
// 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
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
@ -273,10 +279,10 @@ describe('git-auth-helper tests', () => {
const localConfigContent = (
await fs.promises.readFile(localGitConfigPath)
).toString()
const realGitDir = (
const realGitDir = convertBackslashes(
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(
@ -295,10 +301,11 @@ describe('git-auth-helper tests', () => {
// Arrange
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()
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)
@ -309,9 +316,9 @@ describe('git-auth-helper tests', () => {
const localConfigContent = (
await fs.promises.readFile(localGitConfigPath)
).toString()
const fallbackGitDir = path
.join(nonexistentPath, '.git')
.replace(/\\/g, '/')
const fallbackGitDir = convertBackslashes(
path.join(nonexistentPath, '.git')
)
expect(
localConfigContent.indexOf(`includeIf.gitdir:${fallbackGitDir}.path`)
).toBeGreaterThanOrEqual(0)

View File

@ -8,9 +8,9 @@ import * as path from 'path'
import * as regexpHelper from './regexp-helper'
import * as stateHelper from './state-helper'
import * as urlHelper from './url-helper'
import { v4 as uuid } from 'uuid'
import { IGitCommandManager } from './git-command-manager'
import { IGitSourceSettings } from './git-source-settings'
import {v4 as uuid} from 'uuid'
import {IGitCommandManager} from './git-command-manager'
import {IGitSourceSettings} from './git-source-settings'
const IS_WINDOWS = process.platform === 'win32'
const SSH_COMMAND_KEY = 'core.sshCommand'
@ -92,7 +92,7 @@ class GitAuthHelper {
assert.ok(runnerTemp, 'RUNNER_TEMP is not defined')
const uniqueId = uuid()
this.temporaryHomePath = path.join(runnerTemp, uniqueId)
await fs.promises.mkdir(this.temporaryHomePath, { recursive: true })
await fs.promises.mkdir(this.temporaryHomePath, {recursive: true})
// Copy the global git config
const gitConfigPath = path.join(
@ -258,11 +258,11 @@ class GitAuthHelper {
const uniqueId = uuid()
this.sshKeyPath = path.join(runnerTemp, uniqueId)
stateHelper.setSshKeyPath(this.sshKeyPath)
await fs.promises.mkdir(runnerTemp, { recursive: true })
await fs.promises.mkdir(runnerTemp, {recursive: true})
await fs.promises.writeFile(
this.sshKeyPath,
this.settings.sshKey.trim() + '\n',
{ mode: 0o600 }
{mode: 0o600}
)
// Remove inherited permissions on Windows