feat(coverage): routing coverage page + editor overlay (#78) #79

Closed
maximus wants to merge 2 commits from feat/78-coverage-ui into deploy
Member

Phase 3 of #78: the routing-coverage UI. It talks to the phase 2 trail-coverage service (homelab-flux #927). Fork-only.

What

Proxy (web/src/lib/server/trail_coverage.ts, routes under /api/v1/trail-coverage/). It follows the trail-analyze proxy pattern:

  • TRAIL_COVERAGE_URL unset or not a plain http(s) URL: the feature is off. Every route answers 404, the settings link and the page are gone, and the editor shows nothing.
  • status, runs/current, estimate, proposals and runs are owner only: TRAIL_COVERAGE_USERS (comma-separated PocketBase ids). This fails closed like TRAIL_ANALYZE_USERS: unset, empty or any malformed entry admits nobody. A non-owner gets 403 and an anonymous user 401.
  • coverage.geojson is open to every logged-in user. It is re-sanitised here (known kinds and properties only) and cached for 5 min, with one shared upstream call. The owner can pass ?fresh=1 after a run.
  • The proxy adds Authorization: Bearer $TRAIL_COVERAGE_SECRET (server-side only; it never appears in a response). The POSTs also send X-Trail-Coverage-User: <acting user id>. No incoming header (cookie, Authorization) is forwarded, upstream paths are fixed, and redirects are not followed.
  • Every POST body is rebuilt from validated fields using the service's own rules (bbox ranges, name regex, one-line title of 120 characters or less, extract paths, action/components). A POST must be same-origin application/json, so a cross-site form cannot start a rebuild with the owner's cookie (the CSRF hook exempts /api/v1).
  • The service's 400/409/413/415/422/429/500/502/503 answers are passed through with their JSON, so the UI can show "run active", "busy window", "rate limit" and "not configured". Its 401 (wrong secret), 404 and redirects become 502.

Owner page /settings/coverage, linked in the settings menu for the owner only:

  • MapLibre map: region bboxes (solid = built, dashed = planned only), 1-degree DEM tiles coloured by source (ign / ign+copernicus / copernicus / none), and probe routes green or red per engine (BRouter solid, offset left; Valhalla dashed, offset right).
  • A legend, plus a built-vs-git pill ("coverage.yaml changed since the last build"), the releases and the busy window.
  • Draw a rectangle (two clicks) or type a bbox, then Estimate. This shows the plan.sh verdict and problems, warnings, the extracts with sizes and their share inside the bbox, the extracts plan.sh does not allow, new DEM and rd5 tiles, and rough artifact sizes against the tmpfs budget.
  • Propose (name + title) opens a PR and links to it (http(s) URLs only). A 503 shows "Proposals aren't set up yet (no bot token)…" and disables the button. 422 problems are listed.
  • Build / Probe / Rollback (rollback asks for confirmation and can do rd5, valhalla or both). A 409 shows the reason, the active jobs and the busy window. A 429 shows "one start per minute".
  • While a run is active, the page polls runs/current every 4 s. It shows each step with its state badge, timing, message and log tail, then the probe results once the run ends (status and geojson are then refreshed).
  • All service data is rendered as text. There is no {@html} anywhere, and map labels use a MapLibre symbol layer, never HTML popups.

Route editor (every logged-in user while the feature is on, read-only):

  • A new map-view button toggles a faint dashed region overlay. It is off by default, remembered per browser, and drawn below the route.
  • A non-blocking pill, "Outside routing coverage — routes may stop here", appears when a route anchor, the loop-generator start or a must-visit point lies outside every region bbox. With no regions loaded (feature off, service down), it never shows.
  • Strings are in en + de.

Tests

  • nice -n 10 npx vitest run: 103 files / 1349 tests pass (13 skipped as before).
  • npm run check: 0 errors. The 2 warnings were there before (editor <tbody> a11y).
  • New tests:
    • trail_coverage.test.ts (53). Feature off → 404 on all six routes. Non-owner → 403 and anonymous → 401 without any upstream call. Malformed allow-lists fail closed. The secret header is added on every call, and the user id header only on the POSTs. Cookies are not forwarded and the secret never leaks. 503 without a secret. A cross-site Origin → 403 and text/plain → 415. Invalid bodies → 422 with no upstream call. Passthrough of 409/429/503/422, and upstream 401/404/302/HTML → 502. Timeout → 504. For the geojson: sanitising, the 5-min cache with single-flight, fresh=1 for the owner only, and failures are not cached.
    • layout_coverage_flag.test.ts: the layout flags, and the page load answering 404, 403, 401 or 200.
    • util/coverage.test.ts: the outside-coverage check (anchors use lon, the loop start uses lng, bbox edges count as inside, no regions means no hint), safeHttpUrl (rejects javascript:, data: and protocol-relative URLs), and the formatting helpers.
    • coverage_escaping.test.ts: an SSR render of the region list, run panel, estimate panel and hint with <img onerror> / <script> payloads; all of them come out escaped.
  • Acceptance script /root/tools/wanderer-shots/acceptance/t9_coverage.mjs (not run yet; the service isn't deployed):
    • With WANDERER_TARGET=preview (preview env below), it expects the page to render the map canvas and legend for claude_test. The missing service must show as an error message, and the sidebar must have the link.
    • On live, it expects /settings/coverage to answer 403/404 for claude_test, the owner API (GET status, POST estimate) to answer 403/404, and no sidebar link.
    • It never POSTs /runs or /proposals.

homelab-flux wiring the deploy needs

  • apps/wanderer/wanderer.yaml, wanderer-web env:
    - { name: TRAIL_COVERAGE_URL, value: "http://trail-coverage-api.trail-coverage.svc.cluster.local:8080" }
    - { name: TRAIL_COVERAGE_SECRET, valueFrom: { secretKeyRef: { name: trail-coverage-client, key: TRAIL_COVERAGE_SECRET } } }
    # Owner page only (status / estimate / proposals / runs). gtc1tsvcarldagg = Jörg. Never add claude_test here.
    - { name: TRAIL_COVERAGE_USERS, value: "gtc1tsvcarldagg" }
    
  • apps/wanderer/kustomization.yaml lists trail-coverage-client.enc.yaml (already in #927's resources): Secret trail-coverage-client in ns default.
  • The wanderer-web image is bumped to the deploy image built from this PR (after merge). Until then the env does nothing.
  • Nothing changes on the trail-coverage side: its NetworkPolicy already admits default/app=wanderer-web, and the live wanderer pods have no egress policy.
  • Preview env, for the t9 test only (apps/wanderer-preview/wanderer-preview.yaml, wanderer-preview-web). This uses the preview's own env, never live config, and no secret: the service is never given to the preview, and its netpol refuses preview pods anyway.
    - { name: TRAIL_COVERAGE_URL, value: "http://trail-coverage-api.trail-coverage.svc.cluster.local:8080" }
    # rlbmwdc6h8c26hi = claude_test: owner-equivalent on the PREVIEW only, so t9 can render the page.
    - { name: TRAIL_COVERAGE_USERS, value: "rlbmwdc6h8c26hi" }
    
    With no TRAIL_COVERAGE_SECRET, the preview proxy answers 503 "TRAIL_COVERAGE_SECRET not set" without opening a connection. The page then shows the map, the legend and that message, which is what t9 checks on the preview.
  • Then run cd /root/tools/wanderer-shots/acceptance && WANDERER_TARGET=preview nice -n 10 node t9_coverage.mjs and, after the live deploy, nice -n 10 node t9_coverage.mjs.

Not done here

  • No local screenshots: the page needs a PocketBase session, and the service isn't deployed.
  • No merge, no image build, no deploy-preview push and no homelab-flux change (all left to the deploy step).

Refs #78

🤖 Generated with Claude Code

https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP

Phase 3 of #78: the routing-coverage UI. It talks to the phase 2 `trail-coverage` service (homelab-flux #927). Fork-only. ## What **Proxy** (`web/src/lib/server/trail_coverage.ts`, routes under `/api/v1/trail-coverage/`). It follows the trail-analyze proxy pattern: - `TRAIL_COVERAGE_URL` unset or not a plain http(s) URL: the feature is off. Every route answers 404, the settings link and the page are gone, and the editor shows nothing. - `status`, `runs/current`, `estimate`, `proposals` and `runs` are owner only: `TRAIL_COVERAGE_USERS` (comma-separated PocketBase ids). This fails closed like `TRAIL_ANALYZE_USERS`: unset, empty or any malformed entry admits nobody. A non-owner gets 403 and an anonymous user 401. - `coverage.geojson` is open to every logged-in user. It is re-sanitised here (known kinds and properties only) and cached for 5 min, with one shared upstream call. The owner can pass `?fresh=1` after a run. - The proxy adds `Authorization: Bearer $TRAIL_COVERAGE_SECRET` (server-side only; it never appears in a response). The POSTs also send `X-Trail-Coverage-User: <acting user id>`. No incoming header (cookie, Authorization) is forwarded, upstream paths are fixed, and redirects are not followed. - Every POST body is rebuilt from validated fields using the service's own rules (bbox ranges, name regex, one-line title of 120 characters or less, extract paths, action/components). A POST must be same-origin `application/json`, so a cross-site form cannot start a rebuild with the owner's cookie (the CSRF hook exempts `/api/v1`). - The service's 400/409/413/415/422/429/500/502/503 answers are passed through with their JSON, so the UI can show "run active", "busy window", "rate limit" and "not configured". Its 401 (wrong secret), 404 and redirects become 502. **Owner page `/settings/coverage`**, linked in the settings menu for the owner only: - MapLibre map: region bboxes (solid = built, dashed = planned only), 1-degree DEM tiles coloured by source (ign / ign+copernicus / copernicus / none), and probe routes green or red per engine (BRouter solid, offset left; Valhalla dashed, offset right). - A legend, plus a built-vs-git pill ("coverage.yaml changed since the last build"), the releases and the busy window. - Draw a rectangle (two clicks) or type a bbox, then Estimate. This shows the plan.sh verdict and problems, warnings, the extracts with sizes and their share inside the bbox, the extracts plan.sh does not allow, new DEM and rd5 tiles, and rough artifact sizes against the tmpfs budget. - Propose (name + title) opens a PR and links to it (http(s) URLs only). A 503 shows "Proposals aren't set up yet (no bot token)…" and disables the button. 422 problems are listed. - Build / Probe / Rollback (rollback asks for confirmation and can do rd5, valhalla or both). A 409 shows the reason, the active jobs and the busy window. A 429 shows "one start per minute". - While a run is active, the page polls `runs/current` every 4 s. It shows each step with its state badge, timing, message and log tail, then the probe results once the run ends (status and geojson are then refreshed). - All service data is rendered as text. There is no `{@html}` anywhere, and map labels use a MapLibre symbol layer, never HTML popups. **Route editor** (every logged-in user while the feature is on, read-only): - A new map-view button toggles a faint dashed region overlay. It is off by default, remembered per browser, and drawn below the route. - A non-blocking pill, "Outside routing coverage — routes may stop here", appears when a route anchor, the loop-generator start or a must-visit point lies outside every region bbox. With no regions loaded (feature off, service down), it never shows. - Strings are in en + de. ## Tests - `nice -n 10 npx vitest run`: 103 files / 1349 tests pass (13 skipped as before). - `npm run check`: 0 errors. The 2 warnings were there before (editor `<tbody>` a11y). - New tests: - `trail_coverage.test.ts` (53). Feature off → 404 on all six routes. Non-owner → 403 and anonymous → 401 without any upstream call. Malformed allow-lists fail closed. The secret header is added on every call, and the user id header only on the POSTs. Cookies are not forwarded and the secret never leaks. 503 without a secret. A cross-site Origin → 403 and text/plain → 415. Invalid bodies → 422 with no upstream call. Passthrough of 409/429/503/422, and upstream 401/404/302/HTML → 502. Timeout → 504. For the geojson: sanitising, the 5-min cache with single-flight, `fresh=1` for the owner only, and failures are not cached. - `layout_coverage_flag.test.ts`: the layout flags, and the page load answering 404, 403, 401 or 200. - `util/coverage.test.ts`: the outside-coverage check (anchors use `lon`, the loop start uses `lng`, bbox edges count as inside, no regions means no hint), `safeHttpUrl` (rejects `javascript:`, `data:` and protocol-relative URLs), and the formatting helpers. - `coverage_escaping.test.ts`: an SSR render of the region list, run panel, estimate panel and hint with `<img onerror>` / `<script>` payloads; all of them come out escaped. - Acceptance script `/root/tools/wanderer-shots/acceptance/t9_coverage.mjs` (not run yet; the service isn't deployed): - With `WANDERER_TARGET=preview` (preview env below), it expects the page to render the map canvas and legend for claude_test. The missing service must show as an error message, and the sidebar must have the link. - On live, it expects `/settings/coverage` to answer 403/404 for claude_test, the owner API (GET status, POST estimate) to answer 403/404, and no sidebar link. - It never POSTs `/runs` or `/proposals`. ## homelab-flux wiring the deploy needs - [ ] `apps/wanderer/wanderer.yaml`, wanderer-web env: ```yaml - { name: TRAIL_COVERAGE_URL, value: "http://trail-coverage-api.trail-coverage.svc.cluster.local:8080" } - { name: TRAIL_COVERAGE_SECRET, valueFrom: { secretKeyRef: { name: trail-coverage-client, key: TRAIL_COVERAGE_SECRET } } } # Owner page only (status / estimate / proposals / runs). gtc1tsvcarldagg = Jörg. Never add claude_test here. - { name: TRAIL_COVERAGE_USERS, value: "gtc1tsvcarldagg" } ``` - [x] `apps/wanderer/kustomization.yaml` lists `trail-coverage-client.enc.yaml` (already in #927's resources): Secret `trail-coverage-client` in ns default. - [ ] The wanderer-web image is bumped to the deploy image built from this PR (after merge). Until then the env does nothing. - [ ] Nothing changes on the trail-coverage side: its NetworkPolicy already admits `default/app=wanderer-web`, and the live wanderer pods have no egress policy. - [ ] Preview env, for the t9 test only (`apps/wanderer-preview/wanderer-preview.yaml`, wanderer-preview-web). This uses the preview's own env, never live config, and **no secret**: the service is never given to the preview, and its netpol refuses preview pods anyway. ```yaml - { name: TRAIL_COVERAGE_URL, value: "http://trail-coverage-api.trail-coverage.svc.cluster.local:8080" } # rlbmwdc6h8c26hi = claude_test: owner-equivalent on the PREVIEW only, so t9 can render the page. - { name: TRAIL_COVERAGE_USERS, value: "rlbmwdc6h8c26hi" } ``` With no `TRAIL_COVERAGE_SECRET`, the preview proxy answers 503 "TRAIL_COVERAGE_SECRET not set" without opening a connection. The page then shows the map, the legend and that message, which is what t9 checks on the preview. - [ ] Then run `cd /root/tools/wanderer-shots/acceptance && WANDERER_TARGET=preview nice -n 10 node t9_coverage.mjs` and, after the live deploy, `nice -n 10 node t9_coverage.mjs`. ## Not done here - No local screenshots: the page needs a PocketBase session, and the service isn't deployed. - No merge, no image build, no deploy-preview push and no homelab-flux change (all left to the deploy step). Refs #78 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP
Same-origin routes under /api/v1/trail-coverage forward to
TRAIL_COVERAGE_URL with the server-side TRAIL_COVERAGE_SECRET, mirroring
the trail-analyze proxy: unset URL = feature off (404), status/estimate/
proposals/runs only for TRAIL_COVERAGE_USERS (fail closed), the POSTs
carry X-Trail-Coverage-User, bodies are rebuilt from validated fields and
must be same-origin application/json. coverage.geojson is open to every
logged-in user, sanitised and cached for 5 minutes. The root layout
exposes coverageEnabled / coverageOwner for the UI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP
feat(coverage): routing coverage page + editor overlay (#78)
All checks were successful
CI / web (push) Successful in 1m14s
CI / go (push) Successful in 11m20s
97594574a2
Owner page /settings/coverage (linked in the settings menu for the
owner): MapLibre map of regions, DEM tiles by source and probe routes
per engine with a legend, built-vs-git status, draw a rectangle ->
estimate (extracts, sizes, new tiles, plan.sh verdict), Propose (PR link,
503 "not configured" explained), Build / Probe / Rollback (confirm) with
409/429 reasons, and live run progress polled from /runs/current (steps,
timings, log tails, probe results). Service data is rendered as text
only; PR links must be http(s).

Route editor, every user while the feature is on: a faint, toggleable
coverage overlay (off by default) and a non-blocking hint when an anchor
or the loop start/must-visit points lie outside every region. en + de.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP
Author
Member

landed in #80 as abc536cc42

landed in https://git.mirus-tech.com/public/wanderer/pulls/80 as abc536cc4221420a50f65f5b685997d31e9f60d5
maximus closed this pull request 2026-11-06 16:25:09 +00:00
Author
Member

Review fixes pushed in 116ed430 (no merge, no image build):

  1. Origin check: a cookie-authenticated POST now needs Origin equal to ours, or Sec-Fetch-Site: same-origin when the browser sends no Origin. A missing Origin alone gets 403. wanderer_key API-token requests (hooks.server.ts authenticates Authorization: Bearer wanderer_key… and then ignores the cookie) need neither. There are tests for each case: no headers, cross-site, same-site, Origin: null, a sibling origin, a foreign Origin with same-origin Sec-Fetch-Site, a non-token Authorization header, and the accepted cases.
  2. Stale runs: only the service's active flag (unfinished Jobs) drives polling and disables Build/Probe/Rollback. A run.json stuck at running with nothing active shows a "stale" badge and an explanation, and the page does not poll. After a 201, polling continues for a 15 s grace period in case the new Job is not listed yet. Stale steps no longer count their timer up to now.
  3. Served regions only: the editor hint and overlay use only regions with state: "served". The service sets "planned" when coverage.json has no regions and it falls back to plan.json. With no served regions, no hint is shown.
  4. Titles: one rule (validRegionTitle) is shared by the proxy and the page, matching the service's 1 <= len(title) <= 120 and title.isprintable(). Length is counted in code points, so an emoji counts once. Emoji and flags pass; ZWJ sequences (U+200D is Cf), NBSP, tabs and line separators are refused, as in Python. I cross-checked the cases with Python 3.13. The title input dropped maxlength, which counts UTF-16 units.

Results: vitest has 103 files / 1384 tests passing (13 skipped). npm run check has 0 errors and the same 2 warnings as before (the editor <tbody>).

🤖 Generated with Claude Code

Review fixes pushed in 116ed430 (no merge, no image build): 1. **Origin check:** a cookie-authenticated POST now needs `Origin` equal to ours, or `Sec-Fetch-Site: same-origin` when the browser sends no Origin. A missing Origin alone gets 403. `wanderer_key` API-token requests (hooks.server.ts authenticates `Authorization: Bearer wanderer_key…` and then ignores the cookie) need neither. There are tests for each case: no headers, cross-site, same-site, `Origin: null`, a sibling origin, a foreign Origin with same-origin Sec-Fetch-Site, a non-token Authorization header, and the accepted cases. 2. **Stale runs:** only the service's `active` flag (unfinished Jobs) drives polling and disables Build/Probe/Rollback. A run.json stuck at `running` with nothing active shows a "stale" badge and an explanation, and the page does not poll. After a 201, polling continues for a 15 s grace period in case the new Job is not listed yet. Stale steps no longer count their timer up to now. 3. **Served regions only:** the editor hint and overlay use only regions with `state: "served"`. The service sets `"planned"` when coverage.json has no regions and it falls back to plan.json. With no served regions, no hint is shown. 4. **Titles:** one rule (`validRegionTitle`) is shared by the proxy and the page, matching the service's `1 <= len(title) <= 120 and title.isprintable()`. Length is counted in code points, so an emoji counts once. Emoji and flags pass; ZWJ sequences (U+200D is Cf), NBSP, tabs and line separators are refused, as in Python. I cross-checked the cases with Python 3.13. The title input dropped `maxlength`, which counts UTF-16 units. Results: vitest has 103 files / 1384 tests passing (13 skipped). `npm run check` has 0 errors and the same 2 warnings as before (the editor `<tbody>`). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Member

#79 was already merged into deploy (train #80), so the review fixes above are now in follow-up PR #81 (c78be3de, based on deploy).

#79 was already merged into deploy (train #80), so the review fixes above are now in follow-up PR #81 (c78be3de, based on deploy).
All checks were successful
CI / web (push) Successful in 1m14s
Required
Details
CI / go (push) Successful in 11m20s
Required
Details

Pull request closed

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
public/wanderer!79
No description provided.