First of six. Everything here is transport and boundary: a job can run, its answer can be parsed, and nothing yet judges whether that answer is safe to act on. The validator and the apply path are the next PR, and the seam is explicit — jobs.js carries an answer no further than `unvalidated`, and a test pins that so the next PR has something to replace. Whose account pays, settled first because it decides what the rest may be: instance one account in coach.json, for the single-profile instance profile one account per profile, in its own coach-auth-<uid>.json In instance mode the credential binds to the first profile that spends it and every other profile is refused — no job, not a dismissible warning. A warning moves the decision onto whoever clicks past it and the decision is about somebody's personal subscription. A profile credential is deliberately not a field on state-<uid>.json: that blob syncs and travels in the user's export, and a credential in a backup is the mistake we are avoiding, not repeating. openGym does not interpret any provider's terms; it offers the shape that does not need the interpretation and refuses the shape that does. The privilege drop now fails closed. It only ever engaged when the server ran as root, so adding a USER line to the Dockerfile for unrelated hardening would have silently left the provider runtime on the server's uid. On Linux, no drop means no job, and the admin card says so. ./data is no longer sealed with a blanket 0700. It is a host bind mount and this container is root, so sealing it landed on the host as root-owned and took the owner's own directory hostage — backup scripts, jq, the MCP server in issue #19. The files that hold secrets carry 0600 themselves instead, which is what the directory mode was standing in for; db.json gained an explicit mode rather than inheriting umask once the blanket came off. Bodyweight and per-side, folded in rather than deferred: v1.2.4 made `weight` mean *added* load on a bodyweight exercise, so it is 0 on a good session and every load-shaped signal reads flat. Uncorrected, the Coach would have looked at a working push-up progression and proposed adding weight to a push-up. The payload carries bodyweight/side/repsMax, the session reader carries set count, and the prompts say reps then sets are the progression and per-side targets step in twos. coach-parity.test.js pins the server's three copied reading rules against the frontend's originals over a table of configs — modeOf was never actually pinned, and it is the one that was predicted to drift. No AI dependency lands here: api/ still installs @simplewebauthn/server and web-push and nothing else. Jobs run against the in-repo fixture provider, so CI needs no account, no network and no image build. 33 api tests, 361 frontend tests (169 of them parity), locales in sync.
50 lines
2.0 KiB
JavaScript
50 lines
2.0 KiB
JavaScript
/* Shared scaffolding for the api tests.
|
|
*
|
|
* Every module under coach/ resolves DATA_DIR at import time (the same way server.js does),
|
|
* so a test that wants its own data directory has to set the variable before the first
|
|
* import. Hence dynamic imports everywhere below, and one helper that does it in the right
|
|
* order. node:test runs each file in its own process, so one directory per file is enough.
|
|
*/
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
|
|
export function tempData() {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'coach-test-'));
|
|
fs.writeFileSync(path.join(dir, 'secret'), 'a'.repeat(64), { mode: 0o600 });
|
|
process.env.DATA_DIR = dir;
|
|
return dir;
|
|
}
|
|
|
|
export function writeState(dir, uid, S) {
|
|
fs.writeFileSync(path.join(dir, 'state-' + uid + '.json'), JSON.stringify(S));
|
|
}
|
|
|
|
/** A profile that has consented and has some history — the usual starting point. */
|
|
export function sampleState(over = {}) {
|
|
return {
|
|
unit: 'kg', lang: 'en', effort: 'rpe', targetW: 80,
|
|
coach: { consent: { agreedAt: new Date().toISOString(), version: 1 }, profile: { goal: 'muscle', daysPerWeek: 3, equipment: ['dumbbell'] } },
|
|
routines: [{
|
|
id: 'r1', name: 'Full body A', emoji: '💪', prog: 'linear',
|
|
ex: [
|
|
{ id: '0001', sets: 3, reps: 10, mode: 'reps', weight: 20, prog: 'linear' },
|
|
{ id: '0007', sets: 3, sec: 45, mode: 'time' }
|
|
]
|
|
}],
|
|
week: { 1: 'r1', 3: 'r1', 5: 'r1' },
|
|
dayPlan: {},
|
|
exWeights: { '0001': { w: 20 } },
|
|
bodyweight: [{ d: '2026-07-01', w: 78 }, { d: '2026-07-20', w: 78.5 }],
|
|
customEx: [],
|
|
workouts: [{
|
|
id: 'w1', d: '2026-07-20', name: 'Full body A', start: 1000, end: 1000 + 45 * 60000, vol: 600, prs: [],
|
|
entries: [{
|
|
id: '0001', target: { sets: 3, reps: 10, weight: 20 },
|
|
sets: [{ w: 20, r: 10, done: true, rpe: 9.5 }, { w: 20, r: 9, done: true, rpe: 10 }, { w: 20, r: 8, done: true, rpe: 10 }]
|
|
}]
|
|
}],
|
|
...over
|
|
};
|
|
}
|