Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(control-api): cover gfs proxy timeout + error passthrough (A4)
Alfredo Lopez8fbd2055fc73
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 25186a050..7ca75bea1 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.423",+ "version": "0.1.424","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.423",+ "version": "0.1.424","dependencies": {"@clerum/image-policy": "file:../packages/image-policy","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-api/package.json b/control-api/package.jsonindex 42d242d1f..fa5d70b7b 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.423",+ "version": "0.1.424","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/test/routes.gfsProxy.test.ts b/control-api/test/routes.gfsProxy.test.tsindex 19d7c6d2c..404da5539 100644--- a/control-api/test/routes.gfsProxy.test.ts+++ b/control-api/test/routes.gfsProxy.test.ts@@ -8,6 +8,7 @@ vi.mock('../src/config.js', () => ({config: {gfscBaseUrl: 'http://gfsc.gfs.svc:8087',gfscWriteBaseUrl: 'http://gfsc-writer.gfs.svc:8087',+ gfscProxyTimeoutMs: 300_000,},}))@@ -91,4 +92,72 @@ describe('/api/v1/gfs/proxy', () => {}))})++ it('returns 504 gfsc_timeout when the gfsc fetch times out', async () => {+ const fetchMock = vi.fn(async () => {+ const err = new Error('The operation was aborted due to timeout')+ err.name = 'TimeoutError'+ throw err+ })+ vi.stubGlobal('fetch', fetchMock)++ const app = await buildApp()+ const res = await request(app)+ .post('/api/v1/gfs/proxy/v1/resources/root/children')+ .send({ name: 'x', kind: 'file' })++ expect(res.status).toBe(504)+ expect(res.body).toEqual({ error: 'gfsc_timeout' })+ })++ it('returns 502 gfsc_unreachable when the gfsc fetch fails', async () => {+ const fetchMock = vi.fn(async () => {+ throw new Error('connect ECONNREFUSED')+ })+ vi.stubGlobal('fetch', fetchMock)++ const app = await buildApp()+ const res = await request(app).get('/api/v1/gfs/proxy/v1/resources/root/children')++ expect(res.status).toBe(502)+ expect(res.body).toEqual({ error: 'gfsc_unreachable' })+ })++ it('forwards a gfsc 5xx error body verbatim (never a silent 500)', async () => {+ const fetchMock = vi.fn(+ async () =>+ new Response(JSON.stringify({ ok: false, error: { code: 'internal', message: 'boom' } }), {+ status: 500,+ headers: { 'content-type': 'application/json' },+ })+ )+ vi.stubGlobal('fetch', fetchMock)++ const app = await buildApp()+ const res = await request(app)+ .post('/api/v1/gfs/proxy/v1/resources/root/children')+ .send({ name: 'x', kind: 'file' })++ expect(res.status).toBe(500)+ expect(res.body).toEqual({ ok: false, error: { code: 'internal', message: 'boom' } })+ })++ it('forwards a gfsc 413 payload_too_large verbatim', async () => {+ const fetchMock = vi.fn(+ async () =>+ new Response(JSON.stringify({ ok: false, error: { code: 'payload_too_large' } }), {+ status: 413,+ headers: { 'content-type': 'application/json' },+ })+ )+ vi.stubGlobal('fetch', fetchMock)++ const app = await buildApp()+ const res = await request(app)+ .post('/api/v1/gfs/proxy/v1/resources/root/children')+ .send({ name: 'x', kind: 'file' })++ expect(res.status).toBe(413)+ expect(res.body).toEqual({ ok: false, error: { code: 'payload_too_large' } })+ })})