mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 02:14:01 +00:00
Merge remote-tracking branch 'origin/main' into feat/alpr-visual-treatment
# Conflicts: # scripts/package-boundaries.json
This commit is contained in:
commit
fdf030cbc9
56 files changed
+10029
-47
No files matched your search
+3
-2
@@ -168,8 +168,9 @@ AISSTREAM_API_KEY=
|
||||
# CCTV_WARENDORF_ENABLED=1 # set 0 to disable the Warendorf (Germany) municipal webcams
|
||||
# CCTV_NSW_ENABLED=1 # set 0 to disable the Live Traffic NSW (Australia) cameras
|
||||
# CCTV_NSW_MAX_SOURCES=250 # cap cameras loaded from Live Traffic NSW
|
||||
# CCTV_CALGARY_ENABLED=1 # set 0 to disable the Open Calgary (Alberta) cameras
|
||||
# CCTV_CALGARY_MAX_SOURCES=220 # cap cameras loaded from the Open Calgary catalog
|
||||
# CCTV_CALGARY_ROWS_URL= # override the Open Calgary catalog URL
|
||||
# CCTV_MAX_SOURCES=4000 # catalog-wide ceiling, shared round-robin across packs
|
||||
# CCTV_PREFER_AUSTIN=1 # prioritize Austin cameras in the registry
|
||||
# CCTV_FORCE_AUSTIN= # force live default sources when a source-pack JSON is configured
|
||||
# CCTV_AUTO_CALIBRATE=1 # auto-calibrate camera projection (client flag)
|
||||
# CCTV_DRAPE_MESH=1 # drape frames onto 3D geometry (client flag)
|
||||
@@ -26,12 +26,12 @@ jobs:
|
||||
GEV_REQUIRE_ALLOCATION_GATE: ${{ matrix.node == '24.14.0' && '1' || '0' }}
|
||||
steps:
|
||||
- name: Check out source
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
cache: npm
|
||||
@@ -63,12 +63,12 @@ jobs:
|
||||
GEV_REQUIRE_ALLOCATION_GATE: '0'
|
||||
steps:
|
||||
- name: Check out source
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
with:
|
||||
node-version: 24.14.0
|
||||
cache: npm
|
||||
@@ -83,7 +83,7 @@ jobs:
|
||||
run: npm run check:boundaries
|
||||
|
||||
- name: Run focused onboarding tests
|
||||
run: node --test src/setupDoctor.test.mjs src/pinokioEnvironment.test.mjs src/pinokioPreflight.test.mjs src/pinokioLauncherContract.test.mjs src/mapStartup.test.mjs src/hudSummaryResponse.test.mjs
|
||||
run: node --test src/setupDoctor.test.mjs src/pinokioEnvironment.test.mjs src/pinokioPreflight.test.mjs src/pinokioLauncherContract.test.mjs src/keySetupHardening.test.mjs src/mapStartup.test.mjs src/hudSummaryResponse.test.mjs
|
||||
|
||||
- name: Build production bundle
|
||||
run: npm run build
|
||||
+103
@@ -121,14 +121,45 @@ of current runtime behavior, see [`docs/CURRENT-STATE.md`](docs/CURRENT-STATE.md
|
||||
|
||||
- Separate submarine cable sources and rendering components, and export bundled geography lookup modules.
|
||||
|
||||
### Added
|
||||
|
||||
- DISPLAY ▸ Draw: draw on the world by hand. Pick Area, Line or Pin, click the
|
||||
vertices, double-click or press Enter to finish, label and colour it; Backspace
|
||||
undoes a vertex, Esc cancels the shape and a second Esc leaves draw mode, and
|
||||
Clear wipes the board. Drawn shapes go through the same annotation engine as
|
||||
spoken ones, so they render with the whiteboard look, persist, de-dup and clear
|
||||
together. While you are drawing, the draw tool owns the pointer and no layer
|
||||
selects what you click through (#235 — thanks @cora-fresh-labs).
|
||||
|
||||
### Fixed
|
||||
|
||||
- Draped annotation geometry — area fills and outlines, routes and arrows —
|
||||
classifies onto terrain as well as 3D tiles. On a keyless boot, where Cesium's
|
||||
own globe carries the imagery, marks previously rendered their labels and no
|
||||
geometry at all. This affected spoken annotations as much as hand-drawn ones.
|
||||
|
||||
- A finished drawn area closes its ring, so its outline no longer misses the
|
||||
edge back to the first vertex.
|
||||
|
||||
- Areas measured and anchored across the antimeridian use unwrapped longitudes:
|
||||
a shape straddling 180° reported an area thousands of times too large and
|
||||
placed its label on the opposite side of the world.
|
||||
|
||||
- Traffic now retries a failed destination after city navigation without a layer
|
||||
toggle. Camera departure cancels pending work, arrival checks the final view,
|
||||
and superseded requests cannot keep a newer view loading.
|
||||
|
||||
### Added
|
||||
|
||||
- Add Open Calgary traffic cameras as a keyless CCTV source pack (thanks
|
||||
@rileygramlich): the public City of Calgary catalog, frames pinned to the
|
||||
city's own host and upgraded to HTTPS, with the Open Government Licence –
|
||||
City of Calgary attribution. The dataset publishes no camera facing — its
|
||||
quadrant field and the quadrant suffix on each camera name are Calgary's
|
||||
address grid — so headings use the shared id-hash fallback at low confidence
|
||||
and are corrected with the calibration gizmo. `CCTV_CALGARY_MAX_SOURCES` sets
|
||||
the cap and `CCTV_CALGARY_ENABLED=0` turns the pack off.
|
||||
|
||||
- Add Ontario 511 as a keyless CCTV source pack, including Kitchener-area
|
||||
highway cameras, with server-registered still URLs and attribution.
|
||||
- CCTV Mesh adds Finland: Fintraffic road weather cameras, keyless, nationwide, 300 by default. Each camera view of a station is placed separately; ambient stills refresh on the source's 10-minute cadence (the active camera keeps the usual 10-second refresh).
|
||||
@@ -218,6 +249,28 @@ of current runtime behavior, see [`docs/CURRENT-STATE.md`](docs/CURRENT-STATE.md
|
||||
|
||||
### Security
|
||||
|
||||
- The CCTV media route no longer forwards a client `Range` header to the upstream
|
||||
camera host as it arrived. A single `bytes=` range is canonicalized and
|
||||
forwarded, with every accepted form — explicit span, open-ended and suffix —
|
||||
bounded to 64 MiB, the ceiling the relay already applies to a response that
|
||||
declares its length. A response that declares no length has no ceiling — live
|
||||
streamed media, and anything an upstream sends chunked while ignoring the
|
||||
`Range` — which is unchanged. Multi-range, malformed, inverted, non-`bytes` and
|
||||
unsafe-integer values are dropped and the request proceeds without a `Range`,
|
||||
as RFC 7233 §3.1 prescribes; a multi-range value previously invited a
|
||||
`multipart/byteranges` answer, whose parts nothing here reads. A value carrying
|
||||
CR or LF made the outbound request throw, and the route recorded the thrown
|
||||
message — which contains the caller's own string — as that camera's entry in
|
||||
the health report. A request the browser has stopped waiting for is now
|
||||
released: whether the viewer leaves while the camera is still answering or
|
||||
part-way through the picture, the upstream request is cancelled rather than
|
||||
left running, and neither case marks the camera degraded. Ordinary seeking is
|
||||
unaffected. Contributed by Maher-Reven (#253).
|
||||
- CI pins `actions/checkout` and `actions/setup-node` to the commits their
|
||||
`v4.4.0` tags name, so a repointed tag cannot change what runs in CI. The
|
||||
version stays in a trailing comment, and moving to a later release is a
|
||||
deliberate edit. Contributed by SurefireStudios (#309).
|
||||
|
||||
- Validate configured Google Places coordinates and text queries before rate
|
||||
limiting or upstream requests; preserve the keyless capability response.
|
||||
- Bound CCTV media response headers to 15 seconds and cancel error bodies.
|
||||
@@ -229,6 +282,44 @@ of current runtime behavior, see [`docs/CURRENT-STATE.md`](docs/CURRENT-STATE.md
|
||||
|
||||
### Fixed
|
||||
|
||||
- `DATA_SOURCES.md` states what the project does with camera frame content: a
|
||||
successful upstream response is relayed as the provider served it, nothing in
|
||||
the camera pipeline enhances it or recognises what is in it, resampling for
|
||||
display is the only change made to the picture, and no frame is written to disk.
|
||||
It also names what a viewer sees when an upstream has no frame — including a
|
||||
last good picture kept after a failed refresh — and the one feature that sends
|
||||
imagery anywhere: the voice assistant's viewport screenshot. Contributed by
|
||||
Lob26 (#357).
|
||||
- Pinokio's Update shows what it is about to install before it installs it: the
|
||||
tracking branch, the remote it fetched from, the incoming commits and their
|
||||
diffstat. The remote is printed as host and path — a password or token in the
|
||||
URL's user field is replaced and any query string dropped, though a secret
|
||||
spelled as an ordinary path segment cannot be told from a repository name. It
|
||||
fetches once and applies exactly the revision it named, so a commit that lands
|
||||
mid-update cannot be installed unannounced. A git read it cannot complete is
|
||||
reported as such instead of as "already up to date", and if the revision to
|
||||
apply cannot be resolved at all the update stops without installing anything
|
||||
and exits unsuccessfully. Contributed by Lob26 (#356).
|
||||
- On Windows, the credential-file hardening step verifies the file's permissions
|
||||
through the system PowerShell. A side-by-side PowerShell 7 install prepends its
|
||||
own module directories, which the 5.1 verifier cannot load, so the check failed
|
||||
and the credential was refused. The verify script now sets its module path from
|
||||
the running interpreter's own home, and the environment it is launched with
|
||||
carries that one value and no differently cased alias of it. The tests that
|
||||
cover it drive a stubbed process launcher, so what they check is the command
|
||||
and environment the code builds; the Windows onboarding CI job now also runs
|
||||
this file, where its one Windows-only case exercises the real hardener against
|
||||
real native tools. Contributed by michaelhan1208 (#161).
|
||||
- The panel-recovery instructions in `docs/KNOWN-ISSUES.md`, `docs/CURRENT-STATE.md`
|
||||
and `scripts/dev-fresh.sh` describe what the interface does. The rails lay panels
|
||||
out themselves and write no stored position, so a CCTV panel that looks missing
|
||||
is collapsed or its layer is off; the collapsed-state key is what opens it, and
|
||||
the value to store is `'0'`, since removing the key returns the panel to its
|
||||
default, which is collapsed. A view opened from a share link is laid out from
|
||||
the link and ignores the stored value, so the console workaround is for ordinary
|
||||
loads only. A check keeps the documented keys and outcomes in step with the
|
||||
code. Contributed by vegettto (#408).
|
||||
|
||||
- Extract panel disclosure and hover/focus controls into a reusable module;
|
||||
cancel their listeners and pending work during replacement and teardown.
|
||||
|
||||
@@ -271,6 +362,15 @@ of current runtime behavior, see [`docs/CURRENT-STATE.md`](docs/CURRENT-STATE.md
|
||||
|
||||
|
||||
### Changed
|
||||
|
||||
- The interface asks Google Fonts for only the icon glyphs it draws, instead of
|
||||
the whole variable icon font, and no longer requests a second icon family that
|
||||
nothing renders. A check fails when a source names a glyph the request is
|
||||
missing, because an absent glyph does not draw a placeholder — the element
|
||||
renders the glyph's name as text. The check reads the panel templates as well
|
||||
as the scripts, and reads glyph names written as literals, so a glyph chosen
|
||||
through a variable has to be added to the request by hand. Contributed by
|
||||
mml-studio (#239).
|
||||
- Separate explicit browser build settings from standalone environment loading
|
||||
and local provider middleware. Preserve provider behavior and root named exports.
|
||||
- Rename standalone browser startup to `src/standalone/` and add a Node-only
|
||||
@@ -298,6 +398,9 @@ of current runtime behavior, see [`docs/CURRENT-STATE.md`](docs/CURRENT-STATE.md
|
||||
whoever adds the next destination; it passes on the current entries and makes
|
||||
no claim about how well any destination is framed. Contributed by daikaginza
|
||||
(#168).
|
||||
- Drop `CCTV_AUTO_CALIBRATE` and `CCTV_DRAPE_MESH` from `.env.example`. Nothing
|
||||
reads either name; the features they once switched no longer exist, so setting
|
||||
them did nothing. Contributed by dajiaohuang (#283).
|
||||
|
||||
- Extract application lifecycle and viewer exports. Split standalone startup into
|
||||
scene setup, controls, layer registration, tools and loading UI. Startup failure
|
||||
|
||||
@@ -44,6 +44,7 @@ How to read this:
|
||||
| **Ontario 511** | CCTV camera catalog + frames, Ontario highways including Kitchener-area routes | [Open Government Licence – Ontario](https://www.ontario.ca/page/open-government-licence-ontario) | "Ontario 511" plus Open Government Licence - Ontario |
|
||||
| **Fintraffic / Digitraffic (weathercams)** | CCTV camera catalog + frames, Finland | [CC BY 4.0](https://www.digitraffic.fi/en/terms-of-service/) — attribution REQUIRED | "Fintraffic / digitraffic.fi, license CC BY 4.0" |
|
||||
| **DriveBC** (Government of British Columbia) | CCTV camera catalog + frames, British Columbia highways | [Open Government Licence – British Columbia](https://www2.gov.bc.ca/gov/content/data/open-data/open-government-licence-bc) — attribution REQUIRED | "DriveBC. Contains information licensed under the Open Government Licence – British Columbia" |
|
||||
| **Open Calgary** (`data.calgary.ca`) | CCTV camera catalog + frames, Calgary | [Open Government Licence – City of Calgary](https://data.calgary.ca/stories/s/Open-Calgary-Terms-of-Use/u45n-7awa) — attribution REQUIRED | "Contains information licensed under the Open Government Licence – City of Calgary" |
|
||||
| **GBFS (Lyft / BCycle)** | Bikeshare availability | Per-feed (attribution-only) | Credit the operator (e.g. Austin BCycle) + its `license_url` |
|
||||
| **Radio Browser** | Geolocated internet-radio station directory and station-level tags | Public-domain directory data under PDDL 1.0; individual broadcaster stream terms apply | "Radio Browser" plus a link to the selected broadcaster |
|
||||
| **Re:Earth Terrain** (Mapterhorn) | Terrain (keyless globe stacks — OSM etc. — + `/api/terrain/heights` ellipsoidal-height lookups) | Terrain mesh: CC BY 4.0; geoid: EGM2008 (NGA, public domain) | "Terrain (keyless globe stacks): Re:Earth Terrain / Mapterhorn (CC BY 4.0) / EGM2008 (NGA)" |
|
||||
@@ -63,6 +64,8 @@ How to read this:
|
||||
- **Tarktee / Transpordiamet.** Estonia road-weather camera locations and current JPEG URLs come from keyless DATEX2 endpoints on `tarktee.transpordiamet.ee` (`/api/v1/datex/roadCameraLocations` + `roadCameraImages`). Frame URLs rotate with each capture; the 15-minute CCTV source cache refreshes them. Only `https://tarktee.transpordiamet.ee/images/…` URLs are registered. Disable with `CCTV_TARKTEE_ENABLED=0`.
|
||||
- **Warendorf webcam.** The Stadt Warendorf Marktplatz webcam, registered from the curated `config/cctv_sources.warendorf.json` (the Kreis Warendorf registration-office cameras from the contributing PR are indoor waiting rooms and were left out); only the municipal image host is proxied, frames are fetched at request time and never stored or redistributed. Disable with `CCTV_WARENDORF_ENABLED=0`.
|
||||
- **Live Traffic NSW cameras.** The camera list is the keyless public `data.livetraffic.com/cameras/traffic-cam.json` feed (Transport for NSW open data, CC BY 4.0); frames are stills on `webcams.transport.nsw.gov.au`, and only that host is registered. That image host answers non-browser clients with an HTML placeholder, so the proxy identifies as a browser for that one host and as itself everywhere else. Frames are fetched at request time and never stored or redistributed. Disable with `CCTV_NSW_ENABLED=0`.
|
||||
- **Open Calgary traffic cameras.** Keyless. The camera list is the public Socrata dataset `k7p9-kppz` on `data.calgary.ca`; frames are stills on the city's own `trafficcam.calgary.ca` host, and only that host is registered. Most rows publish an `http://` frame URL and the host redirects those to HTTPS, so URLs are upgraded and pinned to that origin before registration. Frames are fetched at request time and never stored or redistributed. The dataset publishes no camera facing: the `quadrant` field and the quadrant suffix on each camera name are Calgary's address grid, not a bearing, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. The licence requires the attribution statement above. Disable with `CCTV_CALGARY_ENABLED=0`.
|
||||
- **Camera frame content.** Public camera frames can contain people, vehicles and license plates, and the camera layer does nothing with them beyond putting them on the map. A successful upstream response is relayed as the provider served it: nothing in the camera pipeline blurs, redacts, enhances or restores it, and nothing there runs face, plate or object detection or otherwise recognises or classifies what is in the picture. (The ALPR layer described below maps where plate-reader cameras are, from locations contributors tagged in OpenStreetMap; it reads nothing from any camera frame.) When an upstream has no frame for a camera, what you see instead is a Google Street View still or the app's own placeholder card; the panel's source badge names which of them you are looking at, and a refresh that fails after a frame has arrived leaves the last good picture on screen rather than replacing it. The browser resamples each frame for display: onto a fixed 1920x1080 surface for the camera's projection plane in the scene, and onto a 192x108 canvas for the small ambient card. That scaling is the only change made to the picture, and the only pixels the camera layer reads back are a 64x36 downscale hashed to tell whether the picture has changed. Live streams are piped through; the still path reads the image into memory to pass it on — TxDOT wraps its JPEG in a JSON envelope, which is decoded there — and no frame is written to disk (the disk cache, `.gev-cache/`, holds feed JSON for other layers and never camera imagery). Outside that pipeline, the voice assistant is the one feature that sends imagery anywhere: when it answers a question about what is in view it may attach a downscaled screenshot of the rendered scene — including any camera plane on screen — to the request it sends to the voice model. Frames are fetched only from server-registered camera URLs — a client cannot hand the proxy a URL (see [SECURITY.md](SECURITY.md)). What the app does stays inside the line README draws: no named-person search, no face recognition, no tracking individuals.
|
||||
- **Radio Browser.** `/api/radio/stations` discovers official API mirrors, makes bounded and coalesced healthy/geolocated HTTPS-station queries, caches the normalized public-domain directory for 45 minutes, and may serve the last good catalog for up to seven days during an outage. Refreshes must meet minimum accepted-query and station coverage before replacing a warm catalog; schema-valid responses whose rows all fail the product's health policy do not count as successful queries. A usable partial cold catalog is explicitly `DEGRADED`, and malformed or empty successful payloads are rejected atomically. Every directory and click-count request rejects redirects, validates all resolved addresses as globally routable (including reserved/documentation IPv4 and special/non-global IPv6 exclusions), and pins the TLS connection to a validated address. Only MP3/AAC non-HLS directory rows with public HTTPS stream targets are returned; favicons are intentionally omitted. Pressing play connects one browser audio element directly to the selected broadcaster and calls the directory's click counter through known-ID-only `POST /api/radio/click/:uuid`. GEV never proxies, caches, records, bundles, or redistributes audio. Radio Browser supplies station-level tags, not dependable current-song or upcoming-program metadata, so Radio filtering never claims either. Direct playback exposes the listener's IP address to the broadcaster, whose own stream terms apply.
|
||||
- **TomTom Traffic.** Optional and BYOK: without `TOMTOM_API_KEY` the traffic layer runs its built-in simulation and no TomTom data (or attribution) appears. With a key, flow vector tiles are fetched through the server-side `/api/tomtom` proxy (120 s cache + a daily tile-budget governor — `TOMTOM_DAILY_TILE_BUDGET`, default 40,000, a configurable application safety ceiling, not a guarantee of staying within TomTom's monthly free allowance; TomTom's [current pricing](https://docs.tomtom.com/pricing/) lists 200K free tile requests per month) and the "Traffic flow data © TomTom" credit is registered in the Data attribution popover the moment live mode activates. TomTom data is served live and cached only transiently (≤120 s TTL under `.gev-cache/`, gitignored) — it is not bundled or redistributed. One 23 KB point-in-time tile snapshot is committed as a decode-test fixture (`src/data/fixtures/`, © TomTom, never served to the app).
|
||||
- **Re:Earth Terrain.** Keyless (no API key). Used two ways: (1) `src/mapStackController.js` swaps in a `Cesium.CesiumTerrainProvider` pointed at Re:Earth's `cesium-mesh/ellipsoid` quantized-mesh endpoint for globe stacks without a Cesium ion token (e.g. OSM), replacing a flat `EllipsoidTerrainProvider`; falls back to the flat provider if the endpoint can't be reached. (2) The server-side `/api/terrain/heights` proxy (disk-cached, serve-stale) resolves per-point ellipsoidal ground height for entity placement. Both are best-effort with a keyless-safe fallback (bundled EGM96 geoid math) if Re:Earth is unreachable.
|
||||
|
||||
@@ -243,6 +243,8 @@ Twenty-eight tools, four jobs — the commands below come straight from the prod
|
||||
**🖊️ Annotate it** — a whiteboard over the real world:
|
||||
> 🗣️ *"Outline the state of Texas."* · *"Annotate the Texas State Capitol and its grounds"* — it draws the **actual enclosing boundary**, not a circle. · *"How far is the Eiffel Tower from the Louvre?"* — a connector arrow appears and it speaks the distance. Everything persists until you say *"clear the map."*
|
||||
|
||||
**✍️ Or draw it yourself** — DISPLAY ▸ **Draw**: pick Area, Line or Pin, click the vertices on the real world, double-click to finish, label it. Same whiteboard, same persistence, no microphone needed.
|
||||
|
||||

|
||||
|
||||

|
||||
@@ -275,7 +277,7 @@ Thirteen layers and map sources. **Eleven have a keyless path.** Some offer addi
|
||||
| 🛰️ **Satellites** | 838-object catalog, color-coded by class with a live legend — the **DENSE** chip drops in the whole Starlink shell | CelesTrak | 🟢 |
|
||||
| 🌍 **Earthquakes** | Global seismic activity, last 24h | USGS | 🟢 |
|
||||
| 🚗 **Traffic** | Simulated vehicles on OSM roads. With TomTom, live flow speeds drive the simulation and congestion colors below ~8 km; individual vehicle positions are not live observations | TomTom + OSM | 🟢 simulation · 🟡 live flow speeds |
|
||||
| 📹 **CCTV Mesh** | ~3,400 public cameras projected *into* the 3D space — Austin · Texas (TxDOT) · California (Caltrans) · London (TfL) · Ontario (511) · Finland (Fintraffic) · British Columbia (DriveBC) · Estonia (Tallinn, Tarktee) · New South Wales (Live Traffic NSW). Positions are published; poses are estimated priors **you calibrate by dragging a gizmo on the camera itself** | City APIs | 🟢 |
|
||||
| 📹 **CCTV Mesh** | ~3,600 public cameras projected *into* the 3D space — Austin · Texas (TxDOT) · California (Caltrans) · London (TfL) · Ontario (511) · Finland (Fintraffic) · British Columbia (DriveBC) · Estonia (Tallinn, Tarktee) · New South Wales (Live Traffic NSW) · Calgary. Positions are published; poses are estimated priors **you calibrate by dragging a gizmo on the camera itself** | City APIs | 🟢 |
|
||||
| 📻 **Radio** | Geolocated world radio with an **analog tuner** — drag the needle across up to 750 stations and the globe flies to each broadcaster | Radio Browser / broadcasters | 🟢 |
|
||||
| 🚲 **Bikeshare** | Live station availability | GBFS | 🟢 |
|
||||
| 🔥 **Active Fires** | Live NASA FIRMS detections, trailing 24h | NASA FIRMS | 🟡 |
|
||||
|
||||
@@ -63,6 +63,7 @@ The data proxies under `server/providers/` are written so the browser cannot tur
|
||||
|
||||
- **No arbitrary-URL fetching.** The CCTV frame proxy fetches only server-registered camera/frame URLs — clients cannot pass an upstream URL to fetch (SSRF mitigation). Other proxies target fixed upstream hosts.
|
||||
- **Radio is not an audio relay.** `/api/radio/stations` contacts only allowlisted Radio Browser HTTPS hosts and paths, rejects redirects, rejects any hostname with a loopback/private/link-local/metadata/non-public A or AAAA result, and pins each TLS connection to a validated address. It returns normalized public HTTPS stream URLs; `/api/radio/click/:uuid` applies the same destination policy and accepts only station IDs from the current bounded catalog. The browser then connects directly to the broadcaster after an explicit playback action, so the broadcaster sees the listener's IP address. GEV never proxies, caches, records, or redistributes audio.
|
||||
- **No verbatim client headers upstream.** The CCTV media route is the one route that relays a request header (`Range`, for video seeking). It is parsed and canonicalized before it is forwarded: one `bytes=` range only, with every accepted form — explicit span, open-ended and suffix — bounded to the same 64 MiB ceiling the relay applies to a declared response body. Multi-range, malformed, inverted and non-`bytes` values are dropped and the request proceeds without a `Range`, as RFC 7233 §3.1 prescribes. Bounding the request bounds what is asked for: a response that declares no length — live streamed media, or a chunked body from an upstream that ignores the `Range` — has no ceiling. An upstream request the browser has stopped waiting for is cancelled rather than left running, whether the viewer leaves before the headers arrive or during the body.
|
||||
- **Response-size caps and timeouts** on proxied responses.
|
||||
- **Sanitized errors** — internal error details are not echoed back to clients.
|
||||
- **Coalesced OAuth refresh** and cached successful responses only (OpenSky).
|
||||
|
||||
+19
-2
@@ -2374,7 +2374,7 @@ its criteria cannot be silently ignored.
|
||||
| Satellites | CelesTrak | `src/data/satellites.js` | `/api/celestrak` | 120s |
|
||||
| Space Missions (30d) | Launch Library 2 + CelesTrak | `src/data/rocketLaunches.js` | `/api/launches` + `/api/celestrak/active` | 5 min |
|
||||
| Traffic | OSM Overpass (+ optional TomTom live flow) | `src/data/traffic.js` | `/api/overpass` + `/api/tomtom` | viewport-driven |
|
||||
| CCTV | Austin + Caltrans (CA) + TfL London + Ontario 511 + Fintraffic (FI) + DriveBC (BC) + TxDOT (TX) + Estonia (Tallinn, Tarktee) + Live Traffic NSW Open Data + Street View fallback | `src/data/cctv.js` | `/api/cctv` | 10s (active) |
|
||||
| CCTV | Austin + Caltrans (CA) + TfL London + Ontario 511 + Fintraffic (FI) + DriveBC (BC) + TxDOT (TX) + Estonia (Tallinn, Tarktee) + Live Traffic NSW + Open Calgary Open Data + Street View fallback | `src/data/cctv.js` | `/api/cctv` | 10s (active) |
|
||||
| Radio | Radio Browser (public-domain station directory) | `src/data/radio.js` | `/api/radio/stations`, `/api/radio/click/:uuid` | 45 min directory refresh |
|
||||
| Bikeshare 🚲 | GBFS (Lyft + BCycle) | `src/data/bikeshare.js` | `/api/gbfs` | 60s |
|
||||
| Datacenters ▣ | OSM extract (bundled) | `src/data/localLayers.js` | — | static |
|
||||
@@ -3009,6 +3009,23 @@ are omitted rather than framing the wrong part of the globe.
|
||||
- Console/dev API: `window.__gevAnnotations.tour()`, `.demo()`, `.annotate()`, `.clear()`, `.count()`, and `.list()` are the deterministic no-mic test surface.
|
||||
- Current known resolver gap: mall/lifestyle districts such as "The Domain, Austin" can prefer a named building over the broader retail envelope. Product decision is that districts should become envelope + key buildings, but the scoring change still needs a careful multi-case validation pass.
|
||||
|
||||
### Manual Whiteboard Drawing (September 2026)
|
||||
|
||||
- DISPLAY ▸ **Draw** turns the globe into a whiteboard drawn by hand. Pick a shape (Area, Line, Pin), click the vertices on the real world, type an optional label and pick a colour, and finish. **Keyboard contract, live only while Draw is on and never while you are typing in another field:** Enter finishes the shape (as does a double-click, and the two cannot both submit it — the session is replaced before the annotate call is awaited); Backspace removes the last vertex; Esc cancels the shape in progress, and a second Esc — Esc on an empty session — leaves draw mode. Typing in the label field keeps Backspace; Enter there also finishes. **Clear** wipes the board (the shape in progress and every placed mark), so removing marks does not require the console or the microphone.
|
||||
- Runtime entry: `createApplicationTools` (`src/app/tools.js`, behind the `src/standalone/tools.js` shim) calls `initDrawTool({ viewer, annotations })` after `initAnnotations` and defers its `destroy()`, so disposing the shell returns every DOM listener, the Cesium handler, the preview data source, the borrowed click actions and the `window.__gevDrawTool` handle. Its markup is a DISPLAY-rail component template (`src/ui/templates/display-controls.html`), assembled into `index.html` at build time. That handle (`setActive`, `setShape`, `addVertex(lon, lat)`, `finish`, `cancel`, `clearAll`, `diagnostics`) is the no-mouse test seam.
|
||||
- Contract: a finished shape is submitted through the SAME `annotationEngine.annotate()` the voice agent uses, with geometry supplied and `manual: true` (`type: area` + `ring`, `type: route` + `path`, `type: pin` + coordinates). `resolveSpec` short-circuits manual specs (`resolveManualSpec`) so no geocoder, Places or Overpass call is made. A drawn area is a real (not synthesized) outline and drapes solid; a drawn line is a `route` with `mode: 'manual'`, labelled with its length and never a travel time; a pin is a point. Drawn marks therefore render with the whiteboard look, persist, de-dup, appear in `.list()`, and clear with `clear_annotations` / `.clear()`.
|
||||
- **A vertex is a lon/lat, and the mark is DRAPED.** Clicks are picked through `pickWorldFromScreen` — one of two scene helpers the annotation resolver factory (`src/annotations/resolver.js`) exposes alongside `sampleGroundHeight`, so the app has ONE depth-aware pick cascade rather than a second written beside it — which returns the height the pick landed on as well as the coordinate, so the live preview hangs on the roof or hillside under the pointer instead of sinking to sea level. The world renderer draws areas and routes with `clampToGround`, so the height is dropped at finish in one place (`finishSpec`) rather than being carried downstream and discarded silently: what you get is the outline you drew, lying on the surface beneath it.
|
||||
- **Draped marks classify onto `ClassificationType.BOTH`** — terrain AND 3D tiles — not onto 3D tiles alone. With only `CESIUM_3D_TILE`, every area fill, area outline, route and arrow rendered to nothing on a keyless boot, where Cesium's own globe carries Esri/OSM imagery and there are no tiles to classify against; the labels appeared and the geometry did not. That hit spoken annotations exactly as hard as hand-drawn ones. `scripts/qa-draw-tool.mjs` counts the mark's own colour in the rendered frame before and after a shape is finished, on a keyed AND a keyless server, so "the board says there is a mark" can no longer pass for "the mark is on screen".
|
||||
- **A finished area is a CLOSED ring.** The fill polygon closes itself but the outline beside it is a polyline, so an open ring drew every edge except the one back to the first vertex — a triangle with two sides. `finishSpec` repeats the first position at the end. A line is never closed: joining its ends would invent a segment nobody drew.
|
||||
- **Measurements and centres are computed on unwrapped longitudes** (`unwrapLongitudes` / `wrapLongitude` in `drawMode.js`, used by `ringAreaM2`, `ringCentroid` and the engine's manual-area anchor). A ~50,000 m² rectangle straddling the antimeridian reads its 0.002° width as 359.998° under raw arithmetic: it measured thousands of square kilometres and anchored on the Greenwich meridian, half a world from the shape. Path length was already safe — haversine is periodic in the longitude delta — and a test pins that so a "fix" cannot break it.
|
||||
- **Bounds.** One shape holds at most `MAX_VERTICES` = 512 points; two clicks within 0.5 m are one vertex (that is what makes a double-click finish without leaving a stray point); a vertex that is not a finite on-globe coordinate is refused. A shape that encloses nothing is refused rather than placed: three collinear points are not an area and a line under a metre long is not a line, and the hint says which.
|
||||
- Pointer ownership: while a session is open the tool holds the single pointer claim (`claimPointer('draw')`, `src/data/inputOwnership.js`) and **every** ambient scene selection handler — the shared tracking click gesture behind flights, military and CCTV, plus vessels, satellites, launches, fires, installations, bikeshare, radio, submarine cables, the bundled GeoJSON layers and the CCTV calibration gizmo — returns before picking. A vertex over an aircraft is a vertex, not a selection.
|
||||
- **The claim is a LEASE.** `claimPointer(owner)` returns an opaque token or `null`; `releasePointer(lease)` takes that token. A second claim fails even under the same owner name, because two live instances of one tool — an old one mid-teardown and its replacement — are two owners; releasing by name let the old instance free the claim its successor was holding, and every layer started selecting through the live session's vertices. A superseded lease now releases nothing.
|
||||
- **Cesium's own click actions are borrowed too.** The Viewer binds a selecting LEFT_CLICK and a tracking LEFT_DOUBLE_CLICK on its own handler, outside every layer and therefore outside the shared claim — guarding the layers alone still left a drawn vertex selecting the entity under it. Both are removed for the session and restored, as the same function objects, when it ends or the tool is destroyed.
|
||||
- **Enter belongs to whatever has the keyboard.** The finish key is taken only from the canvas, the page body and the tool's own label field. With a control focused — Clear, a shape button — Enter activates that control, as a keyboard user expects; it does not quietly finish the shape.
|
||||
- Pure half: `src/annotations/drawMode.js` (session, minimum vertices, double-click de-dup at 0.5 m, vertex ceiling, degenerate-geometry refusal, ring closing, dateline-safe length/area/centroid, hint text). Regression surface: `src/annotations/drawMode.test.mjs` and `src/data/inputOwnership.test.mjs` (pure), `src/annotations/drawToolBehaviour.test.mjs` (the tool driven against DOM and viewer doubles — leases, borrowed input actions, teardown, the Enter key, preview heights), `src/annotations/drawTool.test.mjs` (structural: where files live, which ids the markup carries, what the docs may claim), and the rendered harness `scripts/qa-draw-tool.mjs`.
|
||||
- The annotation tree is a declared ownership group: `./annotations` → `src/annotations/index.js` in `package.json`, with its module graph listed in `scripts/package-boundaries.json`, so an annotation module reaching outside that graph is a gate failure rather than a surprise in a layer's bundle. `drawMode.js`, `drawTool.js` and their tests are in `scripts/format-scope.json`.
|
||||
|
||||
### 3D Aircraft + Tracking (June 2026)
|
||||
|
||||
- **The TRACKED contact's 2D↔3D handoff is DEFAULT behaviour (2026-08-19), driven by camera distance alone.** It does NOT consult the DISPLAY-rail `3D` toggle, which continues to own the FLEET (the un-instanced draw-call budget stays the operator's decision). Policy lives in `src/data/trackedModelRegime.js` and is shared by both layers: enter below `TRACKED_MODEL_ENTER_ALT_M` = 150,000 m and hand back to the billboard only above `TRACKED_MODEL_EXIT_ALT_M` = 172,500 m. **The swap distance was set by playtesting on 2026-08-20:** a first pass at 1,000,000 m switched too early; 2D reads correctly at ~600 km and the handoff belongs at ~150 km. **Consequence, recorded on purpose:** the tracked contact now enters 3D NEARER than the FLEET does (`MODEL_ALT_CEIL_M` = 800,000 m, unchanged), so with the DISPLAY-rail `3D` toggle on, 150–800 km draws surrounding contacts as models while the selected one is still a glyph. Nothing double-draws (the fleet pass skips the tracked icao) and aligning the two is a fleet-side decision, deliberately out of scope. **The two thresholds are asymmetric on purpose:** a single threshold makes a tracked orbit sitting ON the boundary strobe billboard↔model as the camera's altitude wobbles across it. Do not collapse them. The latch is scoped per selection, so a new target re-evaluates against the ENTER ceiling rather than inheriting the previous target's exit band. Exactly ONE model is involved; it loads on demand when the regime opens, is HIDDEN (not released) on regime exit so re-entry has no load gap, and is released by the existing teardown on deselect/re-track/destroy. Cockpit and TR-3B suppression are unchanged. **Two invariants around it:** (a) the hysteresis latch AND the load-failure latch are per-selection state cleared by `_resetTrackedSelectionState()` in the tracking lifecycle (deselect / re-track / cross-layer / init / destroy) — the predicate's icao-change guard is defence only, since it needs a drawn frame while nothing is selected and the render governor's idle mode does not promise one; (b) on-demand loading is bounded at 3 attempts per selection with a 1.5 s backoff and one console warning naming the asset — the driver runs every `scene.preUpdate`, so an unbounded catch means a missing GLB spins load→reject at frame rate. The billboard stays the visual throughout a failed load.
|
||||
@@ -3312,7 +3329,7 @@ easier to meet (detection is now on more often), but does not create it.
|
||||
samples and constant elevation during E/N drag; one shared-floor resolution on
|
||||
release; late one-shot shared-cell work is permitted during viewshed idle. The
|
||||
A+B harness intentionally excludes citywide LOD assertions.
|
||||
- Draggable panel positions persist at `godsEyeView.v7.panelPos.<panel-id>` (collapsed states at `godsEyeView.v6.panelCollapsed.<panel-id>`).
|
||||
- Panel positions have a versioned storage name, `godsEyeView.v8.panelPos.<panel-id>`, but the current rails lay panels out adaptively and write none. Collapsed state does persist for every panel at `godsEyeView.v6.panelCollapsed.<panel-id>` (`'0'` open, `'1'` closed, absent means the panel's own default).
|
||||
- Legacy draggable-panel position keys may remain in local storage for backward compatibility, but the map-mode right rail ignores them; collapsed states still persist at `godsEyeView.v6.panelCollapsed.<panel-id>`.
|
||||
- Flight/military tracked entities cache dead-reckoned positions per frame to avoid callback desync flicker.
|
||||
- Aircraft 3D-model and tracking invariants are covered by `npm run test:track`; run this before touching `flights.js`, `militaryFlights.js`, `detection.js`, or `trackedReadout.js`.
|
||||
|
||||
+21
-6
@@ -30,21 +30,36 @@ Next iteration candidates:
|
||||
|
||||
---
|
||||
|
||||
### CCTV panel can appear "missing" after layout refactors
|
||||
### CCTV panel can appear "missing"
|
||||
Status: Open (workaround available)
|
||||
|
||||
Context:
|
||||
- Panel positions are persisted in local storage and can restore off-screen after UI changes.
|
||||
- The rails lay their panels out themselves. No panel is dragged into place at
|
||||
startup and no stored position is read, so a panel that looks missing is
|
||||
collapsed or its layer is off rather than parked off-screen. The CCTV panel
|
||||
starts collapsed and stays that way until you open it or a camera activates.
|
||||
|
||||
Workaround:
|
||||
- In browser console:
|
||||
- `localStorage.removeItem('godsEyeView.v6.panelPos.cctv-panel');`
|
||||
- Check that the CCTV layer is enabled in the Layers panel, then open the panel
|
||||
from its header control; it also opens on its own when a camera activates.
|
||||
- To force it open on an ordinary load, store the expanded state and reload. In
|
||||
the browser console:
|
||||
- `localStorage.setItem('godsEyeView.v6.panelCollapsed.cctv-panel', '0');`
|
||||
- `location.reload();`
|
||||
- Removing that key instead returns the panel to its default, which is collapsed:
|
||||
- `localStorage.removeItem('godsEyeView.v6.panelCollapsed.cctv-panel');`
|
||||
- `location.reload();`
|
||||
- Neither console line changes anything when the page was opened from a share
|
||||
link: a shared view is laid out from the link, not from what this browser has
|
||||
stored, so open the panel from its header control instead.
|
||||
|
||||
Related keys (current versions):
|
||||
- Panel positions: `godsEyeView.v7.panelPos.<panel-id>` (re-versioned 2026-06-10)
|
||||
- Panel collapsed state: `godsEyeView.v6.panelCollapsed.<panel-id>`
|
||||
- Panel collapsed state: `godsEyeView.v6.panelCollapsed.<panel-id>` — `'0'` open,
|
||||
`'1'` closed, absent means the panel's own default. A view opened from a share
|
||||
link ignores the stored value entirely.
|
||||
- Panel positions: `godsEyeView.v8.panelPos.<panel-id>` — the versioned name for a
|
||||
stored position. The current layout writes none, so deleting one changes
|
||||
nothing.
|
||||
- CCTV calibration: `godsEyeView.cctv.calibration.v2`
|
||||
|
||||
---
|
||||
|
||||
+5
-2
@@ -9,8 +9,11 @@
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700&family=Inter:wght@300;400;500;600&display=swap" rel="stylesheet" />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20,400,0,0" rel="stylesheet" />
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons+Round" rel="stylesheet" />
|
||||
<!-- Icon font subset to the glyphs this app renders. Keep `icon_names` in sync
|
||||
with the sources: src/materialSymbolsSubset.test.mjs fails when a source
|
||||
names a glyph this list is missing, because a missing glyph does not draw
|
||||
a box — the ligature never forms and the element renders the literal word. -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20,400,0,0&icon_names=adjust,arrow_drop_down,arrow_forward,arrow_left,arrow_right,bolt,chevron_left,chevron_right,close,close_fullscreen,dark_mode,draw,east,flare,flight,layers_clear,light_mode,local_fire_department,my_location,navigation,normal,on,open_in_full,public,radar,radio,right_panel_close,right_panel_open,rocket_launch,skip_next,skip_previous,view_in_ar" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<!-- gev:template scene-chrome -->
|
||||
|
||||
@@ -16,7 +16,8 @@ HOST="${HOST:-localhost}"
|
||||
# including Kitchener-area highways), and Fintraffic Finland weathercams
|
||||
# (~2,260 live presets). Caps keep the densest cores per pack; override
|
||||
# per-run for lighter/heavier loads. Kill switches: CCTV_CALTRANS_DISTRICTS='',
|
||||
# CCTV_TFL_ENABLED=0, CCTV_ONTARIO_ENABLED=0 and CCTV_FINTRAFFIC_ENABLED=0.
|
||||
# CCTV_TFL_ENABLED=0, CCTV_ONTARIO_ENABLED=0, CCTV_FINTRAFFIC_ENABLED=0 and
|
||||
# CCTV_CALGARY_ENABLED=0 (Open Calgary, ~215 live upstream).
|
||||
CCTV_AUSTIN_MAX_SOURCES="${CCTV_AUSTIN_MAX_SOURCES:-250}"
|
||||
# Use `-` not `:-` so an explicit empty string (the documented kill switch)
|
||||
# is preserved rather than replaced by the default. Still set-u-safe when unset.
|
||||
@@ -41,6 +42,8 @@ CCTV_TARKTEE_MAX_SOURCES="${CCTV_TARKTEE_MAX_SOURCES:-179}"
|
||||
CCTV_WARENDORF_ENABLED="${CCTV_WARENDORF_ENABLED:-1}"
|
||||
CCTV_NSW_ENABLED="${CCTV_NSW_ENABLED:-1}"
|
||||
CCTV_NSW_MAX_SOURCES="${CCTV_NSW_MAX_SOURCES:-250}"
|
||||
CCTV_CALGARY_ENABLED="${CCTV_CALGARY_ENABLED:-1}"
|
||||
CCTV_CALGARY_MAX_SOURCES="${CCTV_CALGARY_MAX_SOURCES:-220}"
|
||||
CCTV_MAX_SOURCES="${CCTV_MAX_SOURCES:-4000}"
|
||||
|
||||
# Capture which provider credentials genuinely came from the parent shell
|
||||
@@ -306,8 +309,8 @@ case "${HOST}" in
|
||||
esac
|
||||
echo "Google Maps key source: ${GOOGLE_MAPS_API_KEY_SOURCE}"
|
||||
echo "Tip: after server starts, hard refresh browser (Cmd+Shift+R)."
|
||||
echo "If panels are still missing, run this once in browser console:"
|
||||
echo "localStorage.removeItem('godsEyeView.v6.panelPos.cctv-panel'); location.reload();"
|
||||
echo "The CCTV panel starts collapsed; open it from its header, or in browser console:"
|
||||
echo "localStorage.setItem('godsEyeView.v6.panelCollapsed.cctv-panel', '0'); location.reload();"
|
||||
echo "OpenSky auth mode: ${OPENSKY_AUTH_MODE}"
|
||||
if [[ -n "${OPENSKY_CREDENTIALS_FILE}" ]]; then
|
||||
if [[ -f "${OPENSKY_CREDENTIALS_FILE}" ]]; then
|
||||
@@ -402,6 +405,8 @@ put_env CCTV_TARKTEE_MAX_SOURCES "${CCTV_TARKTEE_MAX_SOURCES}"
|
||||
put_env CCTV_WARENDORF_ENABLED "${CCTV_WARENDORF_ENABLED}"
|
||||
put_env CCTV_NSW_ENABLED "${CCTV_NSW_ENABLED}"
|
||||
put_env CCTV_NSW_MAX_SOURCES "${CCTV_NSW_MAX_SOURCES}"
|
||||
put_env CCTV_CALGARY_ENABLED "${CCTV_CALGARY_ENABLED}"
|
||||
put_env CCTV_CALGARY_MAX_SOURCES "${CCTV_CALGARY_MAX_SOURCES}"
|
||||
put_env CCTV_MAX_SOURCES "${CCTV_MAX_SOURCES}"
|
||||
put_env OPENSKY_AUTH_MODE "${OPENSKY_AUTH_MODE}"
|
||||
put_env_if_set OPENSKY_CREDENTIALS_FILE "${OPENSKY_CREDENTIALS_FILE}"
|
||||
|
||||
@@ -10,11 +10,18 @@
|
||||
"src/tooling/fixtureRoot.mjs",
|
||||
"src/tooling/fixtureRoot.test.mjs",
|
||||
"src/tooling/format.test.mjs",
|
||||
"src/tooling/panelStorageDocs.test.mjs",
|
||||
"src/tooling/packageBoundaries.test.mjs",
|
||||
"src/data/infrastructure.js",
|
||||
"src/data/infrastructure.test.mjs",
|
||||
"src/data/localGeojsonCore.js",
|
||||
"src/data/localGeojsonLod.js",
|
||||
"src/data/inputOwnership.js",
|
||||
"src/annotations/drawMode.js",
|
||||
"src/annotations/drawMode.test.mjs",
|
||||
"src/annotations/drawTool.js",
|
||||
"src/annotations/drawTool.test.mjs",
|
||||
"src/data/inputOwnership.test.mjs",
|
||||
"docs/CODE-BOUNDARIES.md",
|
||||
"src/main.js",
|
||||
"docs/APPLICATION.md",
|
||||
@@ -155,6 +162,7 @@
|
||||
"src/styles/noir.js",
|
||||
"src/styles/snow.js",
|
||||
"scripts/qa-visual-effects.mjs",
|
||||
"scripts/qa-draw-tool.mjs",
|
||||
"src/ui/mapSource.js",
|
||||
"src/ui/mapSourceControls.js",
|
||||
"src/ui/mapSourceControls.test.mjs",
|
||||
@@ -467,6 +475,7 @@
|
||||
"src/data/cctvFootprint.test.mjs",
|
||||
"src/data/cctvEstonia.test.mjs",
|
||||
"src/data/cctvWarendorf.test.mjs",
|
||||
"src/data/cctvCalgary.test.mjs",
|
||||
"src/data/cctvNswSource.test.mjs",
|
||||
"src/data/cctvTxdotSource.test.mjs",
|
||||
"src/layers/cctv/source.test.mjs",
|
||||
@@ -615,5 +624,10 @@
|
||||
"src/layers/vessels/snapshotRenderer.js",
|
||||
"src/layers/vessels/records.test.mjs",
|
||||
"src/layers/vessels/ingestion.test.mjs",
|
||||
"src/cityPresets.test.mjs"
|
||||
"src/cityPresets.test.mjs",
|
||||
"server/providers/cctv/range.js",
|
||||
"src/data/cctvMediaRange.test.mjs",
|
||||
"src/materialSymbolsSubset.test.mjs",
|
||||
"scripts/pinokio-update.mjs",
|
||||
"src/pinokioUpdatePreview.test.mjs"
|
||||
]
|
||||
@@ -8,7 +8,8 @@
|
||||
"modules": [
|
||||
"src/data/infrastructure.js",
|
||||
"src/data/localGeojsonCore.js",
|
||||
"src/data/localGeojsonLod.js"
|
||||
"src/data/localGeojsonLod.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -152,7 +153,9 @@
|
||||
"server/providers/cctv/constants.js",
|
||||
"server/providers/cctv/media.js",
|
||||
"server/providers/cctv/normalize.js",
|
||||
"server/providers/cctv/range.js",
|
||||
"server/providers/cctv/sources.js",
|
||||
"server/providers/common/http.js",
|
||||
"src/data/directionText.js",
|
||||
"server/providers/common/geo.js",
|
||||
"server/providers/places/google-key.js",
|
||||
@@ -626,7 +629,8 @@
|
||||
"src/layers/flights/tracking.js",
|
||||
"src/layers/flights/records.js",
|
||||
"src/layers/flights/recordPolicy.js",
|
||||
"src/layers/flights/snapshotRenderer.js"
|
||||
"src/layers/flights/snapshotRenderer.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -660,7 +664,8 @@
|
||||
"src/layers/military/tracking.js",
|
||||
"src/layers/military/records.js",
|
||||
"src/layers/military/recordPolicy.js",
|
||||
"src/layers/military/snapshotRenderer.js"
|
||||
"src/layers/military/snapshotRenderer.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -683,7 +688,8 @@
|
||||
"src/data/trackedModelRegime.js",
|
||||
"src/data/trackingClickGesture.js",
|
||||
"src/layers/aircraft/classification.js",
|
||||
"src/layers/aircraft/index.js"
|
||||
"src/layers/aircraft/index.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -706,7 +712,8 @@
|
||||
"src/data/vesselLabels.js",
|
||||
"src/layers/vessels/records.js",
|
||||
"src/layers/vessels/recordPolicy.js",
|
||||
"src/layers/vessels/snapshotRenderer.js"
|
||||
"src/layers/vessels/snapshotRenderer.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -737,7 +744,8 @@
|
||||
"src/layers/firms/selection.js",
|
||||
"src/layers/firms/source.js",
|
||||
"src/layers/firms/state.js",
|
||||
"src/layers/firms/viewport.js"
|
||||
"src/layers/firms/viewport.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -759,7 +767,8 @@
|
||||
"src/layers/satellites/source.js",
|
||||
"src/layers/satellites/state.js",
|
||||
"src/layers/satellites/testing.js",
|
||||
"src/layers/satellites/tracking.js"
|
||||
"src/layers/satellites/tracking.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium", "satellite.js"]
|
||||
},
|
||||
@@ -784,7 +793,8 @@
|
||||
"src/layers/launches/selection.js",
|
||||
"src/layers/launches/source.js",
|
||||
"src/layers/launches/state.js",
|
||||
"src/layers/launches/testing.js"
|
||||
"src/layers/launches/testing.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -803,7 +813,8 @@
|
||||
"src/layers/installations/selection.js",
|
||||
"src/layers/installations/source.js",
|
||||
"src/layers/installations/state.js",
|
||||
"src/layers/installations/viewport.js"
|
||||
"src/layers/installations/viewport.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -877,7 +888,8 @@
|
||||
"src/layers/bikeshare/source.js",
|
||||
"src/layers/bikeshare/state.js",
|
||||
"src/layers/bikeshare/testing.js",
|
||||
"src/layers/bikeshare/viewport.js"
|
||||
"src/layers/bikeshare/viewport.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -914,7 +926,8 @@
|
||||
"src/layers/cctv/state.js",
|
||||
"src/layers/cctv/testing.js",
|
||||
"src/overlays/worldOverlayTokens.js",
|
||||
"src/data/cctvFootprint.js"
|
||||
"src/data/cctvFootprint.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -927,7 +940,8 @@
|
||||
"src/layers/alpr/presentation.js",
|
||||
"src/layers/alpr/visuals.js",
|
||||
"src/layers/alpr/overlay.js",
|
||||
"src/layers/alpr/source.js"
|
||||
"src/layers/alpr/source.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -959,7 +973,8 @@
|
||||
"src/layers/radio/tuning.js",
|
||||
"src/layers/radio/tuningNoise.js",
|
||||
"src/layers/radio/volume.js",
|
||||
"src/ui/radioTunerModel.js"
|
||||
"src/ui/radioTunerModel.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -975,7 +990,8 @@
|
||||
"src/layers/submarineCables/policy.js",
|
||||
"src/layers/submarineCables/rendering.js",
|
||||
"src/layers/submarineCables/state.js",
|
||||
"src/layers/submarineCables/surface.js"
|
||||
"src/layers/submarineCables/surface.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
@@ -1559,7 +1575,10 @@
|
||||
"src/layers/military/snapshotRenderer.js",
|
||||
"src/layers/vessels/records.js",
|
||||
"src/layers/vessels/recordPolicy.js",
|
||||
"src/layers/vessels/snapshotRenderer.js"
|
||||
"src/layers/vessels/snapshotRenderer.js",
|
||||
"src/data/inputOwnership.js",
|
||||
"src/annotations/drawMode.js",
|
||||
"src/annotations/drawTool.js"
|
||||
],
|
||||
"external": [
|
||||
"@mapbox/vector-tile",
|
||||
@@ -1893,7 +1912,8 @@
|
||||
"src/layers/military/snapshotRenderer.js",
|
||||
"src/layers/vessels/records.js",
|
||||
"src/layers/vessels/recordPolicy.js",
|
||||
"src/layers/vessels/snapshotRenderer.js"
|
||||
"src/layers/vessels/snapshotRenderer.js",
|
||||
"src/data/inputOwnership.js"
|
||||
],
|
||||
"external": [
|
||||
"cesium",
|
||||
|
||||
+237
-3
@@ -1,5 +1,239 @@
|
||||
#!/usr/bin/env node
|
||||
import { installPinokioDependencies, runChecked } from './pinokio-install.mjs';
|
||||
/**
|
||||
* Pinokio "Update": disclose what is about to land, then fast-forward and reinstall.
|
||||
*
|
||||
* Update is a fixed menu item aimed at people who only want to run the app, and
|
||||
* it executes install scripts from whatever the configured remote serves. It
|
||||
* cannot ask for confirmation — Pinokio drives it non-interactively — so the
|
||||
* safety it can offer is disclosure: fetch once, print the remote it fetched
|
||||
* from plus the incoming commits and their diffstat, and then apply that exact
|
||||
* revision. Someone who sees an unfamiliar remote or an unexpected set of
|
||||
* commits can close the window before any install script runs.
|
||||
*
|
||||
* @module scripts/pinokio-update
|
||||
*/
|
||||
import { realpathSync } from 'node:fs';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import {
|
||||
installPinokioDependencies,
|
||||
isDirectInvocation,
|
||||
runChecked,
|
||||
} from './pinokio-install.mjs';
|
||||
|
||||
runChecked('git', ['pull', '--ff-only']);
|
||||
installPinokioDependencies();
|
||||
const MODULE_PATH = fileURLToPath(import.meta.url);
|
||||
const ROOT = realpathSync(path.resolve(path.dirname(MODULE_PATH), '..'));
|
||||
|
||||
/**
|
||||
* Read a git value.
|
||||
*
|
||||
* @param {string[]} args - git arguments.
|
||||
* @param {object} [options]
|
||||
* @param {string} [options.cwd] - Repository to read.
|
||||
* @returns {string|null} Trimmed stdout, `''` when git succeeded with no
|
||||
* output, or null when git failed (no upstream, detached HEAD, not a
|
||||
* checkout). Callers must keep those two apart: an empty range and an
|
||||
* unreadable one mean very different things to someone about to install.
|
||||
*/
|
||||
export function readGit(args, { cwd = ROOT } = {}) {
|
||||
const result = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
||||
if (result.error || result.status !== 0) return null;
|
||||
return result.stdout.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove credentials from a remote URL before it is printed.
|
||||
*
|
||||
* A remote can carry a password or an access token in its userinfo
|
||||
* (`https://token@host/org/repo.git`) or in a query parameter
|
||||
* (`?access_token=…`). The point of printing the remote is to show WHERE the
|
||||
* update comes from, which the host and path already say — so the userinfo is
|
||||
* replaced and the query string and fragment are dropped whole, rather than
|
||||
* matched against a list of parameter names that would miss the next one.
|
||||
*
|
||||
* A secret spelled as an ordinary path segment is not detected; nothing here
|
||||
* can tell one of those from a repository name.
|
||||
*
|
||||
* @param {string|null|undefined} url - Remote URL as git reports it.
|
||||
* @returns {string|null} Printable URL, or null when there is nothing to print.
|
||||
*/
|
||||
export function redactRemoteUrl(url) {
|
||||
if (typeof url !== 'string' || url.length === 0) return null;
|
||||
let parsed;
|
||||
try {
|
||||
parsed = new URL(url);
|
||||
} catch {
|
||||
// Not a URL: scp-style `git@host:org/repo.git`, or a local path. Neither
|
||||
// has a userinfo field to hide.
|
||||
return url;
|
||||
}
|
||||
const hadUserinfo = Boolean(parsed.username || parsed.password);
|
||||
const hadQuery = Boolean(parsed.search || parsed.hash);
|
||||
if (!hadUserinfo && !hadQuery) return url;
|
||||
parsed.password = '';
|
||||
if (hadUserinfo) parsed.username = '***';
|
||||
parsed.search = '';
|
||||
parsed.hash = '';
|
||||
return parsed.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the remote, the commits about to be applied, and their diffstat.
|
||||
*
|
||||
* @param {object} [io] - Injection seam for tests.
|
||||
* @param {string} [io.cwd] - Repository to inspect.
|
||||
* @param {(line: string) => void} [io.log] - Normal output.
|
||||
* @param {(line: string) => void} [io.warn] - Degraded-path output.
|
||||
* @param {(remote: string) => void} [io.fetchRemote] - Fetch step; throws or
|
||||
* exits on failure, because a report built on a stale remote ref describes
|
||||
* the wrong changes.
|
||||
* @param {(args: string[]) => (string|null)} [io.read] - git reader.
|
||||
* @returns {{apply: string|null, fallback: boolean, stopped?: boolean}}
|
||||
* `apply` is the exact revision that was disclosed and must now be applied.
|
||||
* `fallback` asks the caller to run the plain pull so git itself reports
|
||||
* whatever went wrong, and is only ever set before anything has been fetched.
|
||||
* `stopped` means the update gave up: nothing can be shown, so nothing is
|
||||
* applied.
|
||||
*/
|
||||
export function reportIncomingChanges(io = {}) {
|
||||
const {
|
||||
cwd = ROOT,
|
||||
log = (line) => console.log(line),
|
||||
warn = (line) => console.warn(line),
|
||||
fetchRemote = (remote) => runChecked('git', ['fetch', '--quiet', remote]),
|
||||
read = (args) => readGit(args, { cwd }),
|
||||
} = io;
|
||||
|
||||
const upstream = read([
|
||||
'rev-parse',
|
||||
'--abbrev-ref',
|
||||
'--symbolic-full-name',
|
||||
'@{u}',
|
||||
]);
|
||||
// The full ref name is what later reads resolve, so a remote whose own name
|
||||
// contains a slash (`team/origin`) cannot be mistaken for a path segment.
|
||||
const upstreamRef = read(['rev-parse', '--symbolic-full-name', '@{u}']);
|
||||
const branch = read(['rev-parse', '--abbrev-ref', 'HEAD']);
|
||||
const remote =
|
||||
branch && branch !== 'HEAD'
|
||||
? read(['config', '--get', `branch.${branch}.remote`])
|
||||
: null;
|
||||
if (!upstream || !upstreamRef || !remote) {
|
||||
warn('[update] No upstream branch is configured — cannot preview changes.');
|
||||
warn('[update] Continuing; `git pull --ff-only` will report the problem.');
|
||||
return { apply: null, fallback: true };
|
||||
}
|
||||
|
||||
log(`[update] Tracking ${upstream}`);
|
||||
if (remote === '.') {
|
||||
// The upstream is another branch in this same checkout; there is nothing
|
||||
// to fetch and no remote URL to disclose.
|
||||
log('[update] Upstream is a local branch — nothing to fetch.');
|
||||
} else {
|
||||
const url = redactRemoteUrl(read(['remote', 'get-url', remote]));
|
||||
log(`[update] Fetching from ${url || remote}`);
|
||||
// Fetch once, here. Everything below describes and then applies the
|
||||
// revision this fetch brought in; a second fetch inside `git pull` could
|
||||
// apply something newer than what was printed.
|
||||
fetchRemote(remote);
|
||||
}
|
||||
|
||||
const target = read(['rev-parse', upstreamRef]);
|
||||
const head = read(['rev-parse', 'HEAD']);
|
||||
if (!target || !head) {
|
||||
// Stop. Falling through to `git pull` here would fetch a second time and
|
||||
// could install a revision this run never resolved, let alone disclosed.
|
||||
warn(`[update] Could not resolve ${upstream} after fetching.`);
|
||||
warn(
|
||||
'[update] Stopping: nothing is applied, because nothing can be shown.',
|
||||
);
|
||||
return { apply: null, fallback: false, stopped: true };
|
||||
}
|
||||
if (target === head) {
|
||||
log('[update] Already up to date — reinstalling dependencies only.');
|
||||
return { apply: null, fallback: false };
|
||||
}
|
||||
|
||||
const commits = read([
|
||||
'log',
|
||||
'--oneline',
|
||||
'--no-decorate',
|
||||
`${head}..${target}`,
|
||||
]);
|
||||
if (commits === null) {
|
||||
// A read that failed is not an empty range. Saying "up to date" here would
|
||||
// tell someone nothing is arriving while a revision is about to be applied.
|
||||
warn(`[update] Could not list the commits in ${head}..${target}.`);
|
||||
warn(
|
||||
`[update] Applying ${target} anyway; it is the revision that was fetched.`,
|
||||
);
|
||||
return { apply: target, fallback: false };
|
||||
}
|
||||
|
||||
const lines = commits.length > 0 ? commits.split('\n') : [];
|
||||
if (lines.length > 0) {
|
||||
log(`\n[update] ${lines.length} incoming commit(s):`);
|
||||
for (const line of lines) log(` ${line}`);
|
||||
} else {
|
||||
log(
|
||||
`\n[update] ${upstream} is at ${target}, which is not ahead of this checkout.`,
|
||||
);
|
||||
}
|
||||
|
||||
const stat = read(['diff', '--stat', `${head}..${target}`]);
|
||||
if (stat === null) {
|
||||
warn(`[update] Could not read the diffstat for ${head}..${target}.`);
|
||||
} else if (stat) {
|
||||
log('\n[update] Files affected:');
|
||||
for (const line of stat.split('\n')) log(` ${line}`);
|
||||
}
|
||||
log(`\n[update] Applying ${target}, then reinstalling dependencies.\n`);
|
||||
return { apply: target, fallback: false };
|
||||
}
|
||||
|
||||
/**
|
||||
* Disclose, then apply exactly what was disclosed.
|
||||
*
|
||||
* @param {object} [io] - Same seam as {@link reportIncomingChanges}, plus
|
||||
* `apply`, which runs one git command and must fail loudly.
|
||||
* @returns {{apply: string|null, fallback: boolean}} What the report decided.
|
||||
*/
|
||||
export function updateFromRemote(io = {}) {
|
||||
const { apply = (args) => runChecked('git', args) } = io;
|
||||
const plan = reportIncomingChanges(io);
|
||||
// `merge --ff-only <revision>` applies the object the report named. A second
|
||||
// `pull` would fetch again and could land a different one.
|
||||
if (plan.apply) apply(['merge', '--ff-only', plan.apply]);
|
||||
else if (plan.fallback) apply(['pull', '--ff-only']);
|
||||
return plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* What running this script does: disclose, apply, install.
|
||||
*
|
||||
* @param {object} [io] - The seam above, plus `install` and `fail`.
|
||||
* @returns {{apply: string|null, fallback: boolean, stopped?: boolean}} The plan.
|
||||
*/
|
||||
export function runPinokioUpdate(io = {}) {
|
||||
const {
|
||||
install = installPinokioDependencies,
|
||||
fail = (code) => process.exit(code),
|
||||
} = io;
|
||||
const plan = updateFromRemote(io);
|
||||
if (plan.stopped) {
|
||||
// Nothing could be shown, so nothing was applied. Reinstalling now would
|
||||
// run install scripts under the banner of an update that did not happen,
|
||||
// and report success for it.
|
||||
fail(1);
|
||||
return plan;
|
||||
}
|
||||
install();
|
||||
return plan;
|
||||
}
|
||||
|
||||
// Guarded like pinokio-start.mjs so the report above can be exercised without
|
||||
// pulling and reinstalling as an import side effect.
|
||||
if (isDirectInvocation(process.argv[1], MODULE_PATH)) {
|
||||
runPinokioUpdate();
|
||||
}
|
||||
@@ -0,0 +1,876 @@
|
||||
#!/usr/bin/env node
|
||||
/** Rendered acceptance for DISPLAY ▸ Draw: real clicks, real keys, real teardown. */
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import puppeteer from 'puppeteer';
|
||||
|
||||
const BASE_URL = process.env.QA_BASE_URL || 'http://localhost:4173';
|
||||
const SHOT_DIR = process.env.QA_SHOT_DIR || 'qa-shots/draw';
|
||||
const SHOT_PREFIX = process.env.QA_SHOT_PREFIX || '';
|
||||
const HEADFUL = process.env.QA_HEADFUL === '1';
|
||||
// A dense, recognisable grid: neighbourhood blocks to enclose and a straight
|
||||
// road to trace along.
|
||||
const VIEW = {
|
||||
lon: -122.4194,
|
||||
lat: 37.7749,
|
||||
height: 900,
|
||||
heading: 0,
|
||||
pitch: -85,
|
||||
};
|
||||
|
||||
const browser = await puppeteer.launch({
|
||||
headless: !HEADFUL,
|
||||
...(HEADFUL
|
||||
? {
|
||||
executablePath:
|
||||
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||
}
|
||||
: {}),
|
||||
args: [
|
||||
'--no-sandbox',
|
||||
'--disable-background-timer-throttling',
|
||||
'--disable-renderer-backgrounding',
|
||||
...(HEADFUL ? ['--window-size=1280,860'] : []),
|
||||
...(process.platform === 'darwin'
|
||||
? ['--use-angle=metal', '--enable-gpu']
|
||||
: ['--use-gl=angle', '--use-angle=swiftshader']),
|
||||
],
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
const errors = [];
|
||||
page.on('pageerror', (error) => errors.push(`pageerror: ${error.message}`));
|
||||
let failures = 0;
|
||||
function check(name, passed, detail = '') {
|
||||
console.log(
|
||||
`[${passed ? 'PASS' : 'FAIL'}] ${name}${detail ? ` — ${detail}` : ''}`,
|
||||
);
|
||||
if (!passed) failures++;
|
||||
}
|
||||
fs.mkdirSync(SHOT_DIR, { recursive: true });
|
||||
const shot = (name) =>
|
||||
page.screenshot({
|
||||
path: path.join(SHOT_DIR, `${SHOT_PREFIX}${name}.jpg`),
|
||||
type: 'jpeg',
|
||||
quality: 82,
|
||||
});
|
||||
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
/** A clip of the globe canvas, clear of the panels on every side. */
|
||||
const CANVAS_CLIP = { x: 340, y: 200, width: 560, height: 380 };
|
||||
|
||||
/**
|
||||
* How many amber pixels the clip contains. The drawn area's stroke and fill are
|
||||
* the only amber in this scene, so the count going UP after a shape is finished
|
||||
* is the shape actually painting — which is what CESIUM_3D_TILE-only
|
||||
* classification failed to do on a keyless boot while still reporting a mark on
|
||||
* the board. Decoding happens in the page because Node here has no image
|
||||
* decoder.
|
||||
*/
|
||||
async function amberPixels() {
|
||||
const shot64 = await page.screenshot({
|
||||
clip: CANVAS_CLIP,
|
||||
type: 'png',
|
||||
encoding: 'base64',
|
||||
});
|
||||
return page.evaluate(async (base64) => {
|
||||
const bitmap = await createImageBitmap(
|
||||
await (await fetch(`data:image/png;base64,${base64}`)).blob(),
|
||||
);
|
||||
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
|
||||
const context = canvas.getContext('2d');
|
||||
context.drawImage(bitmap, 0, 0);
|
||||
const { data } = context.getImageData(0, 0, bitmap.width, bitmap.height);
|
||||
let amber = 0;
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
const r = data[i];
|
||||
const g = data[i + 1];
|
||||
const b = data[i + 2];
|
||||
// Warm and saturated: the amber mark (#ffb547) blended over imagery.
|
||||
if (r > 150 && g > 90 && g < 220 && b < 130 && r - b > 70 && r - g > 20)
|
||||
amber += 1;
|
||||
}
|
||||
return amber;
|
||||
}, shot64);
|
||||
}
|
||||
|
||||
/**
|
||||
* Press Enter as the person drawing does — with the map focused, not a button.
|
||||
* Enter on a focused control means "press this control", so the tool ignores it
|
||||
* there; the harness has to move focus the way a user would before using the
|
||||
* finish key.
|
||||
*/
|
||||
async function pressFinish() {
|
||||
await page.evaluate(() => document.activeElement?.blur?.());
|
||||
await page.keyboard.press('Enter');
|
||||
}
|
||||
|
||||
/** One click on the globe canvas, the way a person makes one. */
|
||||
async function clickWorld(x, y, options = {}) {
|
||||
await page.mouse.click(x, y, options);
|
||||
await wait(options.settle ?? 140);
|
||||
}
|
||||
|
||||
const drawState = () =>
|
||||
page.evaluate(() => {
|
||||
const tool = window.__gevDrawTool;
|
||||
return {
|
||||
...tool.diagnostics(),
|
||||
shape: tool.shape,
|
||||
vertices: tool.session?.vertices?.length ?? null,
|
||||
hint: document.getElementById('draw-hint')?.textContent || '',
|
||||
marks: window.__gevAnnotations.count(),
|
||||
};
|
||||
});
|
||||
|
||||
const marks = () =>
|
||||
page.evaluate(() =>
|
||||
window.__gevAnnotations.list().map((mark) => ({
|
||||
type: mark.type,
|
||||
label: mark.label,
|
||||
color: mark.color,
|
||||
source: mark.source ?? null,
|
||||
})),
|
||||
);
|
||||
|
||||
/** Wait until the board has settled at `expected` marks (annotate is async). */
|
||||
async function waitForMarks(expected, timeout = 15_000) {
|
||||
try {
|
||||
await page.waitForFunction(
|
||||
(want) => window.__gevAnnotations.count() === want,
|
||||
{ timeout },
|
||||
expected,
|
||||
);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await page.setViewport({ width: 1280, height: 860 });
|
||||
await page.goto(`${BASE_URL}/?welcome=0`, { waitUntil: 'domcontentloaded' });
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
window.__gevDrawTool &&
|
||||
window.__gevAnnotations &&
|
||||
document.getElementById('loading-screen')?.classList.contains('hidden'),
|
||||
{ timeout: 90_000 },
|
||||
);
|
||||
await page.evaluate((view) => {
|
||||
const viewer = window.__godsEyeView.viewer;
|
||||
viewer.camera.cancelFlight?.();
|
||||
viewer.scene.tweens?.removeAll?.();
|
||||
viewer.camera.setView({
|
||||
destination: viewer.scene.globe.ellipsoid.cartographicToCartesian({
|
||||
longitude: (view.lon * Math.PI) / 180,
|
||||
latitude: (view.lat * Math.PI) / 180,
|
||||
height: view.height,
|
||||
}),
|
||||
orientation: {
|
||||
heading: (view.heading * Math.PI) / 180,
|
||||
pitch: (view.pitch * Math.PI) / 180,
|
||||
roll: 0,
|
||||
},
|
||||
});
|
||||
viewer.scene.requestRender();
|
||||
}, VIEW);
|
||||
const settled = await page
|
||||
.waitForFunction(
|
||||
() => {
|
||||
const primitives = window.__godsEyeView.viewer.scene.primitives;
|
||||
for (let index = 0; index < primitives.length; index++) {
|
||||
const primitive = primitives.get(index);
|
||||
if (
|
||||
typeof primitive.tilesLoaded === 'boolean' &&
|
||||
!primitive.tilesLoaded
|
||||
)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
{ timeout: 90_000 },
|
||||
)
|
||||
.then(
|
||||
() => true,
|
||||
() => false,
|
||||
);
|
||||
check('visible tile content settles before drawing', settled);
|
||||
|
||||
// The DISPLAY rail starts collapsed on a first run: open it the way a user does.
|
||||
await page.evaluate(() => {
|
||||
const rail = document.getElementById('pp-toggles');
|
||||
if (rail?.classList.contains('collapsed'))
|
||||
document
|
||||
.querySelector('.panel-collapse-btn[data-collapse-target="pp-toggles"]')
|
||||
?.click();
|
||||
});
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.getElementById('draw-toggle')?.getBoundingClientRect().width > 0,
|
||||
{ timeout: 10_000 },
|
||||
);
|
||||
check(
|
||||
'the Draw control is on the DISPLAY rail and starts off',
|
||||
await page.evaluate(() => {
|
||||
const toggle = document.getElementById('draw-toggle');
|
||||
return (
|
||||
toggle?.getAttribute('aria-pressed') === 'false' &&
|
||||
!document.getElementById('draw-mode-row')?.classList.contains('visible')
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
// The viewer's OWN click actions, captured before the tool ever runs. Both
|
||||
// must be absent while drawing and back — as the SAME functions — after.
|
||||
await page.evaluate(() => {
|
||||
const Cesium = window.__CESIUM__;
|
||||
const stock = window.__godsEyeView.viewer.screenSpaceEventHandler;
|
||||
window.__qaStock = {
|
||||
click:
|
||||
stock.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK) || null,
|
||||
double:
|
||||
stock.getInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) ||
|
||||
null,
|
||||
};
|
||||
});
|
||||
const stockActions = () =>
|
||||
page.evaluate(() => {
|
||||
const Cesium = window.__CESIUM__;
|
||||
const stock = window.__godsEyeView.viewer.screenSpaceEventHandler;
|
||||
const live = {
|
||||
click:
|
||||
stock.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK) || null,
|
||||
double:
|
||||
stock.getInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) ||
|
||||
null,
|
||||
};
|
||||
return {
|
||||
clickPresent: Boolean(live.click),
|
||||
doublePresent: Boolean(live.double),
|
||||
clickIsOriginal: live.click === window.__qaStock.click,
|
||||
doubleIsOriginal: live.double === window.__qaStock.double,
|
||||
hadClick: Boolean(window.__qaStock.click),
|
||||
hadDouble: Boolean(window.__qaStock.double),
|
||||
};
|
||||
});
|
||||
|
||||
// ── enable / disable cycles leave nothing behind ────────────────────────
|
||||
const before = await drawState();
|
||||
for (let cycle = 0; cycle < 3; cycle += 1) {
|
||||
await page.click('#draw-toggle');
|
||||
await wait(120);
|
||||
await page.click('#draw-toggle');
|
||||
await wait(120);
|
||||
}
|
||||
const after = await drawState();
|
||||
check(
|
||||
'three enable/disable cycles add no listener, handler or preview data source',
|
||||
after.domListeners === before.domListeners &&
|
||||
after.previewDataSources === 1 &&
|
||||
before.previewDataSources === 1 &&
|
||||
after.sceneHandler === false &&
|
||||
after.pointerOwner === null &&
|
||||
after.stockDoubleClick === before.stockDoubleClick,
|
||||
`listeners ${before.domListeners}→${after.domListeners}, previews ${after.previewDataSources}, ` +
|
||||
`handler ${after.sceneHandler}, owner ${after.pointerOwner}, stock dblclick ${after.stockDoubleClick}`,
|
||||
);
|
||||
|
||||
// ── the viewer's own click actions are borrowed, then given back ────────
|
||||
await page.click('#draw-toggle');
|
||||
const duringDraw = await stockActions();
|
||||
check(
|
||||
"Cesium's own selecting click and tracking double-click are both borrowed while drawing",
|
||||
duringDraw.clickPresent === false && duringDraw.doublePresent === false,
|
||||
`click present ${duringDraw.clickPresent}, double present ${duringDraw.doublePresent} ` +
|
||||
`(viewer had click ${duringDraw.hadClick}, double ${duringDraw.hadDouble})`,
|
||||
);
|
||||
await page.click('#draw-toggle');
|
||||
const afterDraw = await stockActions();
|
||||
check(
|
||||
'and both are restored as the SAME functions, not replacements',
|
||||
afterDraw.clickPresent === duringDraw.hadClick &&
|
||||
afterDraw.doublePresent === duringDraw.hadDouble &&
|
||||
afterDraw.clickIsOriginal &&
|
||||
afterDraw.doubleIsOriginal,
|
||||
JSON.stringify(afterDraw),
|
||||
);
|
||||
|
||||
// ── a pin, finished with Enter ──────────────────────────────────────────
|
||||
await page.click('#draw-toggle');
|
||||
await page.click('.pp-mode-btn[data-shape="pin"]');
|
||||
await page.click('#draw-label-input');
|
||||
await page.keyboard.type('Pin one');
|
||||
await clickWorld(520, 330);
|
||||
check(
|
||||
'the pointer is claimed while a session is open',
|
||||
(await drawState()).pointerOwner === 'draw',
|
||||
);
|
||||
await page.keyboard.press('Enter');
|
||||
check(
|
||||
'a pin placed by mouse and finished with Enter lands on the board',
|
||||
await waitForMarks(1),
|
||||
);
|
||||
|
||||
// ── a line along a road, with Backspace ─────────────────────────────────
|
||||
await page.click('.pp-mode-btn[data-shape="line"]');
|
||||
await clickWorld(360, 300);
|
||||
await clickWorld(470, 380);
|
||||
await clickWorld(600, 470);
|
||||
const beforeBackspace = (await drawState()).vertices;
|
||||
await page.keyboard.press('Backspace');
|
||||
await wait(120);
|
||||
const afterBackspace = (await drawState()).vertices;
|
||||
check(
|
||||
'Backspace removes the last vertex only',
|
||||
beforeBackspace === 3 && afterBackspace === 2,
|
||||
`${beforeBackspace} → ${afterBackspace}`,
|
||||
);
|
||||
await clickWorld(640, 500);
|
||||
await page.click('#draw-label-input');
|
||||
await page.keyboard.type('Market St');
|
||||
await page.keyboard.press('Enter');
|
||||
check(
|
||||
'a line finished from the label field lands on the board',
|
||||
await waitForMarks(2),
|
||||
);
|
||||
const lineMark = (await marks()).find((mark) =>
|
||||
mark.label?.startsWith('Market St'),
|
||||
);
|
||||
check(
|
||||
'a drawn line reports its length and never a travel time',
|
||||
Boolean(lineMark) &&
|
||||
/\d/.test(lineMark.label) &&
|
||||
!/min|walk|drive/i.test(lineMark.label),
|
||||
lineMark?.label,
|
||||
);
|
||||
await shot('02-line-along-a-road');
|
||||
|
||||
// ── an area, coloured and labelled, finished with a double-click ────────
|
||||
await page.click('.pp-mode-btn[data-shape="area"]');
|
||||
await page.select('#draw-color-select', 'amber');
|
||||
const amberBefore = await amberPixels();
|
||||
await page.click('#draw-label-input');
|
||||
await page.keyboard.type('Civic Center block');
|
||||
await clickWorld(400, 280);
|
||||
await clickWorld(700, 290);
|
||||
await clickWorld(720, 520);
|
||||
await clickWorld(410, 500);
|
||||
const areaVertices = (await drawState()).vertices;
|
||||
check(
|
||||
'four clicks on the globe are four vertices',
|
||||
areaVertices === 4,
|
||||
`${areaVertices} vertices`,
|
||||
);
|
||||
await page.mouse.click(410, 500, { count: 2 });
|
||||
const areaLanded = await waitForMarks(3);
|
||||
await wait(900);
|
||||
const afterDoubleClick = await page.evaluate(() =>
|
||||
window.__gevAnnotations.count(),
|
||||
);
|
||||
check('an area finished by double-click lands on the board', areaLanded);
|
||||
check(
|
||||
'a double-click finishes the shape exactly once',
|
||||
afterDoubleClick === 3,
|
||||
`${afterDoubleClick} marks`,
|
||||
);
|
||||
const areaMark = (await marks()).find(
|
||||
(mark) => mark.label === 'Civic Center block',
|
||||
);
|
||||
check(
|
||||
'the label and colour chosen in the panel are what is drawn',
|
||||
areaMark?.color === 'amber',
|
||||
JSON.stringify(areaMark),
|
||||
);
|
||||
await wait(1200);
|
||||
const amberAfter = await amberPixels();
|
||||
check(
|
||||
'the finished area actually PAINTS — amber pixels appear on this surface',
|
||||
amberAfter - amberBefore > 500,
|
||||
`${amberBefore} → ${amberAfter} amber pixels (+${amberAfter - amberBefore})`,
|
||||
);
|
||||
await shot('01-area-with-label');
|
||||
await shot('03-pins-and-shapes');
|
||||
|
||||
// ── Escape cancels the shape, a second Escape leaves draw mode ──────────
|
||||
await page.evaluate(() => window.__gevDrawTool.cancel());
|
||||
await clickWorld(500, 300);
|
||||
await clickWorld(560, 340);
|
||||
check('a new shape is in progress', (await drawState()).vertices === 2);
|
||||
await page.keyboard.press('Escape');
|
||||
await wait(150);
|
||||
const afterFirstEscape = await drawState();
|
||||
check(
|
||||
'Escape cancels the shape in progress and stays in draw mode',
|
||||
afterFirstEscape.vertices === 0 && afterFirstEscape.active === true,
|
||||
`vertices ${afterFirstEscape.vertices}, active ${afterFirstEscape.active}`,
|
||||
);
|
||||
await page.keyboard.press('Escape');
|
||||
await wait(150);
|
||||
const afterSecondEscape = await drawState();
|
||||
check(
|
||||
'a second Escape leaves draw mode and gives the pointer back',
|
||||
afterSecondEscape.active === false &&
|
||||
afterSecondEscape.pointerOwner === null &&
|
||||
afterSecondEscape.sceneHandler === false,
|
||||
JSON.stringify(afterSecondEscape),
|
||||
);
|
||||
check(
|
||||
'cancelling never removes a mark already on the board',
|
||||
afterSecondEscape.marks === 3,
|
||||
`${afterSecondEscape.marks} marks`,
|
||||
);
|
||||
|
||||
// ── a click that would select something selects nothing while drawing ───
|
||||
const target = await findClickableTarget();
|
||||
check(
|
||||
'a selectable layer entity is on screen to test click ownership against',
|
||||
Boolean(target),
|
||||
target
|
||||
? `${target.layer} at ${target.x},${target.y}`
|
||||
: 'no CCTV camera or bundled site could be reached — the ownership case cannot be proved',
|
||||
);
|
||||
if (target) {
|
||||
await clickWorld(target.x, target.y, { settle: 900 });
|
||||
const selectedNormally = await page.evaluate(() =>
|
||||
Boolean(window.__godsEyeView.viewer.selectedEntity),
|
||||
);
|
||||
check(
|
||||
`clicking a ${target.layer} selects it when nothing owns the pointer`,
|
||||
selectedNormally,
|
||||
);
|
||||
await page.evaluate(() => {
|
||||
window.__godsEyeView.viewer.selectedEntity = undefined;
|
||||
});
|
||||
await page.click('#draw-toggle');
|
||||
await page.click('.pp-mode-btn[data-shape="area"]');
|
||||
await clickWorld(target.x, target.y, { settle: 900 });
|
||||
const whileDrawing = await drawState();
|
||||
const selectedWhileDrawing = await page.evaluate(() =>
|
||||
Boolean(window.__godsEyeView.viewer.selectedEntity),
|
||||
);
|
||||
check(
|
||||
`clicking the same ${target.layer} while drawing adds a vertex and selects nothing`,
|
||||
whileDrawing.vertices === 1 && selectedWhileDrawing === false,
|
||||
`vertices ${whileDrawing.vertices}, selected ${selectedWhileDrawing}`,
|
||||
);
|
||||
await page.keyboard.press('Escape');
|
||||
await page.keyboard.press('Escape');
|
||||
await wait(150);
|
||||
}
|
||||
|
||||
// ── what a reload actually does ─────────────────────────────────────────
|
||||
const beforeReload = await page.evaluate(() =>
|
||||
window.__gevAnnotations.count(),
|
||||
);
|
||||
await page.reload({ waitUntil: 'domcontentloaded' });
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
window.__gevAnnotations &&
|
||||
document.getElementById('loading-screen')?.classList.contains('hidden'),
|
||||
{ timeout: 90_000 },
|
||||
);
|
||||
const afterReload = await page.evaluate(() =>
|
||||
window.__gevAnnotations.count(),
|
||||
);
|
||||
check(
|
||||
'a reload starts an empty board — marks live for the session, not across reloads',
|
||||
beforeReload > 0 && afterReload === 0,
|
||||
`${beforeReload} before, ${afterReload} after`,
|
||||
);
|
||||
|
||||
// ── Clear wipes the board ───────────────────────────────────────────────
|
||||
await page.evaluate(() => {
|
||||
const rail = document.getElementById('pp-toggles');
|
||||
if (rail?.classList.contains('collapsed'))
|
||||
document
|
||||
.querySelector('.panel-collapse-btn[data-collapse-target="pp-toggles"]')
|
||||
?.click();
|
||||
});
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.getElementById('draw-toggle')?.getBoundingClientRect().width > 0,
|
||||
{ timeout: 10_000 },
|
||||
);
|
||||
// The reload built a new page context: re-capture the viewer's own click
|
||||
// actions so the identity comparisons below still mean something.
|
||||
await page.evaluate(() => {
|
||||
const Cesium = window.__CESIUM__;
|
||||
const stock = window.__godsEyeView.viewer.screenSpaceEventHandler;
|
||||
window.__qaStock = {
|
||||
click:
|
||||
stock.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK) || null,
|
||||
double:
|
||||
stock.getInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) ||
|
||||
null,
|
||||
};
|
||||
});
|
||||
await page.evaluate((view) => {
|
||||
const viewer = window.__godsEyeView.viewer;
|
||||
viewer.camera.cancelFlight?.();
|
||||
viewer.camera.setView({
|
||||
destination: viewer.scene.globe.ellipsoid.cartographicToCartesian({
|
||||
longitude: (view.lon * Math.PI) / 180,
|
||||
latitude: (view.lat * Math.PI) / 180,
|
||||
height: view.height,
|
||||
}),
|
||||
orientation: { heading: 0, pitch: (view.pitch * Math.PI) / 180, roll: 0 },
|
||||
});
|
||||
}, VIEW);
|
||||
await wait(2500);
|
||||
await page.click('#draw-toggle');
|
||||
await page.click('.pp-mode-btn[data-shape="area"]');
|
||||
await clickWorld(420, 280);
|
||||
await clickWorld(700, 300);
|
||||
await clickWorld(660, 520);
|
||||
await pressFinish();
|
||||
const drewAgain = await waitForMarks(1);
|
||||
check('a shape can be drawn again after a reload', drewAgain);
|
||||
|
||||
// Enter belongs to whatever the keyboard is on. With Clear focused it must
|
||||
// PRESS CLEAR — the shape in progress goes, and so does the mark already on
|
||||
// the board — and it must NOT quietly finish a second shape.
|
||||
await clickWorld(430, 300);
|
||||
await clickWorld(690, 320);
|
||||
await clickWorld(670, 500);
|
||||
const beforeButtonEnter = await drawState();
|
||||
await page.focus('#draw-clear');
|
||||
await page.keyboard.press('Enter');
|
||||
await wait(600);
|
||||
const afterButtonEnter = await drawState();
|
||||
check(
|
||||
'Enter on a keyboard-focused button activates the button, it does not finish the shape',
|
||||
beforeButtonEnter.vertices === 3 &&
|
||||
beforeButtonEnter.marks === 1 &&
|
||||
afterButtonEnter.marks === 0 &&
|
||||
afterButtonEnter.vertices === 0,
|
||||
`before ${beforeButtonEnter.vertices} vertices / ${beforeButtonEnter.marks} marks, ` +
|
||||
`after ${afterButtonEnter.vertices} / ${afterButtonEnter.marks} ` +
|
||||
'(a finish would have made it 2 marks)',
|
||||
);
|
||||
|
||||
// Put one back so the Clear BUTTON check below has something to remove.
|
||||
await clickWorld(420, 280);
|
||||
await clickWorld(700, 300);
|
||||
await clickWorld(660, 520);
|
||||
await pressFinish();
|
||||
check(
|
||||
'a shape can be drawn after the board was cleared from the keyboard',
|
||||
await waitForMarks(1),
|
||||
);
|
||||
await page.click('#draw-clear');
|
||||
await wait(400);
|
||||
const cleared = await drawState();
|
||||
check(
|
||||
'Clear removes every mark from the board',
|
||||
cleared.marks === 0,
|
||||
`${cleared.marks} marks left`,
|
||||
);
|
||||
await shot('04-after-clear');
|
||||
|
||||
// ── a shape that describes nothing is refused, not placed ───────────────
|
||||
const degenerateVertices = await page.evaluate(() => {
|
||||
const tool = window.__gevDrawTool;
|
||||
tool.cancel();
|
||||
// Three points on one line, placed through the same addVertex the clicks use.
|
||||
tool.addVertex(-122.42, 37.77);
|
||||
tool.addVertex(-122.42, 37.771);
|
||||
tool.addVertex(-122.42, 37.772);
|
||||
return tool.session?.vertices?.length ?? null;
|
||||
});
|
||||
check(
|
||||
'three collinear vertices are accepted into the session',
|
||||
degenerateVertices === 3,
|
||||
`${degenerateVertices} vertices`,
|
||||
);
|
||||
await pressFinish();
|
||||
await wait(600);
|
||||
const degenerate = await drawState();
|
||||
check(
|
||||
'three points in a line are refused with a reason, not placed',
|
||||
degenerate.marks === 0 && /in a line/.test(degenerate.hint),
|
||||
`${degenerate.marks} marks, hint "${degenerate.hint}"`,
|
||||
);
|
||||
|
||||
// ── a shape drawn across the antimeridian lands where it was drawn ──────
|
||||
await page.evaluate(() => {
|
||||
const viewer = window.__godsEyeView.viewer;
|
||||
viewer.camera.cancelFlight?.();
|
||||
viewer.camera.setView({
|
||||
destination: viewer.scene.globe.ellipsoid.cartographicToCartesian({
|
||||
longitude: (179.9995 * Math.PI) / 180,
|
||||
latitude: 0,
|
||||
height: 3000,
|
||||
}),
|
||||
orientation: { heading: 0, pitch: (-88 * Math.PI) / 180, roll: 0 },
|
||||
});
|
||||
viewer.scene.requestRender();
|
||||
});
|
||||
await wait(2500);
|
||||
await page.evaluate(() => {
|
||||
const tool = window.__gevDrawTool;
|
||||
tool.cancel();
|
||||
tool.setShape('area');
|
||||
// A ~200 m square straddling 180.
|
||||
tool.addVertex(179.999, -0.001);
|
||||
tool.addVertex(-179.999, -0.001);
|
||||
tool.addVertex(-179.999, 0.001);
|
||||
tool.addVertex(179.999, 0.001);
|
||||
});
|
||||
await pressFinish();
|
||||
const datelineLanded = await waitForMarks(1);
|
||||
const datelineAnchor = await page.evaluate(() => {
|
||||
const mark = window.__gevAnnotations.list()[0];
|
||||
return mark ? { lon: mark.anchor?.lon, lat: mark.anchor?.lat } : null;
|
||||
});
|
||||
check(
|
||||
'a shape drawn across the antimeridian anchors there, not on the Greenwich meridian',
|
||||
datelineLanded &&
|
||||
datelineAnchor &&
|
||||
Math.abs(Math.abs(datelineAnchor.lon) - 180) < 0.1 &&
|
||||
Math.abs(datelineAnchor.lat) < 0.1,
|
||||
JSON.stringify(datelineAnchor),
|
||||
);
|
||||
await page.evaluate(() => window.__gevAnnotations.clear());
|
||||
|
||||
await page.click('#draw-toggle');
|
||||
await wait(200);
|
||||
const finalState = await drawState();
|
||||
check(
|
||||
'leaving draw mode gives back the pointer, the handler and the double-click',
|
||||
finalState.active === false &&
|
||||
finalState.pointerOwner === null &&
|
||||
finalState.sceneHandler === false &&
|
||||
finalState.previewDataSources === 1,
|
||||
JSON.stringify(finalState),
|
||||
);
|
||||
// ── destroy(): the shell disposing the tool leaves nothing behind ───────
|
||||
const beforeDestroy = await page.evaluate(
|
||||
() => window.__godsEyeView.viewer.dataSources.length,
|
||||
);
|
||||
await page.click('#draw-toggle'); // destroy from an ACTIVE session: the harder case
|
||||
await wait(200);
|
||||
const destroyed = await page.evaluate(async () => {
|
||||
const tool = window.__gevDrawTool;
|
||||
const wasActive = tool.active;
|
||||
await tool.destroy();
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
const Cesium = window.__CESIUM__;
|
||||
const viewer = window.__godsEyeView.viewer;
|
||||
const stock = viewer.screenSpaceEventHandler;
|
||||
let previews = 0;
|
||||
for (let i = 0; i < viewer.dataSources.length; i += 1)
|
||||
if (viewer.dataSources.get(i)?.name === 'gev-draw-preview') previews += 1;
|
||||
return {
|
||||
wasActive,
|
||||
diagnostics: tool.diagnostics(),
|
||||
previews,
|
||||
dataSources: viewer.dataSources.length,
|
||||
handleGone: window.__gevDrawTool === undefined,
|
||||
clickRestored:
|
||||
stock.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK) ===
|
||||
window.__qaStock.click,
|
||||
doubleRestored:
|
||||
stock.getInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) ===
|
||||
window.__qaStock.double,
|
||||
drawingClass: document.body.classList.contains('gev-drawing'),
|
||||
};
|
||||
});
|
||||
check(
|
||||
'destroy() from an active session releases the pointer, handler and listeners',
|
||||
destroyed.wasActive === true &&
|
||||
destroyed.diagnostics.destroyed === true &&
|
||||
destroyed.diagnostics.pointerOwner === null &&
|
||||
destroyed.diagnostics.sceneHandler === false &&
|
||||
destroyed.diagnostics.domListeners === 0 &&
|
||||
destroyed.drawingClass === false,
|
||||
JSON.stringify(destroyed.diagnostics),
|
||||
);
|
||||
check(
|
||||
'destroy() detaches the preview data source and gives the window handle back',
|
||||
destroyed.previews === 0 &&
|
||||
destroyed.dataSources === beforeDestroy - 1 &&
|
||||
destroyed.handleGone,
|
||||
`previews ${destroyed.previews}, dataSources ${beforeDestroy} → ${destroyed.dataSources}, handle gone ${destroyed.handleGone}`,
|
||||
);
|
||||
check(
|
||||
"destroy() returns Cesium's own click actions",
|
||||
destroyed.clickRestored && destroyed.doubleRestored,
|
||||
`click ${destroyed.clickRestored}, double ${destroyed.doubleRestored}`,
|
||||
);
|
||||
|
||||
check(
|
||||
'no uncaught page errors across the run',
|
||||
errors.length === 0,
|
||||
errors.join(' | '),
|
||||
);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
console.log(`RESULT: ${failures} failures`);
|
||||
process.exitCode = failures ? 1 : 0;
|
||||
|
||||
/**
|
||||
* Find something on screen that a layer would select on click, so the ownership
|
||||
* guard can be proved against a real selection rather than a stub. Bundled
|
||||
* infrastructure first (no network, works keyless); CCTV cameras if they are up.
|
||||
*/
|
||||
async function findClickableTarget() {
|
||||
// CCTV first: it is the layer the brief names, and it goes through the shared
|
||||
// tracking click gesture that flights and military use too.
|
||||
const camera = await page
|
||||
.evaluate(async () => {
|
||||
const manager = window.__godsEyeView.dataManager;
|
||||
await manager.setEnabled('cctv', true, { origin: 'user' });
|
||||
const module = manager.layers.get('cctv')?.module;
|
||||
if (!module?.getUIState) return null;
|
||||
for (let attempt = 0; attempt < 40; attempt += 1) {
|
||||
const cameras = module.getUIState()?.cameras || [];
|
||||
const found = cameras.find((entry) => {
|
||||
const lat = entry.lat ?? entry.latitude;
|
||||
const lon = entry.lon ?? entry.longitude;
|
||||
return Number.isFinite(lat) && Number.isFinite(lon);
|
||||
});
|
||||
if (found)
|
||||
return {
|
||||
id: found.id,
|
||||
lat: found.lat ?? found.latitude,
|
||||
lon: found.lon ?? found.longitude,
|
||||
};
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.catch(() => null);
|
||||
|
||||
if (camera) {
|
||||
await page.evaluate((spot) => {
|
||||
const viewer = window.__godsEyeView.viewer;
|
||||
viewer.camera.cancelFlight?.();
|
||||
viewer.camera.setView({
|
||||
destination: viewer.scene.globe.ellipsoid.cartographicToCartesian({
|
||||
longitude: (spot.lon * Math.PI) / 180,
|
||||
latitude: (spot.lat * Math.PI) / 180,
|
||||
height: 600,
|
||||
}),
|
||||
orientation: { heading: 0, pitch: (-80 * Math.PI) / 180, roll: 0 },
|
||||
});
|
||||
viewer.scene.requestRender();
|
||||
}, camera);
|
||||
await wait(4000);
|
||||
const spot = await onScreen(
|
||||
(entity) => typeof entity.id === 'string' && entity.id.startsWith('CAM-'),
|
||||
);
|
||||
if (spot) return { ...spot, layer: 'CCTV camera' };
|
||||
}
|
||||
|
||||
// Bundled infrastructure as the keyless fallback: a different guarded handler,
|
||||
// the same shared claim, and always present without a key.
|
||||
const site = await page
|
||||
.evaluate(async () => {
|
||||
const viewer = window.__godsEyeView.viewer;
|
||||
await window.__godsEyeView.dataManager.setEnabled(
|
||||
'local-datacenters',
|
||||
true,
|
||||
{
|
||||
origin: 'user',
|
||||
},
|
||||
);
|
||||
const centreOf = (entity) => {
|
||||
const time = viewer.clock.currentTime;
|
||||
const point = entity.position?.getValue?.(time);
|
||||
if (point) return point;
|
||||
const hierarchy = entity.polygon?.hierarchy?.getValue?.(time);
|
||||
if (hierarchy?.positions?.length) return hierarchy.positions[0];
|
||||
const line = entity.polyline?.positions?.getValue?.(time);
|
||||
return line?.length ? line[0] : null;
|
||||
};
|
||||
for (let attempt = 0; attempt < 40; attempt += 1) {
|
||||
for (let i = 0; i < viewer.dataSources.length; i += 1) {
|
||||
for (const entity of viewer.dataSources.get(i).entities.values) {
|
||||
if (entity.__localLayerId !== 'local-datacenters') continue;
|
||||
const point = centreOf(entity);
|
||||
if (!point) continue;
|
||||
const carto = window.Cesium
|
||||
? window.Cesium.Cartographic.fromCartesian(point)
|
||||
: viewer.scene.globe.ellipsoid.cartesianToCartographic(point);
|
||||
if (!carto) continue;
|
||||
return {
|
||||
lon: (carto.longitude * 180) / Math.PI,
|
||||
lat: (carto.latitude * 180) / Math.PI,
|
||||
};
|
||||
}
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.catch(() => null);
|
||||
if (!site) return null;
|
||||
await page.evaluate((spot) => {
|
||||
const viewer = window.__godsEyeView.viewer;
|
||||
viewer.camera.cancelFlight?.();
|
||||
viewer.camera.setView({
|
||||
destination: viewer.scene.globe.ellipsoid.cartographicToCartesian({
|
||||
longitude: (spot.lon * Math.PI) / 180,
|
||||
latitude: (spot.lat * Math.PI) / 180,
|
||||
height: 2500,
|
||||
}),
|
||||
orientation: { heading: 0, pitch: (-88 * Math.PI) / 180, roll: 0 },
|
||||
});
|
||||
viewer.scene.requestRender();
|
||||
}, site);
|
||||
await wait(4000);
|
||||
const spot = await onScreen(
|
||||
(entity) => entity.__localLayerId === 'local-datacenters',
|
||||
);
|
||||
return spot ? { ...spot, layer: 'data centre' } : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Canvas coordinates of the first entity matching `belongs` that is on screen
|
||||
* and clear of the side panels. Annotation marks and the draw tool's own
|
||||
* preview vertices are on screen too, so the predicate has to be specific.
|
||||
*/
|
||||
async function onScreen(belongs, timeout = 20_000) {
|
||||
return page
|
||||
.waitForFunction(
|
||||
(belongsSource) => {
|
||||
// eslint-disable-next-line no-new-func
|
||||
const belongsTo = new Function(`return (${belongsSource})`)();
|
||||
const viewer = window.__godsEyeView.viewer;
|
||||
const scene = viewer.scene;
|
||||
const collections = [viewer.entities];
|
||||
for (let i = 0; i < viewer.dataSources.length; i += 1) {
|
||||
const source = viewer.dataSources.get(i);
|
||||
if (source?.name === 'gev-draw-preview') continue;
|
||||
collections.push(source.entities);
|
||||
}
|
||||
for (const source of collections) {
|
||||
for (const entity of source.values) {
|
||||
if (!belongsTo(entity)) continue;
|
||||
const position = entity.position?.getValue?.(
|
||||
viewer.clock.currentTime,
|
||||
);
|
||||
if (!position) continue;
|
||||
const window2d = scene.cartesianToCanvasCoordinates(position);
|
||||
if (!window2d) continue;
|
||||
const { x, y } = window2d;
|
||||
if (!(x > 300 && x < 900 && y > 180 && y < 600)) continue;
|
||||
// Projecting into the window is not the same as being clickable:
|
||||
// the entity may be beyond the horizon or behind a building. Only a
|
||||
// spot where the scene actually picks it proves the control case.
|
||||
const hit = scene.pick({ x: Math.round(x), y: Math.round(y) });
|
||||
if (!hit?.id || !belongsTo(hit.id)) continue;
|
||||
return { x: Math.round(x), y: Math.round(y) };
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
{ timeout, polling: 500 },
|
||||
belongs.toString(),
|
||||
)
|
||||
.then(
|
||||
(handle) => handle.jsonValue(),
|
||||
() => null,
|
||||
);
|
||||
}
|
||||
@@ -10,11 +10,13 @@ import {
|
||||
fetchCctvImageFromUpstream,
|
||||
fetchTxdotSnapshot,
|
||||
fetchCctvMediaUpstream,
|
||||
watchDownstreamClose,
|
||||
} from './cctv/media.js';
|
||||
import {
|
||||
CCTV_FRAME_FETCH_TIMEOUT_MS,
|
||||
CCTV_MAX_SOURCES_CEILING,
|
||||
} from './cctv/constants.js';
|
||||
import { sanitizeCctvRangeHeader } from './cctv/range.js';
|
||||
import { googleServerApiKey } from './places/google-key.js';
|
||||
export { CCTV_FRAME_FETCH_TIMEOUT_MS, fetchCctvImageFromUpstream };
|
||||
/**
|
||||
@@ -218,15 +220,31 @@ export function cctvProxy({ sourceRoot = process.cwd() } = {}) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bound before the request goes out: most of the wait is before any
|
||||
// header arrives, and a viewer who leaves during it must take the
|
||||
// upstream request with them.
|
||||
const downstream = watchDownstreamClose(res);
|
||||
try {
|
||||
const upstreamHeaders = {
|
||||
'User-Agent': 'gods-eye-view-cctv-proxy/1.0',
|
||||
};
|
||||
const requestRange = req.headers?.range;
|
||||
// Never forward the client's own string: a Range this proxy does
|
||||
// not accept is dropped and the request proceeds without one.
|
||||
const requestRange = sanitizeCctvRangeHeader(req.headers?.range);
|
||||
if (requestRange) upstreamHeaders.Range = requestRange;
|
||||
const upstream = await fetchCctvMediaUpstream(mediaUrl, {
|
||||
headers: upstreamHeaders,
|
||||
signal: downstream.signal,
|
||||
});
|
||||
if (downstream.closed) {
|
||||
// The headers arrived for a viewer who is no longer there.
|
||||
try {
|
||||
await upstream.body?.cancel();
|
||||
} catch {
|
||||
/* already closed */
|
||||
}
|
||||
return;
|
||||
}
|
||||
const contentType = upstream.headers.get('content-type') || '';
|
||||
if (!upstream.ok) {
|
||||
try {
|
||||
@@ -283,6 +301,11 @@ export function cctvProxy({ sourceRoot = process.cwd() } = {}) {
|
||||
});
|
||||
return;
|
||||
} catch (error) {
|
||||
if (downstream.closed) {
|
||||
// The viewer left mid-request. That is not a camera fault and
|
||||
// there is nobody to answer.
|
||||
return;
|
||||
}
|
||||
const timedOut =
|
||||
error?.name === 'AbortError' || error?.name === 'TimeoutError';
|
||||
setHealth(cameraId, {
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
loadTarkteeSourcesFromDatex,
|
||||
loadWarendorfSourcesFromCatalog,
|
||||
loadNswSourcesFromOpenData,
|
||||
loadCalgarySourcesFromOpenData,
|
||||
} from './sources.js';
|
||||
|
||||
/** Env kill switch: unset or anything but "0" means enabled. */
|
||||
@@ -80,6 +81,11 @@ const LIVE_PACKS = [
|
||||
enabled: () => envEnabled('CCTV_NSW_ENABLED'),
|
||||
load: loadNswSourcesFromOpenData,
|
||||
},
|
||||
{
|
||||
name: 'calgary',
|
||||
enabled: () => envEnabled('CCTV_CALGARY_ENABLED'),
|
||||
load: loadCalgarySourcesFromOpenData,
|
||||
},
|
||||
];
|
||||
/**
|
||||
* Load CCTV sources from a local JSON file (CCTV_SOURCES_FILE env or default).
|
||||
|
||||
@@ -220,6 +220,22 @@ export const NSW_IMAGE_USER_AGENT =
|
||||
* out around 120 characters.
|
||||
*/
|
||||
export const NSW_MAX_VIEW_LABEL = 140;
|
||||
/** Open Calgary traffic cameras: one keyless Socrata endpoint for the whole
|
||||
* city; frames are stills on a City of Calgary host. */
|
||||
export const DEFAULT_CALGARY_ROWS_URL =
|
||||
'https://data.calgary.ca/resource/k7p9-kppz.json?$limit=500';
|
||||
/** The only origin Calgary camera frames may come from. The catalog publishes
|
||||
* most rows as `http://`; that host serves HTTPS and 301-redirects to it, so
|
||||
* URLs are upgraded and then pinned here before registration. */
|
||||
export const CALGARY_IMAGE_ORIGIN = 'https://trafficcam.calgary.ca/';
|
||||
export const DEFAULT_CALGARY_MAX_SOURCES = 220;
|
||||
/** Centre Street / 7 Avenue: the prioritization anchor. */
|
||||
export const CALGARY_DOWNTOWN = { lat: 51.0461, lon: -114.0626 };
|
||||
/** Hard ceiling on the Calgary catalog body. The whole city is ~215 rows and
|
||||
* under 100 KB; this only exists so an upstream that streams an unbounded
|
||||
* body cannot be buffered without limit. */
|
||||
export const CALGARY_MAX_CATALOG_BYTES = 4 * 1024 * 1024;
|
||||
|
||||
/** Camera CATALOGS change rarely; 15 min keeps multi-megabyte upstream list refetches (Austin rows.json + 4 Caltrans districts + TfL + Ontario 511) infrequent. Frames are fetched per-request and are unaffected. */
|
||||
export const CCTV_SOURCE_CACHE_MS = 15 * 60 * 1000;
|
||||
/** Per-provider catalog-fetch timeout. Bounds the worst-case refresh so one
|
||||
|
||||
@@ -156,9 +156,65 @@ export async function proxyMediaResponse(
|
||||
stream.on('error', () => {
|
||||
if (!res.writableEnded) res.end();
|
||||
});
|
||||
|
||||
// A live camera feed has no end of its own. When the viewer goes away the
|
||||
// upstream connection must go with it, or every abandoned view leaves a
|
||||
// stream open against the camera host for as long as that host will hold it.
|
||||
let released = false;
|
||||
const releaseUpstream = () => {
|
||||
if (released) return;
|
||||
released = true;
|
||||
stream.unpipe(res);
|
||||
// Destroying the Node stream cancels the web body it wraps; the direct
|
||||
// cancel covers a body that was never wrapped, and rejects harmlessly when
|
||||
// the reader is already held.
|
||||
stream.destroy();
|
||||
try {
|
||||
const cancelled = upstream.body?.cancel?.();
|
||||
if (typeof cancelled?.catch === 'function') cancelled.catch(() => {});
|
||||
} catch {
|
||||
/* already closed */
|
||||
}
|
||||
};
|
||||
res.once('close', () => {
|
||||
if (!res.writableEnded) releaseUpstream();
|
||||
});
|
||||
res.once('error', releaseUpstream);
|
||||
stream.once('end', () => {
|
||||
released = true;
|
||||
});
|
||||
stream.pipe(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Watch a client response for an early goodbye.
|
||||
*
|
||||
* Bound BEFORE the upstream request goes out, because most of the waiting
|
||||
* happens before any header comes back: a viewer who closes the tab while a
|
||||
* slow camera is still thinking would otherwise leave that request running with
|
||||
* nobody to receive it.
|
||||
*
|
||||
* @param {import('http').ServerResponse} res - The client response.
|
||||
* @returns {{signal: AbortSignal, closed: boolean}} `signal` cancels the
|
||||
* upstream request; `closed` says the client left before the response ended.
|
||||
*/
|
||||
export function watchDownstreamClose(res) {
|
||||
const controller = new AbortController();
|
||||
const state = {
|
||||
signal: controller.signal,
|
||||
closed: false,
|
||||
};
|
||||
const onClose = () => {
|
||||
// A response that ended normally also emits close; only an early one counts.
|
||||
if (res.writableEnded) return;
|
||||
state.closed = true;
|
||||
controller.abort();
|
||||
};
|
||||
res.once?.('close', onClose);
|
||||
res.once?.('error', onClose);
|
||||
return state;
|
||||
}
|
||||
|
||||
/** Read a snapshot incrementally, retaining at most maxBytes of owned chunks. */
|
||||
async function readCappedResponseBytes(upstream, maxBytes) {
|
||||
const declared = Number(upstream.headers.get('content-length'));
|
||||
@@ -229,14 +285,21 @@ export async function fetchCctvMediaUpstream(
|
||||
headers = {},
|
||||
fetchImpl = fetch,
|
||||
timeoutMs = CCTV_MEDIA_FETCH_TIMEOUT_MS,
|
||||
signal: downstream = null,
|
||||
} = {},
|
||||
) {
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
||||
// The client going away cancels the upstream request, not just the response
|
||||
// to it.
|
||||
const onDownstreamAbort = () => controller.abort();
|
||||
if (downstream?.aborted) controller.abort();
|
||||
else downstream?.addEventListener?.('abort', onDownstreamAbort);
|
||||
try {
|
||||
return await fetchImpl(url, { headers, signal: controller.signal });
|
||||
} finally {
|
||||
clearTimeout(timeoutId);
|
||||
downstream?.removeEventListener?.('abort', onDownstreamAbort);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -380,6 +380,17 @@ export function isLikelyNswCoordinate(lat, lon) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Calgary's municipal extent, with slack for the ring road. */
|
||||
export function isLikelyCalgaryCoordinate(lat, lon) {
|
||||
return (
|
||||
isPlausibleLatLon(lat, lon) &&
|
||||
lat >= 50.8 &&
|
||||
lat <= 51.25 &&
|
||||
lon >= -114.4 &&
|
||||
lon <= -113.8
|
||||
);
|
||||
}
|
||||
|
||||
export function isLikelyFinlandCoordinate(lat, lon) {
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return false;
|
||||
return lat >= 59.5 && lat <= 70.5 && lon >= 19 && lon <= 32;
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import { CCTV_MEDIA_MAX_BODY_BYTES } from './constants.js';
|
||||
|
||||
/** Digits allowed per Range position — bounds parse cost and absurd offsets. */
|
||||
const RANGE_MAX_DIGITS = 16;
|
||||
|
||||
/**
|
||||
* Validate, canonicalize and bound a client `Range` header before the media
|
||||
* route forwards it to a third-party camera host.
|
||||
*
|
||||
* The route used to copy `req.headers.range` through verbatim. Two things
|
||||
* follow from that. A multi-range value makes the upstream answer
|
||||
* `multipart/byteranges`: when that body declares its length the relay's
|
||||
* ceiling still applies to it, but the parts inside are the upstream's to
|
||||
* choose and nothing here reads them, and a multipart body sent without a
|
||||
* declared length streams through uncapped like any other length-less body.
|
||||
* And a value the outbound request refuses to carry — anything with CR or LF
|
||||
* in it — made `fetch` throw, and the route recorded that error text, which
|
||||
* contains the client's own string, as the camera's health message.
|
||||
*
|
||||
* Bounding the Range bounds what is ASKED FOR, not what arrives: an upstream
|
||||
* that ignores the Range and answers with a length-less chunked body still
|
||||
* streams without a ceiling. That is how live feeds are served and is not
|
||||
* changed here. What is bounded is the request's lifetime: it is cancelled when
|
||||
* the viewer goes away, before the headers arrive as well as during the body.
|
||||
*
|
||||
* Anything that is not a single well-formed `bytes=` range is DROPPED and the
|
||||
* request proceeds with no Range, which is what RFC 7233 §3.1 prescribes for a
|
||||
* Range a server cannot understand: the client gets the whole body rather than
|
||||
* an error it did not ask for. Accepted forms are `bytes=<first>-<last>`,
|
||||
* `bytes=<first>-` and `bytes=-<suffix>`.
|
||||
*
|
||||
* Every accepted form is bounded to {@link CCTV_MEDIA_MAX_BODY_BYTES}, the same
|
||||
* ceiling the relay applies to a declared response body — including the
|
||||
* open-ended and suffix forms, which otherwise ask an upstream for a whole file
|
||||
* of unknown size. A player that wants more than one bound's worth asks for the
|
||||
* next range, which is ordinary partial-content behavior.
|
||||
*
|
||||
* @param {*} value - Raw `req.headers.range`.
|
||||
* @param {number} [maxBytes] - Ceiling for the requested span.
|
||||
* @returns {string} Canonical `bytes=...` value, or '' to send no Range.
|
||||
*/
|
||||
export function sanitizeCctvRangeHeader(
|
||||
value,
|
||||
maxBytes = CCTV_MEDIA_MAX_BODY_BYTES,
|
||||
) {
|
||||
if (typeof value !== 'string') return '';
|
||||
const raw = value.trim();
|
||||
if (!raw) return '';
|
||||
|
||||
// The unit is case-insensitive (RFC 7233 §2.1) and `bytes` is the only one
|
||||
// this proxy understands. A comma anywhere fails this pattern, which is how
|
||||
// multi-range is refused.
|
||||
const match = /^bytes=(\d*)-(\d*)$/i.exec(raw);
|
||||
if (!match) return '';
|
||||
|
||||
const [, firstText, lastText] = match;
|
||||
if (firstText.length > RANGE_MAX_DIGITS || lastText.length > RANGE_MAX_DIGITS)
|
||||
return '';
|
||||
// "bytes=-" carries neither position and is meaningless.
|
||||
if (!firstText && !lastText) return '';
|
||||
|
||||
// Suffix form: the final N bytes. N === 0 is unsatisfiable by definition.
|
||||
if (!firstText) {
|
||||
const suffix = Number(lastText);
|
||||
if (!Number.isSafeInteger(suffix) || suffix <= 0) return '';
|
||||
return `bytes=-${Math.min(suffix, maxBytes)}`;
|
||||
}
|
||||
|
||||
const first = Number(firstText);
|
||||
if (!Number.isSafeInteger(first) || first < 0) return '';
|
||||
|
||||
const ceiling = first + maxBytes - 1;
|
||||
if (!Number.isSafeInteger(ceiling)) return '';
|
||||
|
||||
// Open-ended: everything from `first` on, bounded to one span.
|
||||
if (!lastText) return `bytes=${first}-${ceiling}`;
|
||||
|
||||
const last = Number(lastText);
|
||||
if (!Number.isSafeInteger(last) || last < first) return '';
|
||||
return `bytes=${first}-${Math.min(last, ceiling)}`;
|
||||
}
|
||||
@@ -50,6 +50,11 @@ import {
|
||||
DEFAULT_NSW_MAX_SOURCES,
|
||||
SYDNEY_CENTER,
|
||||
NSW_MAX_VIEW_LABEL,
|
||||
DEFAULT_CALGARY_ROWS_URL,
|
||||
CALGARY_IMAGE_ORIGIN,
|
||||
DEFAULT_CALGARY_MAX_SOURCES,
|
||||
CALGARY_DOWNTOWN,
|
||||
CALGARY_MAX_CATALOG_BYTES,
|
||||
CCTV_SOURCE_FETCH_TIMEOUT_MS,
|
||||
} from './constants.js';
|
||||
import {
|
||||
@@ -67,11 +72,13 @@ import {
|
||||
isLikelyBcCoordinate,
|
||||
isLikelyTexasCoordinate,
|
||||
isLikelyNswCoordinate,
|
||||
isLikelyCalgaryCoordinate,
|
||||
cameraDisplayCode,
|
||||
rowArrayToObject,
|
||||
prioritizeSources,
|
||||
} from './normalize.js';
|
||||
import { directionToHeading } from '../../../src/data/directionText.js';
|
||||
import { readResponseJsonCapped } from '../common/http.js';
|
||||
/**
|
||||
* Fetch and parse Austin traffic camera records from the city Open Data portal.
|
||||
*
|
||||
@@ -1389,3 +1396,201 @@ export async function loadNswSourcesFromOpenData() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade a catalog frame URL to HTTPS and pin it to the City of Calgary host.
|
||||
*
|
||||
* Most rows ship `http://`; the host answers HTTPS and 301-redirects there, so
|
||||
* upgrading avoids a redirect on every frame fetch. Anything not on the
|
||||
* official origin is refused rather than proxied, the same pin the TfL and
|
||||
* Tarktee packs apply.
|
||||
*
|
||||
* @param {string|null|undefined} raw - `camera_url.url` from the dataset.
|
||||
* @returns {?string} Pinned HTTPS URL, or null when unusable.
|
||||
*/
|
||||
export function normalizeCalgaryImageUrl(raw) {
|
||||
const text = String(raw ?? '').trim();
|
||||
if (!text) return null;
|
||||
let parsed;
|
||||
try {
|
||||
parsed = new URL(text);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return null;
|
||||
parsed.protocol = 'https:';
|
||||
const upgraded = parsed.toString();
|
||||
return upgraded.startsWith(CALGARY_IMAGE_ORIGIN) ? upgraded : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stable camera id from a frame URL.
|
||||
*
|
||||
* The dataset carries no id column; the frame filename ("loc86.jpg") is the
|
||||
* only stable per-camera token and is what the city keys on. Falls back to a
|
||||
* slug of the whole path so a filename-scheme change degrades to a still-stable
|
||||
* id rather than dropping the camera.
|
||||
*
|
||||
* @param {string} imageUrl - A normalized Calgary frame URL.
|
||||
* @returns {?string} Provider-stable id, or null when underivable.
|
||||
*/
|
||||
export function calgaryCameraId(imageUrl) {
|
||||
const text = String(imageUrl ?? '').trim();
|
||||
if (!text) return null;
|
||||
let path;
|
||||
try {
|
||||
path = new URL(text).pathname;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
const numbered = path.match(/loc(\d+)\.jpg$/i);
|
||||
if (numbered) return `calgary-${numbered[1]}`;
|
||||
const slug = path
|
||||
.replace(/^\/+|\.[a-z0-9]+$/gi, '')
|
||||
.replace(/[^a-zA-Z0-9]+/g, '-')
|
||||
.toLowerCase();
|
||||
return slug ? `calgary-${slug}` : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Label for one Calgary camera: the intersection an operator recognises
|
||||
* ("Bow Trail / 37 Street SW"), used verbatim including its quadrant suffix,
|
||||
* which is part of the street address. It must never be read as a facing.
|
||||
*
|
||||
* @param {object} record - Raw Socrata row.
|
||||
* @param {string} cameraId - Derived stable id.
|
||||
* @returns {string}
|
||||
*/
|
||||
export function calgaryCameraName(record, cameraId) {
|
||||
const location = String(record?.camera_location ?? '').trim();
|
||||
if (location) return location;
|
||||
const described = String(record?.camera_url?.description ?? '').trim();
|
||||
if (described) return described;
|
||||
return `Calgary Camera ${String(cameraId).replace(/^calgary-/, '')}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* One Open Calgary row -> one catalog source, or null.
|
||||
*
|
||||
* NO HEADING IS DERIVED FROM THE RECORD, and the fields that look like one are
|
||||
* not. Every row carries a `quadrant` ("NE"/"NW"/"SE"/"SW", and combinations
|
||||
* like "NW/NE") and a `camera_location` ending in the same token ("9 Avenue /
|
||||
* 3 Street SE"). That is Calgary's address grid — the quarter of the city the
|
||||
* intersection sits in — not a camera bearing. Handing either to
|
||||
* directionToHeading() returns a confident compass bearing for every row and
|
||||
* every one would be wrong. Headings therefore use the shared id-hash fallback
|
||||
* at low confidence, exactly as headingless TfL and Fintraffic cameras do, and
|
||||
* the operator corrects them with the calibration gizmo.
|
||||
*
|
||||
* @param {object} record - Raw Socrata row.
|
||||
* @returns {?object}
|
||||
*/
|
||||
export function calgaryCameraToSource(record) {
|
||||
if (!record || typeof record !== 'object') return null;
|
||||
const coordinates = record?.point?.coordinates;
|
||||
if (!Array.isArray(coordinates) || coordinates.length < 2) return null;
|
||||
const lon = toFiniteNumber(coordinates[0]);
|
||||
const lat = toFiniteNumber(coordinates[1]);
|
||||
if (!isLikelyCalgaryCoordinate(lat, lon)) return null;
|
||||
|
||||
const imageUrl = normalizeCalgaryImageUrl(record?.camera_url?.url);
|
||||
if (!imageUrl) return null;
|
||||
const cameraId = calgaryCameraId(imageUrl);
|
||||
if (!cameraId) return null;
|
||||
const name = calgaryCameraName(record, cameraId);
|
||||
|
||||
return {
|
||||
id: cameraId,
|
||||
name,
|
||||
city: 'Calgary',
|
||||
cityId: 'calgary',
|
||||
provider: 'The City of Calgary',
|
||||
lat,
|
||||
lon,
|
||||
headingDeg: fallbackHeadingFromId(cameraId),
|
||||
headingConfidence: 'low',
|
||||
pitchDeg: -18,
|
||||
fovDeg: 44,
|
||||
rangeM: 145,
|
||||
mountHeightM: 8,
|
||||
// Calgary sits high on the prairie; the client's one-shot ground snap
|
||||
// corrects this prior wherever 3D tiles are loaded.
|
||||
groundElevationM: 1045,
|
||||
feedType: 'image',
|
||||
url: imageUrl,
|
||||
snapshotUrl: imageUrl,
|
||||
sourceKind: 'calgary-open-data',
|
||||
license:
|
||||
'Contains information licensed under the Open Government Licence – City of Calgary',
|
||||
// Unselected-label code: the intersection, so a camera at rest reads as a
|
||||
// place rather than as its id.
|
||||
code: cameraDisplayCode(name.toUpperCase()),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch City of Calgary traffic cameras from Open Calgary (Socrata dataset
|
||||
* `k7p9-kppz`), keyless. Frames are stills on trafficcam.calgary.ca.
|
||||
*
|
||||
* @returns {Promise<Array<object>>} Normalized camera source objects.
|
||||
*/
|
||||
export async function loadCalgarySourcesFromOpenData() {
|
||||
try {
|
||||
const endpoint =
|
||||
process.env.CCTV_CALGARY_ROWS_URL || DEFAULT_CALGARY_ROWS_URL;
|
||||
const resp = await fetch(endpoint, {
|
||||
headers: { Accept: 'application/json' },
|
||||
redirect: 'manual',
|
||||
signal: AbortSignal.timeout(CCTV_SOURCE_FETCH_TIMEOUT_MS),
|
||||
});
|
||||
// A response this loader will not read still owns its transport until the
|
||||
// body is released, so every rejection path cancels before returning.
|
||||
const discard = async () => {
|
||||
try {
|
||||
await resp.body?.cancel();
|
||||
} catch {
|
||||
/* no-op */
|
||||
}
|
||||
return [];
|
||||
};
|
||||
if (resp.status >= 300 && resp.status < 400) {
|
||||
console.warn(
|
||||
'[CCTV] Calgary catalog redirected; redirects are not followed',
|
||||
);
|
||||
return discard();
|
||||
}
|
||||
if (!resp.ok) {
|
||||
console.warn('[CCTV] Calgary camera download failed:', resp.status);
|
||||
return discard();
|
||||
}
|
||||
const rows = await readResponseJsonCapped(resp, CALGARY_MAX_CATALOG_BYTES);
|
||||
if (!Array.isArray(rows)) return [];
|
||||
const cameras = [];
|
||||
const seen = new Set();
|
||||
for (const record of rows) {
|
||||
const camera = calgaryCameraToSource(record);
|
||||
if (!camera || seen.has(camera.id)) continue;
|
||||
seen.add(camera.id);
|
||||
cameras.push(camera);
|
||||
}
|
||||
const maxRaw = Number(
|
||||
process.env.CCTV_CALGARY_MAX_SOURCES || DEFAULT_CALGARY_MAX_SOURCES,
|
||||
);
|
||||
const maxCount = Number.isFinite(maxRaw)
|
||||
? Math.max(8, Math.min(400, Math.floor(maxRaw)))
|
||||
: DEFAULT_CALGARY_MAX_SOURCES;
|
||||
const prioritized = prioritizeSources(cameras, maxCount, [
|
||||
CALGARY_DOWNTOWN,
|
||||
]);
|
||||
console.log(
|
||||
`[CCTV] Loaded Calgary camera sources: ${cameras.length} (using nearest ${prioritized.length})`,
|
||||
);
|
||||
return prioritized;
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'[CCTV] Calgary camera download error:',
|
||||
error?.message || error,
|
||||
);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { defaultGeospatial } from '../search/defaults.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { holdContinuousRender, releaseContinuousRender } from '../renderGovernor.js';
|
||||
import { isRateLimitedOutcome, resolveAnnotationTarget } from './annotationResolver.js';
|
||||
import { isRateLimitedOutcome, resolveAnnotationTarget, sampleGroundHeight } from './annotationResolver.js';
|
||||
import { ringCentroid } from './drawMode.js';
|
||||
|
||||
// Dev convenience: expose the app's Cesium instance for console/preview probing
|
||||
// (single shared module instance — avoids dual-Cesium state bugs when testing).
|
||||
@@ -387,6 +388,9 @@ export function createAnnotationEngine({
|
||||
|
||||
async function resolveSpec(spec, signal, allowDistant = false) {
|
||||
const type = normalizeType(spec?.type);
|
||||
// MANUAL geometry (drawTool.js): the person clicked the vertices, so there is
|
||||
// nothing to resolve. Same record shapes as a resolved spec, source 'manual'.
|
||||
if (isManualSpec(spec, type)) return resolveManualSpec(spec, type, viewer);
|
||||
if (type === 'route') {
|
||||
const points = Array.isArray(spec.points) ? spec.points : [];
|
||||
if (points.length < 2) throw new Error('a route needs at least 2 waypoints');
|
||||
@@ -1103,6 +1107,67 @@ function round5(n) {
|
||||
return Number.isFinite(n) ? Math.round(n * 1e5) / 1e5 : null;
|
||||
}
|
||||
|
||||
/** A spec whose geometry was supplied by hand (drawTool.js) rather than by a name. */
|
||||
function isManualSpec(spec, type) {
|
||||
if (!spec || spec.manual !== true) return false;
|
||||
if (type === 'route') return Array.isArray(spec.path) && spec.path.length >= 2;
|
||||
if (type === 'area') return Array.isArray(spec.ring) && spec.ring.length >= 3;
|
||||
return Number.isFinite(Number(spec.latitude)) && Number.isFinite(Number(spec.longitude));
|
||||
}
|
||||
|
||||
/** [lon, lat] pairs or {lon, lat} objects → [lon, lat] pairs, invalid entries dropped. */
|
||||
function manualPairs(list) {
|
||||
return (Array.isArray(list) ? list : [])
|
||||
.map((p) => (Array.isArray(p) ? [Number(p[0]), Number(p[1])] : [Number(p?.lon ?? p?.longitude), Number(p?.lat ?? p?.latitude)]))
|
||||
.filter(([lon, lat]) => Number.isFinite(lon) && Number.isFinite(lat) && Math.abs(lat) <= 90 && Math.abs(lon) <= 180);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a hand-drawn spec without any fetch. An area keeps its ring as a real
|
||||
* (not synthesized) outline so it drapes solid; a line is a `route` with mode
|
||||
* 'manual', its length as distance and no travel time; a pin is a point.
|
||||
*/
|
||||
function resolveManualSpec(spec, type, viewer) {
|
||||
if (type === 'route') {
|
||||
// height 0 is a placeholder, not a placement: the world renderer draws a
|
||||
// route with clampToGround + CESIUM_3D_TILE classification, so the line is
|
||||
// draped onto the photoreal surface whatever this number says.
|
||||
const pts = manualPairs(spec.path).map(([lon, lat]) => ({ lon, lat, height: 0 }));
|
||||
if (pts.length < 2) throw new Error('a drawn line needs at least 2 points');
|
||||
let distanceM = 0;
|
||||
for (let i = 1; i < pts.length; i += 1) distanceM += greatCircleM(pts[i - 1], pts[i]);
|
||||
return { path: pts, distanceM, durationS: null, mode: 'manual', source: 'manual', fallback: false };
|
||||
}
|
||||
if (type === 'area') {
|
||||
const ring = manualPairs(spec.ring);
|
||||
if (ring.length < 3) throw new Error('a drawn area needs at least 3 points');
|
||||
// Averaged through ringCentroid, which unwraps longitudes first: a ring
|
||||
// straddling the antimeridian has coordinates like [179.999, -179.999], and
|
||||
// a raw mean of those puts the anchor on the Greenwich meridian, half a
|
||||
// world from the shape it belongs to. A repeated closing vertex is dropped
|
||||
// so it does not weight its own corner twice.
|
||||
const distinct = closedRingWithoutRepeat(ring);
|
||||
const centre = ringCentroid(distinct.map(([lon, lat]) => ({ lon, lat })));
|
||||
const lon = centre.lon;
|
||||
const lat = centre.lat;
|
||||
return {
|
||||
lon, lat, height: sampleGroundHeight(viewer, lon, lat),
|
||||
ring, footprintKind: 'area', buildingHeight: null, synthesized: false, source: 'manual',
|
||||
};
|
||||
}
|
||||
const lon = Number(spec.longitude);
|
||||
const lat = Number(spec.latitude);
|
||||
return { lon, lat, height: sampleGroundHeight(viewer, lon, lat), ring: null, source: 'manual' };
|
||||
}
|
||||
|
||||
/** The ring's distinct positions: a closing vertex that repeats the first is dropped. */
|
||||
function closedRingWithoutRepeat(ring) {
|
||||
if (ring.length < 2) return ring;
|
||||
const [firstLon, firstLat] = ring[0];
|
||||
const [lastLon, lastLat] = ring[ring.length - 1];
|
||||
return firstLon === lastLon && firstLat === lastLat ? ring.slice(0, -1) : ring;
|
||||
}
|
||||
|
||||
function normalizeMode(m) {
|
||||
const t = String(m || '').toLowerCase();
|
||||
if (t === 'car' || t === 'drive' || t === 'driving') return 'car';
|
||||
@@ -1138,6 +1203,7 @@ function composeRouteLabel(baseLabel, distM, durS, mode, fallback) {
|
||||
if (!dist) return baseLabel;
|
||||
const min = Number.isFinite(durS) ? Math.max(1, Math.round(durS / 60)) : null;
|
||||
const word = mode === 'car' ? 'drive' : mode === 'bike' ? 'ride' : 'walk';
|
||||
if (mode === 'manual') return baseLabel ? `${baseLabel} — ${dist}` : dist;
|
||||
// Fallback = routing was unavailable, so we drew a straight line: label it as a
|
||||
// direct line with no travel time (never claim an "X min walk" we didn't compute).
|
||||
let metrics;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createAnnotationResolver } from './resolver.js';
|
||||
import { applicationServices } from '../services/application.js';
|
||||
const resolver = createAnnotationResolver({ boundarySource: applicationServices.boundaries });
|
||||
export const { resolveAnnotationTarget, refineScope, isRateLimitedOutcome, isGroundsLikeAsk, selectFootprint, viewportBias, placesNearViewRecovery, resolveRegionRingForQuery } = resolver;
|
||||
export const { resolveAnnotationTarget, refineScope, isRateLimitedOutcome, isGroundsLikeAsk, selectFootprint, viewportBias, placesNearViewRecovery, resolveRegionRingForQuery, pickWorldFromScreen, sampleGroundHeight } = resolver;
|
||||
@@ -0,0 +1,303 @@
|
||||
/**
|
||||
* Manual whiteboard drawing: the pure half.
|
||||
*
|
||||
* The voice whiteboard resolves NAMES to geometry. This module is for the other
|
||||
* way in: a person clicks the vertices themselves. It holds a draw session (the
|
||||
* shape being drawn and its vertices), decides when a shape is finishable, and
|
||||
* turns a finished session into the SAME annotation spec the engine already
|
||||
* accepts (`type: area | route | pin`, geometry supplied, `manual: true`), so a
|
||||
* hand-drawn mark renders, persists, de-dups and clears exactly like a spoken
|
||||
* one.
|
||||
*
|
||||
* A vertex is a lon/lat and nothing more. The world renderer drapes every mark
|
||||
* onto the photoreal surface (`clampToGround` + `CESIUM_3D_TILE`), so there is
|
||||
* no such thing as a vertex at a height here: the height under the click is
|
||||
* used for the live preview and is deliberately dropped at finish.
|
||||
*
|
||||
* No Cesium, no DOM — importable under `node --test`. The Cesium/DOM half is
|
||||
* `drawTool.js`.
|
||||
*/
|
||||
|
||||
export const DRAW_SHAPES = Object.freeze(['area', 'line', 'pin']);
|
||||
export const MIN_VERTICES = Object.freeze({ area: 3, line: 2, pin: 1 });
|
||||
/**
|
||||
* Hard ceiling on vertices in one shape. Every vertex is a live preview entity
|
||||
* and a position in the finished geometry, so a stuck mouse button or a script
|
||||
* must not be able to grow one shape without limit.
|
||||
*/
|
||||
export const MAX_VERTICES = 512;
|
||||
/** Two clicks closer than this are one vertex: a double-click to finish must not add a stray point. */
|
||||
export const MIN_VERTEX_SEPARATION_M = 0.5;
|
||||
/** A line shorter than this, or an area thinner than this, is a mis-click rather than a shape. */
|
||||
export const MIN_PATH_LENGTH_M = 1;
|
||||
export const MIN_AREA_M2 = 1;
|
||||
|
||||
/** @param {string} shape @returns {'area'|'line'|'pin'} */
|
||||
export function normalizeShape(shape) {
|
||||
const s = String(shape || '').toLowerCase();
|
||||
if (s === 'line' || s === 'path' || s === 'route') return 'line';
|
||||
if (s === 'pin' || s === 'point' || s === 'marker') return 'pin';
|
||||
return 'area';
|
||||
}
|
||||
|
||||
/** @param {string} [shape] @returns {{shape: 'area'|'line'|'pin', vertices: Array<{lon:number, lat:number, height?:number}>}} */
|
||||
export function createDrawSession(shape = 'area') {
|
||||
return { shape: normalizeShape(shape), vertices: [] };
|
||||
}
|
||||
|
||||
/** Great-circle distance in metres between two {lon, lat} points. */
|
||||
export function greatCircleM(a, b) {
|
||||
const R = 6371000;
|
||||
const toRad = (d) => (d * Math.PI) / 180;
|
||||
const dLat = toRad(b.lat - a.lat);
|
||||
const dLon = toRad(b.lon - a.lon);
|
||||
const h =
|
||||
Math.sin(dLat / 2) ** 2 +
|
||||
Math.cos(toRad(a.lat)) * Math.cos(toRad(b.lat)) * Math.sin(dLon / 2) ** 2;
|
||||
return 2 * R * Math.asin(Math.sqrt(Math.min(1, h)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vertex. A vertex that is not a finite lon/lat is refused; one within
|
||||
* MIN_VERTEX_SEPARATION_M of the previous vertex is treated as the same click
|
||||
* (the second half of a double-click) and refused as a duplicate. A pin holds
|
||||
* exactly one vertex: a later click moves it.
|
||||
* @returns {{added: boolean, reason?: 'invalid'|'duplicate'}}
|
||||
*/
|
||||
export function addVertex(
|
||||
session,
|
||||
vertex,
|
||||
{ minSeparationM = MIN_VERTEX_SEPARATION_M } = {},
|
||||
) {
|
||||
if (!session || !isFiniteCoordinate(vertex))
|
||||
return { added: false, reason: 'invalid' };
|
||||
const v = {
|
||||
lon: vertex.lon,
|
||||
lat: vertex.lat,
|
||||
height: Number.isFinite(vertex.height) ? vertex.height : 0,
|
||||
};
|
||||
if (session.shape === 'pin') {
|
||||
session.vertices = [v];
|
||||
return { added: true };
|
||||
}
|
||||
if (session.vertices.length >= MAX_VERTICES)
|
||||
return { added: false, reason: 'full' };
|
||||
const last = session.vertices[session.vertices.length - 1];
|
||||
if (last && greatCircleM(last, v) < minSeparationM)
|
||||
return { added: false, reason: 'duplicate' };
|
||||
session.vertices.push(v);
|
||||
return { added: true };
|
||||
}
|
||||
|
||||
/** A usable click position: finite, and on the globe rather than past its edges. */
|
||||
export function isFiniteCoordinate(vertex) {
|
||||
if (!vertex) return false;
|
||||
const { lon, lat } = vertex;
|
||||
return (
|
||||
Number.isFinite(lon) &&
|
||||
Number.isFinite(lat) &&
|
||||
Math.abs(lon) <= 180 &&
|
||||
Math.abs(lat) <= 90
|
||||
);
|
||||
}
|
||||
|
||||
/** Remove the last vertex. @returns {boolean} whether one was removed */
|
||||
export function removeLastVertex(session) {
|
||||
if (!session?.vertices?.length) return false;
|
||||
session.vertices.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Why a session can or cannot become an annotation.
|
||||
* - `too-few`: not enough vertices yet.
|
||||
* - `degenerate`: enough vertices, but they describe nothing — three collinear
|
||||
* points enclose no area, and a line that doubles back on itself has no
|
||||
* length. Drawing one of those and calling it a mark would put an invisible
|
||||
* entity on the board that the person cannot see, select or explain.
|
||||
* @returns {'ok'|'too-few'|'degenerate'|'invalid'}
|
||||
*/
|
||||
export function finishReason(session) {
|
||||
if (!session || !Array.isArray(session.vertices)) return 'invalid';
|
||||
if (session.vertices.some((vertex) => !isFiniteCoordinate(vertex)))
|
||||
return 'invalid';
|
||||
if (session.vertices.length < (MIN_VERTICES[session.shape] || 1))
|
||||
return 'too-few';
|
||||
if (
|
||||
session.shape === 'line' &&
|
||||
pathLengthM(session.vertices) < MIN_PATH_LENGTH_M
|
||||
)
|
||||
return 'degenerate';
|
||||
if (session.shape === 'area' && ringAreaM2(session.vertices) < MIN_AREA_M2)
|
||||
return 'degenerate';
|
||||
return 'ok';
|
||||
}
|
||||
|
||||
/** @returns {boolean} whether the session can become an annotation right now */
|
||||
export function canFinish(session) {
|
||||
return finishReason(session) === 'ok';
|
||||
}
|
||||
|
||||
/** Length of an open path in metres. */
|
||||
export function pathLengthM(vertices) {
|
||||
let m = 0;
|
||||
for (let i = 1; i < (vertices?.length || 0); i += 1)
|
||||
m += greatCircleM(vertices[i - 1], vertices[i]);
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* The same vertices with longitudes made CONTINUOUS relative to the first one,
|
||||
* so planar maths does not tear at the antimeridian. A small shape straddling
|
||||
* 180° has longitudes like [179.999, -179.999]; subtracting those raw gives
|
||||
* 359.998° of width instead of 0.002°, which is how a 25,000 m² rectangle
|
||||
* measured 4,461 km² and reported its centre on the Greenwich meridian.
|
||||
*
|
||||
* Values may leave the [-180, 180] range on purpose — that is what "continuous"
|
||||
* means. Re-wrap with `wrapLongitude` before handing one back as a coordinate.
|
||||
* @param {Array<{lon:number, lat:number}>} vertices
|
||||
*/
|
||||
export function unwrapLongitudes(vertices) {
|
||||
if (!vertices?.length) return [];
|
||||
const reference = vertices[0].lon;
|
||||
return vertices.map((vertex) => {
|
||||
let lon = vertex.lon;
|
||||
while (lon - reference > 180) lon -= 360;
|
||||
while (lon - reference < -180) lon += 360;
|
||||
return { ...vertex, lon };
|
||||
});
|
||||
}
|
||||
|
||||
/** A continuous longitude brought back into [-180, 180]. */
|
||||
export function wrapLongitude(lon) {
|
||||
if (!Number.isFinite(lon)) return lon;
|
||||
// A value already in range is returned UNCHANGED rather than pushed through
|
||||
// the modulo, which is only exact in binary for some inputs: 0.0005 came back
|
||||
// as 0.0004999999999881766. The seam is the only place the arithmetic is
|
||||
// needed, so it is the only place that pays for it.
|
||||
if (lon >= -180 && lon < 180) return lon;
|
||||
const value = ((((lon + 180) % 360) + 360) % 360) - 180;
|
||||
return Object.is(value, -0) ? 0 : value;
|
||||
}
|
||||
|
||||
/** Planar shoelace area of a ring in square metres (local metre grid; fine at whiteboard scale). */
|
||||
export function ringAreaM2(vertices) {
|
||||
if (!vertices || vertices.length < 3) return 0;
|
||||
const ring = unwrapLongitudes(vertices);
|
||||
const lat0 = ring.reduce((s, v) => s + v.lat, 0) / ring.length;
|
||||
const kx = 111320 * Math.cos((lat0 * Math.PI) / 180);
|
||||
const ky = 111320;
|
||||
let twice = 0;
|
||||
for (let i = 0; i < ring.length; i += 1) {
|
||||
const a = ring[i];
|
||||
const b = ring[(i + 1) % ring.length];
|
||||
twice += a.lon * kx * (b.lat * ky) - b.lon * kx * (a.lat * ky);
|
||||
}
|
||||
return Math.abs(twice) / 2;
|
||||
}
|
||||
|
||||
/** Vertex-average centroid of a ring, {lon, lat}, safe across the antimeridian. */
|
||||
export function ringCentroid(vertices) {
|
||||
if (!vertices?.length) return null;
|
||||
const ring = unwrapLongitudes(vertices);
|
||||
return {
|
||||
lon: wrapLongitude(ring.reduce((s, v) => s + v.lon, 0) / ring.length),
|
||||
lat: ring.reduce((s, v) => s + v.lat, 0) / ring.length,
|
||||
};
|
||||
}
|
||||
|
||||
/** Distance or area, formatted for a label suffix. */
|
||||
export function formatMeasure(session) {
|
||||
if (!session) return '';
|
||||
if (session.shape === 'line') {
|
||||
const m = pathLengthM(session.vertices);
|
||||
return m >= 1000
|
||||
? `${(m / 1000).toFixed(m >= 10000 ? 0 : 1)} km`
|
||||
: `${Math.round(m)} m`;
|
||||
}
|
||||
if (session.shape === 'area') {
|
||||
const m2 = ringAreaM2(session.vertices);
|
||||
if (m2 >= 1e6) return `${(m2 / 1e6).toFixed(2)} km²`;
|
||||
if (m2 >= 1e4) return `${(m2 / 1e4).toFixed(1)} ha`;
|
||||
return `${Math.round(m2)} m²`;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* The annotation spec for a finished session, in the shape `annotationEngine.annotate()`
|
||||
* takes. Null when the session cannot finish. Geometry is supplied outright and
|
||||
* `manual: true` tells the engine to skip name resolution.
|
||||
*
|
||||
* The per-vertex height from the click is dropped here, deliberately and in one
|
||||
* place: the world renderer drapes areas and routes onto the photoreal surface,
|
||||
* so a height carried this far would be discarded further downstream instead,
|
||||
* silently. What the person gets is the outline they drew, lying on the
|
||||
* surface under it.
|
||||
* @param {object} session
|
||||
* @param {{label?: string, color?: string}} [opts]
|
||||
*/
|
||||
export function finishSpec(session, { label = '', color = 'primary' } = {}) {
|
||||
if (!canFinish(session)) return null;
|
||||
const text = String(label || '').trim();
|
||||
const pts = session.vertices.map((v) => [v.lon, v.lat]);
|
||||
if (session.shape === 'area') {
|
||||
// CLOSED explicitly. A polygon fill closes itself, but the outline beside it
|
||||
// is a polyline, and an open ring draws every edge except the one back to
|
||||
// the first vertex — the shape reads as a shape with one side missing.
|
||||
return {
|
||||
type: 'area',
|
||||
manual: true,
|
||||
ring: closeRing(pts),
|
||||
label: text || null,
|
||||
color,
|
||||
};
|
||||
}
|
||||
if (session.shape === 'line') {
|
||||
return {
|
||||
type: 'route',
|
||||
manual: true,
|
||||
path: pts,
|
||||
label: text || null,
|
||||
color,
|
||||
};
|
||||
}
|
||||
const [lon, lat] = pts[0];
|
||||
return {
|
||||
type: 'pin',
|
||||
manual: true,
|
||||
latitude: lat,
|
||||
longitude: lon,
|
||||
label: text || null,
|
||||
color,
|
||||
};
|
||||
}
|
||||
|
||||
/** A ring whose last position repeats its first, so an outline has no gap. */
|
||||
export function closeRing(pairs) {
|
||||
if (!Array.isArray(pairs) || pairs.length < 3) return pairs;
|
||||
const [firstLon, firstLat] = pairs[0];
|
||||
const [lastLon, lastLat] = pairs[pairs.length - 1];
|
||||
if (firstLon === lastLon && firstLat === lastLat) return pairs;
|
||||
return [...pairs, [firstLon, firstLat]];
|
||||
}
|
||||
|
||||
/** One line of guidance for the person drawing, by state. */
|
||||
export function drawHint(session) {
|
||||
if (!session) return 'Pick a shape, then click the map.';
|
||||
const n = session.vertices.length;
|
||||
if (session.shape === 'pin')
|
||||
return n
|
||||
? 'Enter to place the pin, Esc to cancel.'
|
||||
: 'Click where the pin goes.';
|
||||
const need = MIN_VERTICES[session.shape] - n;
|
||||
if (need > 0) return `Click ${need} more point${need === 1 ? '' : 's'}.`;
|
||||
if (finishReason(session) === 'degenerate') {
|
||||
return session.shape === 'area'
|
||||
? 'Those points are in a line — move one off it to enclose an area.'
|
||||
: 'That line has no length — click somewhere further away.';
|
||||
}
|
||||
const full =
|
||||
n >= MAX_VERTICES ? ` · ${MAX_VERTICES}-point limit reached` : '';
|
||||
return `${formatMeasure(session)} · double-click or Enter to finish, Backspace undoes, Esc cancels.${full}`;
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
// Pure tests for the manual draw session. Run with: npm test (node --test). No Cesium, no DOM.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
createDrawSession,
|
||||
addVertex,
|
||||
removeLastVertex,
|
||||
canFinish,
|
||||
finishSpec,
|
||||
normalizeShape,
|
||||
pathLengthM,
|
||||
ringAreaM2,
|
||||
ringCentroid,
|
||||
formatMeasure,
|
||||
drawHint,
|
||||
finishReason,
|
||||
isFiniteCoordinate,
|
||||
closeRing,
|
||||
unwrapLongitudes,
|
||||
wrapLongitude,
|
||||
MAX_VERTICES,
|
||||
MIN_VERTICES,
|
||||
} from './drawMode.js';
|
||||
|
||||
test('shapes normalize to area, line or pin, and unknown words fall back to area', () => {
|
||||
assert.equal(normalizeShape('route'), 'line');
|
||||
assert.equal(normalizeShape('marker'), 'pin');
|
||||
assert.equal(normalizeShape('polygon'), 'area');
|
||||
assert.equal(normalizeShape(undefined), 'area');
|
||||
});
|
||||
|
||||
test('an area needs three vertices, a line two, a pin one', () => {
|
||||
const area = createDrawSession('area');
|
||||
addVertex(area, { lon: -97.74, lat: 30.27 });
|
||||
addVertex(area, { lon: -97.73, lat: 30.27 });
|
||||
assert.equal(canFinish(area), false);
|
||||
addVertex(area, { lon: -97.73, lat: 30.28 });
|
||||
assert.equal(canFinish(area), true);
|
||||
assert.equal(MIN_VERTICES.line, 2);
|
||||
assert.equal(MIN_VERTICES.pin, 1);
|
||||
});
|
||||
|
||||
test('a second click within half a metre is the tail of a double-click, not a vertex', () => {
|
||||
const line = createDrawSession('line');
|
||||
assert.deepEqual(addVertex(line, { lon: 0, lat: 0 }), { added: true });
|
||||
assert.deepEqual(addVertex(line, { lon: 0.000001, lat: 0 }), {
|
||||
added: false,
|
||||
reason: 'duplicate',
|
||||
});
|
||||
assert.deepEqual(addVertex(line, { lon: 'x', lat: 0 }), {
|
||||
added: false,
|
||||
reason: 'invalid',
|
||||
});
|
||||
assert.equal(line.vertices.length, 1);
|
||||
});
|
||||
|
||||
test('a pin keeps exactly one vertex: a later click moves it', () => {
|
||||
const pin = createDrawSession('pin');
|
||||
addVertex(pin, { lon: 1, lat: 1 });
|
||||
addVertex(pin, { lon: 2, lat: 2 });
|
||||
assert.equal(pin.vertices.length, 1);
|
||||
assert.deepEqual(pin.vertices[0], { lon: 2, lat: 2, height: 0 });
|
||||
});
|
||||
|
||||
test('backspace removes the last vertex and reports whether it did', () => {
|
||||
const s = createDrawSession('line');
|
||||
assert.equal(removeLastVertex(s), false);
|
||||
addVertex(s, { lon: 0, lat: 0 });
|
||||
assert.equal(removeLastVertex(s), true);
|
||||
assert.equal(s.vertices.length, 0);
|
||||
});
|
||||
|
||||
test('finishSpec yields the engine spec shapes with manual geometry, or null when unfinished', () => {
|
||||
const area = createDrawSession('area');
|
||||
assert.equal(finishSpec(area), null);
|
||||
[
|
||||
[-97.74, 30.27],
|
||||
[-97.73, 30.27],
|
||||
[-97.73, 30.28],
|
||||
].forEach(([lon, lat]) => addVertex(area, { lon, lat }));
|
||||
assert.deepEqual(finishSpec(area, { label: ' Zilker ', color: 'amber' }), {
|
||||
type: 'area',
|
||||
manual: true,
|
||||
// CLOSED: the last position repeats the first so the outline polyline
|
||||
// draws all three sides of the triangle, not two.
|
||||
ring: [
|
||||
[-97.74, 30.27],
|
||||
[-97.73, 30.27],
|
||||
[-97.73, 30.28],
|
||||
[-97.74, 30.27],
|
||||
],
|
||||
label: 'Zilker',
|
||||
color: 'amber',
|
||||
});
|
||||
const line = createDrawSession('line');
|
||||
addVertex(line, { lon: 0, lat: 0 });
|
||||
addVertex(line, { lon: 0.01, lat: 0 });
|
||||
assert.deepEqual(finishSpec(line), {
|
||||
type: 'route',
|
||||
manual: true,
|
||||
path: [
|
||||
[0, 0],
|
||||
[0.01, 0],
|
||||
],
|
||||
label: null,
|
||||
color: 'primary',
|
||||
});
|
||||
const pin = createDrawSession('pin');
|
||||
addVertex(pin, { lon: 151.2, lat: -33.9 });
|
||||
assert.deepEqual(finishSpec(pin, { label: 'A shed' }), {
|
||||
type: 'pin',
|
||||
manual: true,
|
||||
latitude: -33.9,
|
||||
longitude: 151.2,
|
||||
label: 'A shed',
|
||||
color: 'primary',
|
||||
});
|
||||
});
|
||||
|
||||
test('length and area come out in metres on a local grid', () => {
|
||||
const km = pathLengthM([
|
||||
{ lon: 0, lat: 0 },
|
||||
{ lon: 0, lat: 0.009 },
|
||||
]);
|
||||
assert.ok(km > 990 && km < 1010, `1 km of latitude, got ${km}`);
|
||||
const square = [
|
||||
{ lon: 0, lat: 0 },
|
||||
{ lon: 0.001, lat: 0 },
|
||||
{ lon: 0.001, lat: 0.001 },
|
||||
{ lon: 0, lat: 0.001 },
|
||||
];
|
||||
const m2 = ringAreaM2(square);
|
||||
assert.ok(m2 > 12000 && m2 < 12800, `~111 m square, got ${m2}`);
|
||||
assert.deepEqual(ringCentroid(square), { lon: 0.0005, lat: 0.0005 });
|
||||
});
|
||||
|
||||
test('the measure and the hint follow the shape and the vertex count', () => {
|
||||
const area = createDrawSession('area');
|
||||
assert.equal(drawHint(area), 'Click 3 more points.');
|
||||
[
|
||||
{ lon: 0, lat: 0 },
|
||||
{ lon: 0.01, lat: 0 },
|
||||
{ lon: 0.01, lat: 0.01 },
|
||||
].forEach((v) => addVertex(area, v));
|
||||
assert.match(formatMeasure(area), /ha$|km²$|m²$/);
|
||||
assert.match(drawHint(area), /double-click or Enter to finish/);
|
||||
const pin = createDrawSession('pin');
|
||||
assert.equal(drawHint(pin), 'Click where the pin goes.');
|
||||
assert.equal(drawHint(null), 'Pick a shape, then click the map.');
|
||||
});
|
||||
|
||||
test('a vertex must be a finite coordinate on the globe', () => {
|
||||
assert.equal(isFiniteCoordinate({ lon: 12, lat: -4 }), true);
|
||||
assert.equal(isFiniteCoordinate({ lon: 0, lat: 90 }), true);
|
||||
for (const bad of [
|
||||
null,
|
||||
{},
|
||||
{ lon: NaN, lat: 0 },
|
||||
{ lon: 0, lat: Infinity },
|
||||
{ lon: 181, lat: 0 },
|
||||
{ lon: 0, lat: -90.5 },
|
||||
{ lon: '10', lat: 10 },
|
||||
]) {
|
||||
assert.equal(isFiniteCoordinate(bad), false, JSON.stringify(bad));
|
||||
}
|
||||
const line = createDrawSession('line');
|
||||
assert.deepEqual(addVertex(line, { lon: 200, lat: 0 }), {
|
||||
added: false,
|
||||
reason: 'invalid',
|
||||
});
|
||||
assert.equal(line.vertices.length, 0);
|
||||
});
|
||||
|
||||
test('one shape holds at most MAX_VERTICES points', () => {
|
||||
const line = createDrawSession('line');
|
||||
for (let i = 0; i < MAX_VERTICES + 25; i += 1)
|
||||
addVertex(line, { lon: i * 0.001, lat: 0 });
|
||||
assert.equal(line.vertices.length, MAX_VERTICES);
|
||||
assert.deepEqual(addVertex(line, { lon: 99, lat: 1 }), {
|
||||
added: false,
|
||||
reason: 'full',
|
||||
});
|
||||
assert.match(drawHint(line), /512-point limit reached/);
|
||||
|
||||
// A pin replaces its one vertex forever: the ceiling cannot strand it.
|
||||
const pin = createDrawSession('pin');
|
||||
for (let i = 0; i < MAX_VERTICES + 5; i += 1)
|
||||
assert.equal(addVertex(pin, { lon: i * 0.01, lat: 0 }).added, true);
|
||||
assert.equal(pin.vertices.length, 1);
|
||||
});
|
||||
|
||||
test('a shape that encloses nothing is refused, with a reason', () => {
|
||||
// Three points on one meridian are not an area.
|
||||
const collinear = createDrawSession('area');
|
||||
for (const lat of [0, 0.001, 0.002]) addVertex(collinear, { lon: 0, lat });
|
||||
assert.equal(collinear.vertices.length, 3);
|
||||
assert.equal(finishReason(collinear), 'degenerate');
|
||||
assert.equal(canFinish(collinear), false);
|
||||
assert.equal(finishSpec(collinear), null);
|
||||
assert.match(drawHint(collinear), /in a line/);
|
||||
|
||||
// Moving one point off that line makes it a shape again.
|
||||
collinear.vertices[2].lon = 0.001;
|
||||
assert.equal(finishReason(collinear), 'ok');
|
||||
assert.ok(finishSpec(collinear));
|
||||
|
||||
// A line whose two ends are a handful of centimetres apart has no length.
|
||||
const stub = createDrawSession('line');
|
||||
addVertex(stub, { lon: 0, lat: 0 });
|
||||
addVertex(stub, { lon: 0.000007, lat: 0 }, { minSeparationM: 0.01 });
|
||||
assert.equal(stub.vertices.length, 2);
|
||||
assert.equal(finishReason(stub), 'degenerate');
|
||||
assert.equal(finishSpec(stub), null);
|
||||
assert.match(drawHint(stub), /no length/);
|
||||
|
||||
// And the states in between are named, not lumped together.
|
||||
assert.equal(finishReason(createDrawSession('area')), 'too-few');
|
||||
assert.equal(finishReason(null), 'invalid');
|
||||
});
|
||||
|
||||
test('a finished area is a CLOSED ring, so its outline has no missing side', () => {
|
||||
const area = createDrawSession('area');
|
||||
for (const [lon, lat] of [
|
||||
[-97.74, 30.27],
|
||||
[-97.73, 30.27],
|
||||
[-97.73, 30.28],
|
||||
])
|
||||
addVertex(area, { lon, lat });
|
||||
|
||||
const spec = finishSpec(area);
|
||||
assert.equal(
|
||||
spec.ring.length,
|
||||
4,
|
||||
'three clicked vertices become four ring positions',
|
||||
);
|
||||
assert.deepEqual(
|
||||
spec.ring.at(-1),
|
||||
spec.ring[0],
|
||||
'the last position repeats the first',
|
||||
);
|
||||
// The renderer draws the outline as a polyline over exactly these positions:
|
||||
// an open ring would draw two of the triangle's three sides.
|
||||
assert.equal(spec.ring.length - 1, area.vertices.length);
|
||||
|
||||
// A line is NOT closed — it is a path, and joining its ends would invent a
|
||||
// segment the person never drew.
|
||||
const line = createDrawSession('line');
|
||||
addVertex(line, { lon: 0, lat: 0 });
|
||||
addVertex(line, { lon: 0.01, lat: 0 });
|
||||
assert.equal(finishSpec(line).path.length, 2);
|
||||
|
||||
// closeRing is idempotent: finishing an already-closed ring adds nothing.
|
||||
const closed = closeRing([
|
||||
[0, 0],
|
||||
[1, 0],
|
||||
[1, 1],
|
||||
[0, 0],
|
||||
]);
|
||||
assert.equal(closed.length, 4);
|
||||
});
|
||||
|
||||
test('a shape straddling the antimeridian measures what it looks like', () => {
|
||||
// 0.002 degrees square at the equator — about 223 m a side, so ~49,600 m2 —
|
||||
// sitting across 180. Raw longitude arithmetic reads that 0.002-degree width
|
||||
// as 359.998 degrees: the area came out in the thousands of square
|
||||
// kilometres and the centroid landed on the Greenwich meridian, half a world
|
||||
// from the shape it belongs to.
|
||||
const rectangle = [
|
||||
{ lon: 179.999, lat: -0.001 },
|
||||
{ lon: -179.999, lat: -0.001 },
|
||||
{ lon: -179.999, lat: 0.001 },
|
||||
{ lon: 179.999, lat: 0.001 },
|
||||
];
|
||||
const area = ringAreaM2(rectangle);
|
||||
assert.ok(
|
||||
area > 45_000 && area < 55_000,
|
||||
`a ~223 m x ~223 m patch is ~49,600 m2, got ${Math.round(area)} m2`,
|
||||
);
|
||||
assert.ok(area < 1e6, 'and nowhere near a square kilometre');
|
||||
|
||||
const centre = ringCentroid(rectangle);
|
||||
assert.ok(
|
||||
Math.abs(Math.abs(centre.lon) - 180) < 0.01,
|
||||
`the centre belongs on the antimeridian, got lon ${centre.lon}`,
|
||||
);
|
||||
assert.ok(Math.abs(centre.lat) < 0.01, `got lat ${centre.lat}`);
|
||||
|
||||
// Length was already safe — haversine is periodic in the longitude delta —
|
||||
// and this pins that so a "fix" cannot break it.
|
||||
const across = pathLengthM([
|
||||
{ lon: 179.999, lat: 0 },
|
||||
{ lon: -179.999, lat: 0 },
|
||||
]);
|
||||
assert.ok(
|
||||
across > 150 && across < 300,
|
||||
`about 222 m, got ${Math.round(across)} m`,
|
||||
);
|
||||
|
||||
// The same shape away from the seam still measures the same.
|
||||
const inland = rectangle.map((v) => ({ lon: v.lon - 179.999, lat: v.lat }));
|
||||
assert.ok(
|
||||
Math.abs(ringAreaM2(inland) - area) < 1,
|
||||
'position must not change size',
|
||||
);
|
||||
|
||||
// And the ordinary case is untouched.
|
||||
const austin = [
|
||||
{ lon: -97.75, lat: 30.26 },
|
||||
{ lon: -97.74, lat: 30.26 },
|
||||
{ lon: -97.74, lat: 30.27 },
|
||||
];
|
||||
const centroid = ringCentroid(austin);
|
||||
assert.ok(Math.abs(centroid.lon + 97.7433) < 0.001);
|
||||
assert.ok(Math.abs(centroid.lat - 30.2633) < 0.001);
|
||||
});
|
||||
|
||||
test('longitude unwrapping is continuous and re-wraps to one canonical range', () => {
|
||||
const unwrapped = unwrapLongitudes([
|
||||
{ lon: 179.9, lat: 0 },
|
||||
{ lon: -179.9, lat: 0 },
|
||||
]);
|
||||
assert.equal(unwrapped[0].lon, 179.9);
|
||||
assert.ok(
|
||||
Math.abs(unwrapped[1].lon - 180.1) < 1e-9,
|
||||
`continuous neighbour, got ${unwrapped[1].lon}`,
|
||||
);
|
||||
assert.equal(wrapLongitude(180.1).toFixed(4), (-179.9).toFixed(4));
|
||||
assert.equal(wrapLongitude(-190), 170);
|
||||
assert.equal(wrapLongitude(10), 10);
|
||||
assert.equal(wrapLongitude(180), -180);
|
||||
assert.equal(unwrapLongitudes([]).length, 0);
|
||||
});
|
||||
@@ -0,0 +1,546 @@
|
||||
/**
|
||||
* Manual whiteboard drawing: the Cesium + DOM half.
|
||||
*
|
||||
* DISPLAY ▸ Draw turns the globe into a whiteboard you draw on by hand: pick a
|
||||
* shape (area, line or pin), click the vertices on the real world, double-click
|
||||
* or press Enter to finish, type a label. Each finished shape goes through the
|
||||
* SAME `annotationEngine.annotate()` the voice agent uses, with its geometry
|
||||
* supplied and `manual: true`, so it renders with the whiteboard look,
|
||||
* persists, de-dups, shows up in `.list()`, and clears with the board.
|
||||
*
|
||||
* Two ownership rules make it safe to share the scene with the layers:
|
||||
*
|
||||
* - While a session is open the tool HOLDS THE POINTER
|
||||
* (`src/data/inputOwnership.js`), and every ambient selection handler yields,
|
||||
* so a vertex clicked on top of an aircraft or a camera is a vertex and
|
||||
* nothing else. It is one claim consulted by all of them, not a list of
|
||||
* exceptions inside each.
|
||||
* - Cesium's Viewer binds its OWN left click (select the entity under the
|
||||
* pointer) and double click (track it) on the viewer's handler, outside every
|
||||
* layer and therefore outside the shared claim. Both are borrowed for the
|
||||
* session and given back on the way out, and `destroy()` gives back every
|
||||
* listener, the Cesium handler, the preview data source and the window
|
||||
* handle, so the tool can be turned off or the shell disposed without leaving
|
||||
* anything behind.
|
||||
*
|
||||
* A vertex carries the height the click landed on — a roof, a hillside — and
|
||||
* that height is what the live preview hangs on, so the rubber band follows the
|
||||
* surface under the pointer instead of sinking to sea level. The world renderer
|
||||
* drapes finished areas and routes onto the surface, so the height is dropped
|
||||
* at finish, deliberately and in one place — see `finishSpec` in drawMode.js.
|
||||
*/
|
||||
import * as Cesium from 'cesium';
|
||||
import { pickWorldFromScreen } from './annotationResolver.js';
|
||||
import {
|
||||
claimPointer,
|
||||
pointerOwner,
|
||||
releasePointer,
|
||||
} from '../data/inputOwnership.js';
|
||||
import {
|
||||
DRAW_SHAPES,
|
||||
MAX_VERTICES,
|
||||
addVertex,
|
||||
createDrawSession,
|
||||
drawHint,
|
||||
finishReason,
|
||||
finishSpec,
|
||||
normalizeShape,
|
||||
removeLastVertex,
|
||||
} from './drawMode.js';
|
||||
|
||||
/** The id this tool claims the pointer under. */
|
||||
export const DRAW_POINTER_OWNER = 'draw';
|
||||
const PREVIEW_DATA_SOURCE_NAME = 'gev-draw-preview';
|
||||
|
||||
const COLORS = ['primary', 'amber', 'cyan', 'green', 'red'];
|
||||
const PREVIEW = {
|
||||
primary: '#8be9ff',
|
||||
amber: '#ffb547',
|
||||
cyan: '#39d0ff',
|
||||
green: '#5dff9f',
|
||||
red: '#ff6b6b',
|
||||
};
|
||||
|
||||
/**
|
||||
* Wire the Draw control. Returns a handle with a `destroy()` the application
|
||||
* lifetime owns, plus the console/test seam (`window.__gevDrawTool`).
|
||||
* @param {{viewer: Cesium.Viewer, annotations: {annotate: Function, clear: Function}}} deps
|
||||
* @returns {{destroy: Function}|null}
|
||||
*/
|
||||
export function initDrawTool({ viewer, annotations }) {
|
||||
const toggle = document.getElementById('draw-toggle');
|
||||
const modeRow = document.getElementById('draw-mode-row');
|
||||
const labelRow = document.getElementById('draw-label-row');
|
||||
const labelInput = document.getElementById('draw-label-input');
|
||||
const colorSelect = document.getElementById('draw-color-select');
|
||||
const clearButton = document.getElementById('draw-clear');
|
||||
const hint = document.getElementById('draw-hint');
|
||||
if (!viewer || !annotations || !toggle) return null;
|
||||
|
||||
let active = false;
|
||||
let destroyed = false;
|
||||
let session = null;
|
||||
let shape = 'area';
|
||||
let color = 'primary';
|
||||
let handler = null;
|
||||
let lease = null;
|
||||
let savedDoubleClick = null;
|
||||
let savedSingleClick = null;
|
||||
let cursor = null; // last mouse position on the canvas, for the rubber band
|
||||
// Bumped by anything that supersedes an in-flight finish: cancelling, clearing
|
||||
// the board, leaving draw mode, teardown. An `annotate()` that resolves after
|
||||
// one of those must not write its outcome over the newer state.
|
||||
let generation = 0;
|
||||
const previewEntities = [];
|
||||
// Every DOM listener this tool adds, so teardown is one loop rather than a
|
||||
// list that can fall out of step with the bindings below.
|
||||
const domListeners = [];
|
||||
const listen = (target, type, listener, options) => {
|
||||
if (!target) return;
|
||||
target.addEventListener(type, listener, options);
|
||||
domListeners.push([target, type, listener, options]);
|
||||
};
|
||||
|
||||
const dataSource = new Cesium.CustomDataSource(PREVIEW_DATA_SOURCE_NAME);
|
||||
// `add()` resolves on the NEXT tick, so an init-then-immediate-destroy would
|
||||
// remove a source that had not been attached yet and leave the attachment to
|
||||
// land afterwards — a preview data source nobody owns. Chain the removal onto
|
||||
// the attachment instead of racing it.
|
||||
let attaching = Promise.resolve(viewer.dataSources.add(dataSource)).catch(
|
||||
() => null,
|
||||
);
|
||||
|
||||
const setHint = (text) => {
|
||||
if (hint) hint.textContent = text;
|
||||
};
|
||||
|
||||
// ---- preview ---------------------------------------------------------
|
||||
const vertexPositions = () =>
|
||||
session.vertices.map((v) =>
|
||||
Cesium.Cartesian3.fromDegrees(v.lon, v.lat, v.height || 0),
|
||||
);
|
||||
const previewLine = dataSource.entities.add({
|
||||
show: false,
|
||||
polyline: {
|
||||
positions: new Cesium.CallbackProperty(() => {
|
||||
if (!session) return [];
|
||||
const pts = vertexPositions();
|
||||
if (cursor && session.shape !== 'pin') pts.push(cursor);
|
||||
if (session.shape === 'area' && pts.length >= 3) pts.push(pts[0]);
|
||||
return pts;
|
||||
}, false),
|
||||
width: 3,
|
||||
material: new Cesium.PolylineDashMaterialProperty({
|
||||
color: Cesium.Color.fromCssColorString(PREVIEW.primary).withAlpha(0.9),
|
||||
dashLength: 16,
|
||||
}),
|
||||
depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
|
||||
color: Cesium.Color.fromCssColorString(PREVIEW.primary).withAlpha(0.35),
|
||||
dashLength: 16,
|
||||
}),
|
||||
clampToGround: false,
|
||||
},
|
||||
});
|
||||
const syncPreview = () => {
|
||||
if (destroyed) return;
|
||||
previewEntities.forEach((e) => dataSource.entities.remove(e));
|
||||
previewEntities.length = 0;
|
||||
if (!session) {
|
||||
previewLine.show = false;
|
||||
setHint(drawHint(null));
|
||||
viewer.scene.requestRender();
|
||||
return;
|
||||
}
|
||||
const stroke = Cesium.Color.fromCssColorString(
|
||||
PREVIEW[color] || PREVIEW.primary,
|
||||
);
|
||||
previewLine.polyline.material = new Cesium.PolylineDashMaterialProperty({
|
||||
color: stroke.withAlpha(0.9),
|
||||
dashLength: 16,
|
||||
});
|
||||
previewLine.show = session.shape !== 'pin';
|
||||
for (const v of session.vertices) {
|
||||
previewEntities.push(
|
||||
dataSource.entities.add({
|
||||
position: Cesium.Cartesian3.fromDegrees(v.lon, v.lat, v.height || 0),
|
||||
point: {
|
||||
pixelSize: 8,
|
||||
color: stroke,
|
||||
outlineColor: Cesium.Color.BLACK.withAlpha(0.6),
|
||||
outlineWidth: 2,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
setHint(drawHint(session));
|
||||
viewer.scene.requestRender();
|
||||
};
|
||||
|
||||
// ---- vertices from clicks --------------------------------------------
|
||||
const worldAt = (position) => {
|
||||
const canvas = viewer.scene.canvas;
|
||||
const w = canvas.clientWidth || canvas.width || 1;
|
||||
const h = canvas.clientHeight || canvas.height || 1;
|
||||
return pickWorldFromScreen(viewer, position.x / w, position.y / h);
|
||||
};
|
||||
const onClick = (event) => {
|
||||
if (!session || destroyed) return;
|
||||
const p = worldAt(event.position);
|
||||
if (!p) return;
|
||||
const { added, reason } = addVertex(session, p);
|
||||
if (added) {
|
||||
syncPreview();
|
||||
return;
|
||||
}
|
||||
// A click that changed nothing still deserves an answer when the reason is
|
||||
// a limit rather than the harmless tail of a double-click.
|
||||
if (reason === 'full')
|
||||
setHint(
|
||||
`That shape already has ${MAX_VERTICES} points — finish it or press Backspace.`,
|
||||
);
|
||||
else if (reason === 'invalid')
|
||||
setHint('That point is off the globe — click on the world.');
|
||||
};
|
||||
const onMove = (event) => {
|
||||
if (!session || session.shape === 'pin' || destroyed) return;
|
||||
const p = worldAt(event.endPosition);
|
||||
cursor = p
|
||||
? Cesium.Cartesian3.fromDegrees(p.lon, p.lat, p.height || 0)
|
||||
: null;
|
||||
viewer.scene.requestRender();
|
||||
};
|
||||
|
||||
// ---- finish / cancel -------------------------------------------------
|
||||
const finish = async () => {
|
||||
if (destroyed || !session) return null;
|
||||
const reason = finishReason(session);
|
||||
if (reason !== 'ok') {
|
||||
// 'too-few' is just "keep clicking" and the hint already says so;
|
||||
// a degenerate or off-globe shape needs to be told why it was refused.
|
||||
if (reason !== 'too-few') setHint(drawHint(session));
|
||||
return null;
|
||||
}
|
||||
const spec = finishSpec(session, { label: labelInput?.value || '', color });
|
||||
if (!spec) return null;
|
||||
// Start a fresh session BEFORE awaiting, so a second Enter or the second
|
||||
// half of a double-click cannot submit the same shape twice.
|
||||
session = createDrawSession(shape);
|
||||
cursor = null;
|
||||
syncPreview();
|
||||
if (labelInput) labelInput.value = '';
|
||||
const attempt = generation;
|
||||
try {
|
||||
const result = await annotations.annotate([spec], {
|
||||
persist: true,
|
||||
flyTo: false,
|
||||
});
|
||||
if (destroyed || attempt !== generation) return result;
|
||||
if (result?.drawn === 0) setHint('That shape could not be placed.');
|
||||
return result;
|
||||
} catch (error) {
|
||||
if (destroyed || attempt !== generation) return null;
|
||||
setHint(`Could not place the shape: ${error?.message || error}`);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
const cancel = () => {
|
||||
if (!session) return;
|
||||
generation += 1;
|
||||
session = createDrawSession(shape);
|
||||
cursor = null;
|
||||
syncPreview();
|
||||
};
|
||||
/** Wipe the board: the shape in progress AND every mark already placed. */
|
||||
const clearAll = () => {
|
||||
generation += 1;
|
||||
cursor = null;
|
||||
if (session) session = createDrawSession(shape);
|
||||
annotations.clear();
|
||||
syncPreview();
|
||||
if (!destroyed && !active) setHint('Board cleared.');
|
||||
};
|
||||
|
||||
// ---- keys: only while drawing, never while typing in another field ----
|
||||
const typingElsewhere = (event) => {
|
||||
const t = event.target;
|
||||
if (!t || t === labelInput) return false;
|
||||
return (
|
||||
t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.isContentEditable
|
||||
);
|
||||
};
|
||||
/**
|
||||
* Enter is the finish key, but on a focused control Enter means "press this
|
||||
* control". Keyboard-focusing Clear and pressing Enter must clear the board,
|
||||
* not finish the shape — so the finish key is only taken from the canvas,
|
||||
* the page body, or the label field this tool owns.
|
||||
*/
|
||||
const enterBelongsToDrawing = (event) => {
|
||||
const t = event.target;
|
||||
if (!t || t === labelInput) return true;
|
||||
if (
|
||||
typeof t.closest === 'function' &&
|
||||
t.closest('button, a, select, [role="button"], [role="radio"]')
|
||||
)
|
||||
return false;
|
||||
return (
|
||||
t === document.body || t === viewer.scene.canvas || t.tagName === 'CANVAS'
|
||||
);
|
||||
};
|
||||
const onKey = (event) => {
|
||||
if (!active || destroyed || typingElsewhere(event)) return;
|
||||
// Enter goes to finish() once a shape has been started; finish() owns the
|
||||
// decision and says WHY it refused. Swallowing the key on a degenerate
|
||||
// shape left the person pressing Enter at a silent panel. A focused button
|
||||
// keeps its own Enter — see enterBelongsToDrawing.
|
||||
if (event.key === 'Enter') {
|
||||
if (session?.vertices?.length && enterBelongsToDrawing(event)) {
|
||||
event.preventDefault();
|
||||
void finish();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
if (session?.vertices.length) cancel();
|
||||
else setActive(false);
|
||||
return;
|
||||
}
|
||||
if (event.key === 'Backspace' && event.target !== labelInput) {
|
||||
if (removeLastVertex(session)) {
|
||||
event.preventDefault();
|
||||
syncPreview();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// ---- mode on / off -----------------------------------------------------
|
||||
function setActive(next) {
|
||||
if (destroyed || next === active) return active;
|
||||
if (next) {
|
||||
lease = claimPointer(DRAW_POINTER_OWNER);
|
||||
if (!lease) {
|
||||
// Somebody else is using the pointer — possibly an older instance of
|
||||
// this same tool that has not finished tearing down. Say so instead of
|
||||
// half-starting.
|
||||
setHint(`${pointerOwner()} is using the pointer — close it first.`);
|
||||
return active;
|
||||
}
|
||||
}
|
||||
active = next;
|
||||
toggle.classList.toggle('active', active);
|
||||
toggle.setAttribute('aria-pressed', String(active));
|
||||
modeRow?.classList.toggle('visible', active);
|
||||
labelRow?.classList.toggle('visible', active);
|
||||
document.body.classList.toggle('gev-drawing', active);
|
||||
if (active) {
|
||||
session = createDrawSession(shape);
|
||||
bindSceneHandler();
|
||||
syncPreview();
|
||||
} else {
|
||||
generation += 1;
|
||||
session = null;
|
||||
cursor = null;
|
||||
releaseSceneHandler();
|
||||
releasePointer(lease);
|
||||
lease = null;
|
||||
syncPreview();
|
||||
}
|
||||
return active;
|
||||
}
|
||||
|
||||
function bindSceneHandler() {
|
||||
if (handler) return;
|
||||
handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
||||
handler.setInputAction(onClick, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
handler.setInputAction(onMove, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
||||
handler.setInputAction(() => {
|
||||
void finish();
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
|
||||
// Cesium's Viewer binds BOTH stock click actions on its own handler: the
|
||||
// single click picks an entity into `viewer.selectedEntity`, the double
|
||||
// click tracks it. Neither goes through a layer, so neither can be fixed by
|
||||
// the shared pointer claim — they have to be borrowed outright for the
|
||||
// session and given back on the way out. Borrowing the single click is what
|
||||
// stops a vertex placed on a contact from also selecting it.
|
||||
const stock = viewer.screenSpaceEventHandler;
|
||||
savedSingleClick =
|
||||
stock.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK) || null;
|
||||
savedDoubleClick =
|
||||
stock.getInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) ||
|
||||
null;
|
||||
stock.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
stock.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
|
||||
listen(document, 'keydown', onKey, true);
|
||||
}
|
||||
|
||||
function releaseSceneHandler() {
|
||||
if (handler) {
|
||||
handler.destroy();
|
||||
handler = null;
|
||||
}
|
||||
if (savedSingleClick) {
|
||||
viewer.screenSpaceEventHandler.setInputAction(
|
||||
savedSingleClick,
|
||||
Cesium.ScreenSpaceEventType.LEFT_CLICK,
|
||||
);
|
||||
savedSingleClick = null;
|
||||
}
|
||||
if (savedDoubleClick) {
|
||||
viewer.screenSpaceEventHandler.setInputAction(
|
||||
savedDoubleClick,
|
||||
Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK,
|
||||
);
|
||||
savedDoubleClick = null;
|
||||
}
|
||||
// Drop just the keydown listener bound alongside this handler; the control
|
||||
// listeners below outlive a session and come off in destroy().
|
||||
for (let i = domListeners.length - 1; i >= 0; i -= 1) {
|
||||
const [target, type, listener, options] = domListeners[i];
|
||||
if (listener !== onKey) continue;
|
||||
target.removeEventListener(type, listener, options);
|
||||
domListeners.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
listen(toggle, 'click', () => setActive(!active));
|
||||
const shapeButtons = [
|
||||
...(modeRow?.querySelectorAll('.pp-mode-btn[data-shape]') || []),
|
||||
];
|
||||
for (const btn of shapeButtons) {
|
||||
listen(btn, 'click', () => {
|
||||
shape = normalizeShape(btn.dataset.shape);
|
||||
for (const other of shapeButtons) {
|
||||
const on = other === btn;
|
||||
other.classList.toggle('active', on);
|
||||
other.setAttribute('aria-checked', String(on));
|
||||
}
|
||||
if (active) {
|
||||
generation += 1;
|
||||
session = createDrawSession(shape);
|
||||
cursor = null;
|
||||
syncPreview();
|
||||
}
|
||||
});
|
||||
}
|
||||
listen(colorSelect, 'change', () => {
|
||||
color = COLORS.includes(colorSelect.value) ? colorSelect.value : 'primary';
|
||||
syncPreview();
|
||||
});
|
||||
listen(clearButton, 'click', clearAll);
|
||||
listen(labelInput, 'keydown', (event) => {
|
||||
if (event.key === 'Enter' && session?.vertices?.length) {
|
||||
event.preventDefault();
|
||||
void finish();
|
||||
}
|
||||
});
|
||||
setHint(drawHint(null));
|
||||
|
||||
const api = {
|
||||
get active() {
|
||||
return active;
|
||||
},
|
||||
get shape() {
|
||||
return shape;
|
||||
},
|
||||
get session() {
|
||||
return session;
|
||||
},
|
||||
setActive,
|
||||
setShape(next) {
|
||||
const btn = modeRow?.querySelector(
|
||||
`.pp-mode-btn[data-shape="${normalizeShape(next)}"]`,
|
||||
);
|
||||
btn?.click();
|
||||
},
|
||||
/** Test seam: add a vertex from lon/lat as if it had been clicked. */
|
||||
addVertex(lon, lat, height = 0) {
|
||||
if (!session) return false;
|
||||
const r = addVertex(session, { lon, lat, height });
|
||||
if (r.added) syncPreview();
|
||||
return r.added;
|
||||
},
|
||||
finish,
|
||||
cancel,
|
||||
clearAll,
|
||||
shapes: DRAW_SHAPES,
|
||||
/** What this tool currently holds — for teardown and leak assertions. */
|
||||
diagnostics() {
|
||||
return {
|
||||
active,
|
||||
destroyed,
|
||||
sceneHandler: Boolean(handler),
|
||||
domListeners: domListeners.length,
|
||||
previewDataSources: countPreviewDataSources(viewer),
|
||||
previewEntities: destroyed ? 0 : dataSource.entities.values.length,
|
||||
pointerOwner: pointerOwner(),
|
||||
// The viewer's OWN click actions. While a session is open both are
|
||||
// borrowed (absent here); after it closes both are back. A harness can
|
||||
// compare the restored functions by identity with what it captured
|
||||
// before, which is the only way to prove they were given back rather
|
||||
// than replaced.
|
||||
stockSingleClick: Boolean(
|
||||
viewer.screenSpaceEventHandler?.getInputAction?.(
|
||||
Cesium.ScreenSpaceEventType.LEFT_CLICK,
|
||||
),
|
||||
),
|
||||
stockDoubleClick: Boolean(
|
||||
viewer.screenSpaceEventHandler?.getInputAction?.(
|
||||
Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK,
|
||||
),
|
||||
),
|
||||
};
|
||||
},
|
||||
/** Resolves once every deferred teardown step has run. */
|
||||
whenSettled() {
|
||||
return attaching;
|
||||
},
|
||||
destroy() {
|
||||
if (destroyed) return attaching;
|
||||
// Supersede any finish still in flight before anything is torn down.
|
||||
generation += 1;
|
||||
if (active) setActive(false);
|
||||
destroyed = true;
|
||||
releaseSceneHandler();
|
||||
releasePointer(lease);
|
||||
lease = null;
|
||||
for (const [target, type, listener, options] of domListeners.splice(0)) {
|
||||
target.removeEventListener(type, listener, options);
|
||||
}
|
||||
previewEntities.length = 0;
|
||||
dataSource.entities.removeAll();
|
||||
// Wait for the pending add() before removing: a destroy() in the same
|
||||
// tick as init would otherwise remove nothing and let the attachment land
|
||||
// behind it.
|
||||
attaching = attaching.then(() => {
|
||||
try {
|
||||
viewer.dataSources.remove(dataSource, true);
|
||||
} catch {
|
||||
/* viewer already disposed — nothing to detach from */
|
||||
}
|
||||
});
|
||||
document.body.classList.remove('gev-drawing');
|
||||
toggle.classList.remove('active');
|
||||
toggle.setAttribute('aria-pressed', 'false');
|
||||
modeRow?.classList.remove('visible');
|
||||
labelRow?.classList.remove('visible');
|
||||
if (hint) hint.textContent = '';
|
||||
if (window.__gevDrawTool === api) delete window.__gevDrawTool;
|
||||
return attaching;
|
||||
},
|
||||
};
|
||||
window.__gevDrawTool = api;
|
||||
return api;
|
||||
}
|
||||
|
||||
/** How many draw previews are attached — more than one means a leaked tool. */
|
||||
function countPreviewDataSources(viewer) {
|
||||
const sources = viewer?.dataSources;
|
||||
if (!sources) return 0;
|
||||
let found = 0;
|
||||
for (let index = 0; index < sources.length; index += 1) {
|
||||
if (sources.get(index)?.name === PREVIEW_DATA_SOURCE_NAME) found += 1;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
// STRUCTURAL contracts only: where files live, which ids the markup carries,
|
||||
// what the docs may claim. Things a running test cannot observe.
|
||||
//
|
||||
// Everything about the tool's BEHAVIOUR — the pointer lease, borrowing and
|
||||
// restoring the viewer's own click actions, teardown, the Enter key, preview
|
||||
// heights, Clear — is asserted against the running module in
|
||||
// `drawToolBehaviour.test.mjs`, not by reading this file's source.
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const ROOT = path.resolve(
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
'..',
|
||||
'..',
|
||||
);
|
||||
const read = (rel) => fs.readFileSync(path.join(ROOT, rel), 'utf8');
|
||||
const tool = () => read('src/annotations/drawTool.js');
|
||||
|
||||
test('the application composition wires the draw tool and owns its teardown', () => {
|
||||
const tools = read('src/app/tools.js');
|
||||
const engineAt = tools.indexOf('const annotations = initAnnotations({');
|
||||
const drawAt = tools.indexOf(
|
||||
'const drawTool = initDrawTool({ viewer, annotations });',
|
||||
);
|
||||
assert.ok(engineAt >= 0, 'initAnnotations call missing');
|
||||
assert.ok(
|
||||
drawAt > engineAt,
|
||||
'initDrawTool must follow initAnnotations and receive its engine',
|
||||
);
|
||||
assert.match(
|
||||
tools,
|
||||
/import \{ initDrawTool \} from '\.\.\/annotations\/drawTool\.js';/,
|
||||
);
|
||||
// The tool holds a pointer claim, DOM listeners and a data source, so the
|
||||
// application lifetime disposes it — not whoever last pressed the button.
|
||||
const deferAt = tools.indexOf('defer(() => drawTool?.destroy());');
|
||||
assert.ok(deferAt > drawAt, 'the shell must defer the draw tool teardown');
|
||||
});
|
||||
|
||||
test('the engine resolves manual geometry before any name resolution', () => {
|
||||
const engine = read('src/annotations/annotationEngine.js');
|
||||
const resolveAt = engine.indexOf(
|
||||
'async function resolveSpec(spec, signal) {',
|
||||
);
|
||||
const manualAt = engine.indexOf(
|
||||
'if (isManualSpec(spec, type)) return resolveManualSpec(spec, type, viewer);',
|
||||
resolveAt,
|
||||
);
|
||||
const routeAt = engine.indexOf("if (type === 'route') {", resolveAt);
|
||||
assert.ok(
|
||||
manualAt > resolveAt && manualAt < routeAt,
|
||||
'manual specs must short-circuit ahead of the route/arrow/area resolvers',
|
||||
);
|
||||
assert.match(
|
||||
engine,
|
||||
/if \(mode === 'manual'\) return baseLabel \? `\$\{baseLabel\} — \$\{dist\}` : dist;/,
|
||||
'a drawn line reports length, never a walk time',
|
||||
);
|
||||
});
|
||||
|
||||
test('the Draw control markup carries the ids the tool binds to', () => {
|
||||
// The DISPLAY rail is a component template now, assembled into index.html at
|
||||
// build time — the markup is not in index.html any more.
|
||||
const html = read('src/ui/templates/display-controls.html');
|
||||
const ids = [
|
||||
'draw-toggle',
|
||||
'draw-mode-row',
|
||||
'draw-label-row',
|
||||
'draw-label-input',
|
||||
'draw-color-select',
|
||||
'draw-clear',
|
||||
'draw-hint',
|
||||
];
|
||||
for (const id of ids) {
|
||||
assert.match(
|
||||
html,
|
||||
new RegExp(`id="${id}"`),
|
||||
`#${id} missing from index.html`,
|
||||
);
|
||||
}
|
||||
for (const shape of ['area', 'line', 'pin']) {
|
||||
assert.match(
|
||||
html,
|
||||
new RegExp(`data-shape="${shape}"`),
|
||||
`shape button ${shape} missing`,
|
||||
);
|
||||
}
|
||||
for (const id of ids) {
|
||||
assert.match(
|
||||
tool(),
|
||||
new RegExp(`getElementById\\('${id}'\\)`),
|
||||
`drawTool must bind #${id}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('the DISPLAY rail styles live in their current owner, not the shim', () => {
|
||||
// The PR this came from was written against the pre-refactor layout, where
|
||||
// these rules lived in the root style.css. That file is an import shim now,
|
||||
// and putting rules back into it would silently undo the split.
|
||||
const shim = read('style.css');
|
||||
assert.ok(
|
||||
shim.split('\n').length < 40,
|
||||
'style.css is an import shim, not a stylesheet',
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
shim,
|
||||
/draw-hint|pp-text-input/,
|
||||
'draw styles belong to a component stylesheet',
|
||||
);
|
||||
const controls = read('src/ui/styles/controls.css');
|
||||
for (const rule of [
|
||||
'#draw-mode-row',
|
||||
'#draw-label-row',
|
||||
'.pp-text-input',
|
||||
'.draw-clear-btn',
|
||||
'.draw-hint',
|
||||
'body.gev-drawing',
|
||||
]) {
|
||||
assert.ok(
|
||||
controls.includes(rule),
|
||||
`${rule} must live in src/ui/styles/controls.css`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('nothing promises a GeoJSON export for drawn shapes', () => {
|
||||
for (const file of [
|
||||
'src/annotations/drawTool.js',
|
||||
'src/annotations/drawMode.js',
|
||||
]) {
|
||||
assert.doesNotMatch(
|
||||
read(file),
|
||||
/GeoJSON/i,
|
||||
`${file} still claims a GeoJSON export`,
|
||||
);
|
||||
}
|
||||
for (const file of ['README.md', 'CHANGELOG.md', 'docs/CURRENT-STATE.md']) {
|
||||
const source = read(file);
|
||||
const at = source.indexOf('DISPLAY ▸ **Draw**');
|
||||
const start = at >= 0 ? at : source.indexOf('DISPLAY ▸ Draw');
|
||||
assert.ok(start >= 0, `${file} should describe the Draw control`);
|
||||
const section = source.slice(start, start + 1200);
|
||||
assert.doesNotMatch(
|
||||
section,
|
||||
/GeoJSON/i,
|
||||
`${file} still claims a GeoJSON export for drawn shapes`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('the docs do not promise a vertex height the renderer would discard', () => {
|
||||
// Areas and routes are DRAPED, so a per-vertex height is not a placement.
|
||||
// That the finished spec actually drops it is asserted against the running
|
||||
// module in drawToolBehaviour.test.mjs; this only guards the wording.
|
||||
assert.doesNotMatch(tool(), /lands on the roof/);
|
||||
assert.doesNotMatch(
|
||||
read('docs/CURRENT-STATE.md'),
|
||||
/a vertex on a roof lands on the roof/,
|
||||
);
|
||||
});
|
||||
|
||||
test('draped marks classify onto terrain as well as 3D tiles', () => {
|
||||
// CESIUM_3D_TILE alone rendered nothing on a keyless boot, where Cesium's own
|
||||
// globe carries the imagery and there are no tiles to classify against. The
|
||||
// rendered proof is in scripts/qa-draw-tool.mjs, which counts stroke pixels
|
||||
// against a keyless server; this stops the constant being narrowed again.
|
||||
const renderer = read('src/annotations/worldAnnotationRenderer.js');
|
||||
assert.match(renderer, /const CLASSIFY = Cesium\.ClassificationType\.BOTH;/);
|
||||
assert.doesNotMatch(
|
||||
renderer,
|
||||
/classificationType: Cesium\.ClassificationType\.CESIUM_3D_TILE/,
|
||||
);
|
||||
});
|
||||
|
||||
test('the draw modules are registered for formatting and boundary checks', () => {
|
||||
const formatScope = JSON.parse(read('scripts/format-scope.json'));
|
||||
for (const file of [
|
||||
'src/annotations/drawMode.js',
|
||||
'src/annotations/drawMode.test.mjs',
|
||||
'src/annotations/drawTool.js',
|
||||
'src/annotations/drawTool.test.mjs',
|
||||
'src/data/inputOwnership.js',
|
||||
]) {
|
||||
assert.ok(
|
||||
formatScope.includes(file),
|
||||
`${file} must be in the formatting scope`,
|
||||
);
|
||||
}
|
||||
const boundaries = JSON.parse(read('scripts/package-boundaries.json'));
|
||||
const owners = (file) =>
|
||||
Object.entries(boundaries)
|
||||
.filter(([, group]) => group.modules?.includes(file))
|
||||
.map(([name]) => name);
|
||||
for (const file of [
|
||||
'src/annotations/drawMode.js',
|
||||
'src/annotations/drawTool.js',
|
||||
'src/data/inputOwnership.js',
|
||||
]) {
|
||||
assert.ok(
|
||||
owners(file).length > 0,
|
||||
`${file} must be owned by at least one boundary group`,
|
||||
);
|
||||
}
|
||||
// Every layer that consults the shared claim has to own the module it reads,
|
||||
// or its bundle fails the boundary check.
|
||||
for (const group of ['alpr-cameras', 'vessel-layer', 'satellites-layer']) {
|
||||
assert.ok(
|
||||
boundaries[group]?.modules.includes('src/data/inputOwnership.js'),
|
||||
`${group} consults the pointer claim and must own the module`,
|
||||
);
|
||||
}
|
||||
const exports = JSON.parse(read('package.json')).exports;
|
||||
assert.equal(exports['./annotations'], './src/annotations/index.js');
|
||||
});
|
||||
@@ -0,0 +1,467 @@
|
||||
// Behavioural tests for the draw tool: the module is driven against fake DOM
|
||||
// and viewer doubles and its OBSERVABLE effects are asserted — which lease it
|
||||
// holds, which viewer input actions it borrowed and gave back, what it leaves
|
||||
// behind when destroyed. Nothing here reads the module's source text.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { initDrawTool } from './drawTool.js';
|
||||
import {
|
||||
isPointerFree,
|
||||
pointerOwner,
|
||||
claimPointer,
|
||||
releasePointer,
|
||||
resetPointerOwnership,
|
||||
} from '../data/inputOwnership.js';
|
||||
|
||||
/* ── DOM doubles ───────────────────────────────────────────────────────── */
|
||||
|
||||
class FakeClassList {
|
||||
constructor() {
|
||||
this.names = new Set();
|
||||
}
|
||||
add(...names) {
|
||||
for (const n of names) this.names.add(n);
|
||||
}
|
||||
remove(...names) {
|
||||
for (const n of names) this.names.delete(n);
|
||||
}
|
||||
contains(name) {
|
||||
return this.names.has(name);
|
||||
}
|
||||
toggle(name, force) {
|
||||
const on = force === undefined ? !this.names.has(name) : Boolean(force);
|
||||
if (on) this.names.add(name);
|
||||
else this.names.delete(name);
|
||||
return on;
|
||||
}
|
||||
}
|
||||
|
||||
class FakeElement {
|
||||
constructor(tagName = 'DIV', id = '') {
|
||||
this.tagName = tagName.toUpperCase();
|
||||
this.id = id;
|
||||
this.classList = new FakeClassList();
|
||||
this.dataset = {};
|
||||
this.attributes = new Map();
|
||||
this.textContent = '';
|
||||
this.value = '';
|
||||
this.children = [];
|
||||
this.listeners = [];
|
||||
}
|
||||
setAttribute(name, value) {
|
||||
this.attributes.set(name, String(value));
|
||||
}
|
||||
getAttribute(name) {
|
||||
return this.attributes.get(name) ?? null;
|
||||
}
|
||||
addEventListener(type, listener, options) {
|
||||
this.listeners.push({ type, listener, options });
|
||||
}
|
||||
removeEventListener(type, listener) {
|
||||
const at = this.listeners.findIndex(
|
||||
(entry) => entry.type === type && entry.listener === listener,
|
||||
);
|
||||
if (at >= 0) this.listeners.splice(at, 1);
|
||||
}
|
||||
querySelectorAll(selector) {
|
||||
if (selector === '.pp-mode-btn[data-shape]')
|
||||
return this.children.filter((child) => child.dataset.shape);
|
||||
const shape = /\.pp-mode-btn\[data-shape="([a-z]+)"\]/.exec(selector)?.[1];
|
||||
if (shape) return this.children.filter((child) => child.dataset.shape === shape);
|
||||
return [];
|
||||
}
|
||||
querySelector(selector) {
|
||||
return this.querySelectorAll(selector)[0] ?? null;
|
||||
}
|
||||
click() {
|
||||
return this.emit('click');
|
||||
}
|
||||
closest(selector) {
|
||||
// Only what the tool asks: "am I inside an activatable control?"
|
||||
const activatable = ['button', 'a', 'select', '[role="button"]', '[role="radio"]'];
|
||||
if (!activatable.some((part) => selector.includes(part))) return null;
|
||||
return this.tagName === 'BUTTON' || this.tagName === 'A' || this.tagName === 'SELECT'
|
||||
? this
|
||||
: null;
|
||||
}
|
||||
/** Deliver an event to this element's own listeners. */
|
||||
emit(type, event = {}) {
|
||||
const payload = {
|
||||
type,
|
||||
target: this,
|
||||
preventDefault() {},
|
||||
stopImmediatePropagation() {},
|
||||
...event,
|
||||
};
|
||||
for (const entry of [...this.listeners])
|
||||
if (entry.type === type) entry.listener(payload);
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
|
||||
function fakeDom() {
|
||||
const byId = new Map();
|
||||
const make = (id, tagName = 'DIV') => {
|
||||
const element = new FakeElement(tagName, id);
|
||||
byId.set(id, element);
|
||||
return element;
|
||||
};
|
||||
make('draw-toggle', 'BUTTON');
|
||||
const modeRow = make('draw-mode-row');
|
||||
for (const shape of ['area', 'line', 'pin']) {
|
||||
const button = new FakeElement('BUTTON');
|
||||
button.dataset.shape = shape;
|
||||
modeRow.children.push(button);
|
||||
}
|
||||
make('draw-label-row');
|
||||
make('draw-label-input', 'INPUT');
|
||||
make('draw-color-select', 'SELECT');
|
||||
make('draw-clear', 'BUTTON');
|
||||
make('draw-hint', 'SPAN');
|
||||
|
||||
const body = new FakeElement('BODY');
|
||||
const documentDouble = {
|
||||
body,
|
||||
getElementById: (id) => byId.get(id) ?? null,
|
||||
listeners: [],
|
||||
addEventListener(type, listener, options) {
|
||||
this.listeners.push({ type, listener, options });
|
||||
},
|
||||
removeEventListener(type, listener) {
|
||||
const at = this.listeners.findIndex(
|
||||
(entry) => entry.type === type && entry.listener === listener,
|
||||
);
|
||||
if (at >= 0) this.listeners.splice(at, 1);
|
||||
},
|
||||
emit(type, event = {}) {
|
||||
const payload = {
|
||||
type,
|
||||
target: body,
|
||||
preventDefault() {},
|
||||
stopImmediatePropagation() {},
|
||||
...event,
|
||||
};
|
||||
for (const entry of [...this.listeners])
|
||||
if (entry.type === type) entry.listener(payload);
|
||||
return payload;
|
||||
},
|
||||
};
|
||||
return { byId, documentDouble };
|
||||
}
|
||||
|
||||
/* ── viewer double ─────────────────────────────────────────────────────── */
|
||||
|
||||
function fakeViewer() {
|
||||
const canvas = new FakeElement('CANVAS');
|
||||
canvas.clientWidth = 800;
|
||||
canvas.clientHeight = 600;
|
||||
const actions = new Map();
|
||||
const stockHandler = {
|
||||
getInputAction: (type) => actions.get(type),
|
||||
setInputAction: (action, type) => actions.set(type, action),
|
||||
removeInputAction: (type) => actions.delete(type),
|
||||
};
|
||||
const attached = [];
|
||||
const pendingAdds = [];
|
||||
const dataSources = {
|
||||
get length() {
|
||||
return attached.length;
|
||||
},
|
||||
get: (index) => attached[index],
|
||||
add(source) {
|
||||
// Cesium resolves this on a later tick — the whole point of finding 7.
|
||||
const promise = Promise.resolve().then(() => {
|
||||
attached.push(source);
|
||||
return source;
|
||||
});
|
||||
pendingAdds.push(promise);
|
||||
return promise;
|
||||
},
|
||||
remove(source) {
|
||||
const at = attached.indexOf(source);
|
||||
if (at >= 0) attached.splice(at, 1);
|
||||
return at >= 0;
|
||||
},
|
||||
};
|
||||
return {
|
||||
scene: { canvas, requestRender() {} },
|
||||
screenSpaceEventHandler: stockHandler,
|
||||
dataSources,
|
||||
_attached: attached,
|
||||
_actions: actions,
|
||||
};
|
||||
}
|
||||
|
||||
function fakeAnnotations() {
|
||||
const calls = { annotate: [], clear: 0 };
|
||||
return {
|
||||
calls,
|
||||
async annotate(specs, options) {
|
||||
calls.annotate.push({ specs, options });
|
||||
return { drawn: specs.length };
|
||||
},
|
||||
clear() {
|
||||
calls.clear += 1;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Stand up a tool against fresh doubles, with globals restored afterwards. */
|
||||
function harness() {
|
||||
resetPointerOwnership();
|
||||
const { byId, documentDouble } = fakeDom();
|
||||
const viewer = fakeViewer();
|
||||
const annotations = fakeAnnotations();
|
||||
const previousDocument = globalThis.document;
|
||||
const previousWindow = globalThis.window;
|
||||
globalThis.document = documentDouble;
|
||||
globalThis.window = globalThis.window || {};
|
||||
const tool = initDrawTool({ viewer, annotations });
|
||||
return {
|
||||
tool,
|
||||
viewer,
|
||||
annotations,
|
||||
byId,
|
||||
documentDouble,
|
||||
element: (id) => byId.get(id),
|
||||
restore() {
|
||||
resetPointerOwnership();
|
||||
if (previousDocument === undefined) delete globalThis.document;
|
||||
else globalThis.document = previousDocument;
|
||||
if (previousWindow === undefined) delete globalThis.window;
|
||||
else globalThis.window = previousWindow;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const LEFT_CLICK = Cesium.ScreenSpaceEventType.LEFT_CLICK;
|
||||
const LEFT_DOUBLE_CLICK = Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK;
|
||||
|
||||
/* ── the tests ─────────────────────────────────────────────────────────── */
|
||||
|
||||
test('turning Draw on takes a lease and turning it off gives it back', async () => {
|
||||
const h = harness();
|
||||
try {
|
||||
assert.equal(isPointerFree(), true);
|
||||
h.element('draw-toggle').emit('click');
|
||||
assert.equal(pointerOwner(), 'draw', 'the session owns the pointer');
|
||||
assert.equal(h.tool.active, true);
|
||||
|
||||
h.element('draw-toggle').emit('click');
|
||||
assert.equal(isPointerFree(), true, 'leaving draw mode frees the pointer');
|
||||
assert.equal(h.tool.active, false);
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('Draw refuses to start when something else holds the pointer', async () => {
|
||||
const h = harness();
|
||||
try {
|
||||
const other = claimPointer('directions');
|
||||
h.element('draw-toggle').emit('click');
|
||||
assert.equal(h.tool.active, false, 'it must not half-start');
|
||||
assert.equal(pointerOwner(), 'directions', 'and must not steal the claim');
|
||||
assert.match(h.element('draw-hint').textContent, /directions/);
|
||||
assert.equal(h.tool.diagnostics().sceneHandler, false, 'no handler was bound');
|
||||
|
||||
releasePointer(other);
|
||||
h.element('draw-toggle').emit('click');
|
||||
assert.equal(h.tool.active, true, 'and it starts once the pointer is free');
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('a destroyed instance cannot free the pointer its replacement holds', async () => {
|
||||
const first = harness();
|
||||
try {
|
||||
first.element('draw-toggle').emit('click');
|
||||
assert.equal(pointerOwner(), 'draw');
|
||||
// The replacement takes over before the old one finishes tearing down.
|
||||
first.tool.setActive(false);
|
||||
const second = harness();
|
||||
try {
|
||||
second.element('draw-toggle').emit('click');
|
||||
assert.equal(pointerOwner(), 'draw');
|
||||
await first.tool.destroy();
|
||||
assert.equal(
|
||||
pointerOwner(),
|
||||
'draw',
|
||||
'the live session still owns the pointer after the old one is destroyed',
|
||||
);
|
||||
assert.equal(second.tool.active, true);
|
||||
} finally {
|
||||
second.restore();
|
||||
}
|
||||
} finally {
|
||||
first.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('both stock viewer click actions are borrowed for the session and given back', async () => {
|
||||
const h = harness();
|
||||
try {
|
||||
const stockClick = () => 'viewer picks and selects';
|
||||
const stockDouble = () => 'viewer tracks';
|
||||
h.viewer.screenSpaceEventHandler.setInputAction(stockClick, LEFT_CLICK);
|
||||
h.viewer.screenSpaceEventHandler.setInputAction(stockDouble, LEFT_DOUBLE_CLICK);
|
||||
|
||||
h.element('draw-toggle').emit('click');
|
||||
assert.equal(
|
||||
h.viewer.screenSpaceEventHandler.getInputAction(LEFT_CLICK),
|
||||
undefined,
|
||||
"the viewer's own selecting click must not run while drawing",
|
||||
);
|
||||
assert.equal(
|
||||
h.viewer.screenSpaceEventHandler.getInputAction(LEFT_DOUBLE_CLICK),
|
||||
undefined,
|
||||
);
|
||||
|
||||
h.element('draw-toggle').emit('click');
|
||||
assert.equal(
|
||||
h.viewer.screenSpaceEventHandler.getInputAction(LEFT_CLICK),
|
||||
stockClick,
|
||||
'the exact function is restored, not a replacement',
|
||||
);
|
||||
assert.equal(
|
||||
h.viewer.screenSpaceEventHandler.getInputAction(LEFT_DOUBLE_CLICK),
|
||||
stockDouble,
|
||||
);
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('Enter finishes from the canvas and the label field, never from a focused button', async () => {
|
||||
const h = harness();
|
||||
try {
|
||||
h.element('draw-toggle').emit('click');
|
||||
h.tool.setShape('area');
|
||||
h.tool.addVertex(-97.75, 30.26);
|
||||
h.tool.addVertex(-97.74, 30.26);
|
||||
h.tool.addVertex(-97.74, 30.27);
|
||||
|
||||
// Enter while the Clear button has keyboard focus means "press Clear".
|
||||
h.documentDouble.emit('keydown', { key: 'Enter', target: h.element('draw-clear') });
|
||||
await Promise.resolve();
|
||||
assert.equal(
|
||||
h.annotations.calls.annotate.length,
|
||||
0,
|
||||
'a focused button keeps its own Enter',
|
||||
);
|
||||
assert.equal(h.tool.session.vertices.length, 3, 'and the shape is untouched');
|
||||
|
||||
// Enter from the page body (the canvas has focus in practice) finishes it.
|
||||
h.documentDouble.emit('keydown', { key: 'Enter', target: h.documentDouble.body });
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
assert.equal(h.annotations.calls.annotate.length, 1, 'Enter on the map finishes');
|
||||
assert.equal(h.annotations.calls.annotate[0].specs[0].type, 'area');
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('the live preview hangs at the height the click landed on', async () => {
|
||||
const h = harness();
|
||||
try {
|
||||
h.element('draw-toggle').emit('click');
|
||||
h.tool.setShape('line');
|
||||
h.tool.addVertex(-97.75, 30.26, 187.5);
|
||||
h.tool.addVertex(-97.74, 30.26, 212.25);
|
||||
|
||||
await h.tool.whenSettled();
|
||||
const source = h.viewer._attached[0] ?? null;
|
||||
assert.ok(source, 'the preview data source is attached');
|
||||
const points = source.entities.values.filter((entity) => entity.point);
|
||||
assert.equal(points.length, 2, 'one preview dot per vertex');
|
||||
const heights = points.map((entity) => {
|
||||
const position = entity.position.getValue(Cesium.JulianDate.now());
|
||||
return Cesium.Cartographic.fromCartesian(position).height;
|
||||
});
|
||||
assert.ok(Math.abs(heights[0] - 187.5) < 0.5, `got ${heights[0]}`);
|
||||
assert.ok(Math.abs(heights[1] - 212.25) < 0.5, `got ${heights[1]}`);
|
||||
|
||||
// …and the finished shape is still flattened, deliberately: the renderer
|
||||
// drapes, so a height carried further would be discarded out of sight.
|
||||
h.documentDouble.emit('keydown', { key: 'Enter', target: h.documentDouble.body });
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
const spec = h.annotations.calls.annotate[0].specs[0];
|
||||
assert.deepEqual(spec.path, [
|
||||
[-97.75, 30.26],
|
||||
[-97.74, 30.26],
|
||||
]);
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('destroy in the same tick as init still removes the preview data source', async () => {
|
||||
const h = harness();
|
||||
try {
|
||||
// Nothing has been attached yet — dataSources.add() resolves later.
|
||||
assert.equal(h.viewer._attached.length, 0, 'the add is still pending');
|
||||
await h.tool.destroy();
|
||||
await Promise.resolve();
|
||||
assert.equal(
|
||||
h.viewer._attached.length,
|
||||
0,
|
||||
'the preview must not be left attached behind the teardown',
|
||||
);
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('destroy releases the pointer, the handler, the listeners and the stock actions', async () => {
|
||||
const h = harness();
|
||||
try {
|
||||
const stockClick = () => 'viewer picks and selects';
|
||||
h.viewer.screenSpaceEventHandler.setInputAction(stockClick, LEFT_CLICK);
|
||||
h.element('draw-toggle').emit('click');
|
||||
h.tool.addVertex(-97.75, 30.26);
|
||||
assert.equal(pointerOwner(), 'draw');
|
||||
assert.ok(h.tool.diagnostics().domListeners > 0);
|
||||
|
||||
await h.tool.destroy();
|
||||
await Promise.resolve();
|
||||
|
||||
assert.equal(isPointerFree(), true, 'the pointer is free');
|
||||
const after = h.tool.diagnostics();
|
||||
assert.equal(after.destroyed, true);
|
||||
assert.equal(after.sceneHandler, false, 'the Cesium handler is gone');
|
||||
assert.equal(after.domListeners, 0, 'every DOM listener came off');
|
||||
assert.equal(h.documentDouble.listeners.length, 0, 'including the keydown');
|
||||
assert.equal(h.element('draw-toggle').listeners.length, 0);
|
||||
assert.equal(
|
||||
h.viewer.screenSpaceEventHandler.getInputAction(LEFT_CLICK),
|
||||
stockClick,
|
||||
'the viewer got its selecting click back',
|
||||
);
|
||||
assert.equal(h.viewer._attached.length, 0, 'the preview data source is detached');
|
||||
|
||||
// Idempotent: a second destroy is harmless.
|
||||
await h.tool.destroy();
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('Clear wipes the board and the shape in progress', async () => {
|
||||
const h = harness();
|
||||
try {
|
||||
h.element('draw-toggle').emit('click');
|
||||
h.tool.addVertex(-97.75, 30.26);
|
||||
h.tool.addVertex(-97.74, 30.26);
|
||||
assert.equal(h.tool.session.vertices.length, 2);
|
||||
|
||||
h.element('draw-clear').emit('click');
|
||||
assert.equal(h.annotations.calls.clear, 1, 'placed marks are removed');
|
||||
assert.equal(h.tool.session.vertices.length, 0, 'and so is the shape in progress');
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
@@ -2226,6 +2226,11 @@ export function createAnnotationResolver({
|
||||
return {
|
||||
lat: Cesium.Math.toDegrees(carto.latitude),
|
||||
lon: Cesium.Math.toDegrees(carto.longitude),
|
||||
// The height the pick actually landed on — a roof, a hillside, or 0 on
|
||||
// the ellipsoid. Callers that only want a coordinate ignore it; the draw
|
||||
// tool's live preview needs it, or the rubber band sinks to sea level
|
||||
// while the pointer is on a hill.
|
||||
height: Number.isFinite(carto.height) ? carto.height : 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2331,5 +2336,12 @@ export function createAnnotationResolver({
|
||||
viewportBias,
|
||||
placesNearViewRecovery,
|
||||
resolveRegionRingForQuery,
|
||||
// Scene helpers, not resolution: the manual draw tool turns a click into a
|
||||
// world point with the same depth-aware cascade the agent's pixel fallback
|
||||
// uses, and the engine samples the surface under a hand-placed mark. Both
|
||||
// are exposed so there is ONE pick cascade in the app, not a second one
|
||||
// written beside it.
|
||||
pickWorldFromScreen,
|
||||
sampleGroundHeight,
|
||||
};
|
||||
}
|
||||
@@ -30,7 +30,20 @@ const PALETTE = {
|
||||
red: '#ff6b6b',
|
||||
};
|
||||
|
||||
const CLASSIFY = Cesium.ClassificationType.CESIUM_3D_TILE;
|
||||
/**
|
||||
* What a draped mark is allowed to paint onto.
|
||||
*
|
||||
* This was CESIUM_3D_TILE, which is right with Google's photoreal tiles under
|
||||
* the camera and wrong everywhere else: on a keyless boot (Esri or OSM imagery
|
||||
* on Cesium's own globe) there are no 3D tiles to classify against, so every
|
||||
* area fill, area outline, route and arrow rendered to nothing. The labels
|
||||
* showed and the geometry did not, which reads as a broken feature rather than
|
||||
* an unsupported surface — and it hit spoken annotations exactly as hard as
|
||||
* hand-drawn ones.
|
||||
*
|
||||
* BOTH paints onto terrain AND onto 3D tiles, so one value covers both worlds.
|
||||
*/
|
||||
const CLASSIFY = Cesium.ClassificationType.BOTH;
|
||||
const CLAMP = Cesium.HeightReference.CLAMP_TO_GROUND;
|
||||
|
||||
export function createWorldAnnotationRenderer(viewer) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { SceneDirector } from '../scenes/director.js';
|
||||
import { initAnnotations } from '../annotations/index.js';
|
||||
import { initDrawTool } from '../annotations/drawTool.js';
|
||||
import { initGevVoiceCommands } from '../voice/gevRealtime.js';
|
||||
import { installScopeMask, destroyScopeMask } from '../scopeMask.js';
|
||||
import {
|
||||
@@ -39,6 +40,11 @@ export function createApplicationTools({
|
||||
if (window.__gevAnnotations === annotations) delete window.__gevAnnotations;
|
||||
annotations.destroy();
|
||||
});
|
||||
// DISPLAY ▸ Draw: the same whiteboard, drawn by hand. It claims the pointer
|
||||
// while a session is open, so its teardown belongs to the application
|
||||
// lifetime rather than to whoever last pressed the button.
|
||||
const drawTool = initDrawTool({ viewer, annotations });
|
||||
defer(() => drawTool?.destroy());
|
||||
if (startChrome)
|
||||
defer(startChrome({ loadingScreen, styleManager, dataManager, signal }));
|
||||
// Idle render governor: flips the scene into requestRenderMode whenever
|
||||
|
||||
@@ -0,0 +1,389 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import {
|
||||
calgaryCameraId,
|
||||
calgaryCameraName,
|
||||
calgaryCameraToSource,
|
||||
loadCalgarySourcesFromOpenData,
|
||||
normalizeCalgaryImageUrl,
|
||||
} from '../../server/providers/cctv/sources.js';
|
||||
import {
|
||||
CALGARY_IMAGE_ORIGIN,
|
||||
CALGARY_MAX_CATALOG_BYTES,
|
||||
DEFAULT_CALGARY_ROWS_URL,
|
||||
DEFAULT_CCTV_MAX_SOURCES,
|
||||
} from '../../server/providers/cctv/constants.js';
|
||||
import { CAMERA_CODE_MAX_CHARS } from '../../server/providers/cctv/normalize.js';
|
||||
import { allocateSourceCap } from '../../server/providers/cctv/cap.js';
|
||||
import { createCctvCatalog } from '../../server/providers/cctv/catalog.js';
|
||||
import { directionToHeading } from './directionText.js';
|
||||
|
||||
/**
|
||||
* A response whose body is a live stream, plus a flag that flips when the
|
||||
* stream is cancelled. A rejection path that returns without cancelling holds
|
||||
* the transport open, so the flag is what the refusal tests actually assert.
|
||||
*/
|
||||
const streamingResponse = (init = {}) => {
|
||||
const state = { cancelled: false };
|
||||
const body = new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode('['));
|
||||
},
|
||||
cancel() {
|
||||
state.cancelled = true;
|
||||
},
|
||||
});
|
||||
return { response: new Response(body, init), state };
|
||||
};
|
||||
|
||||
/** One Open Calgary row, shaped like the live `k7p9-kppz` payload. */
|
||||
const row = (overrides = {}) => ({
|
||||
camera_url: {
|
||||
url: 'http://trafficcam.calgary.ca/loc142.jpg',
|
||||
description: 'Camera 143',
|
||||
},
|
||||
quadrant: 'SW',
|
||||
camera_location: 'Bow Trail / 37 Street SW',
|
||||
point: { type: 'Point', coordinates: [-114.1413616, 51.0453097] },
|
||||
...overrides,
|
||||
});
|
||||
|
||||
test('a Calgary row maps to a source on the pinned HTTPS frame host', () => {
|
||||
const source = calgaryCameraToSource(row());
|
||||
assert.equal(source.id, 'calgary-142');
|
||||
assert.equal(source.name, 'Bow Trail / 37 Street SW');
|
||||
assert.equal(source.cityId, 'calgary');
|
||||
assert.equal(source.provider, 'The City of Calgary');
|
||||
assert.equal(source.lat, 51.0453097);
|
||||
assert.equal(source.lon, -114.1413616);
|
||||
assert.equal(source.feedType, 'image');
|
||||
assert.equal(source.sourceKind, 'calgary-open-data');
|
||||
assert.equal(
|
||||
source.license,
|
||||
'Contains information licensed under the Open Government Licence – City of Calgary',
|
||||
);
|
||||
// The catalog publishes http://; the registered URL is the upgraded one.
|
||||
assert.equal(source.url, 'https://trafficcam.calgary.ca/loc142.jpg');
|
||||
assert.equal(source.url, source.snapshotUrl);
|
||||
assert.ok(source.url.startsWith(CALGARY_IMAGE_ORIGIN));
|
||||
});
|
||||
|
||||
test('no heading is derived from the quadrant or the address suffix', () => {
|
||||
// Both fields parse as a confident compass bearing, and both would be wrong
|
||||
// for every camera in the city: they are Calgary's address grid, not a
|
||||
// camera facing. Nobody may "fix" this by wiring either one up.
|
||||
assert.equal(directionToHeading('SW', true), 225);
|
||||
assert.equal(directionToHeading('Bow Trail / 37 Street SW', true), 225);
|
||||
|
||||
for (const quadrant of ['NE', 'NW', 'SE', 'SW', 'NW/NE', 'S']) {
|
||||
const source = calgaryCameraToSource(row({ quadrant }));
|
||||
assert.equal(source.headingConfidence, 'low');
|
||||
assert.ok(Number.isFinite(source.headingDeg));
|
||||
// Same id, same fallback heading, whatever the quadrant says.
|
||||
assert.equal(source.headingDeg, calgaryCameraToSource(row()).headingDeg);
|
||||
}
|
||||
});
|
||||
|
||||
test('rows outside Calgary, off-host frames and unusable geometry are dropped', () => {
|
||||
// Toronto: a plausible lat/lon, but not a Calgary camera.
|
||||
assert.equal(
|
||||
calgaryCameraToSource(
|
||||
row({ point: { type: 'Point', coordinates: [-79.3832, 43.6532] } }),
|
||||
),
|
||||
null,
|
||||
);
|
||||
// Null island, and the string coordinates that would become it.
|
||||
assert.equal(
|
||||
calgaryCameraToSource(
|
||||
row({ point: { type: 'Point', coordinates: [0, 0] } }),
|
||||
),
|
||||
null,
|
||||
);
|
||||
assert.equal(calgaryCameraToSource(row({ point: null })), null);
|
||||
assert.equal(
|
||||
calgaryCameraToSource(row({ point: { coordinates: [-114.14] } })),
|
||||
null,
|
||||
);
|
||||
// A catalog edit cannot steer the frame proxy off the city host.
|
||||
assert.equal(
|
||||
calgaryCameraToSource(
|
||||
row({ camera_url: { url: 'https://evil.example/loc1.jpg' } }),
|
||||
),
|
||||
null,
|
||||
);
|
||||
assert.equal(
|
||||
calgaryCameraToSource(
|
||||
row({
|
||||
camera_url: { url: 'https://trafficcam.calgary.ca.evil.test/1.jpg' },
|
||||
}),
|
||||
),
|
||||
null,
|
||||
);
|
||||
assert.equal(
|
||||
calgaryCameraToSource(row({ camera_url: { url: 'file:///etc/passwd' } })),
|
||||
null,
|
||||
);
|
||||
assert.equal(calgaryCameraToSource(row({ camera_url: null })), null);
|
||||
assert.equal(calgaryCameraToSource(null), null);
|
||||
});
|
||||
|
||||
test('frame URLs upgrade to HTTPS and ids stay stable', () => {
|
||||
assert.equal(
|
||||
normalizeCalgaryImageUrl('http://trafficcam.calgary.ca/loc86.jpg'),
|
||||
'https://trafficcam.calgary.ca/loc86.jpg',
|
||||
);
|
||||
assert.equal(
|
||||
normalizeCalgaryImageUrl('https://trafficcam.calgary.ca/loc86.jpg'),
|
||||
'https://trafficcam.calgary.ca/loc86.jpg',
|
||||
);
|
||||
assert.equal(normalizeCalgaryImageUrl(''), null);
|
||||
assert.equal(normalizeCalgaryImageUrl('not a url'), null);
|
||||
|
||||
assert.equal(
|
||||
calgaryCameraId('https://trafficcam.calgary.ca/loc86.jpg'),
|
||||
'calgary-86',
|
||||
);
|
||||
// A filename-scheme change degrades to a still-stable slug, not a dropped camera.
|
||||
assert.equal(
|
||||
calgaryCameraId('https://trafficcam.calgary.ca/cams/deerfoot_16av.jpg'),
|
||||
'calgary-cams-deerfoot-16av',
|
||||
);
|
||||
assert.equal(calgaryCameraId(''), null);
|
||||
});
|
||||
|
||||
test('a nameless row still gets a label', () => {
|
||||
assert.equal(
|
||||
calgaryCameraName(
|
||||
{ camera_location: ' 9 Avenue / 3 Street SE ' },
|
||||
'calgary-1',
|
||||
),
|
||||
'9 Avenue / 3 Street SE',
|
||||
);
|
||||
assert.equal(
|
||||
calgaryCameraName(
|
||||
{ camera_url: { description: 'Camera 12' } },
|
||||
'calgary-11',
|
||||
),
|
||||
'Camera 12',
|
||||
);
|
||||
assert.equal(calgaryCameraName({}, 'calgary-11'), 'Calgary Camera 11');
|
||||
});
|
||||
|
||||
test('the loader reads the keyless catalog and collapses duplicate ids', async (t) => {
|
||||
t.mock.method(console, 'log', () => {});
|
||||
const requested = [];
|
||||
t.mock.method(globalThis, 'fetch', async (url) => {
|
||||
requested.push(String(url));
|
||||
return Response.json([
|
||||
row(),
|
||||
// Same frame file twice: one camera, not two.
|
||||
row({ camera_location: 'Bow Trail / 37 Street SW (duplicate)' }),
|
||||
row({
|
||||
camera_url: { url: 'http://trafficcam.calgary.ca/loc86.jpg' },
|
||||
camera_location: 'Stoney Trail / Deerfoot Trail SE',
|
||||
point: { type: 'Point', coordinates: [-113.9766063, 50.9007257] },
|
||||
}),
|
||||
row({ camera_url: { url: 'https://evil.example/x.jpg' } }),
|
||||
]);
|
||||
});
|
||||
const cameras = await loadCalgarySourcesFromOpenData();
|
||||
assert.deepEqual(requested, [DEFAULT_CALGARY_ROWS_URL]);
|
||||
assert.deepEqual(
|
||||
cameras.map((camera) => camera.id),
|
||||
// Nearest downtown first: Bow Trail is inner-city, Stoney Trail is the ring road.
|
||||
['calgary-142', 'calgary-86'],
|
||||
);
|
||||
assert.equal(cameras[0].name, 'Bow Trail / 37 Street SW');
|
||||
});
|
||||
|
||||
test('an upstream failure yields an empty pack and releases the response', async (t) => {
|
||||
t.mock.method(console, 'warn', () => {});
|
||||
// A 503 can still arrive with a streaming body; returning without cancelling
|
||||
// it would hold the connection until the socket times out.
|
||||
const failed = streamingResponse({ status: 503 });
|
||||
t.mock.method(globalThis, 'fetch', async () => failed.response);
|
||||
assert.deepEqual(await loadCalgarySourcesFromOpenData(), []);
|
||||
assert.equal(failed.state.cancelled, true, 'the failed body is cancelled');
|
||||
|
||||
t.mock.restoreAll();
|
||||
t.mock.method(console, 'warn', () => {});
|
||||
t.mock.method(globalThis, 'fetch', async () => {
|
||||
throw new Error('network down');
|
||||
});
|
||||
assert.deepEqual(await loadCalgarySourcesFromOpenData(), []);
|
||||
});
|
||||
|
||||
test('the unselected label is the intersection, trimmed to the code width', () => {
|
||||
assert.equal(calgaryCameraToSource(row()).code, 'BOW TRAIL / 37 STREET SW');
|
||||
const long = calgaryCameraToSource(
|
||||
row({
|
||||
camera_location: 'Bow Trail & Old Banff Coach Rd SW / Strathcona Blvd SW',
|
||||
}),
|
||||
);
|
||||
assert.equal(long.code.length, CAMERA_CODE_MAX_CHARS);
|
||||
assert.ok(long.code.endsWith('…'));
|
||||
assert.ok(long.code.startsWith('BOW TRAIL & OLD BANFF'));
|
||||
});
|
||||
|
||||
test('the catalog fetch refuses redirects and oversized bodies', async (t) => {
|
||||
t.mock.method(console, 'warn', () => {});
|
||||
// A redirect is never followed: the list host cannot be steered. Its body is
|
||||
// a live stream, so the test also proves the refusal releases the transport.
|
||||
const seen = [];
|
||||
const redirected = streamingResponse({
|
||||
status: 302,
|
||||
headers: { location: 'https://evil.example/rows.json' },
|
||||
});
|
||||
t.mock.method(globalThis, 'fetch', async (url, init) => {
|
||||
seen.push([String(url), init.redirect]);
|
||||
return redirected.response;
|
||||
});
|
||||
assert.deepEqual(await loadCalgarySourcesFromOpenData(), []);
|
||||
assert.deepEqual(seen, [[DEFAULT_CALGARY_ROWS_URL, 'manual']]);
|
||||
assert.equal(
|
||||
redirected.state.cancelled,
|
||||
true,
|
||||
'the redirect body is cancelled',
|
||||
);
|
||||
|
||||
// A body over the cap is refused rather than buffered.
|
||||
t.mock.restoreAll();
|
||||
t.mock.method(console, 'warn', () => {});
|
||||
t.mock.method(globalThis, 'fetch', async () => {
|
||||
const body = JSON.stringify([row()]);
|
||||
return new Response(body, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'content-length': String(CALGARY_MAX_CATALOG_BYTES + 1),
|
||||
},
|
||||
});
|
||||
});
|
||||
assert.deepEqual(await loadCalgarySourcesFromOpenData(), []);
|
||||
|
||||
// So is a body that only declares its size once it is already too long.
|
||||
t.mock.restoreAll();
|
||||
t.mock.method(console, 'warn', () => {});
|
||||
t.mock.method(globalThis, 'fetch', async () => {
|
||||
const oversized = 'x'.repeat(CALGARY_MAX_CATALOG_BYTES + 1024);
|
||||
return new Response(
|
||||
new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode(oversized));
|
||||
controller.close();
|
||||
},
|
||||
}),
|
||||
{ headers: { 'Content-Type': 'application/json' } },
|
||||
);
|
||||
});
|
||||
assert.deepEqual(await loadCalgarySourcesFromOpenData(), []);
|
||||
});
|
||||
|
||||
test('a reduced catalog cap thins every pack instead of dropping Calgary', () => {
|
||||
// Calgary merges last in LIVE_PACKS, so a positional slice would delete it
|
||||
// outright. The round-robin allocation must give it its share.
|
||||
const lane = (name, count) => ({
|
||||
name,
|
||||
sources: Array.from({ length: count }, (_, i) => ({ id: `${name}-${i}` })),
|
||||
});
|
||||
const { sources, packs } = allocateSourceCap(
|
||||
[lane('austin', 250), lane('nsw', 217), lane('calgary', 215)],
|
||||
30,
|
||||
);
|
||||
assert.equal(sources.length, 30);
|
||||
assert.deepEqual(
|
||||
packs.map((p) => [p.name, p.kept]),
|
||||
[
|
||||
['austin', 10],
|
||||
['nsw', 10],
|
||||
['calgary', 10],
|
||||
],
|
||||
);
|
||||
// Calgary contributes its own highest-priority cameras, in its own order.
|
||||
assert.deepEqual(
|
||||
sources.filter((s) => s.id.startsWith('calgary-')).map((s) => s.id),
|
||||
Array.from({ length: 10 }, (_, i) => `calgary-${i}`),
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Serve the Calgary catalog to the Calgary endpoint and an empty payload to
|
||||
* every other pack, so one catalog refresh exercises the registration without
|
||||
* reaching the network. Returns the URLs that were requested.
|
||||
*/
|
||||
const runCatalogWithMockedUpstreams = async (t) => {
|
||||
const requested = [];
|
||||
t.mock.method(console, 'log', () => {});
|
||||
t.mock.method(console, 'warn', () => {});
|
||||
t.mock.method(globalThis, 'fetch', async (url) => {
|
||||
const href = String(url);
|
||||
requested.push(href);
|
||||
if (href.startsWith('https://data.calgary.ca/')) {
|
||||
return Response.json([
|
||||
row(),
|
||||
row({
|
||||
camera_url: { url: 'http://trafficcam.calgary.ca/loc86.jpg' },
|
||||
camera_location: 'Stoney Trail / Deerfoot Trail SE',
|
||||
point: { type: 'Point', coordinates: [-113.9766063, 50.9007257] },
|
||||
}),
|
||||
]);
|
||||
}
|
||||
return Response.json([]);
|
||||
});
|
||||
// A source root with no curated catalogs or ground-height sidecar, so the
|
||||
// file-based packs contribute nothing and only the live lanes are in play.
|
||||
const sources = await createCctvCatalog({ sourceRoot: '/nonexistent' })();
|
||||
return { requested, sources };
|
||||
};
|
||||
|
||||
test('the Calgary lane is wired into the catalog and its loader runs', async (t) => {
|
||||
const saved = { ...process.env };
|
||||
try {
|
||||
delete process.env.CCTV_SOURCES_FILE;
|
||||
delete process.env.CCTV_SOURCES_JSON;
|
||||
delete process.env.CCTV_CALGARY_ENABLED;
|
||||
const { requested, sources } = await runCatalogWithMockedUpstreams(t);
|
||||
assert.ok(
|
||||
requested.includes(DEFAULT_CALGARY_ROWS_URL),
|
||||
'the catalog refresh invokes the Calgary loader',
|
||||
);
|
||||
assert.deepEqual(
|
||||
sources.filter((s) => s.cityId === 'calgary').map((s) => s.id),
|
||||
['calgary-142', 'calgary-86'],
|
||||
'Calgary cameras reach the served catalog through the registered lane',
|
||||
);
|
||||
} finally {
|
||||
for (const key of Object.keys(process.env)) {
|
||||
if (!(key in saved)) delete process.env[key];
|
||||
}
|
||||
Object.assign(process.env, saved);
|
||||
}
|
||||
});
|
||||
|
||||
test('CCTV_CALGARY_ENABLED=0 keeps the lane from being loaded at all', async (t) => {
|
||||
const saved = { ...process.env };
|
||||
try {
|
||||
delete process.env.CCTV_SOURCES_FILE;
|
||||
delete process.env.CCTV_SOURCES_JSON;
|
||||
process.env.CCTV_CALGARY_ENABLED = '0';
|
||||
const { requested, sources } = await runCatalogWithMockedUpstreams(t);
|
||||
assert.equal(
|
||||
requested.includes(DEFAULT_CALGARY_ROWS_URL),
|
||||
false,
|
||||
'the disabled lane never reaches its upstream',
|
||||
);
|
||||
assert.deepEqual(
|
||||
sources.filter((s) => s.cityId === 'calgary'),
|
||||
[],
|
||||
);
|
||||
} finally {
|
||||
for (const key of Object.keys(process.env)) {
|
||||
if (!(key in saved)) delete process.env[key];
|
||||
}
|
||||
Object.assign(process.env, saved);
|
||||
}
|
||||
});
|
||||
|
||||
test('the shipped catalog ceiling is not raised to make room for this pack', () => {
|
||||
assert.equal(DEFAULT_CCTV_MAX_SOURCES, 4000);
|
||||
});
|
||||
@@ -24,6 +24,7 @@
|
||||
* invariant is untouched.
|
||||
*/
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from './inputOwnership.js';
|
||||
|
||||
// Grazing guard (spec §5): reject plane intersections when the view ray is
|
||||
// nearly parallel to the constraint plane — the hit point races to infinity
|
||||
@@ -506,6 +507,8 @@ export function createCalibrationGizmo({ viewer, getActiveRecord, applyPatch, en
|
||||
}
|
||||
|
||||
handler.setInputAction((event) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the press.
|
||||
if (!isPointerFree()) return;
|
||||
if (!enabled) return;
|
||||
const part = pickGizmoPart(event.position);
|
||||
debugLog('LEFT_DOWN', event.position, 'part:', part);
|
||||
|
||||
@@ -0,0 +1,588 @@
|
||||
// Client `Range` handling for the CCTV media proxy. The route used to relay
|
||||
// req.headers.range verbatim to a third-party upstream; these pin what is now
|
||||
// allowed through, both as string policy and through the mounted route with an
|
||||
// injected upstream.
|
||||
//
|
||||
// Run with: npm test (node --test)
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
import { Readable } from 'node:stream';
|
||||
import { cctvProxy } from '../../server/providers/cctv.js';
|
||||
import { sanitizeCctvRangeHeader } from '../../server/providers/cctv/range.js';
|
||||
import { CCTV_MEDIA_MAX_BODY_BYTES as CAP } from '../../server/providers/cctv/constants.js';
|
||||
|
||||
test('single well-formed byte ranges pass through canonicalized', () => {
|
||||
assert.equal(sanitizeCctvRangeHeader('bytes=0-1023'), 'bytes=0-1023');
|
||||
// A single range that names the same byte twice is legal.
|
||||
assert.equal(sanitizeCctvRangeHeader('bytes=7-7'), 'bytes=7-7');
|
||||
// The unit is case-insensitive (RFC 7233 §2.1); surrounding space is legal.
|
||||
assert.equal(sanitizeCctvRangeHeader(' BYTES=0-99 '), 'bytes=0-99');
|
||||
});
|
||||
|
||||
test('multi-range is dropped so the upstream never answers multipart/byteranges', () => {
|
||||
// The relay forwards Content-Length/Content-Range and caps on a single
|
||||
// declared body; a multipart response defeats that accounting.
|
||||
assert.equal(sanitizeCctvRangeHeader('bytes=0-1,2-3'), '');
|
||||
assert.equal(sanitizeCctvRangeHeader('bytes=0-1, 100-200, 300-'), '');
|
||||
});
|
||||
|
||||
test('malformed, non-byte and CR/LF-bearing values are dropped, not forwarded', () => {
|
||||
for (const bad of [
|
||||
'bytes=abc-def',
|
||||
'bytes=',
|
||||
'bytes=-',
|
||||
'bytes=1-2-3',
|
||||
'0-100', // no unit
|
||||
'items=0-100', // a unit the proxy does not understand
|
||||
'bytes=1.5-2',
|
||||
'bytes=-0', // zero-length suffix is unsatisfiable
|
||||
'bytes=0x10-0x20',
|
||||
'bytes=+5-10',
|
||||
'bytes=-5-10',
|
||||
// An outbound request refuses to carry these, and the failure used to be
|
||||
// written into the camera's health message.
|
||||
'bytes=0-10\r\nX-Injected: 1',
|
||||
'bytes=0-10\nHost: evil.example',
|
||||
]) {
|
||||
assert.equal(
|
||||
sanitizeCctvRangeHeader(bad),
|
||||
'',
|
||||
`expected drop: ${JSON.stringify(bad)}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('non-string and empty inputs yield no Range header', () => {
|
||||
// req.headers.range is undefined on a normal GET, and Node hands back an
|
||||
// array when a client sends the header twice.
|
||||
assert.equal(sanitizeCctvRangeHeader(undefined), '');
|
||||
assert.equal(sanitizeCctvRangeHeader(null), '');
|
||||
assert.equal(sanitizeCctvRangeHeader(''), '');
|
||||
assert.equal(sanitizeCctvRangeHeader(' '), '');
|
||||
assert.equal(sanitizeCctvRangeHeader(['bytes=0-1', 'bytes=2-3']), '');
|
||||
assert.equal(sanitizeCctvRangeHeader(42), '');
|
||||
});
|
||||
|
||||
test('every accepted form is bounded to the relay body cap', () => {
|
||||
// Explicit span.
|
||||
assert.equal(
|
||||
sanitizeCctvRangeHeader('bytes=0-999999999999'),
|
||||
`bytes=0-${CAP - 1}`,
|
||||
);
|
||||
assert.equal(
|
||||
sanitizeCctvRangeHeader('bytes=1000-999999999999'),
|
||||
`bytes=1000-${1000 + CAP - 1}`,
|
||||
);
|
||||
// Open-ended: bounded too, rather than asking an upstream for a whole file
|
||||
// of unknown size.
|
||||
assert.equal(
|
||||
sanitizeCctvRangeHeader('bytes=500-'),
|
||||
`bytes=500-${500 + CAP - 1}`,
|
||||
);
|
||||
// Suffix: bounded to one span of the tail.
|
||||
assert.equal(sanitizeCctvRangeHeader('bytes=-500'), 'bytes=-500');
|
||||
assert.equal(sanitizeCctvRangeHeader('bytes=-999999999999'), `bytes=-${CAP}`);
|
||||
// Exactly at the cap, and comfortably under it, are untouched.
|
||||
assert.equal(
|
||||
sanitizeCctvRangeHeader(`bytes=0-${CAP - 1}`),
|
||||
`bytes=0-${CAP - 1}`,
|
||||
);
|
||||
assert.equal(sanitizeCctvRangeHeader('bytes=0-1048575'), 'bytes=0-1048575');
|
||||
});
|
||||
|
||||
test('inverted and unsafe-integer positions are dropped', () => {
|
||||
assert.equal(sanitizeCctvRangeHeader('bytes=500-100'), '');
|
||||
// Beyond Number.MAX_SAFE_INTEGER the arithmetic silently loses precision.
|
||||
assert.equal(sanitizeCctvRangeHeader('bytes=99999999999999999-'), '');
|
||||
// Absurd digit counts are refused before any Number() conversion.
|
||||
assert.equal(sanitizeCctvRangeHeader(`bytes=0-${'9'.repeat(64)}`), '');
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// The mounted route, with the upstream injected through globalThis.fetch.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const CAMERA = {
|
||||
id: 'range-fixture',
|
||||
name: 'Range fixture',
|
||||
lat: 30.27,
|
||||
lon: -97.74,
|
||||
feedType: 'video',
|
||||
url: 'https://upstream.invalid/live.mp4',
|
||||
};
|
||||
|
||||
/** A minimal upstream Response with a streaming body. */
|
||||
function upstreamResponse({ status = 206, headers = {}, body = 'payload' }) {
|
||||
const store = new Map(
|
||||
Object.entries(headers).map(([key, value]) => [key.toLowerCase(), value]),
|
||||
);
|
||||
return {
|
||||
ok: status >= 200 && status < 300,
|
||||
status,
|
||||
headers: { get: (name) => store.get(String(name).toLowerCase()) ?? null },
|
||||
body:
|
||||
body === null
|
||||
? null
|
||||
: Readable.toWeb(Readable.from([Buffer.from(String(body))])),
|
||||
arrayBuffer: async () => Buffer.from(String(body)),
|
||||
};
|
||||
}
|
||||
|
||||
/** Collects what a handler wrote, the way a Node ServerResponse would. */
|
||||
function recordingResponse() {
|
||||
const chunks = [];
|
||||
let finished;
|
||||
const done = new Promise((resolve) => {
|
||||
finished = resolve;
|
||||
});
|
||||
const res = {
|
||||
statusCode: 0,
|
||||
headers: {},
|
||||
writableEnded: false,
|
||||
body: '',
|
||||
writeHead(status, headers) {
|
||||
res.statusCode = status;
|
||||
res.headers = headers || {};
|
||||
},
|
||||
write(chunk) {
|
||||
chunks.push(Buffer.from(chunk));
|
||||
return true;
|
||||
},
|
||||
end(chunk) {
|
||||
if (chunk) chunks.push(Buffer.from(chunk));
|
||||
res.writableEnded = true;
|
||||
res.body = Buffer.concat(chunks).toString('utf8');
|
||||
finished();
|
||||
},
|
||||
on() {},
|
||||
once() {},
|
||||
emit() {},
|
||||
destroy() {},
|
||||
};
|
||||
return { res, done };
|
||||
}
|
||||
|
||||
/**
|
||||
* Mount the real provider, serve one camera, and answer its upstream from the
|
||||
* supplied function.
|
||||
*/
|
||||
function mount(t, respond) {
|
||||
const before = {
|
||||
json: process.env.CCTV_SOURCES_JSON,
|
||||
file: process.env.CCTV_SOURCES_FILE,
|
||||
austin: process.env.CCTV_FORCE_AUSTIN,
|
||||
};
|
||||
process.env.CCTV_SOURCES_JSON = JSON.stringify([CAMERA]);
|
||||
process.env.CCTV_SOURCES_FILE = 'absent-source-file.json';
|
||||
process.env.CCTV_FORCE_AUSTIN = '0';
|
||||
const nativeFetch = globalThis.fetch;
|
||||
const requests = [];
|
||||
globalThis.fetch = async (url, init = {}) => {
|
||||
requests.push({
|
||||
url: String(url),
|
||||
headers: init.headers || {},
|
||||
signal: init.signal || null,
|
||||
});
|
||||
return respond({ url: String(url), init });
|
||||
};
|
||||
t.after(() => {
|
||||
globalThis.fetch = nativeFetch;
|
||||
for (const [name, value] of [
|
||||
['CCTV_SOURCES_JSON', before.json],
|
||||
['CCTV_SOURCES_FILE', before.file],
|
||||
['CCTV_FORCE_AUSTIN', before.austin],
|
||||
]) {
|
||||
if (value === undefined) delete process.env[name];
|
||||
else process.env[name] = value;
|
||||
}
|
||||
});
|
||||
|
||||
let handler = null;
|
||||
const plugin = cctvProxy();
|
||||
plugin.configureServer({
|
||||
middlewares: {
|
||||
use: (_route, fn) => {
|
||||
handler = fn;
|
||||
},
|
||||
},
|
||||
});
|
||||
assert.ok(handler, 'the CCTV provider must mount a middleware');
|
||||
|
||||
/** Drive one request through the mounted handler. */
|
||||
const call = async (path, headers = {}) => {
|
||||
const { res, done } = recordingResponse();
|
||||
await handler({ url: path, headers, method: 'GET', on() {} }, res);
|
||||
await done;
|
||||
return res;
|
||||
};
|
||||
/** Read the camera's current health entry. */
|
||||
const health = async () => {
|
||||
const res = await call('/health');
|
||||
return JSON.parse(res.body).cameras.find(({ id }) => id === CAMERA.id);
|
||||
};
|
||||
return { call, health, requests, handler: (req, res) => handler(req, res) };
|
||||
}
|
||||
|
||||
test('a canonical range reaches the upstream and its 206 is passed through', async (t) => {
|
||||
const app = mount(t, () =>
|
||||
upstreamResponse({
|
||||
status: 206,
|
||||
headers: {
|
||||
'content-type': 'video/mp4',
|
||||
'content-range': 'bytes 0-1023/4096',
|
||||
'content-length': '1024',
|
||||
'accept-ranges': 'bytes',
|
||||
},
|
||||
body: 'partial',
|
||||
}),
|
||||
);
|
||||
const res = await app.call(`/media/${CAMERA.id}`, { range: 'bytes=0-1023' });
|
||||
assert.equal(app.requests.at(-1).headers.Range, 'bytes=0-1023');
|
||||
assert.equal(res.statusCode, 206);
|
||||
assert.equal(res.headers['Content-Range'], 'bytes 0-1023/4096');
|
||||
assert.equal(res.headers['Accept-Ranges'], 'bytes');
|
||||
assert.equal(res.body, 'partial');
|
||||
});
|
||||
|
||||
test('an unbounded seek is bounded before it is forwarded', async (t) => {
|
||||
const app = mount(t, () =>
|
||||
upstreamResponse({
|
||||
status: 206,
|
||||
headers: { 'content-type': 'video/mp4' },
|
||||
body: 'tail',
|
||||
}),
|
||||
);
|
||||
await app.call(`/media/${CAMERA.id}`, { range: 'bytes=500-' });
|
||||
assert.equal(app.requests.at(-1).headers.Range, `bytes=500-${500 + CAP - 1}`);
|
||||
});
|
||||
|
||||
test('a rejected range is dropped and the request proceeds without one', async (t) => {
|
||||
const app = mount(t, () =>
|
||||
upstreamResponse({
|
||||
status: 200,
|
||||
headers: { 'content-type': 'video/mp4' },
|
||||
body: 'whole body',
|
||||
}),
|
||||
);
|
||||
const res = await app.call(`/media/${CAMERA.id}`, {
|
||||
range: 'bytes=0-10\r\nX-Injected: 1',
|
||||
});
|
||||
// Documented choice: drop the header rather than answer 400, so a client
|
||||
// that sends something this proxy will not carry still gets its media.
|
||||
assert.equal(app.requests.at(-1).headers.Range, undefined);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.equal(res.body, 'whole body');
|
||||
});
|
||||
|
||||
test('a rejected range leaves the camera health report untouched', async (t) => {
|
||||
const app = mount(t, () =>
|
||||
upstreamResponse({
|
||||
status: 200,
|
||||
headers: { 'content-type': 'video/mp4' },
|
||||
body: 'whole body',
|
||||
}),
|
||||
);
|
||||
await app.call(`/media/${CAMERA.id}`, {
|
||||
range: 'bytes=0-10\r\nX-Injected: 1',
|
||||
});
|
||||
const entry = await app.health();
|
||||
assert.equal(entry.status, 'ok');
|
||||
// The client's own string must never appear in a report other callers read.
|
||||
assert.doesNotMatch(JSON.stringify(entry), /X-Injected/);
|
||||
});
|
||||
|
||||
test('a multi-range request is served whole rather than as multipart', async (t) => {
|
||||
const app = mount(t, ({ init }) =>
|
||||
upstreamResponse({
|
||||
status: init?.headers?.Range ? 206 : 200,
|
||||
headers: {
|
||||
'content-type': init?.headers?.Range
|
||||
? 'multipart/byteranges; boundary=x'
|
||||
: 'video/mp4',
|
||||
},
|
||||
body: 'whole body',
|
||||
}),
|
||||
);
|
||||
const res = await app.call(`/media/${CAMERA.id}`, {
|
||||
range: 'bytes=0-1,2-3',
|
||||
});
|
||||
assert.equal(app.requests.at(-1).headers.Range, undefined);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.equal(res.headers['Content-Type'], 'video/mp4');
|
||||
});
|
||||
|
||||
test('an upstream 416 is reported as the upstream status, not as a proxy error', async (t) => {
|
||||
const app = mount(t, () =>
|
||||
upstreamResponse({
|
||||
status: 416,
|
||||
headers: { 'content-range': 'bytes */1024' },
|
||||
body: null,
|
||||
}),
|
||||
);
|
||||
const res = await app.call(`/media/${CAMERA.id}`, {
|
||||
range: `bytes=${2 ** 40}-${2 ** 40 + 10}`,
|
||||
});
|
||||
assert.equal(res.statusCode, 416);
|
||||
assert.match(res.body, /416/);
|
||||
const entry = await app.health();
|
||||
assert.equal(entry.status, 'degraded');
|
||||
assert.equal(entry.message, 'Upstream HTTP 416');
|
||||
});
|
||||
|
||||
test('an upstream that ignores the range still serves its whole body', async (t) => {
|
||||
const app = mount(t, () =>
|
||||
upstreamResponse({
|
||||
status: 200,
|
||||
headers: { 'content-type': 'video/mp4', 'content-length': '10' },
|
||||
body: 'whole body',
|
||||
}),
|
||||
);
|
||||
const res = await app.call(`/media/${CAMERA.id}`, { range: 'bytes=0-1023' });
|
||||
assert.equal(app.requests.at(-1).headers.Range, 'bytes=0-1023');
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.equal(res.body, 'whole body');
|
||||
});
|
||||
|
||||
test('an oversized declared body is refused even when a bounded range asked for it', async (t) => {
|
||||
const app = mount(t, () =>
|
||||
upstreamResponse({
|
||||
status: 206,
|
||||
headers: {
|
||||
'content-type': 'video/mp4',
|
||||
'content-length': String(CAP + 1),
|
||||
},
|
||||
body: 'too big',
|
||||
}),
|
||||
);
|
||||
const res = await app.call(`/media/${CAMERA.id}`, { range: 'bytes=0-1023' });
|
||||
assert.equal(res.statusCode, 502);
|
||||
assert.match(res.body, /exceeds size cap/);
|
||||
});
|
||||
|
||||
test('a client that disconnects mid-stream stops the upstream read', async (t) => {
|
||||
// A live feed with no end of its own, counting what it is asked to produce.
|
||||
let produced = 0;
|
||||
let stopped = false;
|
||||
const endlessBody = () =>
|
||||
Readable.toWeb(
|
||||
Readable.from(
|
||||
(async function* () {
|
||||
try {
|
||||
for (;;) {
|
||||
produced += 1;
|
||||
yield Buffer.from('frame-chunk-');
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
}
|
||||
} finally {
|
||||
stopped = true;
|
||||
}
|
||||
})(),
|
||||
),
|
||||
);
|
||||
const app = mount(t, () => ({
|
||||
ok: true,
|
||||
status: 206,
|
||||
headers: {
|
||||
get: (name) =>
|
||||
String(name).toLowerCase() === 'content-type' ? 'video/mp4' : null,
|
||||
},
|
||||
body: endlessBody(),
|
||||
arrayBuffer: async () => Buffer.alloc(0),
|
||||
}));
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
req.url = req.url.replace('/api/cctv', '') || '/';
|
||||
Promise.resolve(app.handler(req, res)).catch(() => {});
|
||||
});
|
||||
t.after(() => new Promise((resolve) => server.close(resolve)));
|
||||
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
||||
const { port } = server.address();
|
||||
|
||||
const failures = [];
|
||||
const onUncaught = (error) => failures.push(error);
|
||||
process.on('uncaughtException', onUncaught);
|
||||
t.after(() => process.off('uncaughtException', onUncaught));
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
const request = http.get(
|
||||
{
|
||||
host: '127.0.0.1',
|
||||
port,
|
||||
path: `/media/${CAMERA.id}`.replace(/^/, '/api/cctv'),
|
||||
headers: { Range: 'bytes=0-1023' },
|
||||
},
|
||||
(response) => {
|
||||
response.once('data', () => {
|
||||
// Walk away mid-body, the way a browser does when the operator
|
||||
// switches camera.
|
||||
request.destroy();
|
||||
resolve();
|
||||
});
|
||||
response.on('error', () => resolve());
|
||||
},
|
||||
);
|
||||
request.on('error', reject);
|
||||
});
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 150));
|
||||
const afterDisconnect = produced;
|
||||
await new Promise((resolve) => setTimeout(resolve, 400));
|
||||
// The point: the camera host is no longer being read from. Without the
|
||||
// release this counter keeps climbing for as long as the upstream will feed.
|
||||
assert.equal(
|
||||
produced,
|
||||
afterDisconnect,
|
||||
`the upstream was still being read after the client left (${afterDisconnect} → ${produced} chunks)`,
|
||||
);
|
||||
assert.equal(stopped, true, 'the upstream body was never released');
|
||||
assert.deepEqual(
|
||||
failures.map((error) => error?.message),
|
||||
[],
|
||||
'a client walking away must not fault the server',
|
||||
);
|
||||
const entry = await app.health();
|
||||
// The camera was serving fine; the client left. Nothing about that is a
|
||||
// camera fault other viewers should see.
|
||||
assert.equal(entry.status, 'ok');
|
||||
});
|
||||
|
||||
test('a client that leaves before the headers arrive cancels the upstream request', async (t) => {
|
||||
// The camera is slow, or dead: nothing comes back until the request is
|
||||
// cancelled. Everything worth testing here happens before any header.
|
||||
let aborted = false;
|
||||
const app = mount(t, ({ init }) => {
|
||||
return new Promise((_resolve, reject) => {
|
||||
init.signal.addEventListener('abort', () => {
|
||||
aborted = true;
|
||||
reject(Object.assign(new Error('aborted'), { name: 'AbortError' }));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
req.url = req.url.replace('/api/cctv', '') || '/';
|
||||
Promise.resolve(app.handler(req, res)).catch(() => {});
|
||||
});
|
||||
t.after(() => new Promise((resolve) => server.close(resolve)));
|
||||
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
||||
const { port } = server.address();
|
||||
|
||||
const failures = [];
|
||||
const onUncaught = (error) => failures.push(error);
|
||||
process.on('uncaughtException', onUncaught);
|
||||
t.after(() => process.off('uncaughtException', onUncaught));
|
||||
|
||||
const request = http.get({
|
||||
host: '127.0.0.1',
|
||||
port,
|
||||
path: `/api/cctv/media/${CAMERA.id}`,
|
||||
headers: { Range: 'bytes=0-1023' },
|
||||
});
|
||||
request.on('error', () => {});
|
||||
// Let the route reach its upstream request, then walk away before it answers.
|
||||
await new Promise((resolve) => setTimeout(resolve, 150));
|
||||
assert.equal(app.requests.length, 1, 'the upstream request went out');
|
||||
assert.equal(aborted, false, 'nothing was cancelled while the client waited');
|
||||
request.destroy();
|
||||
await new Promise((resolve) => setTimeout(resolve, 250));
|
||||
|
||||
assert.equal(aborted, true, 'the upstream request outlived the client');
|
||||
assert.deepEqual(
|
||||
failures.map((error) => error?.message),
|
||||
[],
|
||||
'a client leaving early must not fault the server',
|
||||
);
|
||||
// The camera did nothing wrong; the viewer left.
|
||||
const entry = await app.health();
|
||||
assert.notEqual(entry?.status, 'degraded');
|
||||
});
|
||||
|
||||
test('a folded CR/LF range never reaches the upstream through a real client', async (t) => {
|
||||
// Node's own parser, not a hand-built headers object, so the reachability of
|
||||
// this shape through an ordinary HTTP request is shown rather than assumed.
|
||||
const app = mount(t, () =>
|
||||
upstreamResponse({
|
||||
status: 200,
|
||||
headers: { 'content-type': 'video/mp4' },
|
||||
body: 'whole body',
|
||||
}),
|
||||
);
|
||||
const server = http.createServer((req, res) => {
|
||||
req.url = req.url.replace('/api/cctv', '') || '/';
|
||||
Promise.resolve(app.handler(req, res)).catch(() => {});
|
||||
});
|
||||
t.after(() => new Promise((resolve) => server.close(resolve)));
|
||||
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
||||
const { port } = server.address();
|
||||
|
||||
// A client can fold a value across a continuation line; Node's parser
|
||||
// rejoins it, so what the route sees contains whitespace a header cannot
|
||||
// carry back out.
|
||||
const raw = await new Promise((resolve, reject) => {
|
||||
const socket = net.connect(port, '127.0.0.1', () => {
|
||||
socket.write(
|
||||
`GET /api/cctv/media/${CAMERA.id} HTTP/1.1\r\n` +
|
||||
'Host: 127.0.0.1\r\n' +
|
||||
'Range: bytes=0-10\r\n\tX-Injected: 1\r\n' +
|
||||
'Connection: close\r\n\r\n',
|
||||
);
|
||||
});
|
||||
let text = '';
|
||||
socket.on('data', (chunk) => {
|
||||
text += chunk.toString('utf8');
|
||||
});
|
||||
socket.on('end', () => resolve(text));
|
||||
socket.on('error', reject);
|
||||
});
|
||||
|
||||
// Either Node's parser refuses the request outright, or it reaches the route
|
||||
// and the route drops the value — but it must never be forwarded.
|
||||
const reachedRoute = app.requests.length > 0;
|
||||
assert.match(raw, /^HTTP\/1\.1 (200|400)/);
|
||||
if (reachedRoute) {
|
||||
assert.equal(
|
||||
app.requests.at(-1).headers.Range,
|
||||
undefined,
|
||||
'nothing was forwarded',
|
||||
);
|
||||
assert.match(raw, /^HTTP\/1\.1 200/);
|
||||
} else {
|
||||
assert.match(raw, /^HTTP\/1\.1 400/);
|
||||
}
|
||||
console.log(
|
||||
` [range] folded CR/LF request ${reachedRoute ? 'reached the route and was dropped' : 'was refused by the HTTP parser'}`,
|
||||
);
|
||||
const entry = await app.health();
|
||||
assert.doesNotMatch(JSON.stringify(entry ?? {}), /X-Injected/);
|
||||
});
|
||||
|
||||
test('two sequential seeks are served as two partial responses', async (t) => {
|
||||
const app = mount(t, ({ init }) => {
|
||||
const range = init?.headers?.Range || '';
|
||||
const [, first, last] = /bytes=(\d+)-(\d+)/.exec(range) || [];
|
||||
return upstreamResponse({
|
||||
status: 206,
|
||||
headers: {
|
||||
'content-type': 'video/mp4',
|
||||
'content-range': `bytes ${first}-${last}/4096`,
|
||||
'content-length': String(Number(last) - Number(first) + 1),
|
||||
'accept-ranges': 'bytes',
|
||||
},
|
||||
body: `chunk-${first}`,
|
||||
});
|
||||
});
|
||||
const first = await app.call(`/media/${CAMERA.id}`, { range: 'bytes=0-99' });
|
||||
const second = await app.call(`/media/${CAMERA.id}`, {
|
||||
range: 'bytes=100-199',
|
||||
});
|
||||
assert.equal(app.requests[0].headers.Range, 'bytes=0-99');
|
||||
assert.equal(app.requests[1].headers.Range, 'bytes=100-199');
|
||||
assert.equal(first.statusCode, 206);
|
||||
assert.equal(second.statusCode, 206);
|
||||
assert.equal(first.headers['Content-Range'], 'bytes 0-99/4096');
|
||||
assert.equal(second.headers['Content-Range'], 'bytes 100-199/4096');
|
||||
assert.equal(first.body, 'chunk-0');
|
||||
assert.equal(second.body, 'chunk-100');
|
||||
});
|
||||
@@ -163,6 +163,12 @@ export const DATA_CREDITS = [
|
||||
'<a href="https://www.digitraffic.fi/en/" target="_blank" rel="noopener">digitraffic.fi</a>, ' +
|
||||
'license CC BY 4.0',
|
||||
},
|
||||
{
|
||||
key: 'calgary-cctv',
|
||||
html:
|
||||
'Traffic cameras (Calgary): contains information licensed under the ' +
|
||||
'<a href="https://data.calgary.ca/stories/s/Open-Calgary-Terms-of-Use/u45n-7awa" target="_blank" rel="noopener">Open Government Licence – City of Calgary</a>',
|
||||
},
|
||||
{
|
||||
key: 'gbfs',
|
||||
html: 'Bikeshare availability: GBFS operator feeds (e.g. Austin BCycle)',
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Who owns the pointer over the globe.
|
||||
*
|
||||
* Most layers bind their own `ScreenSpaceEventHandler` to the same canvas and
|
||||
* select whatever is under a left click. That is right when nothing else is
|
||||
* going on, and wrong the moment a tool needs the pointer for itself: a draw
|
||||
* session placing a vertex on top of an aircraft must not also track the
|
||||
* aircraft, and the next such tool must not have to be added to a list inside
|
||||
* every layer.
|
||||
*
|
||||
* So there is one claim, held by at most one owner at a time:
|
||||
*
|
||||
* - A TOOL that needs the pointer calls `claimPointer('draw')` when it turns on
|
||||
* and gets back a LEASE — an opaque token. It releases with
|
||||
* `releasePointer(lease)` when it turns off. It does not consult anyone;
|
||||
* holding the claim is what makes it the owner.
|
||||
* - An AMBIENT SELECTION HANDLER — anything that picks an entity because the
|
||||
* user clicked — early-returns while `isPointerFree()` is false. It never
|
||||
* claims.
|
||||
*
|
||||
* Claims do not stack and are never stolen: while one owner holds the pointer,
|
||||
* a second `claimPointer` returns null rather than displacing it — and so does
|
||||
* a second claim under the SAME name, because two live instances of one tool
|
||||
* (an old one mid-teardown, its replacement already running) are two owners,
|
||||
* not one. The lease is what tells them apart: releasing takes the token that
|
||||
* was issued, so a superseded instance calling `releasePointer` with its own
|
||||
* stale lease frees nothing and its successor keeps the pointer.
|
||||
*
|
||||
* Ownership is page-scoped, like the layers and handlers it arbitrates.
|
||||
*/
|
||||
|
||||
/** @typedef {{owner: string, id: number}} PointerLease */
|
||||
|
||||
/** @type {PointerLease|null} */
|
||||
let currentLease = null;
|
||||
let nextLeaseId = 1;
|
||||
|
||||
/**
|
||||
* Take the pointer for `owner`.
|
||||
* @param {string} owner Stable identifier for the claiming tool, e.g. 'draw'.
|
||||
* @returns {PointerLease|null} The lease to release with, or null if the
|
||||
* pointer is already held — including by another instance of the same tool.
|
||||
*/
|
||||
export function claimPointer(owner) {
|
||||
const name = normalizeOwner(owner);
|
||||
if (!name) return null;
|
||||
if (currentLease !== null) return null;
|
||||
currentLease = Object.freeze({ owner: name, id: nextLeaseId++ });
|
||||
return currentLease;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the pointer back. Only the exact lease that took it can release it, so a
|
||||
* superseded instance cannot free the claim its replacement now holds.
|
||||
* @param {PointerLease|null} lease The token `claimPointer` returned.
|
||||
* @returns {boolean} Whether this call released the claim.
|
||||
*/
|
||||
export function releasePointer(lease) {
|
||||
if (!currentLease || !lease || lease.id !== currentLease.id) return false;
|
||||
currentLease = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @returns {string|null} The current owner's name, or null when free. */
|
||||
export function pointerOwner() {
|
||||
return currentLease ? currentLease.owner : null;
|
||||
}
|
||||
|
||||
/** @returns {boolean} True when no tool holds the pointer. */
|
||||
export function isPointerFree() {
|
||||
return currentLease === null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} owner
|
||||
* @returns {boolean} True when a tool of that name is holding the pointer.
|
||||
*/
|
||||
export function isPointerOwnedBy(owner) {
|
||||
const name = normalizeOwner(owner);
|
||||
return Boolean(name) && pointerOwner() === name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {PointerLease|null} lease
|
||||
* @returns {boolean} True when THIS lease is the live one.
|
||||
*/
|
||||
export function isLeaseCurrent(lease) {
|
||||
return Boolean(currentLease && lease && lease.id === currentLease.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop any claim. For tests and for application teardown, which cannot rely on
|
||||
* a half-disposed tool to release its own lease.
|
||||
* @returns {string|null} The owner that was holding it, if any.
|
||||
*/
|
||||
export function resetPointerOwnership() {
|
||||
const previous = pointerOwner();
|
||||
currentLease = null;
|
||||
return previous;
|
||||
}
|
||||
|
||||
function normalizeOwner(owner) {
|
||||
return typeof owner === 'string' && owner.trim() ? owner.trim() : null;
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import {
|
||||
claimPointer,
|
||||
isLeaseCurrent,
|
||||
isPointerFree,
|
||||
isPointerOwnedBy,
|
||||
pointerOwner,
|
||||
releasePointer,
|
||||
resetPointerOwnership,
|
||||
} from './inputOwnership.js';
|
||||
|
||||
const ROOT = path.resolve(
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
'..',
|
||||
'..',
|
||||
);
|
||||
const read = (rel) => fs.readFileSync(path.join(ROOT, rel), 'utf8');
|
||||
|
||||
test.beforeEach(() => resetPointerOwnership());
|
||||
|
||||
test('the pointer starts free and a claim hands back a lease', () => {
|
||||
assert.equal(isPointerFree(), true);
|
||||
assert.equal(pointerOwner(), null);
|
||||
|
||||
const lease = claimPointer('draw');
|
||||
assert.ok(lease, 'a successful claim returns a lease, not a boolean');
|
||||
assert.equal(isPointerFree(), false);
|
||||
assert.equal(pointerOwner(), 'draw');
|
||||
assert.equal(isPointerOwnedBy('draw'), true);
|
||||
assert.equal(isPointerOwnedBy('directions'), false);
|
||||
assert.equal(isLeaseCurrent(lease), true);
|
||||
});
|
||||
|
||||
test('a claim is never stolen — not even by the same tool name', () => {
|
||||
const first = claimPointer('draw');
|
||||
assert.ok(first);
|
||||
|
||||
assert.equal(
|
||||
claimPointer('directions'),
|
||||
null,
|
||||
'another tool must not displace it',
|
||||
);
|
||||
assert.equal(
|
||||
claimPointer('draw'),
|
||||
null,
|
||||
'a SECOND instance of the same tool is a second owner, not a no-op',
|
||||
);
|
||||
assert.equal(pointerOwner(), 'draw');
|
||||
assert.equal(isLeaseCurrent(first), true);
|
||||
});
|
||||
|
||||
test('a replaced instance cannot free its successor’s claim', () => {
|
||||
// The bug this rule exists for. An old Draw instance is torn down while a new
|
||||
// one is already running; the old teardown calls releasePointer. Under
|
||||
// release-by-name that freed the LIVE claim and every layer started selecting
|
||||
// through the new instance's vertices.
|
||||
const stale = claimPointer('draw');
|
||||
assert.ok(releasePointer(stale), 'the old instance gives the pointer back');
|
||||
|
||||
const live = claimPointer('draw');
|
||||
assert.ok(live, 'the replacement takes it');
|
||||
assert.notEqual(live.id, stale.id, 'a fresh claim is a fresh lease');
|
||||
|
||||
assert.equal(releasePointer(stale), false, 'the stale lease frees nothing');
|
||||
assert.equal(pointerOwner(), 'draw', 'the replacement still holds it');
|
||||
assert.equal(isLeaseCurrent(stale), false);
|
||||
assert.equal(isLeaseCurrent(live), true);
|
||||
|
||||
assert.equal(releasePointer(live), true);
|
||||
assert.equal(isPointerFree(), true);
|
||||
});
|
||||
|
||||
test('release ignores anything that is not the live lease', () => {
|
||||
const lease = claimPointer('draw');
|
||||
for (const bad of [
|
||||
null,
|
||||
undefined,
|
||||
'draw',
|
||||
{},
|
||||
{ owner: 'draw', id: lease.id + 99 },
|
||||
]) {
|
||||
assert.equal(releasePointer(bad), false, JSON.stringify(bad));
|
||||
assert.equal(pointerOwner(), 'draw');
|
||||
}
|
||||
assert.equal(releasePointer(lease), true);
|
||||
assert.equal(releasePointer(lease), false, 'releasing twice changes nothing');
|
||||
});
|
||||
|
||||
test('a claim needs a real owner id', () => {
|
||||
for (const bad of ['', ' ', null, undefined, 7, {}]) {
|
||||
assert.equal(claimPointer(bad), null, JSON.stringify(bad));
|
||||
assert.equal(isPointerFree(), true);
|
||||
}
|
||||
const lease = claimPointer(' draw ');
|
||||
assert.ok(lease, 'ids are trimmed, not rejected for padding');
|
||||
assert.equal(pointerOwner(), 'draw');
|
||||
assert.equal(releasePointer(lease), true);
|
||||
});
|
||||
|
||||
test('reset reports who was holding it, for teardown', () => {
|
||||
assert.equal(resetPointerOwnership(), null);
|
||||
const lease = claimPointer('draw');
|
||||
assert.equal(resetPointerOwnership(), 'draw');
|
||||
assert.equal(isPointerFree(), true);
|
||||
assert.equal(isLeaseCurrent(lease), false);
|
||||
});
|
||||
|
||||
test('every scene click handler consults ownership before it picks', () => {
|
||||
// This is the whole point of a shared contract: a new tool must not have to
|
||||
// find and edit each of these. If a layer grows a click handler it has to
|
||||
// appear here too.
|
||||
const guarded = [
|
||||
['src/data/trackingClickGesture.js', 'onClick(click, gesture);'],
|
||||
['src/data/localGeojsonCore.js', 'viewer.scene.pick(click.position)'],
|
||||
['src/data/cctvGizmo.js', 'pickGizmoPart(event.position)'],
|
||||
['src/layers/alpr/presentation.js', 'viewer.scene.pick(click.position)'],
|
||||
['src/layers/bikeshare/selection.js', 'viewer.scene.pick(click.position)'],
|
||||
['src/layers/firms/selection.js', 'scene.pick(click.position)'],
|
||||
[
|
||||
'src/layers/installations/selection.js',
|
||||
'viewer.scene.pick(click.position)',
|
||||
],
|
||||
['src/layers/launches/lifecycle.js', 'drillPick(movement.position'],
|
||||
['src/layers/radio/interaction.js', 'pickedRadioStationAt(click.position)'],
|
||||
[
|
||||
'src/layers/satellites/interaction.js',
|
||||
'viewer.scene.pick(click.position)',
|
||||
],
|
||||
[
|
||||
'src/layers/submarineCables/interaction.js',
|
||||
'viewer.scene.pick(click.position)',
|
||||
],
|
||||
['src/layers/vessels/selection.js', 'viewer.scene.pick(click.position)'],
|
||||
];
|
||||
for (const [file, firstPick] of guarded) {
|
||||
const source = read(file);
|
||||
assert.match(
|
||||
source,
|
||||
/import \{ isPointerFree \} from '[^']*inputOwnership\.js';/,
|
||||
`${file} must consult the shared pointer claim`,
|
||||
);
|
||||
const guardAt = source.indexOf('if (!isPointerFree()) return;');
|
||||
const pickAt = source.indexOf(firstPick);
|
||||
assert.ok(guardAt >= 0, `${file} is missing the guard`);
|
||||
assert.ok(
|
||||
pickAt >= 0,
|
||||
`${file}: could not find its pick call (${firstPick})`,
|
||||
);
|
||||
assert.ok(
|
||||
guardAt < pickAt,
|
||||
`${file} must yield before it picks, not after`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('ambient selection handlers never claim the pointer themselves', () => {
|
||||
// Claiming from a selection handler would deadlock every other layer the
|
||||
// moment a user clicked anything. Only tools claim.
|
||||
for (const file of [
|
||||
'src/data/trackingClickGesture.js',
|
||||
'src/data/localGeojsonCore.js',
|
||||
'src/data/cctvGizmo.js',
|
||||
'src/layers/vessels/selection.js',
|
||||
'src/layers/satellites/interaction.js',
|
||||
]) {
|
||||
assert.doesNotMatch(
|
||||
read(file),
|
||||
/claimPointer\(/,
|
||||
`${file} must not claim the pointer`,
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from './inputOwnership.js';
|
||||
import {
|
||||
selectInfraLod,
|
||||
applyInfraEvictionGrace,
|
||||
@@ -768,6 +769,8 @@ export function createLocalGeoJsonLayer(
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
_clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js).
|
||||
if (!isPointerFree()) return;
|
||||
if (!_enabled) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from './inputOwnership.js';
|
||||
|
||||
export const MAX_TRACKING_CLICK_TRAVEL_PX = 6;
|
||||
export const MAX_TRACKING_CLICK_DURATION_MS = 400;
|
||||
@@ -95,6 +96,9 @@ export function bindTrackingClickGesture(handler, onClick, options = {}) {
|
||||
if (pressActive) finishPress(click?.position);
|
||||
const gesture = completedGesture || { travelPx: 0, durationMs: 0 };
|
||||
completedGesture = null;
|
||||
// A tool owns the pointer: a draw vertex placed over an aircraft is a
|
||||
// vertex, not a track request (src/data/inputOwnership.js).
|
||||
if (!isPointerFree()) return;
|
||||
onClick(click, gesture);
|
||||
}, eventTypes.LEFT_CLICK);
|
||||
}
|
||||
@@ -9,6 +9,12 @@ import {
|
||||
/** PowerShell verification for the exact owner-only Windows credential DACL. */
|
||||
const WINDOWS_ACL_VERIFY_SCRIPT = [
|
||||
"$ErrorActionPreference = 'Stop'",
|
||||
// Load Microsoft.PowerShell.Security (Get-Acl) from the module tree of the
|
||||
// interpreter that is actually running. $PSHOME is that interpreter's own
|
||||
// physical directory, so this is correct even when the executable was named
|
||||
// through the Sysnative bridge, and it cannot be steered by anything the
|
||||
// parent environment set.
|
||||
"$env:PSModulePath = Join-Path $PSHOME 'Modules'",
|
||||
'$acl = Get-Acl -LiteralPath $env:GEV_ACL_FILE',
|
||||
'if (-not $acl.AreAccessRulesProtected) { exit 2 }',
|
||||
"$allowed = @($env:GEV_ACL_USER_SID, 'S-1-5-18', 'S-1-5-32-544')",
|
||||
@@ -143,15 +149,40 @@ export function hardenCredentialFile(filepath, {
|
||||
// accept only three explicit FullControl allow principals, with inheritance
|
||||
// disabled. Any unexpected rule, right, command error, or missing principal
|
||||
// fails closed before the secret reaches disk.
|
||||
//
|
||||
// The verify process must load Microsoft.PowerShell.Security (Get-Acl)
|
||||
// from the Windows PowerShell system module tree ONLY. A side-by-side
|
||||
// PowerShell 7 install prepends its own module trees to PSModulePath at
|
||||
// startup; inherited into a 5.1 process, the incompatible 7.x manifest
|
||||
// cannot be autoloaded and the verify step fails. The script itself sets
|
||||
// the path from $PSHOME; this is the same value computed ahead of time, so
|
||||
// nothing inherited is in force even for the moment before it runs. The
|
||||
// Sysnative spelling is a 32-bit caller's bridge and not a directory the
|
||||
// launched native process can read, so the physical name is used.
|
||||
const powershellModuleDirectory = path.win32.join(
|
||||
path.win32
|
||||
.dirname(tools.powershell)
|
||||
.replace(/\\Sysnative\\/i, '\\System32\\'),
|
||||
'Modules',
|
||||
);
|
||||
// Windows environment names are case-insensitive, and a child can end up
|
||||
// carrying a differently cased alias alongside the value set here. Drop
|
||||
// every spelling before setting the trusted one.
|
||||
const verifyEnvironment = Object.fromEntries(
|
||||
Object.entries(environment).filter(
|
||||
([name]) => name.toLowerCase() !== 'psmodulepath',
|
||||
),
|
||||
);
|
||||
const verified = spawn(tools.powershell, [
|
||||
'-NoProfile',
|
||||
'-NonInteractive',
|
||||
'-Command', WINDOWS_ACL_VERIFY_SCRIPT,
|
||||
], {
|
||||
env: {
|
||||
...environment,
|
||||
...verifyEnvironment,
|
||||
GEV_ACL_FILE: filepath,
|
||||
GEV_ACL_USER_SID: sid,
|
||||
PSModulePath: powershellModuleDirectory,
|
||||
},
|
||||
stdio: 'ignore',
|
||||
windowsHide: true,
|
||||
|
||||
@@ -126,6 +126,132 @@ test('Windows hardening applies and then verifies the exact restricted DACL', ()
|
||||
assert.match(calls[2].args.at(-1), /seen\.Count -ne 3/);
|
||||
});
|
||||
|
||||
test('Windows hardening isolates the verify PowerShell from a pwsh7-polluted PSModulePath', () => {
|
||||
const calls = [];
|
||||
// Exactly what a side-by-side PowerShell 7 install prepends at startup:
|
||||
// its own user Documents\PowerShell, Program Files\PowerShell, and
|
||||
// Program Files\PowerShell\7 module trees all shadow the 5.1 system path.
|
||||
const pollutedModulePath = [
|
||||
'C:\\Users\\alice\\Documents\\PowerShell\\Modules',
|
||||
'C:\\Program Files\\PowerShell\\Modules',
|
||||
'c:\\program files\\powershell\\7\\Modules',
|
||||
'C:\\Program Files\\WindowsPowerShell\\Modules',
|
||||
'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules',
|
||||
].join(';');
|
||||
const result = hardenCredentialFile('C:\\GEV\\ENVIRONMENT.tmp', {
|
||||
platform: 'win32',
|
||||
environment: {
|
||||
SYSTEMROOT: WINDOWS_ROOT,
|
||||
PSModulePath: pollutedModulePath,
|
||||
},
|
||||
fileSystem: windowsFileSystem(),
|
||||
spawn(command, args, options) {
|
||||
calls.push({ command, args, options });
|
||||
if (command.endsWith('\\whoami.exe')) {
|
||||
return { status: 0, signal: null, stdout: `"WORKSTATION\\alice","${USER_SID}"\r\n` };
|
||||
}
|
||||
return { status: 0, signal: null };
|
||||
},
|
||||
});
|
||||
assert.equal(result, true);
|
||||
const verify = calls.find(({ command }) => command.endsWith('powershell.exe'));
|
||||
assert.ok(verify, 'the ACL verify powershell must be spawned');
|
||||
const modulePath = verify.options.env.PSModulePath;
|
||||
// Fail closed: the verification interpreter must never inherit pwsh7's
|
||||
// module trees — a 7.x Microsoft.PowerShell.Security manifest cannot be
|
||||
// autoloaded by 5.1, and an untrusted tree must not shadow Get-Acl at all.
|
||||
assert.ok(!/Documents\\PowerShell\\Modules/i.test(modulePath), 'user pwsh7 module tree must be stripped');
|
||||
assert.ok(!/Program Files\\PowerShell\\Modules/i.test(modulePath), 'Program Files pwsh7 module tree must be stripped');
|
||||
assert.ok(!/Program Files\\PowerShell\\7\\Modules/i.test(modulePath), 'pwsh7 install module tree must be stripped');
|
||||
// ... but the 5.1 system module directory (where Get-Acl lives) must remain.
|
||||
assert.match(modulePath, /System32\\WindowsPowerShell\\v1\.0\\Modules/i);
|
||||
});
|
||||
|
||||
test('the verify script takes its module path from the running interpreter', () => {
|
||||
const calls = [];
|
||||
const result = hardenCredentialFile('C:\\GEV\\ENVIRONMENT.tmp', {
|
||||
platform: 'win32',
|
||||
environment: { SYSTEMROOT: WINDOWS_ROOT },
|
||||
fileSystem: windowsFileSystem(),
|
||||
spawn(command, args, options) {
|
||||
calls.push({ command, args, options });
|
||||
if (command.endsWith('\\whoami.exe')) {
|
||||
return { status: 0, signal: null, stdout: `"WORKSTATION\\alice","${USER_SID}"` };
|
||||
}
|
||||
return { status: 0, signal: null };
|
||||
},
|
||||
});
|
||||
assert.equal(result, true);
|
||||
const verify = calls.find(({ command }) => command.endsWith('powershell.exe'));
|
||||
const script = verify.args.at(-1);
|
||||
// $PSHOME is the interpreter's own physical directory, so this holds even
|
||||
// where the executable was named through a bridge path.
|
||||
assert.match(script, /\$env:PSModulePath = Join-Path \$PSHOME 'Modules'/);
|
||||
// ...and it is the first thing the script does, before Get-Acl is resolved.
|
||||
assert.ok(
|
||||
script.indexOf('PSModulePath') < script.indexOf('Get-Acl'),
|
||||
'the module path must be set before Get-Acl is invoked',
|
||||
);
|
||||
});
|
||||
|
||||
test('a 32-bit caller passes the physical module directory, not the Sysnative bridge', () => {
|
||||
const calls = [];
|
||||
const result = hardenCredentialFile('C:\\GEV\\ENVIRONMENT.tmp', {
|
||||
platform: 'win32',
|
||||
architecture: 'ia32',
|
||||
environment: { SYSTEMROOT: WINDOWS_ROOT },
|
||||
fileSystem: windowsFileSystem({ systemDirectory: 'Sysnative' }),
|
||||
spawn(command, args, options) {
|
||||
calls.push({ command, args, options });
|
||||
if (command.endsWith('\\whoami.exe')) {
|
||||
return { status: 0, signal: null, stdout: `"WORKSTATION\\alice","${USER_SID}"` };
|
||||
}
|
||||
return { status: 0, signal: null };
|
||||
},
|
||||
});
|
||||
assert.equal(result, true);
|
||||
const verify = calls.find(({ command }) => command.endsWith('powershell.exe'));
|
||||
// The executable is still named through the bridge the 32-bit caller needs.
|
||||
assert.match(verify.command, /\\Sysnative\\/);
|
||||
// The module directory is not: Sysnative is not a directory the launched
|
||||
// native process can read.
|
||||
assert.doesNotMatch(verify.options.env.PSModulePath, /Sysnative/i);
|
||||
assert.match(
|
||||
verify.options.env.PSModulePath,
|
||||
/^C:\\Windows\\System32\\WindowsPowerShell\\v1\.0\\Modules$/i,
|
||||
);
|
||||
});
|
||||
|
||||
test('differently cased PSModulePath aliases do not survive into the verify process', () => {
|
||||
const calls = [];
|
||||
const result = hardenCredentialFile('C:\\GEV\\ENVIRONMENT.tmp', {
|
||||
platform: 'win32',
|
||||
environment: {
|
||||
SYSTEMROOT: WINDOWS_ROOT,
|
||||
// Windows environment names are case-insensitive; a child can keep a
|
||||
// differently cased alias alongside the value set for it.
|
||||
PSMODULEPATH: 'C:\\Program Files\\PowerShell\\7\\Modules',
|
||||
psmodulepath: 'C:\\Users\\alice\\Documents\\PowerShell\\Modules',
|
||||
PsModulePath: 'C:\\attacker\\Modules',
|
||||
},
|
||||
fileSystem: windowsFileSystem(),
|
||||
spawn(command, args, options) {
|
||||
calls.push({ command, args, options });
|
||||
if (command.endsWith('\\whoami.exe')) {
|
||||
return { status: 0, signal: null, stdout: `"WORKSTATION\\alice","${USER_SID}"` };
|
||||
}
|
||||
return { status: 0, signal: null };
|
||||
},
|
||||
});
|
||||
assert.equal(result, true);
|
||||
const verify = calls.find(({ command }) => command.endsWith('powershell.exe'));
|
||||
const aliases = Object.keys(verify.options.env).filter(
|
||||
(name) => name.toLowerCase() === 'psmodulepath',
|
||||
);
|
||||
assert.deepEqual(aliases, ['PSModulePath'], 'exactly one spelling may reach the child');
|
||||
assert.doesNotMatch(verify.options.env.PSModulePath, /PowerShell\\7|Documents|attacker/i);
|
||||
});
|
||||
|
||||
test('Windows hardening bypasses PATH-shadowed native ACL tools', () => {
|
||||
const commands = [];
|
||||
const result = hardenCredentialFile('D:\\GEV\\ENVIRONMENT.tmp', {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import {
|
||||
LAYER_ID,
|
||||
MAX_VIEWPORT_DEGREES,
|
||||
@@ -427,6 +428,8 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
state.clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
if (!state.enabled) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
const id =
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import {
|
||||
BIKESHARE_SELECTED_OVERLAY_SOURCE_ID,
|
||||
BIKESHARE_SELECTED_OVERLAY_SOURCE_OPTIONS,
|
||||
@@ -153,6 +154,8 @@ export function createSelection({
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
layerState._clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
|
||||
if (picked) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
fireDetectionKey,
|
||||
} from '../../data/firmsLabels.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { CONTEXT_TOP_N } from './policy.js';
|
||||
|
||||
export function createSelection({
|
||||
@@ -35,6 +36,8 @@ export function createSelection({
|
||||
layerState._viewer,
|
||||
);
|
||||
layerState._clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
const picked = layerState._viewer.scene.pick(click.position);
|
||||
const fire = pickedFire(picked);
|
||||
if (fire) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { LAYER_ID } from './policy.js';
|
||||
|
||||
export function createSelection({
|
||||
@@ -24,6 +25,8 @@ export function createSelection({
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
layerState.clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
if (!layerState.enabled) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
const id = typeof picked?.id?.id === 'string' ? picked.id.id : null;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
|
||||
export function createLifecycle({
|
||||
state: layerState,
|
||||
@@ -26,6 +27,8 @@ export function createLifecycle({
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
layerState._clickHandler.setInputAction((movement) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
if (!layerState._enabled || !layerState._dataSource?.show) return;
|
||||
const entity = viewer.scene
|
||||
.drillPick(movement.position, 12)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import {
|
||||
RADIO_PREFIX,
|
||||
RADIO_PICK_OFFSETS,
|
||||
@@ -117,6 +118,8 @@ export function createInteraction({
|
||||
layerState._viewer.scene.canvas,
|
||||
);
|
||||
layerState._clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
if (!radioPresentationAllowed()) return;
|
||||
const stationId = pickedRadioStationAt(click.position);
|
||||
if (!stationId) return;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
|
||||
export function createInteraction({
|
||||
state: layerState,
|
||||
@@ -46,6 +47,8 @@ export function createInteraction({
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
layerState._clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
if (!layerState._enabled) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
|
||||
export function createInteraction({ state, screenSpaceEventHandlerFactory }) {
|
||||
function registerPickEntity(entity, info) {
|
||||
@@ -10,6 +11,8 @@ export function createInteraction({ state, screenSpaceEventHandlerFactory }) {
|
||||
if (state._clickHandler) return;
|
||||
state._clickHandler = screenSpaceEventHandlerFactory(viewer.scene.canvas);
|
||||
state._clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
if (!state._enabled) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
const record = resolvePickRecord(picked);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { VESSEL_OVERLAY_SOURCE_ID } from '../../data/vesselLabels.js';
|
||||
|
||||
export function createSelection({
|
||||
@@ -33,6 +34,8 @@ export function createSelection({
|
||||
function bindVesselInteraction(viewer, handler, keyTarget) {
|
||||
state.clickHandler = handler;
|
||||
handler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
if (!state.feed.enabled) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
const pickedId = resolvePickId(picked);
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync, readdirSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const SRC_ROOT = fileURLToPath(new URL('.', import.meta.url));
|
||||
const REPO_ROOT = path.resolve(SRC_ROOT, '..');
|
||||
const INDEX_HTML = path.join(REPO_ROOT, 'index.html');
|
||||
|
||||
/** The glyph written as element text: `<span class="material-symbols-outlined">radar</span>`. */
|
||||
const SPAN_TEXT =
|
||||
/class="[^"]*material-symbols-outlined[^"]*"[^>]*>\s*([a-z0-9_]+)\s*</g;
|
||||
/** A whole `textContent =` statement, across lines, so a multi-line ternary is read once. */
|
||||
const TEXT_ASSIGNMENT = /(?:textContent|innerText)\s*=\s*([^;]{0,400})/gs;
|
||||
const STRING_LITERAL = /['"`]([a-z0-9_]{2,})['"`]/g;
|
||||
|
||||
/**
|
||||
* Files that SHIP markup. Tests assert on markup, they do not render it.
|
||||
*
|
||||
* The panel markup lives in `src/ui/templates/*.html`, so HTML under `src` is
|
||||
* read as well: a glyph named only in a template is still a glyph the font has
|
||||
* to carry.
|
||||
*/
|
||||
function sourceFiles(directory = SRC_ROOT) {
|
||||
const files = [];
|
||||
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
||||
const absolute = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) files.push(...sourceFiles(absolute));
|
||||
else if (
|
||||
entry.isFile() &&
|
||||
/\.(js|mjs|html)$/.test(entry.name) &&
|
||||
!entry.name.endsWith('.test.mjs')
|
||||
) {
|
||||
files.push(absolute);
|
||||
}
|
||||
}
|
||||
return [...files.sort(), INDEX_HTML];
|
||||
}
|
||||
|
||||
/**
|
||||
* Glyph names the sources ask the icon font for.
|
||||
*
|
||||
* Errs WIDE on purpose. A name the font does not carry costs nothing — Google
|
||||
* ignores an unknown `icon_names` entry and still returns 200 — while a glyph
|
||||
* the subset is missing breaks the interface SILENTLY: the ligature never
|
||||
* forms, so the element renders the literal word `right_panel_open` instead of
|
||||
* falling back to a visible box.
|
||||
*
|
||||
* A literal to the LEFT of a `?` is the condition being tested, not the text
|
||||
* being shown, so it is dropped: `status === 'loading' ? …` must not enrol
|
||||
* `loading`. Optional chaining is neutralised first — `payload?.newsStatus`
|
||||
* is not a ternary, and splitting on its `?` would keep the condition.
|
||||
* @returns {Map<string, string>} glyph -> the first file that names it.
|
||||
*/
|
||||
function referencedGlyphs() {
|
||||
const found = new Map();
|
||||
for (const file of sourceFiles()) {
|
||||
const source = readFileSync(file, 'utf8');
|
||||
const relative = path.relative(REPO_ROOT, file).split(path.sep).join('/');
|
||||
const add = (glyph) => {
|
||||
if (!found.has(glyph)) found.set(glyph, relative);
|
||||
};
|
||||
for (const match of source.matchAll(SPAN_TEXT)) add(match[1]);
|
||||
for (const match of source.matchAll(TEXT_ASSIGNMENT)) {
|
||||
const statement = match[1].replaceAll('?.', '.');
|
||||
const assigned = statement.includes('?')
|
||||
? statement.slice(statement.indexOf('?') + 1)
|
||||
: statement;
|
||||
for (const literal of assigned.matchAll(STRING_LITERAL)) add(literal[1]);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/** The `icon_names` list index.html asks Google for. */
|
||||
function subsettedGlyphs(html = readFileSync(INDEX_HTML, 'utf8')) {
|
||||
const match =
|
||||
/Material\+Symbols\+Outlined[^"]*[?&]icon_names=([a-z0-9_,]+)/.exec(html);
|
||||
assert.ok(
|
||||
match,
|
||||
'index.html must request Material Symbols with an icon_names subset',
|
||||
);
|
||||
return new Set(match[1].split(','));
|
||||
}
|
||||
|
||||
test('every glyph the sources render is in the icon_names subset', () => {
|
||||
const subset = subsettedGlyphs();
|
||||
const missing = [...referencedGlyphs()]
|
||||
.filter(([glyph]) => !subset.has(glyph))
|
||||
.map(([glyph, file]) => `${glyph} (${file})`);
|
||||
|
||||
assert.deepEqual(
|
||||
missing,
|
||||
[],
|
||||
'Glyphs named by the sources but absent from the index.html icon_names list. ' +
|
||||
'Add them there — an unlisted glyph renders as its own name on screen: ' +
|
||||
missing.join(', '),
|
||||
);
|
||||
});
|
||||
|
||||
test('the unused Material Icons Round family is not loaded', () => {
|
||||
// A second icon font, 173 kB, for a family no source ever uses — and
|
||||
// src/cockpitMarkup.test.mjs already asserts the markup must not use it.
|
||||
const html = readFileSync(INDEX_HTML, 'utf8');
|
||||
assert.doesNotMatch(
|
||||
html,
|
||||
/Material\+Icons\+Round/,
|
||||
'index.html loads an icon font nothing renders',
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,447 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { mkdtemp, realpath, rm, writeFile } from 'node:fs/promises';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { tmpdir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import {
|
||||
readGit,
|
||||
redactRemoteUrl,
|
||||
reportIncomingChanges,
|
||||
runPinokioUpdate,
|
||||
updateFromRemote,
|
||||
} from '../scripts/pinokio-update.mjs';
|
||||
|
||||
const source = readFileSync(
|
||||
new URL('../scripts/pinokio-update.mjs', import.meta.url),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
/** Run git in a fixture repository, failing the test on a git error. */
|
||||
function git(cwd, args) {
|
||||
const result = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
||||
assert.equal(
|
||||
result.status,
|
||||
0,
|
||||
`git ${args.join(' ')} failed: ${result.stderr || result.error}`,
|
||||
);
|
||||
return result.stdout.trim();
|
||||
}
|
||||
|
||||
/** Escape a path so it can be matched literally inside a RegExp. */
|
||||
const literal = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
|
||||
/**
|
||||
* Build a disposable origin repository and a clone that tracks it.
|
||||
*
|
||||
* Everything is on disk and driven through real git, so the assertions are
|
||||
* about what the update path does to a checkout rather than about a transcript
|
||||
* of injected strings.
|
||||
*
|
||||
* @param {import('node:test').TestContext} t - Owns the fixture's cleanup.
|
||||
*/
|
||||
async function fixture(t) {
|
||||
const scratch = await realpath(
|
||||
await mkdtemp(path.join(tmpdir(), 'gev-update-')),
|
||||
);
|
||||
t.after(() => rm(scratch, { recursive: true, force: true }));
|
||||
const origin = path.join(scratch, 'origin');
|
||||
const clone = path.join(scratch, 'clone');
|
||||
|
||||
git(scratch, ['init', '--quiet', '--initial-branch=main', origin]);
|
||||
git(origin, ['config', 'user.email', '[email protected]']);
|
||||
git(origin, ['config', 'user.name', 'Fixture']);
|
||||
await writeFile(path.join(origin, 'README.md'), 'first\n');
|
||||
git(origin, ['add', 'README.md']);
|
||||
git(origin, ['commit', '--quiet', '-m', 'first commit']);
|
||||
|
||||
git(scratch, ['clone', '--quiet', origin, clone]);
|
||||
git(clone, ['config', 'user.email', '[email protected]']);
|
||||
git(clone, ['config', 'user.name', 'Fixture']);
|
||||
|
||||
/** Add one commit to the origin repository. */
|
||||
const push = async (message, contents) => {
|
||||
await writeFile(path.join(origin, 'README.md'), contents);
|
||||
git(origin, ['add', 'README.md']);
|
||||
git(origin, ['commit', '--quiet', '-m', message]);
|
||||
return git(origin, ['rev-parse', 'HEAD']);
|
||||
};
|
||||
|
||||
/** Same, from a synchronous callback (used to move the remote mid-update). */
|
||||
const pushSync = (message, contents) => {
|
||||
writeFileSync(path.join(origin, 'README.md'), contents);
|
||||
git(origin, ['add', 'README.md']);
|
||||
git(origin, ['commit', '--quiet', '-m', message]);
|
||||
return git(origin, ['rev-parse', 'HEAD']);
|
||||
};
|
||||
|
||||
const out = [];
|
||||
const io = {
|
||||
cwd: clone,
|
||||
log: (line) => out.push(String(line)),
|
||||
warn: (line) => out.push(String(line)),
|
||||
fetchRemote: (remote) => git(clone, ['fetch', '--quiet', remote]),
|
||||
apply: (args) => git(clone, args),
|
||||
};
|
||||
|
||||
return {
|
||||
scratch,
|
||||
origin,
|
||||
clone,
|
||||
push,
|
||||
pushSync,
|
||||
io,
|
||||
out,
|
||||
text: () => out.join('\n'),
|
||||
};
|
||||
}
|
||||
|
||||
test('a checkout with no upstream is reported and left to the plain pull', async (t) => {
|
||||
const app = await fixture(t);
|
||||
git(app.clone, ['checkout', '--quiet', '-b', 'local-only']);
|
||||
let fetched = null;
|
||||
const plan = reportIncomingChanges({
|
||||
...app.io,
|
||||
fetchRemote: (remote) => {
|
||||
fetched = remote;
|
||||
},
|
||||
});
|
||||
assert.deepEqual(plan, { apply: null, fallback: true });
|
||||
assert.match(app.text(), /No upstream branch is configured/);
|
||||
assert.equal(fetched, null, 'nothing is fetched without an upstream');
|
||||
});
|
||||
|
||||
test('the tracking branch and the remote it fetches from are printed', async (t) => {
|
||||
const app = await fixture(t);
|
||||
await app.push('second commit', 'second\n');
|
||||
reportIncomingChanges(app.io);
|
||||
assert.match(app.text(), /Tracking origin\/main/);
|
||||
assert.match(app.text(), new RegExp(`Fetching from ${literal(app.origin)}`));
|
||||
});
|
||||
|
||||
test('the incoming commits and their diffstat are printed, and the report alone applies nothing', async (t) => {
|
||||
const app = await fixture(t);
|
||||
const before = git(app.clone, ['rev-parse', 'HEAD']);
|
||||
await app.push('second commit', 'second\n');
|
||||
await app.push('third commit', 'third\n');
|
||||
const plan = reportIncomingChanges(app.io);
|
||||
const text = app.text();
|
||||
assert.match(text, /2 incoming commit\(s\)/);
|
||||
assert.match(text, /second commit/);
|
||||
assert.match(text, /third commit/);
|
||||
assert.match(text, /README\.md \| 2 \+-/);
|
||||
assert.equal(plan.fallback, false);
|
||||
assert.equal(
|
||||
git(app.clone, ['rev-parse', 'HEAD']),
|
||||
before,
|
||||
'the report must not move the checkout',
|
||||
);
|
||||
});
|
||||
|
||||
test('the revision that is applied is the revision that was disclosed', async (t) => {
|
||||
const app = await fixture(t);
|
||||
const disclosed = await app.push('second commit', 'second\n');
|
||||
const plan = reportIncomingChanges(app.io);
|
||||
// Something lands on the remote between the disclosure and the apply. A
|
||||
// second fetch would install it without ever naming it.
|
||||
await app.push('a commit nobody was shown', 'fourth\n');
|
||||
assert.equal(plan.apply, disclosed);
|
||||
app.io.apply(['merge', '--ff-only', plan.apply]);
|
||||
assert.equal(git(app.clone, ['rev-parse', 'HEAD']), disclosed);
|
||||
assert.match(app.text(), new RegExp(`Applying ${disclosed}`));
|
||||
});
|
||||
|
||||
test('the whole update applies exactly one disclosed revision', async (t) => {
|
||||
const app = await fixture(t);
|
||||
const disclosed = await app.push('second commit', 'second\n');
|
||||
const plan = updateFromRemote(app.io);
|
||||
assert.equal(plan.apply, disclosed);
|
||||
assert.equal(git(app.clone, ['rev-parse', 'HEAD']), disclosed);
|
||||
});
|
||||
|
||||
test('a remote that moves during the update does not change what is applied', async (t) => {
|
||||
const app = await fixture(t);
|
||||
const disclosed = await app.push('second commit', 'second\n');
|
||||
let later = null;
|
||||
const plan = updateFromRemote({
|
||||
...app.io,
|
||||
fetchRemote: (remote) => {
|
||||
git(app.clone, ['fetch', '--quiet', remote]);
|
||||
// The remote gains a commit after the one fetch this update makes. Only
|
||||
// a second fetch — which there must not be — could reach it.
|
||||
later = app.pushSync('a commit nobody was shown', 'fourth\n');
|
||||
},
|
||||
});
|
||||
assert.equal(plan.apply, disclosed);
|
||||
assert.equal(git(app.clone, ['rev-parse', 'HEAD']), disclosed);
|
||||
assert.notEqual(git(app.clone, ['rev-parse', 'HEAD']), later);
|
||||
});
|
||||
|
||||
test('an up-to-date checkout says so and applies nothing', async (t) => {
|
||||
const app = await fixture(t);
|
||||
const before = git(app.clone, ['rev-parse', 'HEAD']);
|
||||
const plan = updateFromRemote(app.io);
|
||||
assert.deepEqual(plan, { apply: null, fallback: false });
|
||||
assert.match(app.text(), /Already up to date/);
|
||||
assert.equal(git(app.clone, ['rev-parse', 'HEAD']), before);
|
||||
});
|
||||
|
||||
test('an unreadable commit range is reported as unreadable, not as up to date', async (t) => {
|
||||
const app = await fixture(t);
|
||||
const disclosed = await app.push('second commit', 'second\n');
|
||||
const plan = reportIncomingChanges({
|
||||
...app.io,
|
||||
read: (args) =>
|
||||
args[0] === 'log' ? null : readGit(args, { cwd: app.clone }),
|
||||
});
|
||||
const text = app.text();
|
||||
assert.doesNotMatch(text, /Already up to date/);
|
||||
assert.match(text, /Could not list the commits/);
|
||||
assert.equal(plan.apply, disclosed, 'the fetched revision is still applied');
|
||||
});
|
||||
|
||||
test('an upstream that cannot be resolved after fetching stops the update', async (t) => {
|
||||
const app = await fixture(t);
|
||||
const before = git(app.clone, ['rev-parse', 'HEAD']);
|
||||
await app.push('second commit', 'second\n');
|
||||
const plan = updateFromRemote({
|
||||
...app.io,
|
||||
// The target ref resolves to nothing after the fetch — a tracking ref
|
||||
// pruned out from under the run.
|
||||
read: (args) =>
|
||||
args[0] === 'rev-parse' &&
|
||||
args.length === 2 &&
|
||||
args[1].startsWith('refs/')
|
||||
? null
|
||||
: readGit(args, { cwd: app.clone }),
|
||||
});
|
||||
assert.deepEqual(plan, { apply: null, fallback: false, stopped: true });
|
||||
assert.doesNotMatch(app.text(), /Already up to date/);
|
||||
assert.match(app.text(), /Could not resolve origin\/main after fetching/);
|
||||
assert.match(app.text(), /Stopping/);
|
||||
// Nothing may be applied: a fallback pull here would fetch again and could
|
||||
// install a revision this run never resolved.
|
||||
assert.equal(git(app.clone, ['rev-parse', 'HEAD']), before);
|
||||
});
|
||||
|
||||
test('a remote whose name contains a slash is read correctly', async (t) => {
|
||||
const app = await fixture(t);
|
||||
const disclosed = await app.push('second commit', 'second\n');
|
||||
git(app.clone, ['remote', 'rename', 'origin', 'team/origin']);
|
||||
git(app.clone, ['fetch', '--quiet', 'team/origin']);
|
||||
git(app.clone, ['branch', '--set-upstream-to=team/origin/main', 'main']);
|
||||
const plan = updateFromRemote({
|
||||
...app.io,
|
||||
fetchRemote: (remote) => {
|
||||
assert.equal(remote, 'team/origin');
|
||||
git(app.clone, ['fetch', '--quiet', remote]);
|
||||
},
|
||||
});
|
||||
assert.equal(plan.apply, disclosed);
|
||||
assert.equal(git(app.clone, ['rev-parse', 'HEAD']), disclosed);
|
||||
assert.match(app.text(), new RegExp(`Fetching from ${literal(app.origin)}`));
|
||||
});
|
||||
|
||||
test('a diffstat that cannot be read is reported, and the commits still are', async (t) => {
|
||||
const app = await fixture(t);
|
||||
const disclosed = await app.push('second commit', 'second\n');
|
||||
const plan = reportIncomingChanges({
|
||||
...app.io,
|
||||
read: (args) =>
|
||||
args[0] === 'diff' ? null : readGit(args, { cwd: app.clone }),
|
||||
});
|
||||
assert.equal(plan.apply, disclosed);
|
||||
assert.match(app.text(), /1 incoming commit\(s\)/);
|
||||
assert.match(app.text(), /Could not read the diffstat/);
|
||||
assert.doesNotMatch(app.text(), /Files affected/);
|
||||
});
|
||||
|
||||
test('diverged history is refused rather than applied', async (t) => {
|
||||
const app = await fixture(t);
|
||||
await app.push('second commit', 'second\n');
|
||||
await writeFile(path.join(app.clone, 'README.md'), 'local work\n');
|
||||
git(app.clone, ['add', 'README.md']);
|
||||
git(app.clone, ['commit', '--quiet', '-m', 'local commit']);
|
||||
const before = git(app.clone, ['rev-parse', 'HEAD']);
|
||||
const plan = reportIncomingChanges(app.io);
|
||||
const refused = spawnSync('git', ['merge', '--ff-only', plan.apply], {
|
||||
cwd: app.clone,
|
||||
encoding: 'utf8',
|
||||
});
|
||||
assert.notEqual(refused.status, 0, 'a fast-forward-only merge must refuse');
|
||||
assert.equal(git(app.clone, ['rev-parse', 'HEAD']), before);
|
||||
});
|
||||
|
||||
test('a remote that is behind this checkout is named, not announced as incoming', async (t) => {
|
||||
const app = await fixture(t);
|
||||
await writeFile(path.join(app.clone, 'README.md'), 'ahead\n');
|
||||
git(app.clone, ['add', 'README.md']);
|
||||
git(app.clone, ['commit', '--quiet', '-m', 'local commit']);
|
||||
const plan = reportIncomingChanges(app.io);
|
||||
assert.match(app.text(), /is not ahead of this checkout/);
|
||||
assert.doesNotMatch(app.text(), /incoming commit/);
|
||||
assert.ok(plan.apply, 'the fetched revision is still named');
|
||||
});
|
||||
|
||||
test('a stop means nothing is installed, and the script fails', async (t) => {
|
||||
const app = await fixture(t);
|
||||
const before = git(app.clone, ['rev-parse', 'HEAD']);
|
||||
await app.push('second commit', 'second\n');
|
||||
const installs = [];
|
||||
const failures = [];
|
||||
const plan = runPinokioUpdate({
|
||||
...app.io,
|
||||
read: (args) =>
|
||||
args[0] === 'rev-parse' &&
|
||||
args.length === 2 &&
|
||||
args[1].startsWith('refs/')
|
||||
? null
|
||||
: readGit(args, { cwd: app.clone }),
|
||||
install: () => installs.push('install'),
|
||||
fail: (code) => failures.push(code),
|
||||
});
|
||||
assert.equal(plan.stopped, true);
|
||||
// Installing here would run install scripts and report success for an update
|
||||
// that never happened.
|
||||
assert.deepEqual(installs, []);
|
||||
assert.deepEqual(failures, [1]);
|
||||
assert.equal(git(app.clone, ['rev-parse', 'HEAD']), before);
|
||||
});
|
||||
|
||||
test('an ordinary update installs once and does not fail', async (t) => {
|
||||
const app = await fixture(t);
|
||||
const disclosed = await app.push('second commit', 'second\n');
|
||||
const installs = [];
|
||||
const failures = [];
|
||||
const plan = runPinokioUpdate({
|
||||
...app.io,
|
||||
install: () => installs.push('install'),
|
||||
fail: (code) => failures.push(code),
|
||||
});
|
||||
assert.equal(plan.apply, disclosed);
|
||||
assert.equal(git(app.clone, ['rev-parse', 'HEAD']), disclosed);
|
||||
assert.deepEqual(installs, ['install']);
|
||||
assert.deepEqual(failures, []);
|
||||
});
|
||||
|
||||
test('an up-to-date checkout still reinstalls', async (t) => {
|
||||
const app = await fixture(t);
|
||||
const installs = [];
|
||||
const plan = runPinokioUpdate({
|
||||
...app.io,
|
||||
install: () => installs.push('install'),
|
||||
fail: () => assert.fail('an up-to-date checkout is not a failure'),
|
||||
});
|
||||
assert.deepEqual(plan, { apply: null, fallback: false });
|
||||
assert.deepEqual(installs, ['install']);
|
||||
});
|
||||
|
||||
test('the entrypoint is what the direct invocation runs', () => {
|
||||
const guarded = source.slice(source.indexOf('if (isDirectInvocation('));
|
||||
assert.match(guarded, /runPinokioUpdate\(\);/);
|
||||
// The install must not sit beside it in the guard, where a stop could not
|
||||
// prevent it.
|
||||
assert.doesNotMatch(guarded, /installPinokioDependencies\(\)/);
|
||||
});
|
||||
|
||||
test('a password in the remote URL is not printed', () => {
|
||||
assert.equal(
|
||||
redactRemoteUrl('https://someone:[email protected]/org/repo.git'),
|
||||
'https://***@github.com/org/repo.git',
|
||||
);
|
||||
});
|
||||
|
||||
test('a bare token in the remote URL is not printed', () => {
|
||||
const redacted = redactRemoteUrl(
|
||||
'https://[email protected]/org/repo.git',
|
||||
);
|
||||
assert.doesNotMatch(redacted, /ghp_secret/);
|
||||
assert.match(redacted, /github\.com\/org\/repo\.git/);
|
||||
});
|
||||
|
||||
test('a credential in a query parameter is not printed', () => {
|
||||
assert.equal(
|
||||
redactRemoteUrl('https://host.example/org/repo.git?access_token=secret'),
|
||||
'https://host.example/org/repo.git',
|
||||
);
|
||||
// The whole query goes, so a parameter name nobody thought of goes with it.
|
||||
assert.equal(
|
||||
redactRemoteUrl('https://host.example/org/repo.git?sneaky=secret&x=1#frag'),
|
||||
'https://host.example/org/repo.git',
|
||||
);
|
||||
assert.equal(
|
||||
redactRemoteUrl('https://user:[email protected]/org/repo.git?token=secret'),
|
||||
'https://***@host.example/org/repo.git',
|
||||
);
|
||||
});
|
||||
|
||||
test('an ordinary remote URL is printed unchanged', () => {
|
||||
const url = 'https://github.com/bilawalsidhu/gods-eye-view.git';
|
||||
assert.equal(redactRemoteUrl(url), url);
|
||||
assert.equal(
|
||||
redactRemoteUrl('[email protected]:bilawalsidhu/gods-eye-view.git'),
|
||||
'[email protected]:bilawalsidhu/gods-eye-view.git',
|
||||
);
|
||||
assert.equal(redactRemoteUrl(null), null);
|
||||
assert.equal(redactRemoteUrl(''), null);
|
||||
});
|
||||
|
||||
test('a credential-bearing remote is redacted in the printed report', async (t) => {
|
||||
const app = await fixture(t);
|
||||
await app.push('second commit', 'second\n');
|
||||
reportIncomingChanges({
|
||||
...app.io,
|
||||
read: (args) =>
|
||||
args[0] === 'remote'
|
||||
? 'https://someone:[email protected]/org/repo.git'
|
||||
: readGit(args, { cwd: app.clone }),
|
||||
});
|
||||
assert.doesNotMatch(app.text(), /ghp_secret/);
|
||||
assert.match(
|
||||
app.text(),
|
||||
/Fetching from https:\/\/\*\*\*@github\.com\/org\/repo\.git/,
|
||||
);
|
||||
});
|
||||
|
||||
test('a failed git read is null, and an empty successful read is an empty string', async (t) => {
|
||||
const app = await fixture(t);
|
||||
assert.equal(
|
||||
readGit(['rev-parse', '--verify', 'refs/heads/absent'], { cwd: app.clone }),
|
||||
null,
|
||||
);
|
||||
assert.equal(
|
||||
readGit(['log', '--oneline', 'HEAD..HEAD'], { cwd: app.clone }),
|
||||
'',
|
||||
);
|
||||
});
|
||||
|
||||
test('the update and reinstall stay behind the direct-invocation guard', () => {
|
||||
// Without the guard, importing this module to test it would update the
|
||||
// checkout and run npm ci as an import side effect.
|
||||
assert.match(
|
||||
source,
|
||||
/if \(isDirectInvocation\(process\.argv\[1\], MODULE_PATH\)\) \{/,
|
||||
);
|
||||
const entrypoint = source.slice(
|
||||
source.indexOf('export function runPinokioUpdate'),
|
||||
);
|
||||
// Order is the whole point of the fix: disclose and apply, then install.
|
||||
assert.ok(
|
||||
entrypoint.indexOf('updateFromRemote(io)') <
|
||||
entrypoint.indexOf('install()'),
|
||||
'the update must be disclosed and applied before dependencies are installed',
|
||||
);
|
||||
});
|
||||
|
||||
test('the disclosed revision is applied by merge, not by a second pull', () => {
|
||||
const applier = source.slice(
|
||||
source.indexOf('export function updateFromRemote'),
|
||||
);
|
||||
assert.match(applier, /apply\(\['merge', '--ff-only', plan\.apply\]\)/);
|
||||
// The plain pull remains, but only on the path where nothing was disclosed.
|
||||
assert.match(
|
||||
applier,
|
||||
/else if \(plan\.fallback\) apply\(\['pull', '--ff-only'\]\)/,
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,148 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const root = fileURLToPath(new URL('../..', import.meta.url));
|
||||
|
||||
// Documentation consistency only: that every storage key a document spells out
|
||||
// is the key the code writes. Whether deleting one has the effect the document
|
||||
// claims is not checked here.
|
||||
const DOCUMENTED_KEYS = [
|
||||
['docs/KNOWN-ISSUES.md', 'godsEyeView.{layout}.panelCollapsed.cctv-panel'],
|
||||
['docs/KNOWN-ISSUES.md', 'godsEyeView.{layout}.panelCollapsed.<panel-id>'],
|
||||
['docs/KNOWN-ISSUES.md', 'godsEyeView.{position}.panelPos.<panel-id>'],
|
||||
['scripts/dev-fresh.sh', 'godsEyeView.{layout}.panelCollapsed.cctv-panel'],
|
||||
['docs/CURRENT-STATE.md', 'godsEyeView.{position}.panelPos.<panel-id>'],
|
||||
['docs/CURRENT-STATE.md', 'godsEyeView.{position}.panelPos.<id>'],
|
||||
['docs/CURRENT-STATE.md', 'godsEyeView.{layout}.panelCollapsed.<panel-id>'],
|
||||
];
|
||||
|
||||
test('documented panel storage keys are the keys the code writes', async () => {
|
||||
const source = await readFile(
|
||||
path.join(root, 'src/ui/panelPositionControls.js'),
|
||||
'utf8',
|
||||
);
|
||||
const version = (name) => {
|
||||
const [, found] =
|
||||
source.match(new RegExp(`const ${name} = '([^']+)';`)) || [];
|
||||
assert.ok(found, `panelPositionControls.js must declare ${name}`);
|
||||
return found;
|
||||
};
|
||||
const position = version('PANEL_POSITION_STORAGE_VERSION');
|
||||
const layout = version('PANEL_LAYOUT_STORAGE_VERSION');
|
||||
|
||||
const seen = new Map();
|
||||
for (const [file, shape] of DOCUMENTED_KEYS) {
|
||||
if (!seen.has(file))
|
||||
seen.set(file, await readFile(path.join(root, file), 'utf8'));
|
||||
const expected = shape
|
||||
.replace('{position}', position)
|
||||
.replace('{layout}', layout);
|
||||
assert.ok(
|
||||
seen.get(file).includes(expected),
|
||||
`${file} must use ${expected}`,
|
||||
);
|
||||
}
|
||||
|
||||
// A document that still names a superseded version sends the reader to a key
|
||||
// nothing writes.
|
||||
for (const [file, content] of seen) {
|
||||
const stalePositions = [
|
||||
...content.matchAll(/godsEyeView\.(v\d+)\.panelPos/g),
|
||||
]
|
||||
.map(([, found]) => found)
|
||||
.filter((found) => found !== position);
|
||||
assert.deepEqual(
|
||||
stalePositions,
|
||||
[],
|
||||
`${file} names superseded position keys`,
|
||||
);
|
||||
const staleCollapsed = [
|
||||
...content.matchAll(/godsEyeView\.(v\d+)\.panelCollapsed/g),
|
||||
]
|
||||
.map(([, found]) => found)
|
||||
.filter((found) => found !== layout);
|
||||
assert.deepEqual(
|
||||
staleCollapsed,
|
||||
[],
|
||||
`${file} names superseded collapsed-state keys`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('the documented outcomes hold: default, stored open, stored shut, and a shared view', async () => {
|
||||
// The instructions promise two different outcomes; both are exercised here
|
||||
// against the code that decides them.
|
||||
const { PanelPositionControls } =
|
||||
await import('../ui/panelPositionControls.js');
|
||||
const html = await readFile(
|
||||
path.join(root, 'src/ui/templates/layer-panels.html'),
|
||||
'utf8',
|
||||
);
|
||||
assert.match(
|
||||
html,
|
||||
/<div id="cctv-panel" class="panel-collapsible collapsed"/,
|
||||
'the CCTV panel starts collapsed in the markup',
|
||||
);
|
||||
|
||||
const saved = {
|
||||
document: globalThis.document,
|
||||
localStorage: globalThis.localStorage,
|
||||
};
|
||||
const classes = new Set(['panel-collapsible', 'collapsed']);
|
||||
const panel = {
|
||||
classList: {
|
||||
contains: (name) => classes.has(name),
|
||||
toggle: (name, active) =>
|
||||
active ? classes.add(name) : classes.delete(name),
|
||||
add: (name) => classes.add(name),
|
||||
remove: (name) => classes.delete(name),
|
||||
},
|
||||
};
|
||||
const store = new Map();
|
||||
globalThis.document = { getElementById: () => panel };
|
||||
globalThis.localStorage = {
|
||||
getItem: (key) => (store.has(key) ? store.get(key) : null),
|
||||
setItem: (key, value) => store.set(key, String(value)),
|
||||
removeItem: (key) => store.delete(key),
|
||||
};
|
||||
try {
|
||||
const controls = new PanelPositionControls({
|
||||
syncPanelCollapseButton: () => {},
|
||||
layoutRightPanels: () => {},
|
||||
syncCctvPanelViewport: () => {},
|
||||
showToast: () => {},
|
||||
});
|
||||
|
||||
// Nothing stored: the markup default wins, and the panel is collapsed. So
|
||||
// deleting the key is a reset, not a way to open the panel.
|
||||
controls._restorePanelCollapsedState('cctv-panel');
|
||||
assert.equal(classes.has('collapsed'), true);
|
||||
|
||||
// The value the documents tell a reader to set.
|
||||
store.set('godsEyeView.v6.panelCollapsed.cctv-panel', '0');
|
||||
controls._restorePanelCollapsedState('cctv-panel');
|
||||
assert.equal(classes.has('collapsed'), false);
|
||||
|
||||
// ...and the opposite value keeps it shut, so '0' is doing the work.
|
||||
store.set('godsEyeView.v6.panelCollapsed.cctv-panel', '1');
|
||||
controls._restorePanelCollapsedState('cctv-panel');
|
||||
assert.equal(classes.has('collapsed'), true);
|
||||
|
||||
// A view opened from a share link is laid out from the link: the shell
|
||||
// restores with allowStored false, and the stored value is not consulted.
|
||||
// This is why the console workaround is documented for ordinary loads only.
|
||||
store.set('godsEyeView.v6.panelCollapsed.cctv-panel', '0');
|
||||
controls._restorePanelCollapsedState('cctv-panel', { allowStored: false });
|
||||
assert.equal(
|
||||
classes.has('collapsed'),
|
||||
true,
|
||||
'a shared view must ignore the stored open state',
|
||||
);
|
||||
} finally {
|
||||
globalThis.document = saved.document;
|
||||
globalThis.localStorage = saved.localStorage;
|
||||
}
|
||||
});
|
||||
@@ -822,6 +822,52 @@
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* DISPLAY ▸ Draw: shape segment, label field, colour, and the one-line hint */
|
||||
#draw-mode-row {
|
||||
min-width: 184px;
|
||||
}
|
||||
#draw-label-row {
|
||||
flex-wrap: wrap;
|
||||
row-gap: 6px;
|
||||
}
|
||||
.pp-text-input {
|
||||
flex: 1 1 110px;
|
||||
min-width: 0;
|
||||
height: 24px;
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
border: 1px solid rgba(255, 255, 255, 0.14);
|
||||
border-radius: 6px;
|
||||
color: var(--text-primary);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.6px;
|
||||
padding: 2px 6px;
|
||||
outline: none;
|
||||
}
|
||||
.pp-text-input:focus {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
.draw-color-select {
|
||||
flex: 0 0 74px;
|
||||
}
|
||||
.draw-clear-btn {
|
||||
flex: 0 0 auto;
|
||||
padding: 0 8px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.14);
|
||||
border-radius: 6px;
|
||||
}
|
||||
.draw-hint {
|
||||
flex-basis: 100%;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 8px;
|
||||
letter-spacing: 0.6px;
|
||||
color: var(--text-dim);
|
||||
line-height: 1.4;
|
||||
}
|
||||
body.gev-drawing #cesiumContainer canvas {
|
||||
cursor: crosshair;
|
||||
}
|
||||
|
||||
/* Proximity / All segmented control under the 3D toggle */
|
||||
#models3d-mode-row {
|
||||
min-width: 184px;
|
||||
|
||||
@@ -89,6 +89,32 @@
|
||||
<span class="pp-slider-value" id="scope-feather-value">11%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pp-toggle-group">
|
||||
<button class="pp-toggle-btn" id="draw-toggle" title="Draw on the world — click vertices, double-click or Enter to finish, Esc to cancel" aria-pressed="false">
|
||||
<span class="pp-icon material-symbols-outlined" aria-hidden="true">draw</span>
|
||||
<span class="pp-label">Draw</span>
|
||||
</button>
|
||||
<div class="pp-slider-row" id="draw-mode-row">
|
||||
<span class="pp-slider-mini-label">Shape</span>
|
||||
<div class="pp-mode-seg" role="radiogroup" aria-label="Shape to draw">
|
||||
<button class="pp-mode-btn active" data-shape="area" role="radio" aria-checked="true">Area</button>
|
||||
<button class="pp-mode-btn" data-shape="line" role="radio" aria-checked="false">Line</button>
|
||||
<button class="pp-mode-btn" data-shape="pin" role="radio" aria-checked="false">Pin</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pp-slider-row" id="draw-label-row">
|
||||
<input type="text" class="pp-text-input" id="draw-label-input" maxlength="120" placeholder="Label (optional)" aria-label="Label for the drawn shape" autocomplete="off" spellcheck="false">
|
||||
<select class="pp-select draw-color-select" id="draw-color-select" aria-label="Colour of the drawn shape">
|
||||
<option value="primary">Primary</option>
|
||||
<option value="amber">Amber</option>
|
||||
<option value="cyan">Cyan</option>
|
||||
<option value="green">Green</option>
|
||||
<option value="red">Red</option>
|
||||
</select>
|
||||
<button class="pp-mode-btn draw-clear-btn" id="draw-clear" type="button" title="Remove every mark from the board">Clear</button>
|
||||
<span class="draw-hint" id="draw-hint" aria-live="polite"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pp-toggle-group">
|
||||
<button class="pp-toggle-btn" id="celestial-toggle" title="Celestial ring — reveal the full globe" aria-pressed="false">
|
||||
<span class="pp-icon material-symbols-outlined" aria-hidden="true">flare</span>
|
||||
|
||||
Reference in new issue
Block a user