MCP: preview_session — what a routine will actually open with
get_routine reports what a routine stores. That is not what the athlete sees. buildSets() consults the confirmed working weight and the previous session's reps first, and applyPrescription() then overwrites the weight with whatever the progression policy decided — so the routine's own sets/reps/weight are the last fallback, not the first. The gap is not academic. A routine holding "squat 3x8 @ 60 kg" opens at 75 kg when Greyskull deloaded from the last logged session, and an LLM reading get_routine will confidently name a weight the app never shows. Editing the routine to fix it changes nothing, which is worse. preview_session mirrors beginWorkout() exactly — buildSets, applyPrescription, applyIntensifierPlan — and returns, per exercise: the planned target, the policy's decision with its stated reason, the opening set rows including planned drop sets, and which of plan / confirmed weight / history each number came from. `overridden` lists just the exercises where the stored plan and the opening session disagree, so the discrepancy cannot be scrolled past. Read-only, no new dependency, one new tool registration. This is the Phase 1.5 `progression_next` item from the README roadmap, named for what it answers. 9 tests: precedence in both directions (plan wins with no history, confirmed weight beats plan, policy beats both), reps carrying from history, drop-set rows, explicit routine_id, rest day, unknown id. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DUgSPgBBqMYdy4vnKjK3bE
This commit is contained in:
1 parent
272bf785ee
commit
733dfa9d37
3 files changed
+276
-8
No files matched your search
@@ -663,3 +663,126 @@ describe('shared: no-state fallback', () => {
|
||||
// failure rather than inherits null silently.
|
||||
afterAll(() => { _seedStateForTests(S = freshState()) })
|
||||
})
|
||||
|
||||
/* ---------- preview_session ---------- */
|
||||
|
||||
// The gap this tool exists to close: a routine stores sets/reps/weight, but those are the
|
||||
// LAST fallback the session builder consults. These tests pin the precedence — progression
|
||||
// beats the confirmed working weight, which beats the routine's own number — because getting
|
||||
// it backwards is how a coach ends up telling someone to squat a weight the app never shows.
|
||||
describe('preview_session', () => {
|
||||
const WD = new Date(FAKE_TODAY_ISO + 'T12:00:00Z').getDay()
|
||||
|
||||
// One routine, one exercise, scheduled for the pinned "today". Nothing from the demo seed,
|
||||
// so the arithmetic below is checkable by hand.
|
||||
function only(cfg, { prog = 'off', workouts = [], exWeights = {} } = {}) {
|
||||
S.routines = [{ id: 'r-preview', name: 'Preview', emoji: 'barbell', prog, ex: [cfg] }]
|
||||
S.week = { [WD]: 'r-preview' }
|
||||
S.dayPlan = {}
|
||||
S.workouts = workouts
|
||||
S.exWeights = exWeights
|
||||
_seedStateForTests(S)
|
||||
}
|
||||
|
||||
test('defaults to the routine scheduled for today', () => {
|
||||
only({ id: '0025', sets: 3, reps: 8, weight: 50 })
|
||||
const r = call('preview_session')
|
||||
expect(r.date).toBe(FAKE_TODAY_ISO)
|
||||
expect(r.routine_name).toBe('Preview')
|
||||
expect(r.exercises).toHaveLength(1)
|
||||
expect(r.exercises[0].name).toBe('barbell bench press')
|
||||
})
|
||||
|
||||
test('with no history and no confirmed weight, the routine\'s own number is what opens', () => {
|
||||
only({ id: '0025', sets: 3, reps: 8, weight: 50 })
|
||||
const e = call('preview_session').exercises[0]
|
||||
expect(e.weight_source).toBe('routine_plan')
|
||||
expect(e.opening_sets.map(s => s.w)).toEqual([50, 50, 50])
|
||||
expect(e.opening_sets.map(s => s.r)).toEqual([8, 8, 8])
|
||||
expect(e.differs_from_plan).toBe(false)
|
||||
expect(call('preview_session').overridden_count).toBe(0)
|
||||
})
|
||||
|
||||
test('a confirmed working weight beats the routine\'s number', () => {
|
||||
only({ id: '0025', sets: 2, reps: 8, weight: 50 }, { exWeights: { '0025': { w: 72.5, d: '2026-07-20' } } })
|
||||
const e = call('preview_session').exercises[0]
|
||||
expect(e.weight_source).toBe('confirmed_weight')
|
||||
expect(e.opening_sets.every(s => s.w === 72.5)).toBe(true)
|
||||
expect(e.changed).toEqual(['weight'])
|
||||
})
|
||||
|
||||
test('the progression policy beats both, and its reason is reported', () => {
|
||||
// Every rep hit at 60 last time under linear progression → +2.5, regardless of the 100
|
||||
// the routine stores.
|
||||
only({ id: '0025', sets: 3, reps: 5, weight: 100 }, {
|
||||
prog: 'linear',
|
||||
exWeights: { '0025': { w: 100, d: '2026-07-20' } },
|
||||
workouts: [{
|
||||
id: 'w1', d: '2026-07-20', routineId: 'r-preview', name: 'Preview',
|
||||
entries: [{
|
||||
id: '0025',
|
||||
target: { id: '0025', sets: 3, reps: 5, weight: 60 },
|
||||
sets: [{ w: 60, r: 5, done: true }, { w: 60, r: 5, done: true }, { w: 60, r: 5, done: true }]
|
||||
}]
|
||||
}]
|
||||
})
|
||||
const out = call('preview_session')
|
||||
const e = out.exercises[0]
|
||||
expect(e.prescription.kind).toBe('up')
|
||||
expect(e.weight_source).toBe('progression')
|
||||
expect(e.opening_sets.every(s => s.w === 62.5)).toBe(true)
|
||||
expect(e.prescription.why).toMatch(/Every rep last time/)
|
||||
expect(e.changed).toEqual(['weight'])
|
||||
|
||||
expect(out.overridden_count).toBe(1)
|
||||
expect(out.overridden[0]).toMatchObject({
|
||||
name: 'barbell bench press', planned_weight: 100, opening_weight: 62.5
|
||||
})
|
||||
expect(out.overridden[0].reason).toMatch(/Every rep last time/)
|
||||
})
|
||||
|
||||
test('reps carry from the last session even when the routine asks for something else', () => {
|
||||
only({ id: '0025', sets: 2, reps: 12, weight: 60 }, {
|
||||
workouts: [{
|
||||
id: 'w1', d: '2026-07-20', routineId: 'r-preview', name: 'Preview',
|
||||
entries: [{
|
||||
id: '0025',
|
||||
target: { id: '0025', sets: 2, reps: 5, weight: 60 },
|
||||
sets: [{ w: 60, r: 5, done: true }, { w: 60, r: 5, done: true }]
|
||||
}]
|
||||
}]
|
||||
})
|
||||
const e = call('preview_session').exercises[0]
|
||||
expect(e.opening_sets.map(s => s.r)).toEqual([5, 5]) // not the 12 the routine stores
|
||||
expect(e.reps_source).toBe('last_session')
|
||||
expect(e.changed).toContain('reps')
|
||||
})
|
||||
|
||||
test('planned drop sets show up on the opening rows', () => {
|
||||
only({ id: '0025', sets: 2, reps: 10, weight: 50, intensifier: { type: 'dropset', count: 1, pct: 20 } })
|
||||
const e = call('preview_session').exercises[0]
|
||||
expect(e.opening_sets.every(s => s.type === 'dropset')).toBe(true)
|
||||
})
|
||||
|
||||
test('an explicit routine_id overrides the schedule', () => {
|
||||
only({ id: '0025', sets: 3, reps: 8, weight: 50 })
|
||||
const other = { id: 'r-other', name: 'Other', prog: 'off', ex: [{ id: '0043', sets: 5, reps: 5, weight: 80 }] }
|
||||
S.routines.push(other)
|
||||
_seedStateForTests(S)
|
||||
expect(call('preview_session', { routine_id: 'r-other' }).routine_name).toBe('Other')
|
||||
})
|
||||
|
||||
test('a rest day returns no exercises rather than an error', () => {
|
||||
only({ id: '0025', sets: 3, reps: 8, weight: 50 })
|
||||
S.week = {}
|
||||
_seedStateForTests(S)
|
||||
const r = call('preview_session')
|
||||
expect(r.rest_day).toBe(true)
|
||||
expect(r.exercises).toEqual([])
|
||||
})
|
||||
|
||||
test('an unknown routine_id is an error, not an empty session', () => {
|
||||
only({ id: '0025', sets: 3, reps: 8, weight: 50 })
|
||||
expect(() => call('preview_session', { routine_id: 'nope' })).toThrow(/no routine with id/)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user