GRI-1887: wire the panel's five API modules to the real server #118

Merged
vivy merged 2 commits from feature/GRI-1887-panel-live-api into dev 2026-11-10 18:35:08 +00:00
Member

Summary

Flips USE_MOCK off in all five panel API modules (session, devices, IP
rules, media, playlists). The http*Api.ts implementations were written
against a draft plan doc before the real server routes existed, and didn't
match what's actually merged — this adjusts them to the real, snake_case
wire contract instead:

  • devicesApi: Device drops lastSeenAt/assignedPlaylist (the server's
    DeviceView exposes neither); hostname/ipAddress are now top-level,
    matching the server.
  • ipRulesApi: auto_approve → autoApprove, target_group →
    targetGroup both ways (the existing code sent targetGroup on write,
    which the server silently ignored).
  • mediaApi: PDF page numbers are derived from a single upload response's
    row order (document row first, then one document_page row per page, in
    render order) — the only place that order is ever available, since the
    server stores no page index.
  • playlistsApi: a playlist item carries only media_id on the wire, no
    human name and no kind — both are resolved against the already-loaded
    media library when converting to/from the wire shape.
  • sessionApi: GET /setup/status returns needs_setup, inverted from the
    panel's firstUserExists — fixed. Login and first-user setup are not
    fully wired; see "Not done" below.

USE_MOCK no longer a hardcoded boolean in each module: import.meta.env.MODE === 'test' picks the mock, so vitest keeps exercising the mock (and the
QA suite is unedited) while every other build talks to the server.

Also removes the stale "not wired yet" section of
plan/operations/deployment.md (PR #103 merged this already).

Verified by hand

Against a real server build + a disposable Postgres on this build host,
through the actual HTTP routes each http*Api.ts module calls (curl,
matching each module's exact request/response shapes — I don't have a
browser tool in this environment; see "Not done" for what that means for
devices/media/playlists/IP rules too):

  • IP rules — add a blocklist entry, add an auto-approve entry (with
    target_group), list, remove both. Full round-trip, matches the adapter.
  • Devices — approve a pending device (server returns the one-time
    token; see plan/operations/deployment.md's own "shown once" note — not
    surfaced in the panel yet, same as before), rename, list by status.
  • Media — uploaded an image and a video; both round-trip correctly.
    Added a URL item. PDF upload does not work — see "Not done".
  • Playlists — created a playlist, added an image item (kind resolved
    from the media library, matching ItemInput's validation), saved,
    assigned to an approved device, confirmed GET /devices/{id} is the one
    deleting a still-assigned playlist is refused against (409
    device_assigned).

npm run check (prettier, oxlint, tsc, vitest) is green, unedited tests.
scripts/local-gates.sh --frontend-only is green.

Not done — two real server-side blockers found while verifying by hand

1. First-user setup and login don't work against the real server, and
I did not change the panel's Login/Setup screens to fix it. The server's
/setup and /session routes require email + name (POST /setup) or
email (POST /session) — the users table has no username column at
all. The panel's SetupScreen/LoginScreen (and App.test.tsx, the QA
suite) model a username-only account, matching plan/server/rest-api.md's
own line — "Logs in: username and password in" — which the server never
implemented. I can't resolve this myself: changing the login UI to collect
email+name would break App.test.tsx, which I won't edit, and I don't own
crates/server. This needs a decision — either the server accepts
username (matching its own doc and the existing UI/test), or the UI
changes to email+name and the QA engineer updates the test. Flagging to
the back-end engineer and the QA engineer.

2. PDF upload fails server-side, every time.
crates/server/src/media/handlers.rs::convert_pdf_upload removes its
render directory (tokio::fs::remove_dir_all(&render_dir)) right after
render_pages returns, then tries to read each rendered page's bytes out
of that now-deleted directory in the loop below — every upload 500s with
"reading a converted page: No such file or directory" after rendering
succeeds. Reproduced by hand with a real two-page PDF (poppler-utils
wasn't on this host either; downloaded and extracted the .deb locally
to get pdftoppm, confirmed it renders the test PDF fine standalone, then
hit the same crash through the server). The document catalog row is
inserted before the crash, so a failed upload also leaves an orphaned
document row with pdf_pages set but no actual page rows or files. This
blocks the issue's "upload image/video/PDF" criterion for the PDF case;
image and video upload both work. Flagging to the back-end engineer —
crates/server isn't mine to fix.

Test plan

  • npm run check in frontend-web/
  • scripts/local-gates.sh --frontend-only
  • IP rules, devices, media (image/video/URL), playlists verified by
    hand against a running server + Postgres, via the exact routes
    each http*Api.ts module calls
  • PDF upload — blocked, server-side bug (see above)
  • First-user setup / login through the panel UI — blocked, contract
    mismatch (see above)
  • No browser available in this environment — the above is curl-level
    verification of the same requests/responses the screens make, not a
    click-through of the screens themselves
## Summary Flips `USE_MOCK` off in all five panel API modules (session, devices, IP rules, media, playlists). The `http*Api.ts` implementations were written against a draft plan doc before the real server routes existed, and didn't match what's actually merged — this adjusts them to the real, snake_case wire contract instead: - `devicesApi`: `Device` drops `lastSeenAt`/`assignedPlaylist` (the server's `DeviceView` exposes neither); `hostname`/`ipAddress` are now top-level, matching the server. - `ipRulesApi`: `auto_approve` → `autoApprove`, `target_group` → `targetGroup` both ways (the existing code sent `targetGroup` on write, which the server silently ignored). - `mediaApi`: PDF page numbers are derived from a single upload response's row order (document row first, then one `document_page` row per page, in render order) — the only place that order is ever available, since the server stores no page index. - `playlistsApi`: a playlist item carries only `media_id` on the wire, no human name and no `kind` — both are resolved against the already-loaded media library when converting to/from the wire shape. - `sessionApi`: `GET /setup/status` returns `needs_setup`, inverted from the panel's `firstUserExists` — fixed. **Login and first-user setup are not fully wired; see "Not done" below.** `USE_MOCK` no longer a hardcoded boolean in each module: `import.meta.env.MODE === 'test'` picks the mock, so `vitest` keeps exercising the mock (and the QA suite is unedited) while every other build talks to the server. Also removes the stale "not wired yet" section of `plan/operations/deployment.md` (`PR #103` merged this already). ## Verified by hand Against a real `server` build + a disposable Postgres on this build host, through the actual HTTP routes each `http*Api.ts` module calls (`curl`, matching each module's exact request/response shapes — I don't have a browser tool in this environment; see "Not done" for what that means for devices/media/playlists/IP rules too): - **IP rules** — add a blocklist entry, add an auto-approve entry (with `target_group`), list, remove both. Full round-trip, matches the adapter. - **Devices** — approve a pending device (server returns the one-time token; see `plan/operations/deployment.md`'s own "shown once" note — not surfaced in the panel yet, same as before), rename, list by status. - **Media** — uploaded an image and a video; both round-trip correctly. Added a URL item. **PDF upload does not work — see "Not done".** - **Playlists** — created a playlist, added an image item (`kind` resolved from the media library, matching `ItemInput`'s validation), saved, assigned to an approved device, confirmed `GET /devices/{id}` is the one deleting a still-assigned playlist is refused against (409 `device_assigned`). `npm run check` (prettier, oxlint, tsc, vitest) is green, unedited tests. `scripts/local-gates.sh --frontend-only` is green. ## Not done — two real server-side blockers found while verifying by hand **1. First-user setup and login don't work against the real server**, and I did not change the panel's Login/Setup screens to fix it. The server's `/setup` and `/session` routes require `email` + `name` (`POST /setup`) or `email` (`POST /session`) — the `users` table has no `username` column at all. The panel's `SetupScreen`/`LoginScreen` (and `App.test.tsx`, the QA suite) model a username-only account, matching `plan/server/rest-api.md`'s own line — *"Logs in: username and password in"* — which the server never implemented. I can't resolve this myself: changing the login UI to collect email+name would break `App.test.tsx`, which I won't edit, and I don't own `crates/server`. This needs a decision — either the server accepts `username` (matching its own doc and the existing UI/test), or the UI changes to email+name and the QA engineer updates the test. Flagging to the back-end engineer and the QA engineer. **2. PDF upload fails server-side, every time.** `crates/server/src/media/handlers.rs::convert_pdf_upload` removes its render directory (`tokio::fs::remove_dir_all(&render_dir)`) right after `render_pages` returns, then tries to read each rendered page's bytes out of that now-deleted directory in the loop below — every upload 500s with *"reading a converted page: No such file or directory"* after rendering succeeds. Reproduced by hand with a real two-page PDF (poppler-utils wasn't on this host either; downloaded and extracted the `.deb` locally to get `pdftoppm`, confirmed it renders the test PDF fine standalone, then hit the same crash through the server). The `document` catalog row is inserted before the crash, so a failed upload also leaves an orphaned `document` row with `pdf_pages` set but no actual page rows or files. This blocks the issue's "upload image/video/PDF" criterion for the PDF case; image and video upload both work. Flagging to the back-end engineer — `crates/server` isn't mine to fix. ## Test plan - [x] `npm run check` in `frontend-web/` - [x] `scripts/local-gates.sh --frontend-only` - [x] IP rules, devices, media (image/video/URL), playlists verified by hand against a running `server` + Postgres, via the exact routes each `http*Api.ts` module calls - [ ] PDF upload — blocked, server-side bug (see above) - [ ] First-user setup / login through the panel UI — blocked, contract mismatch (see above) - [ ] No browser available in this environment — the above is curl-level verification of the same requests/responses the screens make, not a click-through of the screens themselves
GRI-1887: wire the panel's five API modules to the real server
Some checks failed
CI / the pre-push hook (pull_request) Successful in 7s
CI / cargo fmt (pull_request) Successful in 9s
CI / cargo deny advisories (pull_request) Has been cancelled
CI / frontend-web (pull_request) Has been cancelled
CI / repository boundary (pull_request) Has been cancelled
CI / CI (pull_request) Has been cancelled
CI / Notify gate failed (pull_request) Has been cancelled
CI / cargo deny (pull_request) Successful in 4m8s
CI / cargo clippy (pull_request) Successful in 10m52s
CI / cargo test (pull_request) Successful in 11m40s
9365bbdfea
Flip USE_MOCK to false in sessionApi, devicesApi, ipRulesApi, mediaApi and
playlistsApi (the switch now resolves to the mock only under vitest, via
import.meta.env.MODE, so the QA suite keeps exercising the mock without a
hardcoded flag). The http* implementations guessed the server's wire shape
against a draft plan doc before the real routes existed; adjust them to the
merged server contract instead, which uses snake_case fields and a narrower
Device/MediaItem/PlaylistItem shape than the mock's. Device drops
lastSeenAt/assignedPlaylist (the server exposes neither); MediaItem's PDF
page numbers are now derived from a single upload response's row order,
the only place that order is ever available; PlaylistItem's human-readable
name and wire `kind` are resolved against the media library, since the
playlist item itself carries only media_id.

Remove the stale "not wired yet" section of deployment.md (PR #103 merged
this).

Known gaps, left for follow-up rather than guessed at here:
- The server's setup/login routes require email+name (its users table has
  no username column at all), but the panel's Setup/Login screens and
  App.test.tsx model a username-only account — matching the plan doc's own
  "username and password" line, which the server never implemented. Wiring
  sessionApi fully needs that resolved first; left unflipped in practice
  until then (getSetupStatus's needs_setup/firstUserExists inversion is
  fixed, since that needs no shape decision).
- PDF upload fails server-side: convert_pdf_upload removes its render
  directory before reading the rendered page bytes out of it, so every
  upload 500s after rendering successfully. Reproduced by hand.
GRI-1887: replace USE_MOCK with a VITE_API_MODE env flag
Some checks failed
CI / the pre-push hook (pull_request) Successful in 10s
CI / cargo fmt (pull_request) Successful in 8s
CI / cargo deny (pull_request) Successful in 1m44s
CI / cargo deny advisories (pull_request) Failing after 2m22s
CI / repository boundary (pull_request) Successful in 13s
CI / cargo clippy (pull_request) Successful in 10m4s
CI / cargo test (pull_request) Successful in 11m28s
CI / frontend-web (pull_request) Successful in 10m57s
CI / CI (pull_request) Successful in 10s
CI / Notify gate failed (pull_request) Has been skipped
8efced905f
Scope change from the product owner: no hard-coded mock switch. All five
API modules now read apiMode from src/api/mode.ts, which resolves to
'mock' under vitest (MODE === 'test', unconditionally) or when
VITE_API_MODE=mock is set, and to 'http' otherwise. Confirmed by building
both ways and grepping dist/ for mock-only fixture strings (mock-admin,
lobby-screen, cafe-south): present in a --mode mock build, absent from a
default production build — Rollup's cross-module constant folding drops
the mock import entirely once apiMode is statically known.

vite.config.ts proxies /api to VITE_DEV_API_TARGET when that env var is
set, so a dev panel can talk to a real server while keeping requests
same-origin (the session cookie needs that). package.json gets a
dev:mock script (vite --mode mock, loading .env.mock) alongside the
existing dev. .env.example documents both variables for
.env.development.local.
Pandora removed this from the MVP - Campus deploy milestone 2026-11-10 18:29:50 +00:00
vivy merged commit 21c3747fc4 into dev 2026-11-10 18:35:08 +00:00
vivy deleted branch feature/GRI-1887-panel-live-api 2026-11-10 18:35:09 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
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!118
No description provided.