"use strict"; const test = require("node:test"); const assert = require("node:assert/strict"); const { createTTSAdapter } = require("../src/integrations/tts-client"); test("synthesize returns buffer from qwen-compatible audio endpoint", async () => { const calls = []; const adapter = createTTSAdapter({ apiKey: "qwen-key", baseURL: "https://qwen.example/v1", fetchImpl: async (url, init) => { calls.push({ url, init }); return { ok: true, status: 200, async arrayBuffer() { return Uint8Array.from([1, 2, 3]).buffer; }, }; }, }); const bytes = await adapter.synthesize("hello"); assert.equal(Buffer.isBuffer(bytes), true); assert.equal(bytes.length, 3); assert.equal(calls.length, 1); assert.equal(calls[0].url, "https://qwen.example/v1/audio/speech"); assert.match(String(calls[0].init.headers.authorization), /^Bearer qwen-key$/); assert.match(String(calls[0].init.body), /"model":"qwen-tts-latest"/); }); test("throws when tts adapter is not configured", async () => { const adapter = createTTSAdapter({}); await assert.rejects(() => adapter.synthesize("hello"), /tts_not_configured/); }); test("throws with upstream status code when synthesis fails", async () => { const adapter = createTTSAdapter({ apiKey: "qwen-key", fetchImpl: async () => ({ ok: false, status: 401, async arrayBuffer() { return new ArrayBuffer(0); }, }), }); await assert.rejects(() => adapter.synthesize("hello"), /tts_request_failed:401/); });