Skip to content

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

TypeScript

Merge remote-tracking branch 'origin/dev' into feat/mcp-server-oauth

Diego Zacarias5ad250267824
diff --cc control-api/src/db.ts
index f335c7a18,4d37efad1..ced7f8a51
--- a/control-api/src/db.ts
+++ b/control-api/src/db.ts
@@@ -5915,9 -5915,23 +5915,27 @@@ export const CONTROL_API_MIGRATIONS: Db
apply: applyGfsUploadFinalizingSchema,
},
{
- version: '0100_oauth_grants_owner_generalization',
+ version: '0100_seed_minimax_allowed_model',
+ apply: async db => {
+ // Seed one sensible default model for the newly added `minimax` provider
+ // (packages/llm-providers). Same shape as 0056/0057/0058: enabled=true (a
+ // provider without credentials is unusable regardless), a `vendor` label
+ // for UI grouping, and ON CONFLICT DO NOTHING so the migration stays
+ // idempotent and never clobbers an admin-edited row. `MiniMax-M2` mirrors
+ // registryCore's minimax defaultModel. Operators curate the rest via
+ // /llm-models.
+ await db.query(`
+ INSERT INTO llm_allowed_models (provider, model, vendor)
+ VALUES
+ ('minimax', 'MiniMax-M2', 'MiniMax')
+ ON CONFLICT DO NOTHING;
+ `)
+ },
+ },
++ {
++ version: '0101_oauth_grants_owner_generalization',
+ apply: applyOAuthGrantsOwnerGeneralization,
+ },
]
async function consolidateWorkflowAllowedUsersToTriggers(db: DbClient): Promise<void> {
diff --cc control-api/test/db.oauthGrantsOwnerGeneralization.test.ts
index 37139c880,000000000..6b7ce605c
mode 100644,000000..100644
--- a/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts
+++ b/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts
@@@ -1,65 -1,0 +1,66 @@@
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+
+const clientQuery = vi.fn()
+const clientRelease = vi.fn()
+const mockConnect = vi.fn()
+const mockPoolCtor = vi.fn(function MockPool() {
+ return { connect: mockConnect, query: vi.fn() }
+})
+
+vi.mock('pg', () => ({ Pool: mockPoolCtor }))
+
+describe('0091 oauth_grants owner generalization migration', () => {
+ beforeEach(() => {
+ vi.resetModules()
+ vi.clearAllMocks()
+ mockConnect.mockResolvedValue({ query: clientQuery, release: clientRelease })
+ clientQuery.mockResolvedValue({ rows: [], rowCount: 0 })
+ })
+
- it('is registered last in the migration array, after 0099', async () => {
++ it('is registered last in the migration array, after 0100_seed_minimax', async () => {
+ const { CONTROL_API_MIGRATIONS } = await import('../src/db.js')
+ const versions = CONTROL_API_MIGRATIONS.map(m => m.version)
- expect(versions.at(-1)).toBe('0100_oauth_grants_owner_generalization')
++ expect(versions.at(-1)).toBe('0101_oauth_grants_owner_generalization')
+ expect(versions).toContain('0099_gfs_upload_finalizing_recovery')
++ expect(versions).toContain('0100_seed_minimax_allowed_model')
+ })
+
+ it('adds owner_kind/context_id/bootstrapped_by, replaces the kind CHECK to admit shared, and rebuilds uniqueness', async () => {
+ const { initDb } = await import('../src/db.js')
+ await initDb()
+ const sqls = clientQuery.mock.calls.map(([sql]) => String(sql))
+ const migration = sqls.find(
+ sql => sql.includes('ADD COLUMN IF NOT EXISTS owner_kind') && sql.includes('oauth_grants')
+ )
+ expect(migration, 'the 0091 DDL was applied').toBeDefined()
+ const ddl = migration as string
+
+ // New columns (idempotent).
+ expect(ddl).toContain("ADD COLUMN IF NOT EXISTS owner_kind TEXT NOT NULL DEFAULT 'recipe'")
+ expect(ddl).toContain('ADD COLUMN IF NOT EXISTS context_id TEXT')
+ expect(ddl).toContain('ADD COLUMN IF NOT EXISTS bootstrapped_by_user_id TEXT')
+
+ // The kind/user_id CHECK is DROP+re-ADD to admit 'shared' — without this a
+ // shared INSERT would violate the old user/service-only CHECK.
+ expect(ddl).toContain('DROP CONSTRAINT IF EXISTS oauth_grants_kind_userid_check')
+ expect(ddl).toContain("grant_kind = 'shared' AND user_id IS NULL")
+ expect(ddl).toContain('context_id IS NOT NULL')
+ expect(ddl).toContain('bootstrapped_by_user_id IS NOT NULL')
+
+ // oauth_grants_unique recreated as a superset with owner_kind.
+ expect(ddl).toContain('DROP CONSTRAINT IF EXISTS oauth_grants_unique')
+ expect(ddl).toContain(
+ 'UNIQUE (owner_kind, recipe_namespace, recipe_name, user_id, oauth_client_id)'
+ )
+
+ // Shared partial unique index keyed by context_id.
+ expect(ddl).toContain('CREATE UNIQUE INDEX IF NOT EXISTS oauth_grants_shared_unique')
+ expect(ddl).toContain(
+ 'ON oauth_grants (owner_kind, recipe_namespace, recipe_name, context_id, oauth_client_id)'
+ )
+ expect(ddl).toContain("WHERE grant_kind = 'shared'")
+
+ // Non-destructive: recipe_namespace/recipe_name are NOT renamed.
+ expect(ddl).not.toContain('RENAME COLUMN')
+ })
+})