The core of "build a routine with AI": muscles, cardio, intensity
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
The screen that will drive this needs three things underneath it, and all three
are here, tested, with no UI yet.
1. `librarySlice` can be narrowed to the muscles someone picked. A selector is
`{ bp }` or `{ tg }` — the target muscle matters because "biceps" and "triceps"
are both `upper arms`, and asking for one must not hand back the other — and an
exercise is kept when it matches any of them, so "back and biceps" is one list.
`catalogueOnly` drops the person's own exercises, which are the only rows in
the app with no animation; the builder promises every pick can be watched.
Both answers ride in the existing `intake` object rather than a second channel:
the intake is already how "which muscles" reaches the payload, and it travels
the whole way (route → job → build, and local → build) untouched. `cleanGroups`
sanitises it, since it is the one intake field that reaches a filter rather than
the model's reading.
2. `lib/ai-routine.js` — the three questions and what to do with the answer: the
intake the model is asked with, and the routine it hands back, normalised for
this app. Cardio lands in the library and not only in the sentence (a model told
to start with cardio but handed no cardio exercise can only improvise, which is
what it did the first time this was tried), a cardio row becomes one bout
whatever set count came back, and a missing mode is read from the exercise the
same way `modeOf` reads it everywhere else.
3. A validator fix found on the way: the cardio branch set `min` and `speed` but
never `clean.mode = 'cardio'`, unlike the time and reps branches. The app
recovered it from the catalogue, so nothing was visibly broken — but the bundle
did not describe its own prescription, and a model that omitted `mode` (which is
what a model prescribing "8 minutes of cardio" usually does) got "3 × 10 reps"
with a stray `min` nothing reads. Now the mode is stated, and inferred from the
catalogue when it is missing. `time` is deliberately not inferred: nothing in the
catalogue says an exercise is held for seconds.
Verified against the real router behind gym.dploy.lol with the real pipeline: a
back+biceps request produced a 6-exercise routine from an 80/80/22 library slice.
This commit is contained in:
1 parent
ea1af681c2
commit
327aa5211b
7 files changed
+409
-7
No files matched your search
@@ -55,6 +55,28 @@ test('a plan may reference a custom exercise it defines in the same answer', ()
|
||||
assert.equal(r.bundle.customEx[0].n, 'Sandbag carry');
|
||||
});
|
||||
|
||||
// A cardio row is defined by its body part in the catalogue, and the app resolves an absent
|
||||
// `mode` the same way (modeOf in history.js). Leaving it out used to produce "3 × 10 reps" with a
|
||||
// stray `min` nothing reads — which is what the routine builder's "start with cardio" answer hit,
|
||||
// since a model that prescribes 8 minutes rarely also remembers to say mode: "cardio".
|
||||
test('an exercise whose catalogue body part is cardio comes back as a cardio prescription', () => {
|
||||
const r = validatePlan({
|
||||
routines: [{ id: 'r1', name: 'A', ex: [{ id: '3220', sets: 1, min: 8 }] }]
|
||||
});
|
||||
assert.equal(r.ok, true, JSON.stringify(r.errors));
|
||||
const ex = r.bundle.routines[0].ex[0];
|
||||
assert.equal(ex.mode, 'cardio');
|
||||
assert.equal(ex.min, 8);
|
||||
// …and a stated mode still wins, so nothing else about the answer is rewritten.
|
||||
const timed = validatePlan({ routines: [{ id: 'r1', name: 'A', ex: [{ id: '3220', sets: 1, mode: 'time', sec: 60 }] }] });
|
||||
assert.equal(timed.bundle.routines[0].ex[0].mode, 'time');
|
||||
assert.equal(timed.bundle.routines[0].ex[0].sec, 60);
|
||||
// A rep exercise is untouched: the inference is only ever cardio, never "time from a stray
|
||||
// field", which would rewrite a prescription nobody asked to change.
|
||||
const reps = validatePlan({ routines: [{ id: 'r1', name: 'A', ex: [{ id: '0001', sets: 3, sec: 45 }] }] });
|
||||
assert.equal(reps.bundle.routines[0].ex[0].mode, 'reps');
|
||||
});
|
||||
|
||||
test('the week may only point at routines the plan actually defines', () => {
|
||||
const r = validatePlan({ routines: [{ id: 'r1', name: 'A', ex: [{ id: '0001', sets: 3, reps: 10 }] }], week: { 1: 'ghost' } });
|
||||
assert.equal(r.ok, false);
|
||||
|
||||
Reference in new issue
Block a user