Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { env } from 'cloudflare:test'
3
4import { getDb } from '../db/index.ts'
5import { openApiDocument } from '../server/openapi.ts'
6import { createAuth } from './auth.ts'
7
8const TEST_SECRET = 'vitest-only-better-auth-secret-0123456789'
9
10function makeAuth() {
11 return createAuth(getDb(env), {
12 secret: TEST_SECRET,
13 baseUrl: 'http://test.local',
14 })
15}
16
17describe('agent-auth provider surface', () => {
18 it('serves the discovery document with our provider identity and modes', async () => {
19 const config = (await makeAuth().api.getAgentConfiguration()) as {
20 provider_name: string
21 modes: Array<string>
22 endpoints: Record<string, string>
23 default_location: string
24 }
25 expect(config.provider_name).toBe('modelschemas')
26 expect(config.modes).toEqual(
27 expect.arrayContaining(['autonomous', 'delegated']),
28 )
29 expect(config.endpoints.register).toBe(
30 'http://test.local/api/auth/agent/register',
31 )
32 expect(config.default_location).toBe(
33 'http://test.local/api/auth/capability/execute',
34 )
35 })
36
37 it('lists capabilities derived from openapi.json plus manage_subscriptions, minus admin', async () => {
38 const listed = (await makeAuth().api.listCapabilities()) as {
39 capabilities: Array<{ name: string; approval_strength?: string }>
40 }
41 const names = listed.capabilities.map((c) => c.name)
42 for (const expected of [
43 'getSchema',
44 'getProviderOpenApi',
45 'listModels',
46 'getModel',
47 'listProviders',
48 'listProviderSchemas',
49 'getActivitySchemas',
50 'validatePayload',
51 'estimateCost',
52 'listChanges',
53 'getStatus',
54 'manage_subscriptions',
55 ]) {
56 expect(names).toContain(expected)
57 }
58 // Every admin op in the spec, so a renamed operationId cannot leak.
59 const adminOps = Object.entries(openApiDocument.paths)
60 .filter(([path]) => path.startsWith('/v1/admin/'))
61 .flatMap(([, ops]) =>
62 Object.values(ops as Record<string, { operationId: string }>).map(
63 (op) => op.operationId,
64 ),
65 )
66 expect(adminOps).toEqual(
67 expect.arrayContaining([
68 'syncProvider',
69 'extractFalPricing',
70 'exportCatalog',
71 ]),
72 )
73 for (const op of adminOps) expect(names).not.toContain(op)
74
75 // Read/validate capabilities are approval-free for autonomous agents.
76 const getSchema = listed.capabilities.find((c) => c.name === 'getSchema')
77 expect(getSchema?.approval_strength).toBe('none')
78 })
79})