Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | 44x 44x 122x 122x 122x 122x 44x 44x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 17x 17x 17x 17x 17x 17x 17x 17x 11x 11x 11x 1x 10x 11x 11x 11x 11x 11x 11x 17x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 17x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 17x 3x 3x 3x 3x 3x 3x 3x 3x 3x 17x | import type {
ModelProvider,
ModelTier,
AIInteraction,
WorkoutGenerationContext,
WorkoutAdaptationContext,
ReviewContext,
NarrativeContext,
WorkoutPlan,
AdaptedWorkout,
ReviewPrompt,
} from '../model-provider.js';
import type { PrescribedExercise, SetPrescription } from '@strengthsys/shared';
// ── Options ──────────────────────────────────────────────────
export interface TestModelProviderOptions {
/**
* When true, generateWorkout returns a workout that fails validateSession
* (all exercises use the 'squat' pattern → volume_concentration violation).
* Use this to test the validation-retry path.
*/
produceInvalidWorkout?: boolean;
}
// ── Helpers ──────────────────────────────────────────────────
function makeSets(count: number, weightKg: number, reps: number, rpe: number): SetPrescription[] {
return Array.from({ length: count }, () => ({
target_weight_kg: weightKg,
target_reps: reps,
target_rpe: rpe,
rest_seconds: 90,
}));
}
function makeInteraction(
athleteId: string,
actionType: string,
contextSent: unknown,
responseReceived: unknown,
): AIInteraction {
return {
athlete_id: athleteId,
action_type: actionType,
context_sent: contextSent,
response_received: responseReceived,
tools_called: ['validateSession'],
tool_results: [],
duration_ms: 50,
};
}
// ── Normal fixture (4 balanced exercises) ────────────────────
function buildNormalWorkout(isDeload: boolean): PrescribedExercise[] {
const setCount = isDeload ? 2 : 3;
return [
{
id: 'test-ex-1',
exercise_id: 'test-squat',
exercise_name: 'Test Squat',
order: 1,
sets: makeSets(setCount, isDeload ? 60 : 100, 8, 7),
is_warmup: false,
is_backup: false,
notes: null,
movement_patterns: ['squat'],
},
{
id: 'test-ex-2',
exercise_id: 'test-hinge',
exercise_name: 'Test Hinge',
order: 2,
sets: makeSets(setCount, isDeload ? 48 : 80, 8, 7),
is_warmup: false,
is_backup: false,
notes: null,
movement_patterns: ['hinge'],
},
{
id: 'test-ex-3',
exercise_id: 'test-press',
exercise_name: 'Test Press',
order: 3,
sets: makeSets(setCount, isDeload ? 42 : 70, 10, 7),
is_warmup: false,
is_backup: false,
notes: null,
movement_patterns: ['push'],
},
{
id: 'test-ex-4',
exercise_id: 'test-row',
exercise_name: 'Test Row',
order: 4,
sets: makeSets(setCount, isDeload ? 36 : 60, 10, 7),
is_warmup: false,
is_backup: false,
notes: null,
movement_patterns: ['pull'],
},
];
}
// ── Invalid fixture (all squat → volume_concentration violation) ──
function buildInvalidWorkout(): PrescribedExercise[] {
return [
{
id: 'test-invalid-1',
exercise_id: 'test-squat-a',
exercise_name: 'Test Squat A',
order: 1,
sets: makeSets(3, 100, 8, 7),
is_warmup: false,
is_backup: false,
notes: null,
movement_patterns: ['squat'],
},
{
id: 'test-invalid-2',
exercise_id: 'test-squat-b',
exercise_name: 'Test Squat B',
order: 2,
sets: makeSets(3, 90, 8, 7),
is_warmup: false,
is_backup: false,
notes: null,
movement_patterns: ['squat'],
},
{
id: 'test-invalid-3',
exercise_id: 'test-squat-c',
exercise_name: 'Test Squat C',
order: 3,
sets: makeSets(3, 80, 8, 7),
is_warmup: false,
is_backup: false,
notes: null,
movement_patterns: ['squat'],
},
{
id: 'test-invalid-4',
exercise_id: 'test-pull',
exercise_name: 'Test Pull',
order: 4,
sets: makeSets(1, 60, 8, 7),
is_warmup: false,
is_backup: false,
notes: null,
movement_patterns: ['pull'],
},
];
}
// ── TestModelProvider ─────────────────────────────────────────
/**
* Deterministic ModelProvider for use in tests and Edge Function integration tests.
*
* Returns fixture data that passes validateSession by default.
* Pass `{ produceInvalidWorkout: true }` to get a workout that fails validation
* (useful for testing the validation-retry path).
*/
export class TestModelProvider implements ModelProvider {
readonly tier: ModelTier = 'complex';
private readonly options: Required<TestModelProviderOptions>;
constructor(options: TestModelProviderOptions = {}) {
this.options = {
produceInvalidWorkout: options.produceInvalidWorkout ?? false,
};
}
async generateWorkout(
context: WorkoutGenerationContext,
): Promise<{ result: WorkoutPlan; interaction: AIInteraction }> {
const exercises = this.options.produceInvalidWorkout
? buildInvalidWorkout()
: buildNormalWorkout(context.is_deload);
const result: WorkoutPlan = { prescribed_exercises: exercises };
return {
result,
interaction: makeInteraction(context.athlete_id, 'generate_workout', context, result),
};
}
async adaptWorkout(
context: WorkoutAdaptationContext,
): Promise<{ result: AdaptedWorkout; interaction: AIInteraction }> {
const result: AdaptedWorkout = {
prescribed_exercises: context.current_exercises,
explanation:
'Workout adapted for test fixture: volume reduced slightly to account for current state.',
};
return {
result,
interaction: makeInteraction(context.athlete_id, 'adapt_workout', context, result),
};
}
async generateReviewQuestions(
context: ReviewContext,
): Promise<{ result: ReviewPrompt[]; interaction: AIInteraction }> {
const result: ReviewPrompt[] = [
{
question: 'How did the workout feel overall?',
options: ['Great', 'Good', 'OK', 'Hard', 'Awful'],
kind: 'standard',
},
{
question: 'Were you able to complete all prescribed sets?',
options: ['Yes, all sets', 'Missed 1–2 sets', 'Missed more than 2 sets'],
kind: 'standard',
},
{
question: 'Do you have any specific goals you would like to work towards?',
options: null,
kind: 'goal_refinement',
},
];
return {
result,
interaction: makeInteraction(context.athlete_id, 'generate_review_questions', context, result),
};
}
async generateNarrative(
context: NarrativeContext,
): Promise<{ result: string; interaction: AIInteraction }> {
const result =
'Test narrative: You have been consistent and progressive in your training. Keep it up.';
return {
result,
interaction: makeInteraction(context.athlete_id, 'generate_narrative', context, result),
};
}
}
|