Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Dated history of structural work on this repo: the append-only narrative of what
operating facts live in `CLAUDE.md` and the docs ([`docs/README.md`](docs/README.md)).


## [1.12.2] - 2026-12-01

- **Coach view:** the first-run assistant no longer opens over the page of a person you are viewing (it is theirs to
fill in, and the view is read-only). If a save is refused because you are viewing somebody, the page now says so
instead of "server error".

## [1.12.1] - 2026-12-01

- **Profile:** the "Share with my coach" switch now sits on the line of its label; on a phone it was drawn above it.
Expand Down
4 changes: 2 additions & 2 deletions README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ página) y la imagen `loop-web` (sirve la página).

```sh
mkdir loop && cd loop
curl -fsSLO https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.1/docker/docker-compose.yml
curl -fsSL -o .env https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.1/docker/example.env
curl -fsSLO https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.2/docker/docker-compose.yml
curl -fsSL -o .env https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.2/docker/example.env
mkdir -p files/import files/manuals files/documents
```

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ and the endpoint the iOS Shortcut sends your Apple Health data to. Three contain

```sh
mkdir loop && cd loop
curl -fsSLO https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.1/docker/docker-compose.yml
curl -fsSL -o .env https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.1/docker/example.env
curl -fsSLO https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.2/docker/docker-compose.yml
curl -fsSL -o .env https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.2/docker/example.env
mkdir -p files/import files/manuals files/documents
```

Expand Down
8 changes: 4 additions & 4 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ services:

loop-server:
# the published image (Docker Hub); `docker compose up -d --build` builds it from a clone instead
image: mralexandersaavedra/loop-server:${HC_VERSION:-1.12.1}
image: mralexandersaavedra/loop-server:${HC_VERSION:-1.12.2}
build:
context: ..
dockerfile: docker/loop-server.Dockerfile
args:
VERSION: ${HC_VERSION:-1.12.1}
VERSION: ${HC_VERSION:-1.12.2}
container_name: loop-server${HC_INSTANCE:+-${HC_INSTANCE}}
restart: unless-stopped
# SIGTERM lets in-flight requests finish for up to 10 s and stops a running build; docker waits this long
Expand Down Expand Up @@ -132,12 +132,12 @@ services:
loop-web:
# the published image (Docker Hub); `docker compose up -d --build` builds it from a clone instead. The nginx
# template and hosts.sh are baked in from services/loop-web (docker/loop-web.Dockerfile), never bind-mounted.
image: mralexandersaavedra/loop-web:${HC_VERSION:-1.12.1}
image: mralexandersaavedra/loop-web:${HC_VERSION:-1.12.2}
build:
context: ..
dockerfile: docker/loop-web.Dockerfile
args:
VERSION: ${HC_VERSION:-1.12.1}
VERSION: ${HC_VERSION:-1.12.2}
container_name: loop-web${HC_INSTANCE:+-${HC_INSTANCE}}
restart: unless-stopped
# The same hardening as services/loop-web/docker-compose.yml: a read-only root filesystem; tmpfs for what the
Expand Down
2 changes: 1 addition & 1 deletion docker/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# and is never committed (docker/.gitignore).

# The image tag: mralexandersaavedra/loop-server:<HC_VERSION> and mralexandersaavedra/loop-web:<HC_VERSION>
HC_VERSION=1.12.1
HC_VERSION=1.12.2
# Empty for the first install; a short name (e.g. second) for another install on the same host
HC_INSTANCE=

Expand Down
4 changes: 4 additions & 0 deletions docs/profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,5 +484,9 @@ The document may carry `sports` — `[{sport, minutes, perWeek}]`, one entry per
- It opens on its own once, when the server has neither an onboarding document nor a goal and the page was not
opened on a sheet deep link.
- "Later" is remembered in `localStorage` (`hc.onboarding.later`, a convenience only).
- In the admin's coach view (the tab shows another person's page, `sessionStorage` `hc.viewing`) the assistant never
opens by itself and asks the server nothing: the page is read-only and the profile is that person's to fill in. Opened
by hand there, **Save** answers "Read-only: you are viewing another person's page. Nothing was saved." without a
request; a save the server refuses with `403 read_only` gets the same line, never "server error".
- The profile sheet opens it from the **Edit** chip at the end of its header row (name, age, place) on the LAN
page.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "loop",
"version": "1.12.1",
"version": "1.12.2",
"private": true,
"description": "Tooling for the plan single source of truth (data/nutrition + data/training) and its Astro build (web/).",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions services/loop-ingest/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/loop-ingest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "loop-ingest",
"version": "1.12.1",
"version": "1.12.2",
"private": true,
"license": "MIT",
"type": "module",
Expand Down
52 changes: 49 additions & 3 deletions web/src/client/onboarding.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const source = clientScriptSource('onboarding.ts');
/** @typedef {import('node:vm').Context} VmGlobals the script's globals (a vm context: untyped by nature) */
/**
* @param {{locale?: string, profile?: unknown, settings?: {goal: string | null}, protocol?: string, later?: boolean, putFails?: boolean,
* hash?: string, statusNode?: {textContent: string} | null}} [opts]
* hash?: string, statusNode?: {textContent: string} | null, viewing?: string, putError?: {status: number, code?: string} | null}} [opts]
* `viewing`: the tab shows that person's page (the coach view); `putError`: what the save is rejected with
*/
function setup({ locale = 'en', profile = null, settings = { goal: null }, protocol = 'http:', later = false, putFails = false, hash = '', statusNode = null } = {}) {
function setup({ locale = 'en', profile = null, settings = { goal: null }, protocol = 'http:', later = false, putFails = false, hash = '', statusNode = null, viewing = '', putError = null } = {}) {
/** @type {Record<string, ((e: unknown) => void)[]>} */
const listeners = {};
/** @type {[string, string, any][]} the API calls; [2] = the JSON round-trip of the body the script sent */
Expand All @@ -35,7 +36,7 @@ function setup({ locale = 'en', profile = null, settings = { goal: null }, proto
calls.push([method, p, body && JSON.parse(JSON.stringify(body))]);
if (method === 'GET' && p === '/profile') return Promise.resolve({ profile });
if (method === 'GET' && p === '/settings') return Promise.resolve({ settings });
if (method === 'PUT' && p === '/profile') return putFails ? Promise.reject({ status: 0 }) : Promise.resolve({ profile: body });
if (method === 'PUT' && p === '/profile') return putError ? Promise.reject(putError) : putFails ? Promise.reject({ status: 0 }) : Promise.resolve({ profile: body });
return Promise.reject({ status: 404 });
};
/** @type {VmGlobals} */
Expand All @@ -61,6 +62,8 @@ function setup({ locale = 'en', profile = null, settings = { goal: null }, proto
},
location: { protocol, origin: 'http://192.168.1.50:8091', hash },
localStorage: { getItem: (/** @type {string} */ k) => (k in store ? store[k] : null), setItem: (/** @type {string} */ k, /** @type {unknown} */ v) => { store[k] = String(v); }, removeItem: (/** @type {string} */ k) => { delete store[k]; } },
// whose page the tab shows (client/signin.ts): the viewed person's name in the admin's coach view, else nothing
sessionStorage: { getItem: (/** @type {string} */ k) => (k === 'hc.viewing' && viewing ? viewing : null) },
PROFILE: { weight: { kg: 60, date: '2026-10-13' } },
I18N_ONB: locale === 'es' ? esO : enO,
LOCALE: locale,
Expand Down Expand Up @@ -527,3 +530,46 @@ test('each adjust cell names its day type (sr-only), so "kcal" is never ambiguou
es.act('next'); es.act('next'); es.act('adjust');
assert.match(es.html(), new RegExp(`<span class="sr-only">${esO.summary.days.rest} </span>`));
});

test('the coach view (the tab shows another person\'s page): the assistant never opens by itself and asks the server nothing', async () => {
const s = setup({ viewing: 'ana' });
await flush(); await flush();
assert.deepEqual(s.opened, [], 'not opened over a page that is read-only');
assert.deepEqual(s.calls, [], 'no first-run lookup either');
// the same person-less page on their OWN tab still gets it
const own = setup();
await flush(); await flush();
assert.deepEqual(own.opened.map((o) => o[0]), ['onboarding']);
});

test('the coach view: a save says "read-only" at once, sends nothing and keeps the sheet open (en / es)', async () => {
for (const [locale, text] of /** @type {[string, RegExp][]} */ ([['en', /Read-only: you are viewing another person&#39;s page\. Nothing was saved\.|Read-only: you are viewing another person's page\. Nothing was saved\./], ['es', /Solo lectura: estás viendo la página de otra persona\. No se ha guardado nada\./]])) {
const s = setup({ viewing: 'ana', locale });
toSafety(s, [['team', '90', '2']]);
s.act('next'); s.act('next'); s.act('next'); s.act('next');
s.act('save');
await flush(); await flush();
assert.match(s.html(), text, locale);
assert.deepEqual(s.calls.filter((c) => c[0] === 'PUT'), [], 'nothing was sent');
assert.deepEqual(s.saved, []);
assert.equal(s.synced, 0);
}
});

test('a save the server refuses as read_only (the view began elsewhere) gets that reason, not "server error"', async () => {
const s = setup({ putError: { status: 403, code: 'read_only' } });
toSafety(s, [['team', '90', '2']]);
s.act('next'); s.act('next'); s.act('next'); s.act('next');
s.act('save');
await flush(); await flush();
assert.match(s.html(), /Read-only: you are viewing another person/);
assert.doesNotMatch(s.html(), /server error/);
assert.deepEqual(s.saved, []);
// any other refusal keeps the generic reason
const other = setup({ putError: { status: 500, code: 'internal' } });
toSafety(other, [['team', '90', '2']]);
other.act('next'); other.act('next'); other.act('next'); other.act('next');
other.act('save');
await flush(); await flush();
assert.match(other.html(), /Could not save \(server error\)/);
});
12 changes: 10 additions & 2 deletions web/src/client/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ type OnbDoc = {
function save() {
var call = api();
if (!call) return;
if (viewing()) { setStatus(T.errors.readOnly); return; }
setStatus(T.saving);
var st = window.HCSettings;
call('PUT', '/profile', doc()).then(function () {
Expand All @@ -408,7 +409,9 @@ type OnbDoc = {
close();
var b = document.getElementById ? document.getElementById('sync-btn') : null;
if (b && !b.hidden && typeof b.click === 'function') b.click();
}).catch(function (err: { status?: number } | null | undefined) {
}).catch(function (err: { status?: number; code?: string } | null | undefined) {
// the server refuses every write of a session that is viewing somebody (403 read_only): not a server error
if (err && err.code === 'read_only') { setStatus(T.errors.readOnly); return; }
setStatus(format(T.errors.save, { reason: err && err.status === 0 ? T.reasons.offline : T.reasons.generic }));
});
}
Expand Down Expand Up @@ -477,13 +480,18 @@ type OnbDoc = {

HC.registerView('onboarding', { title: function () { return T.title; }, render: render });

// While this tab shows ANOTHER person's page (the admin's coach view, read-only; client/signin.ts keeps sessionStorage
// `hc.viewing`) the assistant is nobody's to fill in: it never opens by itself, and a save says so without asking the server.
function viewing() {
try { return typeof sessionStorage !== 'undefined' && !!sessionStorage.getItem('hc.viewing'); } catch (e) { return false; }
}
// first run (LAN only): neither an onboarding document nor a goal on the server, and not postponed here
function laterSet() {
try { return localStorage.getItem(LATER_KEY) === '1'; } catch (e) { return false; }
}
function firstRun() {
var call = api();
if (!call || laterSet()) return;
if (!call || laterSet() || viewing()) return;
Promise.all([call('GET', '/profile'), call('GET', '/settings')]).then(function (r) {
var prof = r[0] && r[0].profile, set = r[1] && r[1].settings;
if (prof || (set && set.goal)) return;
Expand Down
2 changes: 2 additions & 0 deletions web/src/i18n/onboarding-templates.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const en = {
proteinMax: 'Protein above 2.4 g per kg.',
fatMin: 'Fat below 0.5 g per kg.',
save: 'Could not save ({reason}). Try again.',
readOnly: 'Read-only: you are viewing another person\'s page. Nothing was saved.',
},
warnings: {
proteinRange: 'Protein outside the usual 1.6-2.2 g per kg.',
Expand Down Expand Up @@ -222,6 +223,7 @@ export const es = {
proteinMax: 'Proteína por encima de 2,4 g por kg.',
fatMin: 'Grasa por debajo de 0,5 g por kg.',
save: 'No se pudo guardar ({reason}). Inténtalo de nuevo.',
readOnly: 'Solo lectura: estás viendo la página de otra persona. No se ha guardado nada.',
},
warnings: {
proteinRange: 'Proteína fuera del rango habitual de 1,6-2,2 g por kg.',
Expand Down