feat: finaliser l’intégration au Référentiel IA
All checks were successful
Deploy Production / deploy (push) Has been skipped
Deploy Recette / deploy (push) Successful in 1m4s

This commit is contained in:
manus-admin
2026-10-06 16:58:11 +02:00
parent fd58573685
commit ba34233189
9 changed files with 218 additions and 183 deletions

View File

@@ -2,25 +2,51 @@ import { describe, expect, it, vi } from "vitest";
import { ENV } from "./env";
import { invokeSelectedReference } from "./aiReferenceClient";
const recommendation = {
application: { slug: "veille-reglementaire" },
decision: {
selected: {
origin: "manual",
engine: { slug: "manus-forge", name: "Manus Forge", provider: "Manus" },
connection: { configured: true, model: "gemini-2.5-flash" },
},
},
};
describe("client Référentiel IA", () => {
it("transmet seulement le payload métier et restitue la trace résolue", async () => {
it("résout le moteur du Référentiel puis transmet son slug exact", async () => {
ENV.aiReferentielUrl = "https://referentiel-ia.recette.santinova-soft.org";
ENV.aiReferentielToken = "token-de-test";
const fetcher = vi.fn(async () => new Response(JSON.stringify({ choices: [] }), {
status: 200,
headers: {
"x-santinova-ia-provider": "Manus",
"x-santinova-ia-model": "gemini-2.5-flash",
"x-santinova-ia-transport": "manus-forge",
"x-santinova-ia-origin": "manual",
},
}));
ENV.aiReferentielAppSlug = "veille-reglementaire";
const fetcher = vi.fn()
.mockResolvedValueOnce(new Response(JSON.stringify(recommendation), { status: 200 }))
.mockResolvedValueOnce(new Response(JSON.stringify({ choices: [] }), {
status: 200,
headers: {
"x-santinova-ia-provider": "Manus",
"x-santinova-ia-model": "gemini-2.5-flash",
"x-santinova-ia-transport": "manus-forge",
"x-santinova-ia-origin": "manual",
},
}));
const response = await invokeSelectedReference<{ choices: unknown[] }>({ messages: [{ role: "user", content: "test" }] }, fetcher as typeof fetch);
expect(response.choices).toEqual([]);
expect(fetcher).toHaveBeenCalledOnce();
const [, options] = fetcher.mock.calls[0] as [string, RequestInit];
expect(JSON.parse(String(options.body))).toEqual({ payload: { messages: [{ role: "user", content: "test" }] } });
expect(fetcher).toHaveBeenCalledTimes(2);
const [, invokeOptions] = fetcher.mock.calls[1] as [string, RequestInit];
expect(JSON.parse(String(invokeOptions.body))).toEqual({
engineSlug: "manus-forge",
payload: { messages: [{ role: "user", content: "test" }] },
});
});
it("refuse une décision rattachée à une autre application", async () => {
ENV.aiReferentielUrl = "https://referentiel-ia.recette.santinova-soft.org";
ENV.aiReferentielToken = "token-de-test";
ENV.aiReferentielAppSlug = "veille-reglementaire";
const fetcher = vi.fn().mockResolvedValue(new Response(JSON.stringify({ ...recommendation, application: { slug: "autre-app" } }), { status: 200 }));
await expect(invokeSelectedReference({ messages: [] }, fetcher as typeof fetch)).rejects.toThrow("application attendue");
});
});