-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathcapability-config.test.ts
More file actions
95 lines (88 loc) · 2.86 KB
/
Copy pathcapability-config.test.ts
File metadata and controls
95 lines (88 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { describe, expect, it } from 'bun:test'
import {
defineCapability,
ENV_CAPABILITIES,
envField,
OAUTH_CLIENT_CAPABILITIES,
} from '../../apps/sim/lib/core/config/env-capabilities.ts'
import {
CAPABILITY_SETUPS,
defineCapabilitySetup,
EMAIL_SETUP,
getOAuthClientSetupFields,
KNOWLEDGE_EMBEDDINGS_SETUP,
STORAGE_SETUP,
} from './capability-config.ts'
import { getCapabilitySetupOptions } from './capability-setup.ts'
describe('capability setup configuration', () => {
it('maps every runtime capability and provider exactly once', () => {
expect(CAPABILITY_SETUPS.map((setup) => setup.definition.id)).toEqual(
ENV_CAPABILITIES.map((capability) => capability.id)
)
for (const setup of CAPABILITY_SETUPS) {
expect(Object.keys(setup.providers).sort()).toEqual(
setup.definition.providers.map((provider) => provider.id).sort()
)
}
})
it('fails fast when CLI prompts omit a runtime-owned provider field', () => {
const definition = defineCapability({
strategy: 'fallback',
id: 'sample',
label: 'Sample',
providers: [
{
id: 'remote',
label: 'Remote',
activation: { mode: 'any-present', keys: ['REMOTE_KEY'] },
requires: envField('REMOTE_KEY'),
},
],
} as const)
expect(() =>
defineCapabilitySetup(definition, {
label: 'Sample',
message: 'Sample provider?',
actions: {},
providers: { remote: { prompts: [] } },
optionOrder: ['remote'],
} as never)
).toThrow(/missing: REMOTE_KEY/)
expect(() =>
defineCapabilitySetup(definition, {
label: 'Sample',
message: 'Sample provider?',
actions: {},
providers: {
remote: {
env: { MISSPELLED_REMOTE_KEY: 'true' },
prompts: [{ type: 'field', key: 'REMOTE_KEY', input: 'secret' }],
},
},
optionOrder: ['remote'],
})
).toThrow(/unknown: MISSPELLED_REMOTE_KEY/)
})
it('keeps presets out of the generic provider choices', () => {
expect(getCapabilitySetupOptions(EMAIL_SETUP).map((option) => option.id)).not.toContain(
'mailhog'
)
expect(getCapabilitySetupOptions(STORAGE_SETUP).map((option) => option.id)).not.toContain(
's3-compatible'
)
})
it('offers OpenAI first for fresh knowledge embedding setup', () => {
expect(
getCapabilitySetupOptions(KNOWLEDGE_EMBEDDINGS_SETUP).map((option) => option.id)
).toEqual(['openai', 'azure-openai', 'openrouter'])
})
it('maps every OAuth runtime field to a CLI input mode in runtime order', () => {
for (const id of Object.keys(OAUTH_CLIENT_CAPABILITIES) as Array<
keyof typeof OAUTH_CLIENT_CAPABILITIES
>) {
expect(getOAuthClientSetupFields(id).map((field) => field.key)).toEqual(
OAUTH_CLIENT_CAPABILITIES[id]
)
}
})
})