mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix(events): clear stale pending questions from remote servers
- Drop pending forms and permissions when a session is deleted or its page returns 404 - Reconcile remembered remote directories on browser reconnect, not only local repos - Purge pending items from remote servers that are disabled or removed - Prefer the viewed session's pending item over a pinned item from another session - Time out remote proxy GET/HEAD requests that never send headers (504)
This commit is contained in:
1 parent
b00b74f5a1
commit
382b26806e
7 files changed
+307
-21
No files matched your search
@@ -21,9 +21,13 @@ const passThroughAuth: MiddlewareHandler = async (_c, next) => {
|
||||
function buildApp(
|
||||
fetchFn: typeof fetch,
|
||||
requireAuth: MiddlewareHandler = passThroughAuth,
|
||||
upstreamHeadersTimeoutMs?: number,
|
||||
): Hono {
|
||||
const app = new Hono()
|
||||
app.route('/api/opencode/servers', createOpenCodeServerProxyRoutes(registry, requireAuth, fetchFn))
|
||||
app.route(
|
||||
'/api/opencode/servers',
|
||||
createOpenCodeServerProxyRoutes(registry, requireAuth, fetchFn, upstreamHeadersTimeoutMs),
|
||||
)
|
||||
return app
|
||||
}
|
||||
|
||||
@@ -200,6 +204,65 @@ describe('opencode server proxy routes', () => {
|
||||
expect(await res.json()).toEqual({ error: 'Remote OpenCode server unreachable' })
|
||||
})
|
||||
|
||||
it('returns 504 when a GET upstream does not send headers before the timeout', async () => {
|
||||
const fetchMock = vi.fn((_url: string, init: RequestInit) => new Promise<Response>((_resolve, reject) => {
|
||||
init.signal?.addEventListener('abort', () => {
|
||||
reject(new DOMException('Aborted', 'AbortError'))
|
||||
})
|
||||
}))
|
||||
const app = buildApp(fetchMock as unknown as typeof fetch, passThroughAuth, 20)
|
||||
|
||||
const res = await app.request('/api/opencode/servers/srv_1/api/session')
|
||||
|
||||
expect(res.status).toBe(504)
|
||||
expect(await res.json()).toEqual({ error: 'Remote OpenCode server timed out' })
|
||||
})
|
||||
|
||||
it('does not time out a POST that takes longer than the headers timeout', async () => {
|
||||
let receivedSignal: AbortSignal | null | undefined
|
||||
const fetchMock = vi.fn(async (_url: string, init: RequestInit) => {
|
||||
receivedSignal = init.signal
|
||||
await new Promise((resolve) => setTimeout(resolve, 40))
|
||||
return new Response('ok', { status: 200 })
|
||||
})
|
||||
const app = buildApp(fetchMock as unknown as typeof fetch, passThroughAuth, 10)
|
||||
|
||||
const res = await app.request('/api/opencode/servers/srv_1/api/session/ses_1/message', {
|
||||
method: 'POST',
|
||||
body: '{}',
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(receivedSignal?.aborted).toBe(false)
|
||||
})
|
||||
|
||||
it('keeps streaming the upstream body after headers arrive', async () => {
|
||||
const encoder = new TextEncoder()
|
||||
let receivedSignal: AbortSignal | null | undefined
|
||||
const fetchMock = vi.fn(async (_url: string, init: RequestInit) => {
|
||||
receivedSignal = init.signal
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
async start(controller) {
|
||||
controller.enqueue(encoder.encode('data: one\n\n'))
|
||||
await new Promise((resolve) => setTimeout(resolve, 40))
|
||||
controller.enqueue(encoder.encode('data: two\n\n'))
|
||||
controller.close()
|
||||
},
|
||||
})
|
||||
return new Response(stream, {
|
||||
status: 200,
|
||||
headers: { 'content-type': 'text/event-stream' },
|
||||
})
|
||||
})
|
||||
const app = buildApp(fetchMock as unknown as typeof fetch, passThroughAuth, 10)
|
||||
|
||||
const res = await app.request('/api/opencode/servers/srv_1/api/event')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.text()).toBe('data: one\n\ndata: two\n\n')
|
||||
expect(receivedSignal?.aborted).toBe(false)
|
||||
})
|
||||
|
||||
it('streams the upstream response body and drops set-cookie', async () => {
|
||||
const encoder = new TextEncoder()
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
|
||||
Reference in new issue
Block a user