mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix(backend): classify clone auth failures before not-found and isolate server tests from host PIDs
Clone error mapping matched a bare '404' anywhere in git's stderr, so an authentication failure on a URL whose port contained 404 was reported as repository not found. 401 and 404 are now matched as HTTP statuses and authentication is checked first. The single-server tests stub process.kill so they never probe or signal real host processes; PID 1234 existing on a Linux runner made them fail.
This commit is contained in:
1 parent
80e7f78a9b
commit
92c2d49e5c
3 files changed
+71
-9
No files matched your search
@@ -17,6 +17,15 @@ const spawnMock = vi.hoisted(() => vi.fn(() => ({
|
||||
|
||||
const spawnSyncMock = vi.hoisted(() => vi.fn())
|
||||
|
||||
const processKillMock = vi.hoisted(() => vi.fn((_pid: number, signal?: number | NodeJS.Signals) => {
|
||||
if (signal === 0) {
|
||||
const error = new Error('kill ESRCH') as NodeJS.ErrnoException
|
||||
error.code = 'ESRCH'
|
||||
throw error
|
||||
}
|
||||
return true
|
||||
}))
|
||||
|
||||
const readFileSyncMock = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('bun:sqlite', () => ({
|
||||
@@ -186,6 +195,16 @@ const routeVersionProbeThroughExecSyncStub = () => {
|
||||
|
||||
beforeEach(routeVersionProbeThroughExecSyncStub)
|
||||
|
||||
const originalProcessKill = process.kill
|
||||
|
||||
beforeEach(() => {
|
||||
process.kill = processKillMock as unknown as typeof process.kill
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
process.kill = originalProcessKill
|
||||
})
|
||||
|
||||
// Reset singleton before any tests run to clear any polluted state from previous test files
|
||||
beforeAll(async () => {
|
||||
const { OpenCodeServerManager } = await import('../../src/services/opencode-single-server')
|
||||
@@ -2823,6 +2842,7 @@ describe('OpenCodeServerManager - server auth', () => {
|
||||
await manager.start()
|
||||
await manager.stop()
|
||||
|
||||
expect(processKillMock).toHaveBeenCalledWith(1234, 'SIGTERM')
|
||||
const rmMock = fs.rm as unknown as ReturnType<typeof vi.fn>
|
||||
expect(rmMock).toHaveBeenCalledWith('/test/workspace/.opencode/state/opencode-server-child.json', { force: true })
|
||||
} finally {
|
||||
@@ -2869,6 +2889,7 @@ describe('OpenCodeServerManager - server auth', () => {
|
||||
await secondManager.start()
|
||||
|
||||
expect(spawnMock).toHaveBeenCalledTimes(2)
|
||||
expect(processKillMock).toHaveBeenCalledWith(1234, 'SIGKILL')
|
||||
} finally {
|
||||
readFileMock.mockReset()
|
||||
Object.defineProperty(ENV.SERVER, 'NODE_ENV', { value: originalNodeEnv, configurable: true, writable: true })
|
||||
|
||||
Reference in new issue
Block a user