feat(coverage): routing coverage page + editor overlay (#78) #79
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
public/wanderer!79
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/78-coverage-ui"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Phase 3 of #78: the routing-coverage UI. It talks to the phase 2
trail-coverageservice (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_URLunset 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,proposalsandrunsare owner only:TRAIL_COVERAGE_USERS(comma-separated PocketBase ids). This fails closed likeTRAIL_ANALYZE_USERS: unset, empty or any malformed entry admits nobody. A non-owner gets 403 and an anonymous user 401.coverage.geojsonis 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=1after a run.Authorization: Bearer $TRAIL_COVERAGE_SECRET(server-side only; it never appears in a response). The POSTs also sendX-Trail-Coverage-User: <acting user id>. No incoming header (cookie, Authorization) is forwarded, upstream paths are fixed, and redirects are not followed.application/json, so a cross-site form cannot start a rebuild with the owner's cookie (the CSRF hook exempts/api/v1).Owner page
/settings/coverage, linked in the settings menu for the owner only:runs/currentevery 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).{@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):
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).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=1for 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 uselon, the loop start useslng, bbox edges count as inside, no regions means no hint),safeHttpUrl(rejectsjavascript:,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./root/tools/wanderer-shots/acceptance/t9_coverage.mjs(not run yet; the service isn't deployed):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./settings/coverageto answer 403/404 for claude_test, the owner API (GET status, POST estimate) to answer 403/404, and no sidebar link./runsor/proposals.homelab-flux wiring the deploy needs
apps/wanderer/wanderer.yaml, wanderer-web env:apps/wanderer/kustomization.yamlliststrail-coverage-client.enc.yaml(already in #927's resources): Secrettrail-coverage-clientin ns default.default/app=wanderer-web, and the live wanderer pods have no egress policy.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. With noTRAIL_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.cd /root/tools/wanderer-shots/acceptance && WANDERER_TARGET=preview nice -n 10 node t9_coverage.mjsand, after the live deploy,nice -n 10 node t9_coverage.mjs.Not done here
Refs #78
🤖 Generated with Claude Code
https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP
landed in #80 as
abc536cc42Review fixes pushed in
116ed430(no merge, no image build):Originequal to ours, orSec-Fetch-Site: same-originwhen the browser sends no Origin. A missing Origin alone gets 403.wanderer_keyAPI-token requests (hooks.server.ts authenticatesAuthorization: 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.activeflag (unfinished Jobs) drives polling and disables Build/Probe/Rollback. A run.json stuck atrunningwith 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.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.validRegionTitle) is shared by the proxy and the page, matching the service's1 <= 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 droppedmaxlength, which counts UTF-16 units.Results: vitest has 103 files / 1384 tests passing (13 skipped).
npm run checkhas 0 errors and the same 2 warnings as before (the editor<tbody>).🤖 Generated with Claude Code
#79 was already merged into deploy (train #80), so the review fixes above are now in follow-up PR #81 (
c78be3de, based on deploy).Pull request closed