|
5 | 5 | getEffectiveBlockOutputs, |
6 | 6 | getEffectiveBlockOutputType, |
7 | 7 | } from '@/lib/workflows/blocks/block-outputs' |
| 8 | +import { getBlockReferenceTags } from '@/lib/workflows/blocks/block-reference-tags' |
8 | 9 | import { evaluateSubBlockCondition } from '@/lib/workflows/subblocks/visibility' |
9 | 10 | import { AgentBlock } from '@/blocks/blocks/agent' |
10 | 11 | import { getAgentModelOptions, getModelOptions } from '@/blocks/utils' |
@@ -75,6 +76,110 @@ describe('Agent evaluation configuration', () => { |
75 | 76 | expect(getModelOptions().map((option) => option.id)).not.toContain('jev-1.13.0') |
76 | 77 | }) |
77 | 78 |
|
| 79 | + describe('evaluation answer references', () => { |
| 80 | + const questions = { |
| 81 | + category: { type: 'choice', instructions: 'Choose a category', criteria: { a: 'A', b: 'B' } }, |
| 82 | + rating: { type: 'score', instructions: 'Rate the result', criteria: ['Low', 'High'] }, |
| 83 | + passed: { type: 'noul', instructions: 'Did it pass?' }, |
| 84 | + } |
| 85 | + |
| 86 | + it.each(['jev-1.13.0', 'jev-latest', 'jev-preview', '<start.model>', '{{MODEL_ID}}'])( |
| 87 | + 'exposes typed question fields for %s without an execution result', |
| 88 | + (model) => { |
| 89 | + const values = { |
| 90 | + model: { value: model }, |
| 91 | + evaluationQuestions: { value: JSON.stringify(questions) }, |
| 92 | + responseFormat: { |
| 93 | + value: { schema: { type: 'object', properties: { title: { type: 'string' } } } }, |
| 94 | + }, |
| 95 | + } |
| 96 | + const tags = getBlockReferenceTags({ |
| 97 | + block: { id: 'agent-test', type: 'agent', name: 'Evaluate', subBlocks: values }, |
| 98 | + }) |
| 99 | + const fields = { |
| 100 | + 'answers.category.choice': 'string', |
| 101 | + 'answers.category.confidence': 'number', |
| 102 | + 'answers.category.probabilities': 'json', |
| 103 | + 'answers.category.type': 'string', |
| 104 | + 'answers.rating.score': 'number', |
| 105 | + 'answers.rating.confidence': 'number', |
| 106 | + 'answers.rating.legend': 'json', |
| 107 | + 'answers.passed.noul': 'number', |
| 108 | + } |
| 109 | + for (const [path, type] of Object.entries(fields)) { |
| 110 | + expect(tags).toContain(`evaluate.${path}`) |
| 111 | + expect(getEffectiveBlockOutputType('agent', path, values)).toBe(type) |
| 112 | + } |
| 113 | + expect(getEffectiveBlockOutputType('agent', 'answers', values)).toBe('json') |
| 114 | + expect(getEffectiveBlockOutputType('agent', 'answers.category', values)).toBe('json') |
| 115 | + expect(tags).not.toContain('evaluate.answers.passed.confidence') |
| 116 | + expect(tags.includes('evaluate.title')).toBe(!model.startsWith('jev-')) |
| 117 | + } |
| 118 | + ) |
| 119 | + |
| 120 | + it.each([undefined, '', '{', '<start.questions>', '{{QUESTIONS}}', [], null, { unknown: {} }])( |
| 121 | + 'keeps the answers object selectable when questions cannot be inferred: %j', |
| 122 | + (value) => { |
| 123 | + const values = { model: { value: 'jev-latest' }, evaluationQuestions: { value } } |
| 124 | + expect(getEffectiveBlockOutputPaths('agent', values)).toContain('answers') |
| 125 | + expect(getEffectiveBlockOutputType('agent', 'answers', values)).toBe('json') |
| 126 | + } |
| 127 | + ) |
| 128 | + |
| 129 | + it('uses structured questions and follows edits without leaking fields into chat models', () => { |
| 130 | + const values = { |
| 131 | + model: { value: 'jev-latest' }, |
| 132 | + evaluationQuestions: { value: { result: questions.category } }, |
| 133 | + } |
| 134 | + expect(getEffectiveBlockOutputPaths('agent', values)).toContain('answers.result.choice') |
| 135 | + expect( |
| 136 | + getEffectiveBlockOutputPaths('agent', { |
| 137 | + ...values, |
| 138 | + evaluationQuestions: { value: { result: questions.passed } }, |
| 139 | + }) |
| 140 | + ).not.toContain('answers.result.choice') |
| 141 | + expect( |
| 142 | + getEffectiveBlockOutputPaths('agent', { |
| 143 | + ...values, |
| 144 | + model: { value: 'gpt-4o' }, |
| 145 | + }).some((path) => path.startsWith('answers')) |
| 146 | + ).toBe(false) |
| 147 | + }) |
| 148 | + |
| 149 | + it('does not offer ambiguous reference paths for special question IDs', () => { |
| 150 | + const values = { |
| 151 | + model: { value: 'jev-latest' }, |
| 152 | + evaluationQuestions: { |
| 153 | + value: { |
| 154 | + 'with.dot': questions.passed, |
| 155 | + 'with space': questions.passed, |
| 156 | + 'with[0]': questions.passed, |
| 157 | + '<start.question>': questions.passed, |
| 158 | + 'valid-id_1': questions.passed, |
| 159 | + }, |
| 160 | + }, |
| 161 | + } |
| 162 | + const paths = getEffectiveBlockOutputPaths('agent', values) |
| 163 | + expect(paths.filter((path) => path.startsWith('answers.'))).toEqual([ |
| 164 | + 'answers.valid-id_1.noul', |
| 165 | + 'answers.valid-id_1.type', |
| 166 | + ]) |
| 167 | + expect(getEffectiveBlockOutputType('agent', 'answers', values)).toBe('json') |
| 168 | + }) |
| 169 | + |
| 170 | + it.each(['type', 'properties', 'description', '__proto__'])( |
| 171 | + 'resolves the question named %s through schema properties', |
| 172 | + (id) => { |
| 173 | + const values = { |
| 174 | + model: { value: 'jev-latest' }, |
| 175 | + evaluationQuestions: { value: { [id]: questions.passed } }, |
| 176 | + } |
| 177 | + expect(getEffectiveBlockOutputPaths('agent', values)).toContain(`answers.${id}.noul`) |
| 178 | + expect(getEffectiveBlockOutputType('agent', `answers.${id}.noul`, values)).toBe('number') |
| 179 | + } |
| 180 | + ) |
| 181 | + }) |
| 182 | + |
78 | 183 | it.each([false, true])( |
79 | 184 | 'serializes native fields without requiring messages, advanced=%s', |
80 | 185 | (advancedMode) => { |
|
0 commit comments