|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { z } from 'zod'; |
| 3 | +import { judgeNode } from '../builders/nodes.js'; |
| 4 | + |
| 5 | +describe('judgeNode', () => { |
| 6 | + it('creates a gmi node with judge instructions', () => { |
| 7 | + const node = judgeNode({ |
| 8 | + rubric: 'Score accuracy (1-10) and credibility (1-10)', |
| 9 | + schema: z.object({ accuracy: z.number(), credibility: z.number() }), |
| 10 | + }); |
| 11 | + expect(node.type).toBe('gmi'); |
| 12 | + expect(node.executionMode).toBe('single_turn'); |
| 13 | + expect(node.executorConfig.type).toBe('gmi'); |
| 14 | + if (node.executorConfig.type === 'gmi') { |
| 15 | + expect(node.executorConfig.instructions).toContain('evaluation judge'); |
| 16 | + expect(node.executorConfig.instructions).toContain('Score accuracy'); |
| 17 | + } |
| 18 | + }); |
| 19 | + |
| 20 | + it('includes threshold in instructions', () => { |
| 21 | + const node = judgeNode({ |
| 22 | + rubric: 'Score quality 1-10', |
| 23 | + schema: z.object({ quality: z.number() }), |
| 24 | + threshold: 7, |
| 25 | + }); |
| 26 | + if (node.executorConfig.type === 'gmi') { |
| 27 | + expect(node.executorConfig.instructions).toContain('7'); |
| 28 | + expect(node.executorConfig.instructions).toContain('Pass Threshold'); |
| 29 | + } |
| 30 | + }); |
| 31 | + |
| 32 | + it('sets outputSchema from Zod schema', () => { |
| 33 | + const node = judgeNode({ |
| 34 | + rubric: 'Rate it', |
| 35 | + schema: z.object({ score: z.number() }), |
| 36 | + }); |
| 37 | + expect(node.outputSchema).toBeDefined(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('generates unique ID with judge prefix', () => { |
| 41 | + const a = judgeNode({ rubric: 'r', schema: z.object({}) }); |
| 42 | + const b = judgeNode({ rubric: 'r', schema: z.object({}) }); |
| 43 | + expect(a.id).not.toBe(b.id); |
| 44 | + expect(a.id).toMatch(/judge/); |
| 45 | + }); |
| 46 | +}); |
0 commit comments