Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(control-api): r1-m4 key membership fixture by user id

Diego Zacariasc19fd4b382fa
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index df3391491..d8062d02c 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.740",
+ "version": "0.1.741",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.740",
+ "version": "0.1.741",
"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.json
index f03e556c0..fedcb3320 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.740",
+ "version": "0.1.741",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/fixtures/contextAllowlist.ts b/control-api/test/fixtures/contextAllowlist.ts
index 08711be59..42a20f0e4 100644
--- a/control-api/test/fixtures/contextAllowlist.ts
+++ b/control-api/test/fixtures/contextAllowlist.ts
@@ -25,18 +25,57 @@ export async function seedAllowlistedContext(
}
/**
- * Answer `getUserContexts` (the `FROM user_contexts` read) with `contextIds` on
- * the suite's mocked `pool.query`; every other query resolves empty.
+ * Who belongs to what, keyed by user id. `contexts` answers the
+ * `getUserContexts` read (`FROM user_contexts`), `agents` the `getUserAgents`
+ * read (`FROM user_agents`). A user not listed has no rows.
*/
-export function memberOf(poolQuery: Mock, contextIds: string[]): void {
- poolQuery.mockImplementation((sql: unknown) => {
- const text = typeof sql === 'string' ? sql : ''
- if (text.includes('FROM user_contexts')) {
- return Promise.resolve({
- rows: contextIds.map(context_id => ({ context_id })),
- rowCount: contextIds.length,
- })
- }
- return Promise.resolve({ rows: [], rowCount: 0 })
+export interface Membership {
+ contexts?: Record<string, string[]>
+ agents?: Record<string, string[]>
+}
+
+type QueryResult = { rows: unknown[]; rowCount: number }
+
+/**
+ * Unit stand-in for the two membership reads: answers by the queried user id
+ * (`values[0]`), so a reader that asks for the wrong user gets that user's
+ * (usually empty) rows instead of the intended ones. Returns `null` for any
+ * other SQL so a suite with its own pool fake can delegate the rest.
+ *
+ * Hand-written by necessity (the readers' SQL runs, the table does not); the
+ * real-table contract (`lifecycle_state`, team tables not counting) belongs
+ * to suites that run against a real Postgres.
+ */
+export function membershipResult(
+ sql: unknown,
+ values: unknown,
+ membership: Membership
+): QueryResult | null {
+ const text = typeof sql === 'string' ? sql : ''
+ const userId = Array.isArray(values) ? String(values[0]) : ''
+ if (text.includes('FROM user_contexts')) {
+ const ids = membership.contexts?.[userId] ?? []
+ return { rows: ids.map(context_id => ({ context_id })), rowCount: ids.length }
+ }
+ if (text.includes('FROM user_agents')) {
+ const names = membership.agents?.[userId] ?? []
+ return { rows: names.map(agent_name => ({ agent_name })), rowCount: names.length }
+ }
+ return null
+}
+
+/**
+ * Install `membershipResult` as the suite's mocked `pool.query`. Every other
+ * query goes to `otherwise` (default: no rows).
+ */
+export function membership(
+ poolQuery: Mock,
+ value: Membership,
+ otherwise: (sql: unknown, values: unknown) => Promise<QueryResult> = () =>
+ Promise.resolve({ rows: [], rowCount: 0 })
+): void {
+ poolQuery.mockImplementation((sql: unknown, values: unknown) => {
+ const answered = membershipResult(sql, values, value)
+ return answered ? Promise.resolve(answered) : otherwise(sql, values)
})
}
diff --git a/control-api/test/oauth.remoteSpecCoherence.test.ts b/control-api/test/oauth.remoteSpecCoherence.test.ts
index 152d5b83b..ca53bf20f 100644
--- a/control-api/test/oauth.remoteSpecCoherence.test.ts
+++ b/control-api/test/oauth.remoteSpecCoherence.test.ts
@@ -13,7 +13,7 @@ import { signOAuthState } from '../src/oauth/state.js'
import { buildRemoteOAuthSpec } from '../src/routes/admin/remoteMcp.js'
import { normalizeMcpServerOwnerDecl } from '../src/routes/mcpOauth.js'
import { issueMcpHostControlJwt } from '../src/utils/auth/mcpHostJwtToken.js'
-import { seedAllowlistedContext } from './fixtures/contextAllowlist.js'
+import { membership, seedAllowlistedContext } from './fixtures/contextAllowlist.js'
import {
ATLASSIAN_V2_PILOT,
DROPBOX_PILOT,
@@ -341,16 +341,12 @@ describe('routes refuse an incoherent remote server with 409 remote_oauth_spec_i
gateway = new MockGateway(MCP_NS)
app = createApp(gateway as never)
mockPoolQuery.mockReset()
- mockPoolQuery.mockImplementation((sql: unknown) => {
- const text = typeof sql === 'string' ? sql : ''
- if (text.includes('FROM user_contexts')) {
- return Promise.resolve({ rows: [{ context_id: CONTEXT }], rowCount: 1 })
- }
- if (text.includes('DELETE FROM oauth_grants')) {
- return Promise.resolve({ rows: [], rowCount: 1 })
- }
- return Promise.resolve({ rows: [], rowCount: 0 })
- })
+ membership(mockPoolQuery, { contexts: { 'user-1': [CONTEXT] } }, sql =>
+ Promise.resolve({
+ rows: [],
+ rowCount: typeof sql === 'string' && sql.includes('DELETE FROM oauth_grants') ? 1 : 0,
+ })
+ )
config.mcpOauthBrokerEnabled = true
})
@@ -389,13 +385,7 @@ describe('routes refuse an incoherent remote server with 409 remote_oauth_spec_i
it(`${c.label}: authorize-url for a non-member → 403, configuration not disclosed`, async () => {
await seed('srv', c.oauth())
- mockPoolQuery.mockImplementation((sql: unknown) => {
- const text = typeof sql === 'string' ? sql : ''
- if (text.includes('FROM user_contexts')) {
- return Promise.resolve({ rows: [{ context_id: 'ctx-other' }], rowCount: 1 })
- }
- return Promise.resolve({ rows: [], rowCount: 0 })
- })
+ membership(mockPoolQuery, { contexts: { 'user-2': ['ctx-other'] } })
const res = await request(app)
.post('/api/v1/internal/mcp-oauth/authorize-url')
.set('Authorization', `Bearer ${RPC_PROXY_TOKEN}`)
diff --git a/control-api/test/routes.internal.mcpOauthAuthorizeUrl.test.ts b/control-api/test/routes.internal.mcpOauthAuthorizeUrl.test.ts
index 16fd8be57..86c9fd780 100644
--- a/control-api/test/routes.internal.mcpOauthAuthorizeUrl.test.ts
+++ b/control-api/test/routes.internal.mcpOauthAuthorizeUrl.test.ts
@@ -4,7 +4,7 @@ import { createApp } from '../src/app.js'
import { config } from '../src/config.js'
import { verifyOAuthStateSignature } from '../src/oauth/state.js'
import { checkAndIncrement } from '../src/services/rateLimiterService.js'
-import { memberOf, seedAllowlistedContext } from './fixtures/contextAllowlist.js'
+import { membership, seedAllowlistedContext } from './fixtures/contextAllowlist.js'
import { MockGateway } from './mockGateway.js'
/**
@@ -114,7 +114,7 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {
seedOauthServer(gateway, { name: 'gdrive', grantScope: 'user' })
// user-7 is a member of ctx-9, whose allowlist enables gdrive.
await seedAllowlistedContext(gateway, 'ctx-9', ['gdrive'])
- memberOf(mockPoolQuery, ['ctx-9'])
+ membership(mockPoolQuery, { contexts: { 'user-7': ['ctx-9'] } })
const res = await post(app)
.set('Authorization', 'Bearer dev-rpc-proxy-token')
.set('x-service-token', 'rpc-proxy')
@@ -189,7 +189,7 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {
it('context server: accepts a matching body contextId from a MEMBER and mints the URL', async () => {
seedOauthServer(gateway, { name: 'gdrive', grantScope: 'context', contextRef: 'ctx-A' })
// Membership check (getUserContexts → user_contexts): user-2 is a member of ctx-A.
- mockPoolQuery.mockResolvedValue({ rows: [{ context_id: 'ctx-A' }], rowCount: 1 })
+ membership(mockPoolQuery, { contexts: { 'user-2': ['ctx-A'] } })
const res = await post(app)
.set('Authorization', 'Bearer dev-rpc-proxy-token')
.set('x-service-token', 'rpc-proxy')
@@ -202,11 +202,8 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {
// rejected at the MINT boundary — fail early, never sent to the provider.
it('context server: a NON-member is rejected 403 at mint, with NO authorizeUrl', async () => {
seedOauthServer(gateway, { name: 'gdrive', grantScope: 'context', contextRef: 'ctx-A' })
- // getUserContexts returns contexts that do NOT include ctx-A.
- mockPoolQuery.mockResolvedValue({
- rows: [{ context_id: 'ctx-other' }, { context_id: 'ctx-else' }],
- rowCount: 2,
- })
+ // The user's Contexts do NOT include ctx-A.
+ membership(mockPoolQuery, { contexts: { 'user-nomember': ['ctx-other', 'ctx-else'] } })
const res = await post(app)
.set('Authorization', 'Bearer dev-rpc-proxy-token')
.set('x-service-token', 'rpc-proxy')
@@ -223,7 +220,7 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {
it('context server: membership in an allowlisting Context other than contextRef → still 403', async () => {
seedOauthServer(gateway, { name: 'gdrive', grantScope: 'context', contextRef: 'ctx-A' })
await seedAllowlistedContext(gateway, 'ctx-B', ['gdrive'])
- memberOf(mockPoolQuery, ['ctx-B'])
+ membership(mockPoolQuery, { contexts: { 'user-2': ['ctx-B'] } })
const res = await post(app)
.set('Authorization', 'Bearer dev-rpc-proxy-token')
.set('x-service-token', 'rpc-proxy')
@@ -234,7 +231,7 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {
it('context server: a contextRef member mints even when no allowlist names the server', async () => {
seedOauthServer(gateway, { name: 'gdrive', grantScope: 'context', contextRef: 'ctx-A' })
- memberOf(mockPoolQuery, ['ctx-A'])
+ membership(mockPoolQuery, { contexts: { 'user-2': ['ctx-A'] } })
const res = await post(app)
.set('Authorization', 'Bearer dev-rpc-proxy-token')
.set('x-service-token', 'rpc-proxy')
@@ -256,17 +253,26 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {
seedOauthServer(gateway, { name: 'gdrive', grantScope: 'user', contextRef: 'ctx-owner' })
await seedAllowlistedContext(gateway, 'ctx-owner', ['gdrive'])
await seedAllowlistedContext(gateway, 'ctx-business', ['gdrive'])
- memberOf(mockPoolQuery, ['ctx-business', 'ctx-unrelated'])
+ membership(mockPoolQuery, { contexts: { 'user-7': ['ctx-business', 'ctx-unrelated'] } })
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(200)
expect(res.body.authorizeUrl).toContain('https://accounts.google.com/')
- const membershipQuery = mockPoolQuery.mock.calls.find(
- ([sql]) => typeof sql === 'string' && sql.includes('FROM user_contexts')
- )
- expect(membershipQuery?.[1]).toEqual(['user-7'])
+ })
+
+ it('user flavor: the requesting user is not a member but another user is → 403, NO authorizeUrl', async () => {
+ seedOauthServer(gateway, { name: 'gdrive', grantScope: 'user', contextRef: 'ctx-owner' })
+ await seedAllowlistedContext(gateway, 'ctx-business', ['gdrive'])
+ membership(mockPoolQuery, { contexts: { 'someone-else': ['ctx-business'] } })
+ 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(403)
+ expect(res.body.error).toBe('context_membership_denied')
+ expect(res.body.authorizeUrl).toBeUndefined()
})
it('user flavor: a server WITHOUT contextRef that an allowlist enables mints OK', async () => {
@@ -294,7 +300,7 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {
},
})
await seedAllowlistedContext(gateway, 'ctx-business', ['gdrive'])
- memberOf(mockPoolQuery, ['ctx-business'])
+ membership(mockPoolQuery, { contexts: { 'user-7': ['ctx-business'] } })
const res = await post(app)
.set('Authorization', 'Bearer dev-rpc-proxy-token')
.set('x-service-token', 'rpc-proxy')
@@ -306,7 +312,7 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {
it('user flavor: the body contextId is ignored (neither required nor cross-checked)', async () => {
seedOauthServer(gateway, { name: 'gdrive', grantScope: 'user', contextRef: 'ctx-owner' })
await seedAllowlistedContext(gateway, 'ctx-business', ['gdrive'])
- memberOf(mockPoolQuery, ['ctx-business'])
+ membership(mockPoolQuery, { contexts: { 'user-7': ['ctx-business'] } })
const res = await post(app)
.set('Authorization', 'Bearer dev-rpc-proxy-token')
.set('x-service-token', 'rpc-proxy')
@@ -317,7 +323,7 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {
it('user flavor: no Context of the user allowlists the server → 403, NO authorizeUrl', async () => {
seedOauthServer(gateway, { name: 'gdrive', grantScope: 'user', contextRef: 'ctx-9' })
await seedAllowlistedContext(gateway, 'ctx-other', ['some-other-server'])
- memberOf(mockPoolQuery, ['ctx-other'])
+ membership(mockPoolQuery, { contexts: { 'user-8': ['ctx-other'] } })
const res = await post(app)
.set('Authorization', 'Bearer dev-rpc-proxy-token')
.set('x-service-token', 'rpc-proxy')
@@ -330,7 +336,7 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {
it('user flavor: a user with no Contexts at all → 403', async () => {
seedOauthServer(gateway, { name: 'gdrive', grantScope: 'user', contextRef: 'ctx-9' })
await seedAllowlistedContext(gateway, 'ctx-9', ['gdrive'])
- memberOf(mockPoolQuery, [])
+ membership(mockPoolQuery, { contexts: { 'user-8': [] } })
const res = await post(app)
.set('Authorization', 'Bearer dev-rpc-proxy-token')
.set('x-service-token', 'rpc-proxy')
@@ -347,7 +353,7 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {
await seedAllowlistedContext(gateway, 'ctx-9', ['gdrive'])
await seedAllowlistedContext(gateway, 'ctx-business', ['gdrive'])
await seedAllowlistedContext(gateway, 'ctx-other', [])
- memberOf(mockPoolQuery, ['ctx-other'])
+ membership(mockPoolQuery, { contexts: { 'user-8': ['ctx-other'] } })
const res = await post(app)
.set('Authorization', 'Bearer dev-rpc-proxy-token')
.set('x-service-token', 'rpc-proxy')
@@ -379,7 +385,7 @@ describe('POST /api/v1/internal/mcp-oauth/authorize-url (U5)', () => {
// Member of ctx-9, which enables gdrive, so we reach the Secret read (past
// the membership gate).
await seedAllowlistedContext(gateway, 'ctx-9', ['gdrive'])
- memberOf(mockPoolQuery, ['ctx-9'])
+ membership(mockPoolQuery, { contexts: { 'user-1': ['ctx-9'] } })
const res = await post(app)
.set('Authorization', 'Bearer dev-rpc-proxy-token')
.set('x-service-token', 'rpc-proxy')
diff --git a/control-api/test/routes.oauthCallback.remotePerServer.test.ts b/control-api/test/routes.oauthCallback.remotePerServer.test.ts
index 006c5e5fa..f2b86ebce 100644
--- a/control-api/test/routes.oauthCallback.remotePerServer.test.ts
+++ b/control-api/test/routes.oauthCallback.remotePerServer.test.ts
@@ -8,6 +8,7 @@ import { deriveOAuthEncryptionKey } from '../src/oauth/encryption.js'
import { signOAuthState } from '../src/oauth/state.js'
import { buildRemoteOAuthSpec } from '../src/routes/admin/remoteMcp.js'
import { attachServerToContext } from '../src/services/contextAllowlist.js'
+import { membershipResult } from './fixtures/contextAllowlist.js'
import {
discoverPilot,
installRemoteServer,
@@ -46,9 +47,10 @@ vi.mock('../src/db.js', async importActual => {
pool: {
query: (text: string, values?: unknown[]) => {
// Membership is the only non-OAuth read on these paths.
- if (text.includes('FROM user_contexts')) {
- return Promise.resolve({ rows: [{ context_id: dbHolder.context }], rowCount: 1 })
- }
+ const member = membershipResult(text, values, {
+ contexts: { 'user-9': [dbHolder.context] },
+ })
+ if (member) return Promise.resolve(member)
if (!dbHolder.db) throw new Error('test db not initialised')
return dbHolder.db.query(text, values)
},
diff --git a/control-api/test/routes.oauthCallback.userAccessGate.test.ts b/control-api/test/routes.oauthCallback.userAccessGate.test.ts
index 10c55aa3a..440f5eff3 100644
--- a/control-api/test/routes.oauthCallback.userAccessGate.test.ts
+++ b/control-api/test/routes.oauthCallback.userAccessGate.test.ts
@@ -4,7 +4,7 @@ import request from 'supertest'
import { config } from '../src/config.js'
import { signOAuthState } from '../src/oauth/state.js'
import { createOAuthCallbackRouter } from '../src/routes/external/oauthCallback.js'
-import { memberOf, seedAllowlistedContext } from './fixtures/contextAllowlist.js'
+import { membership, seedAllowlistedContext } from './fixtures/contextAllowlist.js'
import { MockGateway } from './mockGateway.js'
/**
@@ -109,7 +109,19 @@ describe('GET /api/v1/oauth-callback/:oauthClientId — per-user access re-check
it('403 context_membership_denied when no Context of the user enables the server; no exchange, no grant', async () => {
await seedAllowlistedContext(gateway, 'ctx-mine', ['some-other-server'])
- memberOf(mockPoolQuery, ['ctx-mine'])
+ membership(mockPoolQuery, { contexts: { [USER_ID]: ['ctx-mine'] } })
+
+ const res = await callback()
+
+ expect(res.status).toBe(403)
+ expect(res.body).toEqual({ error: 'context_membership_denied' })
+ expect(fetchSpy).not.toHaveBeenCalled()
+ expect(grantWrites()).toHaveLength(0)
+ })
+
+ it('403 when the signed user is not a member but another user is; no exchange, no grant', async () => {
+ await seedAllowlistedContext(gateway, 'ctx-business', [SERVER])
+ membership(mockPoolQuery, { contexts: { 'someone-else': ['ctx-business'] } })
const res = await callback()
@@ -121,7 +133,7 @@ describe('GET /api/v1/oauth-callback/:oauthClientId — per-user access re-check
it('200 when a Context of the user enables the server, though not its contextRef; exchanges and writes the user grant', async () => {
await seedAllowlistedContext(gateway, 'ctx-business', [SERVER])
- memberOf(mockPoolQuery, ['ctx-business'])
+ membership(mockPoolQuery, { contexts: { [USER_ID]: ['ctx-business'] } })
const res = await callback()
diff --git a/control-api/test/services.access.userMcpServerAccess.test.ts b/control-api/test/services.access.userMcpServerAccess.test.ts
index 420beb6e5..a8dde8d02 100644
--- a/control-api/test/services.access.userMcpServerAccess.test.ts
+++ b/control-api/test/services.access.userMcpServerAccess.test.ts
@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { config } from '../src/config.js'
import { userHasContextEnablingMcpServer } from '../src/services/access/mcpInvocable.js'
-import { memberOf, seedAllowlistedContext } from './fixtures/contextAllowlist.js'
+import { membership, seedAllowlistedContext } from './fixtures/contextAllowlist.js'
import { MockGateway } from './mockGateway.js'
/**
@@ -40,29 +40,33 @@ describe('userHasContextEnablingMcpServer', () => {
it('true when one of the user Contexts allowlists the server', async () => {
await seedAllowlistedContext(gateway, 'ctx-owner', ['notion'])
await seedAllowlistedContext(gateway, 'ctx-business', ['notion', 'gdrive'])
- memberOf(mockPoolQuery, ['ctx-business', 'ctx-unrelated'])
+ membership(mockPoolQuery, { contexts: { 'user-1': ['ctx-business', 'ctx-unrelated'] } })
expect(await check(gateway, 'user-1', 'notion')).toBe(true)
- const [, params] = mockPoolQuery.mock.calls[0]
- expect(params).toEqual(['user-1'])
+ })
+
+ it('false when another user, not the asked one, belongs to the allowlisting Context', async () => {
+ await seedAllowlistedContext(gateway, 'ctx-business', ['notion'])
+ membership(mockPoolQuery, { contexts: { 'user-2': ['ctx-business'] } })
+ expect(await check(gateway, 'user-1', 'notion')).toBe(false)
})
it('false when none of the user Contexts allowlists the server', async () => {
await seedAllowlistedContext(gateway, 'ctx-a', ['gdrive'])
await seedAllowlistedContext(gateway, 'ctx-b', [])
- memberOf(mockPoolQuery, ['ctx-a', 'ctx-b'])
+ membership(mockPoolQuery, { contexts: { 'user-1': ['ctx-a', 'ctx-b'] } })
expect(await check(gateway, 'user-1', 'notion')).toBe(false)
})
it('false when the allowlisting Context is one the user is NOT a member of', async () => {
await seedAllowlistedContext(gateway, 'ctx-owner', ['notion'])
await seedAllowlistedContext(gateway, 'ctx-mine', [])
- memberOf(mockPoolQuery, ['ctx-mine'])
+ membership(mockPoolQuery, { contexts: { 'user-1': ['ctx-mine'] } })
expect(await check(gateway, 'user-1', 'notion')).toBe(false)
})
it('false without listing Contexts when the user belongs to none', async () => {
await seedAllowlistedContext(gateway, 'ctx-owner', ['notion'])
- memberOf(mockPoolQuery, [])
+ membership(mockPoolQuery, { contexts: { 'user-1': [] } })
const listSpy = vi.spyOn(gateway, 'listResource')
expect(await check(gateway, 'user-1', 'notion')).toBe(false)
expect(listSpy).not.toHaveBeenCalled()
@@ -70,7 +74,7 @@ describe('userHasContextEnablingMcpServer', () => {
it('membership is read from user_contexts only (team membership does not count)', async () => {
await seedAllowlistedContext(gateway, 'ctx-team', ['notion'])
- memberOf(mockPoolQuery, [])
+ membership(mockPoolQuery, { contexts: { 'user-1': [] } })
expect(await check(gateway, 'user-1', 'notion')).toBe(false)
const sqls = mockPoolQuery.mock.calls.map(([sql]) => String(sql))
expect(sqls.some(sql => sql.includes('FROM user_contexts'))).toBe(true)
@@ -78,7 +82,7 @@ describe('userHasContextEnablingMcpServer', () => {
})
it('propagates a Context list failure instead of answering false', async () => {
- memberOf(mockPoolQuery, ['ctx-a'])
+ membership(mockPoolQuery, { contexts: { 'user-1': ['ctx-a'] } })
vi.spyOn(gateway, 'listResource').mockRejectedValueOnce(new Error('apiserver down'))
await expect(check(gateway, 'user-1', 'notion')).rejects.toThrow('apiserver down')
})