Files
ia-fit/tests/domain/ai-brief.test.js
T

70 lines
3.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import { buildOnboardingBrief, buildEvolutionBrief, EXAMPLE_PAYLOAD } from "../../app/domain/ai-brief.js";
import { decodeProposalFragment } from "../../app/domain/link.js";
import { validateProgram } from "../../app/domain/program.js";
import { validateProfile } from "../../app/domain/profile.js";
import { EXERCISES } from "../../app/domain/exercises.js";
import { convertAtelier } from "../../app/domain/atelier.js";
import { foldEvents, emptyState } from "../../app/domain/state.js";
const baseUrl = "https://ia-fit.sans.pub";
test("l'exemple donné à l'IA est valide", () => {
assert.deepEqual(validateProgram(EXAMPLE_PAYLOAD.program), []);
assert.deepEqual(validateProfile(EXAMPLE_PAYLOAD.profile), []);
});
test("accueil : questions, ingestion d'un programme existant, formats, lien, MCP", () => {
const brief = buildOnboardingBrief({ baseUrl });
assert.match(brief, /en une seule fois/);
assert.match(brief, /capture d'écran/);
for (const ref of Object.keys(EXERCISES)) assert.ok(brief.includes("`" + ref + "`"), ref);
assert.match(brief, /sets: entier de 1 à 12/);
assert.match(brief, /sessionMinutes: durée visée/);
assert.ok(brief.includes("https://ia-fit.sans.pub/#import-json=%7B%22program%22%3A"));
assert.match(brief, /## Connecteur MCP \(bientôt\)[\s\S]*https:\/\/ia-fit\.sans\.pub\/mcp/);
// l'exemple du texte se relit tel quel
const example = /```json\n(.*)\n```/.exec(brief)?.[1];
assert.deepEqual(JSON.parse(example ?? "null"), EXAMPLE_PAYLOAD);
});
test("un lien écrit comme le demande le texte devient une proposition", async () => {
const link = baseUrl + "/#import-json=" + encodeURIComponent(JSON.stringify(EXAMPLE_PAYLOAD));
const e = await decodeProposalFragment(link, { device: "phone" });
assert.equal(e.data.source, "link");
assert.deepEqual(/** @type {any} */ (e.data).profile, EXAMPLE_PAYLOAD.profile);
});
test("app/ia.md est à jour (sinon : node scripts/build-prompt.js)", () => {
const published = fs.readFileSync(new URL("../../app/ia.md", import.meta.url), "utf8");
assert.equal(published, buildOnboardingBrief({ baseUrl }));
});
test("évolution : profil, mode, assiduité, historique condensé, programme", () => {
const raw = JSON.parse(fs.readFileSync(new URL("../fixtures/atelier-etat.json", import.meta.url), "utf8"));
const state = foldEvents(convertAtelier(raw, { device: "import", now: new Date("2026-11-18T10:00:00Z") }).events);
const brief = buildEvolutionBrief(state, { today: "2026-11-18", baseUrl });
assert.match(brief, /Objectif : Ancrer l'habitude/);
assert.match(brief, /109\.6 kg le 2026-11-17, en baisse de 0\.\d\d kg par semaine/);
assert.match(brief, /maintien : /);
assert.match(brief, /Jours disponibles : lundi, mercredi, vendredi, samedi\. Jours imposés : lundi = strength:A/);
assert.match(brief, /6 séance\(s\), soit 2\.6 par semaine depuis la première : séance A × 2/);
assert.match(brief, /2026-11-11, 2026-11-14/);
assert.match(brief, /- 2026-11-02 · séance A \(Bas du corps \+ dos\) · échauffement 7\/9\n {2}squat 60 kg \(objectif 4 × 8\) : 8 ok, 8 ok, 8 hard, 7 failure/);
assert.match(brief, /- 2026-11-06 · activité : Foot à 5/);
assert.match(brief, /plank 40 s \(objectif 3 × 40 s\) : faite, faite, faite/);
assert.match(brief, /- C-farmer-walk : 22 kg, 40 s/);
assert.match(brief, /"name": "L'atelier"/);
assert.match(brief, /"profile": … \(seulement s'il change\)/);
});
test("évolution sans programme ni séance", () => {
const state = { ...emptyState(), program: /** @type {any} */ (null) };
const brief = buildEvolutionBrief(state, { today: "2026-11-18", baseUrl });
assert.match(brief, /Aucun programme pour l'instant/);
assert.match(brief, /Aucune séance enregistrée sur la période/);
assert.match(brief, /Objectif : non renseigné/);
});