Something went wrong. Try again.
A collaborative coding-agent orchestrator for atproto radl.app
Something went wrong. Try again.
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172import assert from 'node:assert/strict'import test from 'node:test'import { ensureGitHubAuth, resolveGitHubToken } from '../dist/index.js'
test('GH_TOKEN has priority over legacy and gh', async () => { const token = await resolveGitHubToken({ GH_TOKEN: 'fine', GITHUB_TOKEN: 'legacy' }, async () => { throw new Error('called') }) assert.equal(token, 'fine')})
test('uses legacy token then an existing gh login', async () => { assert.equal( await resolveGitHubToken({ GITHUB_TOKEN: 'legacy' }, async () => ({ code: 0, stdout: 'x', stderr: '', })), 'legacy', ) assert.equal( await resolveGitHubToken({}, async () => ({ code: 0, stdout: ' gh-token\n', stderr: '' })), 'gh-token', )})
test('missing gh resolves as unauthenticated', async () => { assert.equal( await resolveGitHubToken({}, async () => { const error = new Error('spawn gh ENOENT') error.code = 'ENOENT' throw error }), undefined, )})
test('login fallback is interactive and returns the resolved token', async () => { const calls = [] const token = await ensureGitHubAuth({ env: {}, runner: async (command, args, options) => { calls.push({ command, args, options }) if (args[1] === 'login') return { code: 0, stdout: '', stderr: '' } return { code: 0, stdout: calls.length > 2 ? 'token' : '', stderr: '' } }, })
assert.equal(token, 'token') const login = calls.find((call) => call.args[1] === 'login') assert.deepEqual(login, { command: 'gh', args: ['auth', 'login', '--hostname', 'github.com', '--git-protocol', 'https', '--web'], options: { interactive: true }, })})
test('missing gh during login reports an actionable error', async () => { await assert.rejects( ensureGitHubAuth({ env: {}, runner: async (_command, args) => { if (args[1] === 'token') return { code: 1, stdout: '', stderr: '' } const error = new Error('spawn gh ENOENT') error.code = 'ENOENT' throw error }, }), /GitHub CLI \(gh\) is required/, )})