Repository Public
1// Tests unitaires des fournisseurs : nettoyage de sortie, extraction JSON, requête locale sans aucun outil.2import assert from "node:assert/strict"3import { test } from "node:test"4import { cleanText, localRequestBody, parseJsonOutput } from "./ai-providers"56test("sortie : raisonnement apparent retiré, JSON extrait malgré les clôtures et le texte autour", () => {7 assert.equal(cleanText("<think>je réfléchis</think>\nRéponse"), "Réponse")8 assert.equal(cleanText("réflexion sans ouverture</think> Réponse "), "Réponse")9 assert.deepEqual(parseJsonOutput('```json\n{"a": 1}\n```'), { a: 1 })10 assert.deepEqual(parseJsonOutput('Voici : {"a": {"b": [1, 2]}} voilà'), { a: { b: [1, 2] } })11 assert.deepEqual(parseJsonOutput('<think>{"faux": true}</think>{"vrai": true}'), { vrai: true })12 assert.throws(() => parseJsonOutput("aucun objet"), SyntaxError)13 assert.throws(() => parseJsonOutput('{"a": '), SyntaxError)14 assert.throws(() => parseJsonOutput("[1, 2]"), SyntaxError)15})1617test("requête locale : système + messages, plafond de sortie, jamais d'outil ni de flux", () => {18 const body = localRequestBody("maclustr-qwen3", { system: "S", maxTokens: 321 }, [{ role: "user", content: "U" }])19 assert.deepEqual(body.messages, [{ role: "system", content: "S" }, { role: "user", content: "U" }])20 assert.equal(body.max_tokens, 321)21 assert.equal(body.stream, false)22 for (const k of ["tools", "functions", "tool_choice", "function_call"]) assert.ok(!(k in body), k)23})24