Intégration des données : programme d'exemple, programme d'Atelier collé = proposition, glossaire

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pierre MARTIN
2026-11-18 01:05:30 +01:00
co-authored by Claude Opus 5.5
parent b462437f68
commit 21305bf66c
9 changed files with 74 additions and 130 deletions
+8 -5
View File
@@ -4,7 +4,7 @@ import fs from "node:fs";
import { createSnapshot, readImport, mergeLogs } from "../../app/domain/snapshot.js";
import { createEvent } from "../../app/domain/events.js";
import { foldEvents } from "../../app/domain/state.js";
import { DEFAULT_PROGRAM } from "../../app/domain/default-program.js";
import { EXAMPLE_PROGRAM } from "../../app/domain/example-program.js";
const now = new Date("2026-11-18T10:00:00Z");
const opts = { device: "phone", now };
@@ -61,13 +61,16 @@ test("fichiers d'Atelier : les deux formats, entourés ou non de ```json", () =>
assert.ok(exp.report.length > 3);
// fusion (union) : rien ne double ; c'est l'interface qui choisit fusionner ou remplacer
assert.equal(foldEvents(mergeLogs(etat.events, exp.events)).sessions.length, 6);
// programme d'Atelier seul, ou enveloppé
// un programme d'Atelier collé seul, ou enveloppé, est une proposition à valider
const prog = JSON.parse(fixture("etat")).program;
assert.equal(readImport({ program: prog, reason: "?" }, opts).kind, "atelier");
for (const input of [prog, { program: prog, reason: "?" }]) {
const r = readImport(input, opts);
assert.deepEqual(r.events.map((e) => [e.type, /** @type {any} */ (e.data).source]), [["ProgramProposed", "import"]], JSON.stringify(Object.keys(input)));
}
});
test("programme IA-Fit seul : une proposition « import », pas une adoption", () => {
for (const input of [JSON.stringify(DEFAULT_PROGRAM), "```\n" + JSON.stringify({ program: DEFAULT_PROGRAM, reason: "De mon coach" }) + "\n```"]) {
for (const input of [JSON.stringify(EXAMPLE_PROGRAM), "```\n" + JSON.stringify({ program: EXAMPLE_PROGRAM, reason: "De mon coach" }) + "\n```"]) {
const r = readImport(input, opts);
assert.equal(r.kind, "program");
assert.deepEqual(r.events.map((e) => [e.type, /** @type {any} */ (e.data).source]), [["ProgramProposed", "import"]]);
@@ -83,5 +86,5 @@ test("erreurs en français", () => {
assert.throws(() => readImport("[1, 2]", opts), /objet JSON/);
assert.throws(() => readImport({ name: "X", sessions: [{ key: "A", name: "A", exercises: [] }] }, opts),
/ni un instantané IA-Fit.*\n- séance A : aucun exercice/);
assert.throws(() => readImport({ program: DEFAULT_PROGRAM, profile: { goal: 3 } }, opts), /Proposition invalide/);
assert.throws(() => readImport({ program: EXAMPLE_PROGRAM, profile: { goal: 3 } }, opts), /Proposition invalide/);
});