From 021010a338cc04812d1b3026f9aba79841ec264a Mon Sep 17 00:00:00 2001 From: sudacode Date: Sun, 8 Mar 2026 16:11:13 -0700 Subject: [PATCH] test(ai): cover shared client helpers --- src/ai/client.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/ai/client.test.ts diff --git a/src/ai/client.test.ts b/src/ai/client.test.ts new file mode 100644 index 0000000..1643c39 --- /dev/null +++ b/src/ai/client.test.ts @@ -0,0 +1,21 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; + +import { extractAiText, normalizeOpenAiBaseUrl } from './client'; + +test('normalizeOpenAiBaseUrl appends v1 when missing', () => { + assert.equal(normalizeOpenAiBaseUrl('https://openrouter.ai/api'), 'https://openrouter.ai/api/v1'); + assert.equal(normalizeOpenAiBaseUrl('https://example.test/v1'), 'https://example.test/v1'); +}); + +test('extractAiText joins OpenAI structured text parts', () => { + assert.equal( + extractAiText([ + { type: 'text', text: 'hello ' }, + { type: 'text', text: 'world' }, + { type: 'image', text: 'ignored' }, + ]), + 'hello world', + ); + assert.equal(extractAiText(' plain text '), 'plain text'); +});