config-llm-block.test.mjs
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d
docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge
Human
14 hours ago
| 1 | /** |
| 2 | * loadLlmConfig — parsing/validation of the top-level `llm` block (lib/config.mjs). |
| 3 | * |
| 4 | * This is the data-integrity + security boundary for the persisted chat-provider setting: an |
| 5 | * invalid or hostile provider value in config/local.yaml must never reach completeChat as an |
| 6 | * unknown/forced provider. Only whitelisted providers survive; everything else collapses to '' |
| 7 | * (auto-detect). |
| 8 | */ |
| 9 | import { describe, it } from 'node:test'; |
| 10 | import assert from 'node:assert'; |
| 11 | import { loadLlmConfig, CHAT_PROVIDERS } from '../lib/config.mjs'; |
| 12 | |
| 13 | describe('loadLlmConfig', () => { |
| 14 | it('accepts each whitelisted provider', () => { |
| 15 | for (const p of CHAT_PROVIDERS) { |
| 16 | assert.strictEqual(loadLlmConfig({ provider: p }).provider, p); |
| 17 | } |
| 18 | }); |
| 19 | |
| 20 | it('lowercases and trims the provider', () => { |
| 21 | assert.strictEqual(loadLlmConfig({ provider: ' OpenAI ' }).provider, 'openai'); |
| 22 | }); |
| 23 | |
| 24 | it('drops an unknown provider to "" (auto-detect)', () => { |
| 25 | assert.strictEqual(loadLlmConfig({ provider: 'totally-made-up' }).provider, ''); |
| 26 | }); |
| 27 | |
| 28 | it('drops an injection-style provider value', () => { |
| 29 | assert.strictEqual(loadLlmConfig({ provider: 'openai; rm -rf /' }).provider, ''); |
| 30 | assert.strictEqual(loadLlmConfig({ provider: '../../etc/passwd' }).provider, ''); |
| 31 | }); |
| 32 | |
| 33 | it('handles missing / non-object input safely', () => { |
| 34 | assert.strictEqual(loadLlmConfig(undefined).provider, ''); |
| 35 | assert.strictEqual(loadLlmConfig(null).provider, ''); |
| 36 | assert.strictEqual(loadLlmConfig('nope').provider, ''); |
| 37 | assert.strictEqual(loadLlmConfig(42).provider, ''); |
| 38 | }); |
| 39 | |
| 40 | it('passes through model overrides, defaulting absent ones to undefined', () => { |
| 41 | const out = loadLlmConfig({ |
| 42 | provider: 'openrouter', |
| 43 | openrouter_chat_model: 'anthropic/claude-3.5-haiku', |
| 44 | }); |
| 45 | assert.strictEqual(out.openrouter_chat_model, 'anthropic/claude-3.5-haiku'); |
| 46 | assert.strictEqual(out.openai_chat_model, undefined); |
| 47 | assert.strictEqual(out.anthropic_chat_model, undefined); |
| 48 | assert.strictEqual(out.deepinfra_chat_model, undefined); |
| 49 | assert.strictEqual(out.ollama_chat_model, undefined); |
| 50 | }); |
| 51 | |
| 52 | it('CHAT_PROVIDERS lists exactly the providers completeChat handles explicitly', () => { |
| 53 | assert.deepStrictEqual( |
| 54 | [...CHAT_PROVIDERS].sort(), |
| 55 | ['anthropic', 'deepinfra', 'ollama', 'openai', 'openrouter'], |
| 56 | ); |
| 57 | }); |
| 58 | }); |
File History
1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d
docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge
Human
14 hours ago