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 { createAuth } from './auth.ts'
6
7const TEST_SECRET = 'vitest-only-better-auth-secret-0123456789'
8
9function makeAuth() {
10 return createAuth(getDb(env), {
11 secret: TEST_SECRET,
12 baseUrl: 'http://test.local',
13 })
14}
15
16describe('agent-auth provider surface', () => {
17 it('serves the discovery document with our provider identity and modes', async () => {
18 const config = (await makeAuth().api.getAgentConfiguration()) as {
19 provider_name: string
20 modes: Array<string>
21 endpoints: Record<string, string>
22 default_location: string
23 }
24 expect(config.provider_name).toBe('modelschemas')
25 expect(config.modes).toEqual(
26 expect.arrayContaining(['autonomous', 'delegated']),
27 )
28 expect(config.endpoints.register).toBe(
29 'http://test.local/api/auth/agent/register',
30 )
31 expect(config.default_location).toBe(
32 'http://test.local/api/auth/capability/execute',
33 )
34 })
35
36 it('lists capabilities derived from openapi.json plus manage_subscriptions, minus admin', async () => {
37 const listed = (await makeAuth().api.listCapabilities()) as {
38 capabilities: Array<{ name: string; approval_strength?: string }>
39 }
40 const names = listed.capabilities.map((c) => c.name)
41 for (const expected of [
42 'getSchema',
43 'getProviderOpenApi',
44 'listModels',
45 'getModel',
46 'listProviders',
47 'listProviderSchemas',
48 'getActivitySchemas',
49 'validatePayload',
50 'estimateCost',
51 'listChanges',
52 'getStatus',
53 'manage_subscriptions',
54 ]) {
55 expect(names).toContain(expected)
56 }
57 expect(names).not.toContain('syncProvider')
58 expect(names).not.toContain('extractFalPricing')
59
60 // Read/validate capabilities are approval-free for autonomous agents.
61 const getSchema = listed.capabilities.find((c) => c.name === 'getSchema')
62 expect(getSchema?.approval_strength).toBe('none')
63 })
64})