La app avisa cuando la api es más vieja que ella
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

Validado desde afuera, y era esto: **el frontend desplegado es el nuevo y la api no**. Los hashes que
sirve producción coinciden byte a byte con mi build de HEAD, y el bundle contiene las novedades
("What arrived last", "one total an hour"); pero `/api/vitals/hours`, `/api/insights` y
`/api/music/lookup` responden **404** donde esta versión responde 401. O sea: el número de cada
tarjeta lo calcula la api — y la api que corre es la de antes de las horas, la que lee el total del
día como si fuera la hora 00 y suma 840 donde el reloj dice 499.

Eso explica el reporte completo sin ninguna otra suposición: las actualizaciones llegan, se guardan,
y la pantalla nueva pide cosas que ese servidor no tiene (de ahí que el detalle por hora y el recibo
no aparezcan nunca) mientras muestra el número que el servidor viejo le manda.

La causa de fondo es de despliegue: `web` se reconstruye desde el código en cada deploy, pero el
código de la api se copia *dentro* de su contenedor, y Dokploy no recrea un servicio que ya está
Running. Un deploy entonces refresca la mitad de la aplicación.

Arreglar eso no puede depender de que alguien se acuerde, así que la app ahora lo pregunta:
`GET /api/config` publica `features` — una lista de capacidades, nunca configuración ni credenciales —
y Salud muestra una línea ámbar cuando esa lista falta o no llega hasta `vitals.hours`. Un servidor
viejo ya no puede parecer una pantalla rota.

Tests: el config contra el servidor real (la lista existe, nombra las rutas nuevas, y esas rutas
contestan 401 y no 404, sin claves adentro), y el aviso en la pantalla para los dos casos — api sin
lista y api al día. Mutation-check: si el aviso deja de dispararse con una api sin lista, falla.
This commit is contained in:
dsantillan committed 2026-09-23 18:06:50 -04:00
1 parent 407d7c47c9
commit 4ba9e29d1e
6 files changed
+84 -2

No files matched your search

+19
View File
@@ -106,6 +106,25 @@ async function seed(h, uid) {
const ask = (h, uid) => fetch(`${h.api}/api/insights`, { method: 'POST', headers: { ...cookie(uid), 'Sec-Fetch-Site': 'same-origin' } });
const read = (h, uid, q = '') => fetch(`${h.api}/api/insights${q}`, { headers: cookie(uid) });
/* The app and the api are deployed separately — `web` is rebuilt from source on every deploy, the
api's code is copied into a container that a deploy does not have to recreate — so the newest
screen can end up talking to an older server. `/api/config` is how the screen finds out, which
only works if the list is actually there and actually names the new routes. */
test('the public config lists what this build of the api can do', async t => {
const h = await startServer(t);
const cfg = await (await fetch(`${h.api}/api/config`)).json();
assert.equal(typeof cfg.invite_only, 'boolean');
assert.ok(Array.isArray(cfg.features), 'a client cannot detect a stale api without the list');
assert.ok(cfg.features.includes('vitals.hours'));
assert.ok(cfg.features.includes('insights'));
// ...and the routes those names promise are the ones this server actually answers.
assert.equal((await fetch(`${h.api}/api/vitals/hours`)).status, 401, 'a route that exists refuses without a session');
assert.equal((await fetch(`${h.api}/api/insights`)).status, 401);
assert.equal((await fetch(`${h.api}/api/music/lookup`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' })).status, 401);
// Nothing in it is configuration or a credential.
assert.equal(JSON.stringify(cfg).includes('key'), false);
});
test('an instance with no key has no second opinion, and says so instead of failing', async t => {
const h = await startServer(t);
await seed(h, 'u_j1');