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:
co-authored by
Claude Opus 5.5
parent
b462437f68
commit
21305bf66c
@@ -154,8 +154,8 @@ test("programme invalide : signalé, le reste est repris", () => {
|
||||
});
|
||||
|
||||
test("reconnaissance : un programme IA-Fit n'est pas pris pour un fichier d'Atelier", async () => {
|
||||
const { DEFAULT_PROGRAM } = await import("../../app/domain/default-program.js");
|
||||
assert.equal(looksLikeAtelier(DEFAULT_PROGRAM), false);
|
||||
const { EXAMPLE_PROGRAM } = await import("../../app/domain/example-program.js");
|
||||
assert.equal(looksLikeAtelier(EXAMPLE_PROGRAM), false);
|
||||
assert.ok(looksLikeAtelier(fixture("export")));
|
||||
assert.throws(() => convertAtelier("texte", opts), /objet JSON/);
|
||||
});
|
||||
|
||||
+14
-14
@@ -2,7 +2,7 @@ import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { encodeProposalLink, decodeProposalFragment, createProposal } from "../../app/domain/link.js";
|
||||
import { validateEvent } from "../../app/domain/events.js";
|
||||
import { DEFAULT_PROGRAM } from "../../app/domain/default-program.js";
|
||||
import { EXAMPLE_PROGRAM } from "../../app/domain/example-program.js";
|
||||
|
||||
const base = "https://ia-fit.sans.pub/";
|
||||
const opts = { device: "phone", now: new Date("2026-11-18T10:00:00Z") };
|
||||
@@ -12,19 +12,19 @@ const profile = {
|
||||
};
|
||||
|
||||
test("aller-retour d'un lien compressé : une proposition « link » valide", async () => {
|
||||
const url = await encodeProposalLink(base + "#ancien", { program: DEFAULT_PROGRAM, reason: "Plus de volume" });
|
||||
const url = await encodeProposalLink(base + "#ancien", { program: EXAMPLE_PROGRAM, reason: "Plus de volume" });
|
||||
assert.match(url, /^https:\/\/ia-fit\.sans\.pub\/#import=[A-Za-z0-9_-]+$/);
|
||||
const e = await decodeProposalFragment(new URL(url).hash, opts);
|
||||
assert.equal(validateEvent(e), null);
|
||||
assert.equal(e.type, "ProgramProposed");
|
||||
assert.equal(e.data.source, "link");
|
||||
assert.equal(e.data.reason, "Plus de volume");
|
||||
assert.deepEqual(e.data.program, DEFAULT_PROGRAM);
|
||||
assert.deepEqual(e.data.program, EXAMPLE_PROGRAM);
|
||||
assert.equal(e.at, "2026-11-18T10:00:00.000Z");
|
||||
// l'adresse complète est acceptée aussi, et le même lien donne la même proposition
|
||||
assert.equal((await decodeProposalFragment(url, opts)).id, e.id);
|
||||
// taille du lien pour le programme de départ (rapportée dans le plan)
|
||||
const json = JSON.stringify({ program: DEFAULT_PROGRAM, reason: "Plus de volume" });
|
||||
const json = JSON.stringify({ program: EXAMPLE_PROGRAM, reason: "Plus de volume" });
|
||||
const plain = base + "#import-json=" + encodeURIComponent(json);
|
||||
console.log(`# programme de départ : lien compressé ${url.length} caractères, non compressé ${plain.length}, JSON ${json.length}`);
|
||||
assert.ok(url.length < 2000, "un lien compressé tient sous 2 000 caractères");
|
||||
@@ -32,25 +32,25 @@ test("aller-retour d'un lien compressé : une proposition « link » valide", as
|
||||
});
|
||||
|
||||
test("le profil voyage avec le programme et il est validé", async () => {
|
||||
const url = await encodeProposalLink(base, { program: DEFAULT_PROGRAM, profile, reason: "Premier programme" });
|
||||
const url = await encodeProposalLink(base, { program: EXAMPLE_PROGRAM, profile, reason: "Premier programme" });
|
||||
const e = await decodeProposalFragment(url, opts);
|
||||
assert.deepEqual(/** @type {any} */ (e.data).profile, profile);
|
||||
await assert.rejects(encodeProposalLink(base, { program: DEFAULT_PROGRAM, profile: { ...profile, sessionMinutes: 2 }, reason: "" }),
|
||||
await assert.rejects(encodeProposalLink(base, { program: EXAMPLE_PROGRAM, profile: { ...profile, sessionMinutes: 2 }, reason: "" }),
|
||||
/sessionMinutes/);
|
||||
});
|
||||
|
||||
test("variante non compressée #import-json, telle qu'une IA l'écrit", async () => {
|
||||
const payload = { program: DEFAULT_PROGRAM, profile, reason: "Proposé par l'IA" };
|
||||
const payload = { program: EXAMPLE_PROGRAM, profile, reason: "Proposé par l'IA" };
|
||||
const e = await decodeProposalFragment("#import-json=" + encodeURIComponent(JSON.stringify(payload)), opts);
|
||||
assert.equal(e.data.reason, "Proposé par l'IA");
|
||||
assert.deepEqual(e.data.program, DEFAULT_PROGRAM);
|
||||
assert.deepEqual(e.data.program, EXAMPLE_PROGRAM);
|
||||
// un programme nu, et un JSON non encodé, passent aussi
|
||||
const bare = await decodeProposalFragment("#import-json=" + JSON.stringify(DEFAULT_PROGRAM), opts);
|
||||
const bare = await decodeProposalFragment("#import-json=" + JSON.stringify(EXAMPLE_PROGRAM), opts);
|
||||
assert.equal(bare.data.reason, "");
|
||||
});
|
||||
|
||||
test("erreurs en français : programme invalide, lien abîmé, pas de proposition", async () => {
|
||||
const bad = structuredClone(DEFAULT_PROGRAM);
|
||||
const bad = structuredClone(EXAMPLE_PROGRAM);
|
||||
bad.sessions[0].exercises[0].ref = "pompes";
|
||||
bad.sessions[1].exercises[0].sets = 0;
|
||||
await assert.rejects(decodeProposalFragment("#import-json=" + encodeURIComponent(JSON.stringify({ program: bad, reason: "" })), opts),
|
||||
@@ -60,7 +60,7 @@ test("erreurs en français : programme invalide, lien abîmé, pas de propositio
|
||||
assert.match(err.problems[0], /référence inconnue « pompes »/);
|
||||
return true;
|
||||
});
|
||||
const url = await encodeProposalLink(base, { program: DEFAULT_PROGRAM, reason: "" });
|
||||
const url = await encodeProposalLink(base, { program: EXAMPLE_PROGRAM, reason: "" });
|
||||
await assert.rejects(decodeProposalFragment(url.slice(0, -40), opts), /Lien abîmé ou incomplet/);
|
||||
await assert.rejects(decodeProposalFragment("#import=@@@", opts), /Lien abîmé/);
|
||||
await assert.rejects(decodeProposalFragment("#pair=abc", opts), /ne contient pas de proposition/);
|
||||
@@ -68,9 +68,9 @@ test("erreurs en français : programme invalide, lien abîmé, pas de propositio
|
||||
});
|
||||
|
||||
test("createProposal : source « import », identifiant tiré du contenu", () => {
|
||||
const a = createProposal({ program: DEFAULT_PROGRAM, reason: "x" }, "import", opts);
|
||||
const b = createProposal({ program: DEFAULT_PROGRAM, reason: "x" }, "import", { device: "pc" });
|
||||
const a = createProposal({ program: EXAMPLE_PROGRAM, reason: "x" }, "import", opts);
|
||||
const b = createProposal({ program: EXAMPLE_PROGRAM, reason: "x" }, "import", { device: "pc" });
|
||||
assert.equal(a.data.source, "import");
|
||||
assert.equal(a.id, b.id);
|
||||
assert.notEqual(a.id, createProposal({ program: DEFAULT_PROGRAM, reason: "y" }, "import", opts).id);
|
||||
assert.notEqual(a.id, createProposal({ program: EXAMPLE_PROGRAM, reason: "y" }, "import", opts).id);
|
||||
});
|
||||
|
||||
@@ -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/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user