Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(control-api): r1-l4 cover K8s failure in the user-scope gate
Diego Zacarias554cfafb7297
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 6b4c1ff56..c32255081 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.743",+ "version": "0.1.744","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.743",+ "version": "0.1.744","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex f6c177d2c..e855de6fa 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.743",+ "version": "0.1.744","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.internal.mcpOauthAuthorizeUrl.test.ts b/control-api/test/routes.internal.mcpOauthAuthorizeUrl.test.tsindex 9bab267b1..cb11117ab 100644--- a/control-api/test/routes.internal.mcpOauthAuthorizeUrl.test.ts+++ b/control-api/test/routes.internal.mcpOauthAuthorizeUrl.test.ts@@ -385,6 +385,45 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {expect(res.body.authorizeUrl).toBeUndefined()})+ // A K8s read failure in the per-user gate is a backend failure, not a+ // membership verdict: it must neither mint nor read as a 403.+ it('user flavor: 500 without authorizeUrl when listing Contexts fails', async () => {+ seedOauthServer(gateway, { name: 'gdrive', grantScope: 'user', contextRef: 'ctx-owner' })+ await seedAllowlistedContext(gateway, 'ctx-business', ['gdrive'])+ membership(mockPoolQuery, { contexts: { 'user-7': ['ctx-business'] } })+ const realList = gateway.listResource.bind(gateway)+ vi.spyOn(gateway, 'listResource').mockImplementation((plural, ns) =>+ plural === 'contexts'+ ? Promise.reject(Object.assign(new Error('apiserver unavailable'), { statusCode: 503 }))+ : realList(plural, ns)+ )+ const res = await post(app)+ .set('Authorization', 'Bearer dev-rpc-proxy-token')+ .set('x-service-token', 'rpc-proxy')+ .send({ mcpServerName: 'gdrive', userId: 'user-7' })+ expect(res.status).toBe(500)+ expect(res.body.authorizeUrl).toBeUndefined()+ })++ it('user flavor: 500 without authorizeUrl when an assigned agent Host read fails and no direct Context enables the server', async () => {+ seedOauthServer(gateway, { name: 'gdrive', grantScope: 'user', contextRef: 'ctx-owner' })+ await seedAllowlistedContext(gateway, 'ctx-c', ['gdrive'])+ await seedAgentHost(gateway, 'host-c', 'ctx-c')+ membership(mockPoolQuery, { agents: { 'user-7': ['host-c'] } })+ const realGet = gateway.getResource.bind(gateway)+ vi.spyOn(gateway, 'getResource').mockImplementation((plural, name, ns) =>+ plural === 'hosts'+ ? Promise.reject(Object.assign(new Error('apiserver unavailable'), { statusCode: 503 }))+ : realGet(plural, name, ns)+ )+ const res = await post(app)+ .set('Authorization', 'Bearer dev-rpc-proxy-token')+ .set('x-service-token', 'rpc-proxy')+ .send({ mcpServerName: 'gdrive', userId: 'user-7' })+ expect(res.status).toBe(500)+ expect(res.body.authorizeUrl).toBeUndefined()+ })+it('503 integration_not_configured when the client_id Secret is absent', async () => {// Server exists but no google-creds Secret seeded.void gateway.createResource(diff --git a/control-api/test/routes.oauthCallback.userAccessGate.test.ts b/control-api/test/routes.oauthCallback.userAccessGate.test.tsindex ac6220921..eb1a617e1 100644--- a/control-api/test/routes.oauthCallback.userAccessGate.test.ts+++ b/control-api/test/routes.oauthCallback.userAccessGate.test.ts@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import express from 'express'import request from 'supertest'import { config } from '../src/config.js'+import { clerumErrorHandler } from '../src/http/errorHandler.js'import { signOAuthState } from '../src/oauth/state.js'import { createOAuthCallbackRouter } from '../src/routes/external/oauthCallback.js'import { editContextAllowlist } from '../src/services/contextAllowlist.js'@@ -88,6 +89,7 @@ describe('GET /api/v1/oauth-callback/:oauthClientId — per-user access re-checkgateway = new MockGateway(MCP_NS)app = express()app.use('/api/v1', createOAuthCallbackRouter(gateway as never))+ app.use(clerumErrorHandler)mockPoolQuery.mockReset()fetchSpy = vi.spyOn(globalThis, 'fetch')@@ -174,4 +176,38 @@ describe('GET /api/v1/oauth-callback/:oauthClientId — per-user access re-checkexpect(sql).toContain('INSERT INTO oauth_grants')expect(params.slice(0, 5)).toEqual(['mcpserver', MCP_NS, SERVER, USER_ID, OAUTH_CLIENT_ID])})++ it('500 when listing Contexts fails; no exchange, no grant', async () => {+ membership(mockPoolQuery, { contexts: { [USER_ID]: ['ctx-business'] } })+ const realList = gateway.listResource.bind(gateway)+ vi.spyOn(gateway, 'listResource').mockImplementation((plural, ns) =>+ plural === 'contexts'+ ? Promise.reject(Object.assign(new Error('apiserver unavailable'), { statusCode: 503 }))+ : realList(plural, ns)+ )++ const res = await callback()++ expect(res.status).toBe(500)+ expect(fetchSpy).not.toHaveBeenCalled()+ expect(grantWrites()).toHaveLength(0)+ })++ it('500 when an assigned agent Host read fails and no direct Context enables the server; no exchange, no grant', async () => {+ await seedAllowlistedContext(gateway, 'ctx-c', [SERVER])+ await seedAgentHost(gateway, 'host-c', 'ctx-c')+ membership(mockPoolQuery, { agents: { [USER_ID]: ['host-c'] } })+ const realGet = gateway.getResource.bind(gateway)+ vi.spyOn(gateway, 'getResource').mockImplementation((plural, name, ns) =>+ plural === 'hosts'+ ? Promise.reject(Object.assign(new Error('apiserver unavailable'), { statusCode: 503 }))+ : realGet(plural, name, ns)+ )++ const res = await callback()++ expect(res.status).toBe(500)+ expect(fetchSpy).not.toHaveBeenCalled()+ expect(grantWrites()).toHaveLength(0)+ })})