fix: apply CodeRabbit auto-fixes

This commit is contained in:
Chris Scott committed 2026-11-03 08:29:59 -05:00
1 parent 3e6ebbd1dc
commit 8d92f86142
10 files changed
+262 -28

No files matched your search

+11 -5
View File
@@ -5,7 +5,6 @@ import { homedir, networkInterfaces, type NetworkInterfaceInfo } from 'node:os'
import { join } from 'node:path'
import { renderUnicodeCompact } from 'uqr'
import {
ClientError,
buildOpenCodeBasicAuth,
createOpenCodeApi,
encryptOpenCodePairingCredentials,
@@ -187,20 +186,27 @@ export async function probeOpenCodeServer(
credentials: PairingCredentials,
timeoutMs = 3000,
): Promise<OpenCodeServerProbe> {
let responseStatus: number | undefined
const api = createOpenCodeApi({
baseUrl: trimUrlTrailingSlashes(baseUrl),
headers: { authorization: buildOpenCodeBasicAuth(credentials.password, credentials.username) },
fetch: Object.assign(
async (input: RequestInfo | URL, init?: RequestInit) => {
const response = await fetch(input, init)
responseStatus = response.status
return response
},
{ preconnect: fetch.preconnect },
),
})
try {
const info = await api.server.info({ signal: AbortSignal.timeout(timeoutMs) })
return { status: 'ok', version: info.version ?? null }
} catch (error) {
if (openCodeErrorStatus(error) === 401) return { status: 'unauthorized' }
if (responseStatus === 401 || openCodeErrorStatus(error) === 401) return { status: 'unauthorized' }
const status = error instanceof ClientError
? (error.cause as { status?: number } | undefined)?.status
: undefined
const status = responseStatus !== undefined && responseStatus >= 400 ? responseStatus : undefined
return {
status: 'unreachable',
message: status === undefined ? messageOf(error) : `HTTP ${status}`,
+34
View File
@@ -362,6 +362,28 @@ describe('probeOpenCodeServer', () => {
})
})
it('reports unauthorized when the server rejects the credentials with an empty body', async () => {
const server = await startProbeServer((_request, response) => {
response.writeHead(401, { 'content-type': 'text/plain' })
response.end()
})
await expect(probeOpenCodeServer(server.baseUrl, CREDENTIALS, 1000)).resolves.toEqual({
status: 'unauthorized',
})
})
it('reports unauthorized when the server rejects the credentials with a plain text body', async () => {
const server = await startProbeServer((_request, response) => {
response.writeHead(401, { 'content-type': 'text/plain' })
response.end('unauthorized')
})
await expect(probeOpenCodeServer(server.baseUrl, CREDENTIALS, 1000)).resolves.toEqual({
status: 'unauthorized',
})
})
it('reports unreachable with the HTTP status for an unexpected response', async () => {
const server = await startProbeServer((_request, response) => {
response.writeHead(500, { 'content-type': 'application/json' })
@@ -374,6 +396,18 @@ describe('probeOpenCodeServer', () => {
})
})
it('reports unreachable with the HTTP status for an unexpected plain text response', async () => {
const server = await startProbeServer((_request, response) => {
response.writeHead(500, { 'content-type': 'text/plain' })
response.end('boom')
})
await expect(probeOpenCodeServer(server.baseUrl, CREDENTIALS, 1000)).resolves.toEqual({
status: 'unreachable',
message: 'HTTP 500',
})
})
it('reports unreachable when the server refuses the connection', async () => {
const server = await startProbeServer(() => {})
const baseUrl = server.baseUrl