|
1 | 1 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
2 | | -import type { V2BlockDetail } from '@/lib/api/contracts/v2/catalog' |
| 2 | +import { mothershipBlockDetailSchema } from '@/lib/api/contracts/mothership-catalog' |
| 3 | +import { type V2BlockDetail, v2BlockDetailSchema } from '@/lib/api/contracts/v2/catalog' |
3 | 4 | import { curateBlockDetail } from '@/lib/mothership/agent-cli/curation' |
| 5 | +import { PROVIDER_DEFINITIONS } from '@/providers/models' |
4 | 6 |
|
5 | 7 | const { permissionConfig, denied } = vi.hoisted(() => ({ |
6 | 8 | permissionConfig: { current: null as { deniedTools?: string[] } | null }, |
@@ -96,6 +98,61 @@ describe('curateBlockDetail', () => { |
96 | 98 | expect(curated.toolIds).toEqual(['slack_send']) |
97 | 99 | }) |
98 | 100 |
|
| 101 | + it('adds canonical model hints only on the internal curated response', async () => { |
| 102 | + const models = Object.values(PROVIDER_DEFINITIONS) |
| 103 | + .flatMap((provider) => provider.models) |
| 104 | + .filter((model) => model.sunset?.status !== 'deprecated') |
| 105 | + const original = { |
| 106 | + ...blockDetail(), |
| 107 | + inputSchema: [ |
| 108 | + { |
| 109 | + id: 'model', |
| 110 | + type: 'combobox', |
| 111 | + options: [...models.map((model) => ({ id: model.id })), { id: 'private-local-model' }], |
| 112 | + }, |
| 113 | + ], |
| 114 | + } |
| 115 | + const publicShape = v2BlockDetailSchema.parse(original) |
| 116 | + expect(publicShape).toEqual(original) |
| 117 | + const result = await curateBlockDetail(ok(JSON.stringify(original)), viewer) |
| 118 | + const detail = mothershipBlockDetailSchema.parse(JSON.parse(result.stdout)) |
| 119 | + const field = detail.inputSchema[0]! |
| 120 | + expect(field.optionsAvailability).toContain( |
| 121 | + 'deployment, provider credentials and model permissions' |
| 122 | + ) |
| 123 | + expect(field.options).toHaveLength(original.inputSchema[0]!.options.length) |
| 124 | + for (const model of models) { |
| 125 | + const option = field.options!.find((option) => option.id === model.id)! |
| 126 | + expect(option.recommended).toBe(model.recommended || undefined) |
| 127 | + expect(option.speedOptimized).toBe(model.speedOptimized || undefined) |
| 128 | + expect(option.sunset).toEqual(model.sunset) |
| 129 | + expect(option).not.toHaveProperty('runnable') |
| 130 | + expect(option).not.toHaveProperty('pricing') |
| 131 | + } |
| 132 | + expect(field.options!.at(-1)).toEqual({ id: 'private-local-model' }) |
| 133 | + expect(v2BlockDetailSchema.parse(detail)).toEqual(original) |
| 134 | + }) |
| 135 | + |
| 136 | + it('applies denied operation projection before adding model hints', async () => { |
| 137 | + permissionConfig.current = { deniedTools: ['slack_canvas'] } |
| 138 | + denied.current.needsProjection.set('slack', new Set(['canvas'])) |
| 139 | + const original = blockDetail() |
| 140 | + original.inputSchema.push({ |
| 141 | + id: 'model', |
| 142 | + type: 'combobox', |
| 143 | + options: [{ id: 'claude-sonnet-5' }], |
| 144 | + }) |
| 145 | + const result = await curateBlockDetail(ok(JSON.stringify(original)), viewer) |
| 146 | + const detail = mothershipBlockDetailSchema.parse(JSON.parse(result.stdout)) |
| 147 | + expect(Object.keys(detail.operations)).toEqual(['send']) |
| 148 | + expect(detail.inputSchema[0]!.options).toEqual([{ id: 'send' }]) |
| 149 | + expect(detail.inputSchema[1]!.optionsAvailability).toBeDefined() |
| 150 | + denied.current.fullyDenied.add('slack') |
| 151 | + const blocked = await curateBlockDetail(ok(JSON.stringify(original)), viewer) |
| 152 | + expect(blocked.exitCode).toBe(1) |
| 153 | + expect(blocked.stdout).not.toContain('recommended') |
| 154 | + }) |
| 155 | + |
99 | 156 | it('refuses a fully denied block', async () => { |
100 | 157 | permissionConfig.current = { deniedTools: ['slack_send', 'slack_canvas'] } |
101 | 158 | denied.current = { needsProjection: new Map(), fullyDenied: new Set(['slack']) } |
|
0 commit comments