ai-schema-gen.test.ts49 lines · main
| 1 | /** |
| 2 | * AI schema generator boundary tests — pin the not-configured behaviour |
| 3 | * and the validation rules around prompts. The Ollama-touching path is |
| 4 | * exercised by a manual smoke against the live DGX; this file covers |
| 5 | * the pure decisions. |
| 6 | */ |
| 7 | |
| 8 | import { describe, expect, test } from 'bun:test'; |
| 9 | |
| 10 | import { AiNotConfiguredError } from './ai-schema-gen.js'; |
| 11 | |
| 12 | describe('AiNotConfiguredError', () => { |
| 13 | test('carries the documented name', () => { |
| 14 | const err = new AiNotConfiguredError(); |
| 15 | expect(err.name).toBe('AiNotConfiguredError'); |
| 16 | }); |
| 17 | |
| 18 | test('the error message mentions the env var to set', () => { |
| 19 | const err = new AiNotConfiguredError(); |
| 20 | expect(err.message).toContain('BRIVEN_OLLAMA_URL'); |
| 21 | }); |
| 22 | }); |
| 23 | |
| 24 | describe('prompt validation rules', () => { |
| 25 | // Mirrors the zod schema on the route — 1 to 4000 chars. |
| 26 | function isValidPrompt(prompt: unknown): boolean { |
| 27 | return typeof prompt === 'string' && prompt.length >= 1 && prompt.length <= 4000; |
| 28 | } |
| 29 | |
| 30 | test('rejects empty string', () => { |
| 31 | expect(isValidPrompt('')).toBe(false); |
| 32 | }); |
| 33 | |
| 34 | test('rejects non-string', () => { |
| 35 | expect(isValidPrompt(null)).toBe(false); |
| 36 | expect(isValidPrompt(undefined)).toBe(false); |
| 37 | expect(isValidPrompt(42)).toBe(false); |
| 38 | expect(isValidPrompt({})).toBe(false); |
| 39 | }); |
| 40 | |
| 41 | test('accepts a typical prompt', () => { |
| 42 | expect(isValidPrompt('a blog with users + posts + comments')).toBe(true); |
| 43 | }); |
| 44 | |
| 45 | test('caps at 4000 chars (4001 rejected)', () => { |
| 46 | expect(isValidPrompt('x'.repeat(4000))).toBe(true); |
| 47 | expect(isValidPrompt('x'.repeat(4001))).toBe(false); |
| 48 | }); |
| 49 | }); |