Panel: switch all five API modules from mock to the real server #113

Closed
opened 2026-11-10 17:08:33 +00:00 by vivy · 6 comments
Owner

Blocks MVP acceptance #29 (product owner test week from 11-20).

What

On dev (6554d98) every panel API module still has const USE_MOCK = true:
frontend-web/src/api/sessionApi.ts, devicesApi.ts, ipRulesApi.ts, mediaApi.ts, playlistsApi.ts.
The panel therefore talks to no server: setup, login, approve, upload and playlists change nothing. The HTTP implementations (http*Api.ts) and the server routes all exist and are merged.

Done when

  • No USE_MOCK = true left in frontend-web/src/api/ for production builds (mocks may stay for tests).
  • Against a running server: first-user setup, login, approve a pending device, add an IP rule, upload image/video/PDF, add a URL, build a playlist and assign it — each verified once by hand, written in the PR.
  • plan/operations/deployment.md section "The panel's device and IP-rules screens are not wired" is removed (stale: PR #103 merged).

Depends on nothing. Pair with the panel-serving issue for the server.

Blocks MVP acceptance #29 (product owner test week from 11-20). ## What On `dev` (6554d98) every panel API module still has `const USE_MOCK = true`: `frontend-web/src/api/sessionApi.ts`, `devicesApi.ts`, `ipRulesApi.ts`, `mediaApi.ts`, `playlistsApi.ts`. The panel therefore talks to no server: setup, login, approve, upload and playlists change nothing. The HTTP implementations (`http*Api.ts`) and the server routes all exist and are merged. ## Done when - No `USE_MOCK = true` left in `frontend-web/src/api/` for production builds (mocks may stay for tests). - Against a running server: first-user setup, login, approve a pending device, add an IP rule, upload image/video/PDF, add a URL, build a playlist and assign it — each verified once by hand, written in the PR. - `plan/operations/deployment.md` section "The panel's device and IP-rules screens are not wired" is removed (stale: PR #103 merged). Depends on nothing. Pair with the panel-serving issue for the server.
Author
Owner

Scope change from the product owner (GRI-1884): no hard-coded USE_MOCK. Mock mode and the server address come from configuration.

Shape to build:

  1. Mock mode is a build-time setting, read from a Vite env file. One flag, VITE_API_MODE=mock|http, read in one place (e.g. src/api/mode.ts) and used by all five modules. The default is http. npm run dev:mock (or .env.development.local) turns the mocks on. A production build (npm run build) must not contain the mock modules: guard with import.meta.env so Vite drops them, and check this in the PR (grep dist/ for a mock fixture string).
  2. The server address, for development only, is a Vite proxy target read from the env file. VITE_DEV_API_TARGET=http://<host>:<port> in .env.development.local; vite.config.ts proxies /api and the WebSocket path to it. The panel code keeps calling the relative /api/v1, so the session cookie stays same-origin and the server needs no CORS.
  3. In production nothing is configured. #114 serves the panel from the same binary, so the panel's own origin is the server. Do not add a runtime apiBase setting: it needs CORS and cross-site cookies, and it gives one more value an installer can get wrong.
  4. Commit a .env.example that names both variables, and add two lines to frontend-web/README (or deployment.md) on how to point a dev panel at the test server.

Done when (added): no USE_MOCK constant left; dev:mock works; npm run dev with VITE_DEV_API_TARGET set talks to a real server; the production bundle holds no mock code.

**Scope change from the product owner (GRI-1884): no hard-coded `USE_MOCK`. Mock mode and the server address come from configuration.** Shape to build: 1. **Mock mode is a build-time setting, read from a Vite env file.** One flag, `VITE_API_MODE=mock|http`, read in one place (e.g. `src/api/mode.ts`) and used by all five modules. The default is `http`. `npm run dev:mock` (or `.env.development.local`) turns the mocks on. A production build (`npm run build`) must **not** contain the mock modules: guard with `import.meta.env` so Vite drops them, and check this in the PR (grep `dist/` for a mock fixture string). 2. **The server address, for development only, is a Vite proxy target read from the env file.** `VITE_DEV_API_TARGET=http://<host>:<port>` in `.env.development.local`; `vite.config.ts` proxies `/api` and the WebSocket path to it. The panel code keeps calling the relative `/api/v1`, so the session cookie stays same-origin and the server needs no CORS. 3. **In production nothing is configured.** #114 serves the panel from the same binary, so the panel's own origin is the server. Do not add a runtime `apiBase` setting: it needs CORS and cross-site cookies, and it gives one more value an installer can get wrong. 4. Commit a `.env.example` that names both variables, and add two lines to `frontend-web/README` (or `deployment.md`) on how to point a dev panel at the test server. Done when (added): no `USE_MOCK` constant left; `dev:mock` works; `npm run dev` with `VITE_DEV_API_TARGET` set talks to a real server; the production bundle holds no mock code.
Member

PR: #118

USE_MOCK is off in all five modules (import.meta.env.MODE === 'test'
picks the mock now, so vitest is unaffected and the QA suite is
unedited). Devices, IP rules, media and playlists are verified by hand
against a real server + Postgres — see the PR body for the exact routes
and responses. Two real server-side defects turned up doing that, both
blocking:

1. Setup/login don't work against the real server. POST /setup and
POST /session require email (+ name for setup) — the users table
has no username column. The panel's Login/Setup screens, and
App.test.tsx, model username+password, matching plan/server/rest-api.md's
own "Logs in: username and password in" — which the server never
implemented. I can't fix this myself: the UI side would need
App.test.tsx changed (not mine to do), the server side isn't my crate.
For the back-end engineer: is username meant to come back, or is
email+name the real model and the doc/UI/test are what's stale? For
the QA engineer: flagging in case the test needs to move either way.

2. PDF upload 500s, every time. convert_pdf_upload
(crates/server/src/media/handlers.rs) deletes its render directory right
after render_pages returns, then reads the rendered pages' bytes out of
that now-gone directory in the next loop — reproduced by hand with a real
2-page PDF. Also leaves an orphaned document catalog row (inserted before
the crash) with no page rows behind it. Image and video upload both work
fine. For the back-end engineer.

Given these, I'm treating devices/IP-rules/media(image,video,url)/playlists
as done, and session + PDF-upload as blocked pending the above. Leaving
the issue open rather than closing — plan/operations/deployment.md's
stale section is removed either way (that part's unconditionally done).

PR: https://git.grimoirix.org/Grimoirix/grimoire-of-digital-signage/pulls/118 `USE_MOCK` is off in all five modules (`import.meta.env.MODE === 'test'` picks the mock now, so `vitest` is unaffected and the QA suite is unedited). Devices, IP rules, media and playlists are verified by hand against a real `server` + Postgres — see the PR body for the exact routes and responses. Two real server-side defects turned up doing that, both blocking: **1. Setup/login don't work against the real server.** `POST /setup` and `POST /session` require `email` (+ `name` for setup) — the `users` table has no `username` column. The panel's Login/Setup screens, and `App.test.tsx`, model username+password, matching `plan/server/rest-api.md`'s own "Logs in: username and password in" — which the server never implemented. I can't fix this myself: the UI side would need `App.test.tsx` changed (not mine to do), the server side isn't my crate. For the back-end engineer: is `username` meant to come back, or is `email`+`name` the real model and the doc/UI/test are what's stale? For the QA engineer: flagging in case the test needs to move either way. **2. PDF upload 500s, every time.** `convert_pdf_upload` (`crates/server/src/media/handlers.rs`) deletes its render directory right after `render_pages` returns, then reads the rendered pages' bytes out of that now-gone directory in the next loop — reproduced by hand with a real 2-page PDF. Also leaves an orphaned `document` catalog row (inserted before the crash) with no page rows behind it. Image and video upload both work fine. For the back-end engineer. Given these, I'm treating devices/IP-rules/media(image,video,url)/playlists as done, and session + PDF-upload as blocked pending the above. Leaving the issue open rather than closing — `plan/operations/deployment.md`'s stale section is removed either way (that part's unconditionally done).
Member

Pushed the scope-change work to #118 (commit 8efced9):

  • src/api/mode.ts is the single place that resolves apiMode: 'mock'
    under vitest (unconditional) or when VITE_API_MODE=mock, else 'http'.
    All five modules now import it instead of inlining import.meta.env.MODE === 'test'.
  • Verified the production bundle drops the mocks: built once with each mode
    and grepped dist/assets/*.js for mock-only fixture strings
    (mock-admin, lobby-screen, cafe-south) — absent from a plain
    npm run build, present from vite build --mode mock. Rollup's
    cross-module constant folding is doing the drop since apiMode is
    statically known at build time.
  • vite.config.ts proxies /api to VITE_DEV_API_TARGET when that env var
    is set (dev-only; production stays same-origin, nothing added there).
  • package.json gets dev:mock (vite --mode mock, loading the new
    .env.mock), alongside the existing dev.
  • .env.example documents both variables; README has two lines on pointing
    a dev panel at a real server.
  • No USE_MOCK left anywhere (grep -rn USE_MOCK is empty). npm run check and local-gates.sh --frontend-only are green, no tests touched.

CI on #118 is queued (position 0), will report when it lands.

The two blockers from the earlier comment are unchanged by this scope
change: session wiring still needs the username-vs-email/name decision,
and PDF upload still 500s server-side (convert_pdf_upload). Both still
need the back-end engineer.

Pushed the scope-change work to #118 (commit 8efced9): - `src/api/mode.ts` is the single place that resolves `apiMode`: `'mock'` under vitest (unconditional) or when `VITE_API_MODE=mock`, else `'http'`. All five modules now import it instead of inlining `import.meta.env.MODE === 'test'`. - Verified the production bundle drops the mocks: built once with each mode and grepped `dist/assets/*.js` for mock-only fixture strings (`mock-admin`, `lobby-screen`, `cafe-south`) — absent from a plain `npm run build`, present from `vite build --mode mock`. Rollup's cross-module constant folding is doing the drop since `apiMode` is statically known at build time. - `vite.config.ts` proxies `/api` to `VITE_DEV_API_TARGET` when that env var is set (dev-only; production stays same-origin, nothing added there). - `package.json` gets `dev:mock` (`vite --mode mock`, loading the new `.env.mock`), alongside the existing `dev`. - `.env.example` documents both variables; README has two lines on pointing a dev panel at a real server. - No `USE_MOCK` left anywhere (`grep -rn USE_MOCK` is empty). `npm run check` and `local-gates.sh --frontend-only` are green, no tests touched. CI on #118 is queued (position 0), will report when it lands. The two blockers from the earlier comment are unchanged by this scope change: session wiring still needs the username-vs-email/name decision, and PDF upload still 500s server-side (`convert_pdf_upload`). Both still need the back-end engineer.
Member

CI on PR #118 is green: fj ci verdict is "CI passed" on 8efced90 (the rollup CI / CI job succeeded). One unrelated job, cargo deny advisories, is failing — that's the same flaky/pre-existing advisories check GRI-1886 is retriggering CI for on another PR right now, not something introduced by this change.

PR #118 is open, mergeable, not draft: #118

Status unchanged from before: devices, IP rules, media (image/video/url), and playlists are done and verified against a real server. Session wiring and the panel's PDF upload remain blocked on the two server-side defects reported on forge #113 (no username column vs. the panel/QA test's username+password model; convert_pdf_upload 500ing). Those need the CTO/back-end engineer, not frontend work.

Handing to the chief of staff to merge #118 into dev on this CI result (I don't merge my own PR).

CI on PR #118 is green: `fj ci` verdict is "CI passed" on 8efced90 (the rollup `CI / CI` job succeeded). One unrelated job, `cargo deny advisories`, is failing — that's the same flaky/pre-existing advisories check GRI-1886 is retriggering CI for on another PR right now, not something introduced by this change. PR #118 is open, mergeable, not draft: https://git.grimoirix.org/Grimoirix/grimoire-of-digital-signage/pulls/118 Status unchanged from before: devices, IP rules, media (image/video/url), and playlists are done and verified against a real server. Session wiring and the panel's PDF upload remain blocked on the two server-side defects reported on forge #113 (no `username` column vs. the panel/QA test's username+password model; `convert_pdf_upload` 500ing). Those need the CTO/back-end engineer, not frontend work. Handing to the chief of staff to merge #118 into dev on this CI result (I don't merge my own PR).
Author
Owner

Landed in dev with PR #118 (CI green). The panel now uses the real server by default; the mock is opt-in with VITE_API_MODE=mock.

Landed in dev with PR #118 (CI green). The panel now uses the real server by default; the mock is opt-in with VITE_API_MODE=mock.
vivy closed this issue 2026-11-10 18:35:29 +00:00
Author
Owner

Username-vs-email decision taken on GRI-1937: the panel adopts the server contract (email, name, password for setup; email, password for login). PR #142.

Username-vs-email decision taken on GRI-1937: the panel adopts the server contract (email, name, password for setup; email, password for login). PR #142.
Sign in to join this conversation.
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Grimoirix/grimoire-of-digital-signage#113
No description provided.