Textes pour l'IA : accueil (app/ia.md) et évolution du programme

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pierre MARTIN
2026-11-18 01:03:06 +01:00
co-authored by Claude Opus 5.5
parent 36e0db082d
commit 883567fb9c
4 changed files with 525 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
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é/);
});