|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + */ |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | +import { MintlifyBlock } from './mintlify' |
| 6 | + |
| 7 | +/** |
| 8 | + * The executor merges `tools.config.params` on top of the raw inputs, so every |
| 9 | + * assertion runs against the merged result rather than the transform's return |
| 10 | + * value alone. |
| 11 | + */ |
| 12 | +function resolveParams(inputs: Record<string, unknown>) { |
| 13 | + return { ...inputs, ...MintlifyBlock.tools.config.params!(inputs) } |
| 14 | +} |
| 15 | + |
| 16 | +describe('MintlifyBlock', () => { |
| 17 | + describe('tool selection', () => { |
| 18 | + it('maps every operation option to a registered tool ID', () => { |
| 19 | + const operationSubBlock = MintlifyBlock.subBlocks.find((block) => block.id === 'operation') |
| 20 | + const operations = operationSubBlock?.options as { id: string }[] |
| 21 | + |
| 22 | + expect(operations.length).toBeGreaterThan(0) |
| 23 | + for (const { id } of operations) { |
| 24 | + const toolId = MintlifyBlock.tools.config!.tool!({ operation: id }) |
| 25 | + expect(MintlifyBlock.tools.access).toContain(toolId) |
| 26 | + } |
| 27 | + }) |
| 28 | + |
| 29 | + it('exposes one operation option per accessible tool', () => { |
| 30 | + const operationSubBlock = MintlifyBlock.subBlocks.find((block) => block.id === 'operation') |
| 31 | + const operations = operationSubBlock?.options as { id: string }[] |
| 32 | + expect(operations).toHaveLength(MintlifyBlock.tools.access!.length) |
| 33 | + }) |
| 34 | + }) |
| 35 | + |
| 36 | + describe('operation scoping', () => { |
| 37 | + it('clears advanced values retained from another operation', () => { |
| 38 | + const result = resolveParams({ |
| 39 | + operation: 'get_feedback', |
| 40 | + projectId: 'proj_1', |
| 41 | + // Retained from a prior Get Page Views selection, whose limit ceiling is 250. |
| 42 | + offset: '100', |
| 43 | + limit: '200', |
| 44 | + }) |
| 45 | + |
| 46 | + expect(result.offset).toBeUndefined() |
| 47 | + expect(result.limit).toBe(200) |
| 48 | + }) |
| 49 | + |
| 50 | + it('clears a retained search filter when an analytics operation runs', () => { |
| 51 | + const result = resolveParams({ |
| 52 | + operation: 'get_views', |
| 53 | + projectId: 'proj_1', |
| 54 | + query: 'stale query', |
| 55 | + groups: '["internal"]', |
| 56 | + tag: 'api-reference', |
| 57 | + }) |
| 58 | + |
| 59 | + expect(result.query).toBeUndefined() |
| 60 | + expect(result.groups).toBeUndefined() |
| 61 | + expect(result.tag).toBeUndefined() |
| 62 | + }) |
| 63 | + |
| 64 | + it('leaves the model arguments untouched on the agent-tool path', () => { |
| 65 | + const agentArgs = { projectId: 'proj_1', limit: 25 } |
| 66 | + expect(resolveParams(agentArgs)).toEqual(agentArgs) |
| 67 | + }) |
| 68 | + }) |
| 69 | + |
| 70 | + describe('param aliasing', () => { |
| 71 | + it('forwards the prose-check path under the tool param name', () => { |
| 72 | + const result = resolveParams({ |
| 73 | + operation: 'detect_ai_prose', |
| 74 | + projectId: 'proj_1', |
| 75 | + deslopPath: 'guides/quickstart.mdx', |
| 76 | + content: '# Quickstart', |
| 77 | + }) |
| 78 | + |
| 79 | + expect(result.path).toBe('guides/quickstart.mdx') |
| 80 | + }) |
| 81 | + |
| 82 | + it('forwards the page-content path under the tool param name', () => { |
| 83 | + const result = resolveParams({ |
| 84 | + operation: 'get_page_content', |
| 85 | + domain: 'acme', |
| 86 | + pagePath: 'guides/quickstart', |
| 87 | + }) |
| 88 | + |
| 89 | + expect(result.path).toBe('guides/quickstart') |
| 90 | + }) |
| 91 | + |
| 92 | + it('forwards the feedback filters under their tool param names', () => { |
| 93 | + const result = resolveParams({ |
| 94 | + operation: 'get_feedback', |
| 95 | + projectId: 'proj_1', |
| 96 | + feedbackSource: 'contextual', |
| 97 | + feedbackStatus: 'pending,resolved', |
| 98 | + }) |
| 99 | + |
| 100 | + expect(result.source).toBe('contextual') |
| 101 | + expect(result.status).toBe('pending,resolved') |
| 102 | + }) |
| 103 | + }) |
| 104 | + |
| 105 | + describe('numeric coercion', () => { |
| 106 | + it('coerces numeric inputs delivered as strings', () => { |
| 107 | + const result = resolveParams({ |
| 108 | + operation: 'search', |
| 109 | + domain: 'acme', |
| 110 | + query: 'custom domains', |
| 111 | + pageSize: '25', |
| 112 | + scoreThreshold: '0.4', |
| 113 | + }) |
| 114 | + |
| 115 | + expect(result.pageSize).toBe(25) |
| 116 | + expect(result.scoreThreshold).toBe(0.4) |
| 117 | + }) |
| 118 | + |
| 119 | + it('drops a numeric input that cannot be parsed', () => { |
| 120 | + const result = resolveParams({ |
| 121 | + operation: 'get_views', |
| 122 | + projectId: 'proj_1', |
| 123 | + limit: 'not-a-number', |
| 124 | + }) |
| 125 | + |
| 126 | + expect(result.limit).toBeUndefined() |
| 127 | + }) |
| 128 | + |
| 129 | + it('drops empty optional values', () => { |
| 130 | + const result = resolveParams({ |
| 131 | + operation: 'get_searches', |
| 132 | + projectId: 'proj_1', |
| 133 | + dateFrom: '', |
| 134 | + cursor: '', |
| 135 | + }) |
| 136 | + |
| 137 | + expect(result.dateFrom).toBeUndefined() |
| 138 | + expect(result.cursor).toBeUndefined() |
| 139 | + }) |
| 140 | + }) |
| 141 | +}) |
0 commit comments