WOD ponctuel proposé par l'IA et records par WOD (lot 4c)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
06bd91d797
commit
7dc106837b
@@ -414,15 +414,18 @@ function check(scheme, cond, msg) {
|
||||
const wodLink = await page.evaluate(async () => {
|
||||
const { store } = await import("./main.js");
|
||||
const program = structuredClone(store.getState().program);
|
||||
program.sessions.push({ key: "W", name: "Mini Fran", format: { type: "fortime", capMinutes: 2 }, warmup: [],
|
||||
program.sessions.push({ key: "J1", oneOff: true, name: "Mini Fran", format: { type: "fortime", capMinutes: 2 }, warmup: [],
|
||||
exercises: [{ ref: "barbell-thruster", sets: 1, reps: "21-15-9", rest: 0, note: "RX 43 kg / 29 kg" }, { ref: "kipping-pull-up", sets: 1, reps: "21-15-9", rest: 0 }] });
|
||||
return "#import-json=" + encodeURIComponent(JSON.stringify({ program, reason: "Un WOD pour essayer." }));
|
||||
});
|
||||
await go(wodLink);
|
||||
await button("Adopter").click();
|
||||
await settle();
|
||||
await go("#/seance/W");
|
||||
ok(await page.locator(".wod-format__label").textContent() === "For Time · cap 2 min", "WOD : format affiché");
|
||||
await go("#/");
|
||||
ok(await page.getByRole("heading", { name: /WOD proposé/ }).isVisible(), "WOD ponctuel : proposé sur l'accueil");
|
||||
await page.getByRole("link", { name: /Mini Fran/ }).click();
|
||||
await settle();
|
||||
ok(page.url().endsWith("#/seance/J1") && await page.locator(".wod-format__label").textContent() === "For Time · cap 2 min", "WOD : format affiché");
|
||||
ok(await page.locator(".wod-move").count() === 2, "WOD : deux mouvements");
|
||||
await button("Terminer la séance").click();
|
||||
ok(/temps/.test(await page.locator(".status").textContent() ?? ""), "WOD : score exigé avant d'enregistrer");
|
||||
@@ -441,6 +444,10 @@ function check(scheme, cond, msg) {
|
||||
ok(page.url().endsWith("#/bravo"), "WOD : séance enregistrée");
|
||||
await go("#/historique");
|
||||
ok(await page.getByText(`WOD · ${wodTime} · Scaled`).first().isVisible(), "WOD : score dans l'historique");
|
||||
await go("#/");
|
||||
ok(await page.getByRole("heading", { name: /WOD proposé/ }).count() === 0, "WOD ponctuel fait : plus proposé");
|
||||
await go("#/analyses");
|
||||
ok(await page.getByText(`Record ${wodTime} · Scaled`).isVisible(), "analyses : record du WOD");
|
||||
|
||||
// ---- réinitialisation --------------------------------------------------------------
|
||||
await go("#/donnees");
|
||||
|
||||
@@ -65,3 +65,20 @@ test("assiduité : séances par semaine et par nature, semaines vides comprises"
|
||||
]);
|
||||
assert.deepEqual(totals, { strength: 1, cardio: 2, activity: 1, total: 4 });
|
||||
});
|
||||
|
||||
test("records par WOD : même nom et même format, d'une séance à l'autre", async () => {
|
||||
const { wodRecords } = await import("../../app/domain/analysis.js");
|
||||
const { createEvent: ev } = await import("../../app/domain/events.js");
|
||||
const { foldEvents: fold } = await import("../../app/domain/state.js");
|
||||
const format = { type: /** @type {const} */ ("fortime"), capMinutes: 10 };
|
||||
const res = (/** @type {number|null} */ seconds, rx = true, capped = false) => ({ format, rx, seconds, rounds: null, reps: capped ? 70 : null, kg: null, capped });
|
||||
const log = (/** @type {string} */ date, /** @type {string} */ ref, /** @type {string} */ name, /** @type {any} */ wod) =>
|
||||
ev("SessionLogged", { date, kind: "strength", ref, name, warmup: null, exercises: [], wod }, { device: "t", at: date + "T10:00:00.000Z" });
|
||||
const state = fold([log("2026-11-01", "J1", "Fran", res(null, true, true)), log("2026-11-05", "J2", "fran", res(462)), log("2026-11-09", "W", "Fran", res(500)),
|
||||
log("2026-11-10", "W", "Fran", res(300, false)), log("2026-11-11", "X", "Cindy", { ...res(null), format: { type: "amrap", minutes: 20 }, rounds: 12 })]);
|
||||
const records = wodRecords(state);
|
||||
assert.deepEqual(records.map((r) => r.name), ["Cindy", "Fran"]);
|
||||
const fran = records[1];
|
||||
assert.equal(fran.results.length, 4);
|
||||
assert.equal(fran.best.date, "2026-11-05", "7:42 en RX bat le cap, 8:20 et le scaled");
|
||||
});
|
||||
|
||||
@@ -101,3 +101,23 @@ test("trackingFor : choix de l'utilisateur, puis programme, puis déduction", ()
|
||||
assert.equal(targetSeconds("8 squats"), null);
|
||||
assert.equal(exerciseKey("A", { ref: "squat", sets: 4, reps: "8", rest: 120 }), "A-squat");
|
||||
});
|
||||
|
||||
test("séances ponctuelles : hors rotation, en attente tant qu'elles ne sont pas faites, retirées une fois faites", async () => {
|
||||
const { rotationSessions, pendingOneOffs, withOneOff } = await import("../../app/domain/program.js");
|
||||
const wod = { name: "Cindy", format: /** @type {const} */ ({ type: "amrap", minutes: 20 }), exercises: [{ ref: "push-up", sets: 1, reps: "10", rest: 0 }] };
|
||||
const logged = [{ kind: "strength", ref: "A" }];
|
||||
const first = withOneOff(EXAMPLE_PROGRAM, wod, logged);
|
||||
assert.equal(first.key, "J1");
|
||||
assert.deepEqual(validateProgram(first.program), []);
|
||||
assert.deepEqual(rotationSessions(first.program).map((s) => s.key), EXAMPLE_PROGRAM.sessions.map((s) => s.key));
|
||||
assert.deepEqual(pendingOneOffs(first.program, logged).map((s) => s.key), ["J1"]);
|
||||
const done = [...logged, { kind: "strength", ref: "J1" }];
|
||||
assert.deepEqual(pendingOneOffs(first.program, done), []);
|
||||
const second = withOneOff(first.program, wod, done);
|
||||
assert.equal(second.key, "J2");
|
||||
assert.deepEqual(second.program.sessions.filter((s) => s.oneOff).map((s) => s.key), ["J2"], "J1, faite, est retirée");
|
||||
assert.equal(EXAMPLE_PROGRAM.sessions.some((s) => s.oneOff), false, "l'original n'est pas touché");
|
||||
const bad = structuredClone(first.program);
|
||||
/** @type {any} */ (bad.sessions.at(-1)).oneOff = "oui";
|
||||
assert.match(validateProgram(bad)[0], /'oneOff' doit valoir true ou false/);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { clockText, currentMovement, formatLabel, formatSeconds, parseClock, scoreLabel, validateFormat, wodClock, wodResultProblem } from "../../app/domain/wod.js";
|
||||
import { compareScores, wodKey, clockText, currentMovement, formatLabel, formatSeconds, parseClock, scoreLabel, validateFormat, wodClock, wodResultProblem } from "../../app/domain/wod.js";
|
||||
import { validateProgram } from "../../app/domain/program.js";
|
||||
import { estimatedMinutes } from "../../app/domain/progression.js";
|
||||
import { buildOnboardingBrief } from "../../app/domain/ai-brief.js";
|
||||
@@ -65,3 +65,17 @@ test("une séance WOD dans le programme : validée, durée estimée, exemple de
|
||||
assert.equal(estimatedMinutes(fran), 20);
|
||||
assert.match(validateProgram({ name: "P", sessions: [{ ...fran, format: { type: "emom" } }] })[0], /séance W : 'format.minutes'/);
|
||||
});
|
||||
|
||||
test("comparer deux scores : RX d'abord, puis selon le format", () => {
|
||||
const r = (/** @type {any} */ x) => ({ rx: true, seconds: null, rounds: null, reps: null, kg: null, capped: false, ...x });
|
||||
const ft = { type: "fortime", capMinutes: 10 };
|
||||
assert.ok(compareScores(r({ format: ft, seconds: 400 }), r({ format: ft, seconds: 450 })) < 0, "plus court");
|
||||
assert.ok(compareScores(r({ format: ft, seconds: 590 }), r({ format: ft, capped: true, reps: 80 })) < 0, "fini avant le cap");
|
||||
assert.ok(compareScores(r({ format: ft, capped: true, reps: 90 }), r({ format: ft, capped: true, reps: 80 })) < 0);
|
||||
assert.ok(compareScores(r({ format: ft, seconds: 600, rx: true }), r({ format: ft, seconds: 300, rx: false })) < 0, "RX avant scaled");
|
||||
const am = { type: "amrap", minutes: 20 };
|
||||
assert.ok(compareScores(r({ format: am, rounds: 14, reps: 3 }), r({ format: am, rounds: 14, reps: 1 })) < 0);
|
||||
assert.ok(compareScores(r({ format: am, rounds: 15, reps: 0 }), r({ format: am, rounds: 14, reps: 20 })) < 0);
|
||||
assert.equal(compareScores(r({ format: am, rounds: 14, reps: 3 }), r({ format: am, rounds: 14, reps: 3 })), 0);
|
||||
assert.equal(wodKey(" Frân ", { type: "fortime" }), "fran|fortime");
|
||||
});
|
||||
|
||||
@@ -69,7 +69,7 @@ test("initialize, tools/list, notifications et méthodes inconnues", async () =>
|
||||
const list = /** @type {any} */ (await mcp.handle({ jsonrpc: "2.0", id: 2, method: "tools/list" }, syncKey));
|
||||
assert.deepEqual(list.result.tools.map((/** @type {any} */ t) => t.name), [
|
||||
"get_overview", "get_program", "get_training_history", "get_exercise_progress", "get_body_weight",
|
||||
"propose_program", "propose_session_change", "propose_profile",
|
||||
"propose_program", "propose_session_change", "propose_wod", "propose_profile",
|
||||
]);
|
||||
assert.equal((/** @type {any} */ (await mcp.handle({ jsonrpc: "2.0", id: 3, method: "resources/list" }, syncKey))).error.code, -32601);
|
||||
assert.equal((/** @type {any} */ (await mcp.handle({ jsonrpc: "2.0", id: 4, method: "tools/call", params: { name: "rm" } }, syncKey))).error.code, -32602);
|
||||
@@ -170,6 +170,26 @@ test("propose_session_change : une séance d'étirements aux refs inventées dev
|
||||
assert.equal("notices" in (await call("propose_program", { program: EXAMPLE_PROGRAM, reason: "x" })).json, false);
|
||||
});
|
||||
|
||||
test("propose_wod : WOD ponctuel ajouté hors rotation, clé choisie, WOD ponctuels faits retirés", async () => {
|
||||
const wod = { name: "Cindy", format: { type: "amrap", minutes: 20 },
|
||||
exercises: [{ ref: "pull-up", sets: 1, reps: "5", rest: 0 }, { ref: "push-up", sets: 1, reps: "10", rest: 0 }, { ref: "bodyweight-squat", sets: 1, reps: "15", rest: 0 }] };
|
||||
const program = { ...EXAMPLE_PROGRAM, sessions: [...EXAMPLE_PROGRAM.sessions, { ...wod, key: "J1", oneOff: true }] };
|
||||
const events = [...history(), createEvent("ProgramAdopted", { program, source: "ai" }, { device, at: "2026-11-15T10:00:00.000Z" }),
|
||||
createEvent("SessionLogged", { date: "2026-11-16", kind: "strength", ref: "J1", name: "Cindy", warmup: null, exercises: [],
|
||||
wod: { format: wod.format, rx: true, seconds: null, rounds: 14, reps: 3, kg: null, capped: false } }, { device, at: "2026-11-16T19:00:00.000Z" })];
|
||||
const { call, journal } = await setup(events);
|
||||
const overview = (await call("get_overview")).json;
|
||||
assert.deepEqual(overview.program.sessions.find((/** @type {any} */ x) => x.key === "J1"), { key: "J1", name: "Cindy", format: wod.format, oneOff: true, done: true, exercises: ["pull-up 1 × 5", "push-up 1 × 10", "bodyweight-squat 1 × 15"] });
|
||||
const r = await call("propose_wod", { session: { ...wod, name: "Cindy (encore)", key: "A", oneOff: false }, reason: "Un AMRAP pour ce soir" });
|
||||
assert.equal(r.isError, false);
|
||||
assert.equal(r.json.key, "J2", "J1 a déjà servi");
|
||||
const sessions = /** @type {any} */ ((await journal()).at(-1)).data.program.sessions;
|
||||
assert.deepEqual(sessions.map((/** @type {any} */ s) => s.key), [...EXAMPLE_PROGRAM.sessions.map((s) => s.key), "J2"], "J1, faite, est retirée ; la séance A n'est pas touchée");
|
||||
assert.equal(sessions.at(-1).oneOff, true);
|
||||
assert.match((await call("propose_wod", { session: { name: "x", exercises: [] }, reason: "x" })).text, /'session.format' manquant/);
|
||||
assert.match((await call("propose_wod", { session: { ...wod, format: { type: "amrap" } }, reason: "x" })).text, /format.minutes/);
|
||||
});
|
||||
|
||||
test("propose_profile : le programme courant accompagné du nouveau profil ; sans programme, refusé", async () => {
|
||||
const { call, journal } = await setup();
|
||||
const r = await call("propose_profile", { profile: { ...PROFILE, constraints: ["Épaule droite"] }, reason: "Blessure" });
|
||||
|
||||
Reference in New Issue
Block a user