mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-11-22 03:17:04 +00:00
Closes #2428. Adds free and open map providers (topographic, satellite, gray and vector basemaps), a hillshade overlay, and support for operators' own tile servers. Everything is additive and opt-in: Carto stays the default, every new provider group is off until the operator turns it on, and no existing config key or provider was removed. An upgrade with an untouched config changes nothing in the picker. > **Dependency:** #2426 has merged. The branch is rebased onto current `master` (`6c78a1d2`) with no conflicts. ## What's new - **Provider registry** (`public/map-tile-providers.js`). New groups are **opt-in**: each is off until `map.tiles.providers.<group>.enabled` is `true` (the boolean), so licences and volunteer servers are the operator's call: - **EOX**: Sentinel-2 satellite (2025 and 2016), Terrain Light, and a place-labels overlay. EOX 2025 imagery is CC BY-NC-SA 4.0 (non-commercial); a commercial deployment should leave `eox` off or license it. - **OSM France**: Humanitarian, CyclOSM, OSM Gray and OSM Gray Dark (volunteer-run, fair use). - **OpenFreeMap** and **VersaTiles** vector styles: Liberty, Bright, Positron, Dark, Fiord, Colorful, Muted and the Gray variants. - **Hillshade** (below) is opt-in the same way. **OpenTopoMap**, the OSM community server, Stamen and USGS keep their existing opt-in. - **Custom tile servers**: `map.tiles.custom` adds raster (XYZ), vector (MapLibre style URL) and raster-overlay entries as `custom-<id>`. They can be used in `darkDefault` / `lightDefault`. Invalid entries are skipped with a console warning. - **Hillshade overlay** (`public/map-hillshade.js`): shaded in the browser from Terrarium elevation tiles. `map.tiles.providers.hillshade.url` can point at a mirror. - **Vector basemaps** (`public/map-vector.js`) use a vendored MapLibre GL 5.24.0 (CSP build) and `@maplibre/maplibre-gl-leaflet` 0.1.4. - They are lazy-loaded only when a vector map is picked (about 380 KB gzipped). - The load times out after 15 s. - Without WebGL the map falls back to the theme's default raster map. - **One picker on Map, Live and Repeater Planner**: Auto, Street, Topographic, Satellite, plus an Overlays group. - **A map picked there is saved** (`localStorage` `mc-tile-pinned`, untrusted: honoured only while registered). Every picker reopens on it after a reload or on another page, until the visitor picks **Auto**. - The other maps (home mini-map, node detail, node reach, analytics) follow the visitor's choice through the shared builder: the saved pick when it suits the current theme (satellite always does), otherwise the theme's map. - Those small maps never load MapLibre, so a vector choice shows the theme's default raster map there. - **Security contract**: the `CONTRACT` block at the top of `map-tile-providers.js` (S1 to S7) covers one shared tile-URL validator (`https?://` or a same-origin path, no credentials in the authority, whitelisted placeholders), attribution HTML-escaped once, picker labels set with `textContent`, explicit MapLibre options, pinned vendored versions, CORS-safe hillshade decoding, and treating stored picks as untrusted input. `map.tiles` is served publicly in `/api/config/client`, so keys put there are public (the docs warn about this). ## Fixes included The race stress suite written for this PR found teardown races when leaving map pages mid-load: - a lazy MapLibre load finishing after navigation; - a hillshade tile decoding after `remove()`; - a provider-change event arriving during teardown. It also found a pre-existing document-listener leak in `AreaFilter` / `RegionFilter`. All of these are fixed in `e6709e74`, with regression tests in `tests/e2e/test-map-teardown-races.js`. The first CI run then caught a bug in that fix (`7f8d792c`). `MC_safeRemoveMap` called `map.off()` before `map.remove()`, so the map's `unload` event reached no one. Leaflet relies on that event to detach controls and clean up the zoom-animation proxy and BoxZoom, and `test-issue-1206` watches it to confirm node maps are disposed. `off()` now runs after `remove()`, and a new regression test checks that `unload` fires, controls detach and no listener is left. A later stress run (a new seed) found a real two-tab bug, fixed in `0506fc1d`. When another tab's overlay pick is already in localStorage but its `storage` event hasn't arrived, a layer-picker click here triggered a sync that added that overlay while Leaflet was still applying the click. Leaflet doesn't redraw the list for changes it sees mid-click, so the overlay's checkbox stayed unticked, and the next click on any overlay removed it and wrote the removal back to every tab. The overlay set now defers a sync until the click has finished. New E2E check `4b` in `test-map-providers-e2e.js` plants another tab's pick and clicks twice: one write per click, the planted overlay stays ticked. It fails on the previous code. ## Docs - `docs/deployment.md`, "Map Tile Providers" section, rewritten. It covers every provider and its licence, turning groups on and off, custom servers, vector maps, hillshade, self-hosting, and what is public. - User guide: - `map.md` gets a "Map style and overlays" section; - `live.md` notes the picker; - `configuration.md` gets a "Map tiles" section; - the FAQ gets a new entry on satellite, terrain and gray maps. - `CHANGELOG.md`: an Unreleased entry. ## Test data Two datasets were used, so every number below says which one it came from. **1. Large synthetic dataset** (perf A/B and screenshots). It is generated, contains no real mesh data, and is not checked in. - **Generator:** `synthgen` 1.0.0, seed 1, "full" scale. Built from upstream `be16173e` and retimed so its 18-day window (2026-10-31 to 2026-11-18) ends at the time of the run. - **Database:** SQLite, 3.94 GB (586 MB as zstd), 11.6 M rows in all. | Table | Rows | |---|---| | Nodes | 18,102 (12,606 companions, 3,652 repeaters, 953 rooms, 891 sensors) | | Nodes with a location | 13,452, spread worldwide (latitude −37° to 60°, longitude −123° to 175°) | | Observers | 1,175, in 42 regions on six continents | | Transmissions | 759,133 | | Observations | 10,569,668 | | Neighbour edges | 42,806 | | Advert route evidence | 212,142 | During the perf runs, the server's packet store was pinned to the newest 48 h with a 1.5 GB memory cap. Each server held about 65 k transmissions and 0.9 M observations in memory (baseline 65,647 / 906,467; candidate 64,862 / 896,248), plus all 18,102 nodes (about 17,650 active) and 1,175 observers. The tracked store was about 450 MB. **2. The repo's CI fixture** (`test-fixtures/e2e-fixture.db`, 704 KB). All E2E suites and the race stress gates ran against it, freshened the way CI does: 204 nodes, 31 observers, 500 transmissions, 502 observations. A second copy with the Repeater Planner enabled was used for the planner-on stress runs. **Perf environment:** - Headless Chromium 158 via Playwright 1.58.2, at 1280×800 with device scale factor 1. - 9 measured runs per scenario plus 1 warm-up, on each of `master` and this branch. - Host: Linux, AMD Ryzen 7 3700X (16 threads), 63 GB RAM. - **Tiles were stubbed.** The harness answers every tile, elevation and style request locally with the same stub on both sides (`--mode stub`), so perf timings involve no network. Only the screenshot gallery uses real tiles. ## Screenshots These were taken from the synthetic dataset with real tiles in a real browser (headless Chromium, 1280×800). Click a thumbnail for the full size. The images are hosted on a separate assets branch, so they are not in this diff. #### Street | | | | |---|---|---| | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/street-carto-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/street-carto-light.png" width="260" alt="Street: Carto (default) (light)"></a><br>Carto (default) (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/street-carto-dark.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/street-carto-dark.png" width="260" alt="Street: Carto (default) (dark)"></a><br>Carto (default) (dark) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/street-osmfr-hot-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/street-osmfr-hot-light.png" width="260" alt="Street: OSM France Humanitarian (light)"></a><br>OSM France Humanitarian (light) | #### Gray | | | | |---|---|---| | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/gray-osmfr-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/gray-osmfr-light.png" width="260" alt="Gray: OSM France (light)"></a><br>OSM France (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/gray-osmfr-dark.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/gray-osmfr-dark.png" width="260" alt="Gray: OSM France (dark)"></a><br>OSM France (dark) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/gray-versatiles-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/gray-versatiles-light.png" width="260" alt="Gray: VersaTiles (light)"></a><br>VersaTiles (light) | | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/gray-versatiles-dark.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/gray-versatiles-dark.png" width="260" alt="Gray: VersaTiles (dark)"></a><br>VersaTiles (dark) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/gray-openfreemap-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/gray-openfreemap-light.png" width="260" alt="Gray: OpenFreeMap Positron (light)"></a><br>OpenFreeMap Positron (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/gray-openfreemap-dark.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/gray-openfreemap-dark.png" width="260" alt="Gray: OpenFreeMap Dark (dark)"></a><br>OpenFreeMap Dark (dark) | #### Topographic | | | | |---|---|---| | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/topo-cyclosm-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/topo-cyclosm-light.png" width="260" alt="Topo: CyclOSM (light)"></a><br>CyclOSM (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/topo-eox-terrain-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/topo-eox-terrain-light.png" width="260" alt="Topo: EOX Terrain Light (light)"></a><br>EOX Terrain Light (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/topo-opentopomap-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/topo-opentopomap-light.png" width="260" alt="Topo: OpenTopoMap (opt-in) (light)"></a><br>OpenTopoMap (opt-in) (light) | #### Satellite | | | | |---|---|---| | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/sat-s2-2025-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/sat-s2-2025-light.png" width="260" alt="Satellite: Sentinel-2 2025 (light)"></a><br>Sentinel-2 2025 (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/sat-s2-2025-labels-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/sat-s2-2025-labels-light.png" width="260" alt="Satellite: Sentinel-2 2025 with labels (light)"></a><br>Sentinel-2 2025 with labels (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/sat-s2-2025-dark.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/sat-s2-2025-dark.png" width="260" alt="Satellite: Sentinel-2 2025 (dark)"></a><br>Sentinel-2 2025 (dark) | | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/sat-s2-2025-labels-dark.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/sat-s2-2025-labels-dark.png" width="260" alt="Satellite: Sentinel-2 2025 with labels (dark)"></a><br>Sentinel-2 2025 with labels (dark) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/sat-s2-2016-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/sat-s2-2016-light.png" width="260" alt="Satellite: Sentinel-2 2016 (light)"></a><br>Sentinel-2 2016 (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/sat-s2-2016-labels-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/sat-s2-2016-labels-light.png" width="260" alt="Satellite: Sentinel-2 2016 with labels (light)"></a><br>Sentinel-2 2016 with labels (light) | #### Vector (MapLibre) | | | | |---|---|---| | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/vector-liberty-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/vector-liberty-light.png" width="260" alt="Vector: OpenFreeMap Liberty (light)"></a><br>OpenFreeMap Liberty (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/vector-dark-dark.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/vector-dark-dark.png" width="260" alt="Vector: OpenFreeMap Dark (dark)"></a><br>OpenFreeMap Dark (dark) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/vector-versatiles-colorful-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/vector-versatiles-colorful-light.png" width="260" alt="Vector: VersaTiles Colorful (light)"></a><br>VersaTiles Colorful (light) | | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/vector-versatiles-colorful-dark.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/vector-versatiles-colorful-dark.png" width="260" alt="Vector: VersaTiles Colorful Dark (dark)"></a><br>VersaTiles Colorful Dark (dark) | | | #### Hillshade overlay | | | | |---|---|---| | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/overlay-hillshade-s2-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/overlay-hillshade-s2-light.png" width="260" alt="Overlay: hillshade over Sentinel-2 (light)"></a><br>hillshade over Sentinel-2 (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/overlay-hillshade-carto-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/overlay-hillshade-carto-light.png" width="260" alt="Overlay: hillshade over Carto (light)"></a><br>hillshade over Carto (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/overlay-hillshade-s2-dark.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/overlay-hillshade-s2-dark.png" width="260" alt="Overlay: hillshade over Sentinel-2 (dark)"></a><br>hillshade over Sentinel-2 (dark) | | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/overlay-hillshade-carto-dark.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/overlay-hillshade-carto-dark.png" width="260" alt="Overlay: hillshade over Carto (dark)"></a><br>hillshade over Carto (dark) | | | #### Repeater Planner | | | |---|---| | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/planner-s2-hillshade-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/planner-s2-hillshade-light.png" width="260" alt="Planner: Sentinel-2 + hillshade (light)"></a><br>Sentinel-2 + hillshade (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/planner-s2-hillshade-dark.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/planner-s2-hillshade-dark.png" width="260" alt="Planner: Sentinel-2 + hillshade (dark)"></a><br>Sentinel-2 + hillshade (dark) | #### Layer picker | | | |---|---| | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/picker-light.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/picker-light.png" width="260" alt="Layer picker open (light)"></a><br>Layer picker open (light) | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/picker-dark.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/picker-dark.png" width="260" alt="Layer picker open (dark)"></a><br>Layer picker open (dark) | #### Custom tile server | | | |---|---| | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/custom-map.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/custom-map.png" width="260" alt="Custom raster provider on the map"></a><br>Custom raster provider on the map | <a href="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/custom-picker.png"><img src="https://raw.githubusercontent.com/zfouts/CoreScope/35ce760b31b8365e511884fdc5e5ae873f4e28bb/map-providers-2428/thumbs/custom-picker.png" width="260" alt="Custom raster provider in the picker"></a><br>Custom raster provider in the picker | ## Testing The full suite ran twice, each time on a fresh clone: | | Pass 1 | Pass 2 | |---|---|---| | Commit (before rebase) | `8a56e841` | `9355169b` | | `test-all.sh` (unit) | pass | pass | | `npm run lint` | 0 errors (87 warnings, all pre-existing) | 0 errors (87 warnings, all pre-existing) | | Go `cmd/server` / `cmd/ingestor` | ok / ok | ok / ok | | E2E, map-related files (CI fixture) | 44/44 | 44/44 + planner-on run | | `test-e2e-playwright.js` | 149 passed, 3 skipped | 149 passed, 3 skipped | | Race stress gate (seeds) | 101, 202: all pass | 303, 404: all pass | | Stress with planner enabled | pass | pass (seed 505) | | Gallery | 32/32 | 32/32 | The rebased equivalents of the pass 1 and pass 2 commits are `fde2552c` and `e4d5c447`. **After the first CI run.** The two passes covered only the map-related E2E files, and CI exposed two problems: 1. `test-issue-1206` failed 7 checks. This was the `unload` bug described under "Fixes included". 2. The JS unit gate runs without `node_modules`, so the two new jsdom suites crashed `test-all.sh`. Locally, jsdom was reachable from a parent checkout, which hid this. The second problem is fixed in `57720bf3`, following the `domIntegration` convention in `scripts/non-unit-tests.json`. `test-map-teardown-races.js` moved to `tests/e2e/`, and the three jsdom zoom-limit tests split out into `tests/e2e/test-map-vector-leaflet-zoom.js`, so 30 + 3 = 33 tests are kept. Both run from E2E shard 2 and take a few seconds. The heavy suites (race stress, perf, gallery) stay local-only and are not run in GitHub Actions. These checks ran on the fixed, rebased tree (`57720bf3`): | Check | Result | |---|---| | `test-all.sh` from a copy with no `node_modules` (as CI runs it) | pass | | `test-test-inventory.js` | 399 suites classified | | `npm run lint` | 0 errors | | Go `cmd/server` / `cmd/ingestor` | ok / ok | | `test-issue-1206-resize-observer-leak-e2e.js` | 13/13 (7 were failing) | | `test-e2e-playwright.js` | 149 passed, 3 skipped | | `test-map-providers-e2e.js` / harness E2E | 17/17, 16/16 | | `test-map-teardown-races.js` / `test-map-vector-leaflet-zoom.js` | 19/19, 3/3 | | Race stress (3 iterations) | all scenarios pass | The commits since pass 2 are `76c67184` (docs only), `7f8d792c` and `57720bf3`. **GitHub Actions on `0506fc1d` (rebased onto `master`, with the two-tab fix): every check passed** (13 passed, 4 skipped as usual for a PR). That covers Go build and test, all three E2E shards, the server race detector and both image builds. The moved suites ran in shard 2 (`test-map-teardown-races.js` 19/19, `test-map-vector-leaflet-zoom.js` 3/3), and the unit gate ran `test-map-vector.js` (30/30). **Race stress suite** (`tests/e2e/test-map-race-stress-e2e.js`). Each gate run does 20 iterations of scenarios a to e and 50 cycles of f. The scenarios cover: - rapid provider switching; - theme flips during a vector load; - navigating away mid-load (including a 15 s MapLibre timeout); - repeated map-page navigation with heap checks; - overlay toggles; - cross-page picker persistence. Results for each run: - Listener counts stay flat: at most 3 `mc-tile-provider-changed` listeners and 5 `storage` listeners. - At most one live WebGL context at a time. - Heap growth in the second half of scenario d was 0.25 to 0.45 MB across the four gate runs. - Upstream `master` grows about 0.39 MB per map navigation loop in the same scenario; this branch levels off. ## Maintainer review (addressed) 1. **Licence default.** All five new groups (`eox`, `osmfr`, `openfreemap`, `versatiles`, `hillshade`) are opt-in: off unless `enabled: true` (`"true"`, `1` or `{}` don't count). With an untouched config the picker lists the same 6 base maps as before. Docs, `config.example.json` (now `enabled: false` for each) and the changelog say so, and each group's terms are listed before you turn it on. 2. **Saved pick.** The on-map picker now saves the pick (option 1 of your two), as the docs promised. Behaviour, and what an other-theme pick does: - Every picker opens on the pinned map, on any page and after a reload, until **Auto** is picked. A pin is shown whatever the theme, as an explicit pick already was. - Maps without a picker show it when it fits the current theme (`type` is the theme or `any`), otherwise the theme's map. So a light pin isn't drawn on a dark node map; satellite always is. - A stored pin whose group is turned off reads as Auto, and comes back if the group is turned on again; only picking Auto clears it. - On a map with a picker, Auto always means the theme's map: the pin is only the explicit layer, never loaded into the hidden Auto layer. A choice in the customizer, and Reset All, clear the pin. A failed write (quota full) never brings back an older stored pin. - E2E `7a` to `7c` in `test-map-providers-e2e.js`: pick, reload, the radio and tiles are the pick, the node detail map draws it, and a light pin in dark is kept but not drawn. Auto clears the key; junk in it gives Auto; an untouched config lists none of the new groups. 7a and 7b fail with the save line removed. Unit tests are in `test-map-tile-pin.js` (21). 3. **CI.** `test-map-providers-e2e.js` (24 checks, including `4b`, the two-tab regression check) and `test-map-providers-harness-e2e.js` (16) now run in E2E shard 3 against the fixture server: every tile host is stubbed. Non-blocking: - `getTileUrl()` now returns the raster fallback for a vector pick (`MC_rasterTileUrl`). There's a test in `test-tile-resolver.js` that fails on the old code. - The `map-vector.js` header and the binding's vendor README list the Leaflet and binding internals to recheck on an upgrade. - `docs/deployment.md` says SRI makes a JS-rewriting proxy drop vector maps to raster, so serve `public/vendor/` unmodified. - `scripts/map-perf/README.md` says where `SEED_DB` and `SHIFT_SH` come from. - The maps with `attributionControl: false` are left as they are. That predates this PR, and with every new group opt-in, an upgrade adds no uncredited imagery. Follow-up for all of them: #2441. - The OpenFreeMap credit line is `OpenFreeMap © OpenMapTiles Data from OpenStreetMap` (`2424f3c3`), the line OpenFreeMap gives for clients that don't add it automatically. Verified after these changes: - `test-all.sh` and lint pass, with 0 errors. - Both provider E2E suites pass: 24/24 and 16/16. - Race stress, seed 979: scenarios a, b, d and e pass. c (15/15) and f (37/37) pass after updating their model of the pick: they expected Auto after a return, which was the old unsaved behaviour. - The stress suite now enables the five groups itself, so it keeps exercising them. ## Performance A/B test: `master` against this branch on the large synthetic dataset, with 9 runs per scenario and stubbed tiles (see Test data; `scripts/map-perf/`). The full HTML report is not attached; ask if you want it. - **No budget failures** in either pass. The `raster-no-maplibre` budget holds: no raster scenario loads MapLibre. - **DOMContentLoaded is unchanged on every page**, even with the two new scripts (`map-hillshade.js` and `map-vector.js`, about 635 lines in all; MapLibre itself loads only on demand). - **Switching providers 50 times (raster only), median ms per switch:** - dark: 146 → 108.5; - light: 208 → 208.5. - Heap growth during the run: 0.3 to 0.4% on both sides. - **Flagged and checked:** - Live and Analytics `loadEventMs` are flagged in some runs. This metric has two modes on **both** branches: `load` fires either before Leaflet adds its first tile `<img>`s (about 150 ms) or after they finish (about 400 ms). A direct probe of `master` alone gave 428, 404 and 124 ms. On these scenarios, map creation, first tile, all tiles, first marker and wall time are within a few ms on both sides. - Carto and Positron `allTilesSinceMapMs` are 4 to 6 ms slower, just above `master`'s p95. Tiles are stubbed locally, so this is not network noise. The cause is not isolated. Both providers now go through the shared layer builder, and on the same scenarios first tile, all tiles and wall time are within 10 ms of `master` (Carto Voyager +2 to +3 ms; Positron Dark +6 to +9 ms). - The Analytics map shows one long task of about 50 ms against a `master` median of 0, but `master`'s p95 is 52 to 84 ms. This is disclosed in case it shows up for you. - Other desktop apps were running during the perf runs, so expect some noise. ## Commits 1. `c6bf12ed` feat(map): tile provider registry with custom servers, gray, topo and satellite maps, and overlays 2. `9237230b` feat(map): client-side hillshade overlay 3. `781e41b4` feat(map): vector basemaps via vendored MapLibre GL 5.24.0 4. `dae36d2e` refactor(map): every map surface uses the shared basemap builder 5. `3d4afcdc` fix(map): teardown races and listener leaks when leaving map pages 6. `b798b2fe` test(server): pin map.tiles passthrough in /api/config/client 7. `171b1bc4` test(map): E2E, race stress suite, perf harness and screenshot gallery 8. `61f73875` docs(map): providers, custom tile servers, overlays and self-hosting 9. `135a9b12` test(map): gallery shows opt-in OpenTopoMap and retries slow tile servers 10. `3833572b` test(map): harness waits for vector basemaps; stress suite fixes from test pass 1 11. `3e543cad` test(map-perf): redact tile-URL credentials; compare switch50 like with like 12. `d5006111` docs(map): user guide for map styles, overlays and map.tiles 13. `90ee1d5d` fix(map): MC_safeRemoveMap lets unload listeners run before dropping them 14. `5fc57b5c` test(map): run the jsdom map suites in the E2E job, not the unit gate 15. `bd36b634` fix(map): another tab's overlay pick that lands mid-click is no longer removed 16. `38df65d2` fix(map): new tile groups are opt-in; a map picked in the picker is saved 17. `eafbcac9` ci(e2e): run the map provider E2E suites in shard 3 18. `65b223ec` fix(map): getTileUrl() never returns a vector style url; review notes 19. `f3402c5d` test(map): race stress enables the opt-in groups and expects the saved pick 20. `e92b8631` fix(map): Auto on a picker map ignores the saved pick; customizer clears it 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
451 lines
27 KiB
JavaScript
451 lines
27 KiB
JavaScript
/**
|
|
* E2E for the #2428 map tile providers: picker structure, gray / satellite
|
|
* filters, operator custom entries (valid + hostile), overlays (Hillshade)
|
|
* incl. persistence across reload and the planner, vector (MapLibre or raster
|
|
* fallback), and the Auto-group invariant on #/live. Every tile / style /
|
|
* elevation request is answered by tests/e2e/lib/map-harness.js; nothing
|
|
* reaches a real tile host.
|
|
*
|
|
* The #2428 groups (eox, osmfr, openfreemap, versatiles, hillshade) are opt-in,
|
|
* so newPage rewrites the client config to enable them (providers: null leaves
|
|
* the config untouched). Section 7 covers the saved pick (mc-tile-pinned).
|
|
*
|
|
* Usage: BASE_URL=http://localhost:13581 node tests/e2e/test-map-providers-e2e.js
|
|
*/
|
|
'use strict';
|
|
const { chromium } = require('playwright');
|
|
const MH = require('./lib/map-harness');
|
|
|
|
const BASE = process.env.BASE_URL || 'http://localhost:13581';
|
|
const CUSTOM_HOST = 'tiles.e2e-custom.test';
|
|
const T0 = Date.now();
|
|
|
|
let passed = 0, failed = 0;
|
|
async function test(name, fn) {
|
|
try { await fn(); passed++; console.log(` ✅ ${name}`); }
|
|
catch (e) { failed++; console.log(` ❌ ${name}: ${e.message}`); }
|
|
}
|
|
function assert(cond, msg) { if (!cond) throw new Error(msg || 'Assertion failed'); }
|
|
|
|
const CUSTOM_ENTRIES = [
|
|
{ id: 'e2e-sat', label: 'E2E Custom Sat', type: 'any', category: 'satellite', format: 'raster',
|
|
url: `https://${CUSTOM_HOST}/{z}/{x}/{y}.png`, attribution: 'E2E attribution', maxZoom: 18 },
|
|
{ id: 'evil', label: 'Evil', type: 'light', category: 'street', format: 'raster',
|
|
url: 'javascript:alert(1)', attribution: '<img src=x onerror=window.__x=1>' },
|
|
];
|
|
|
|
// map.tiles.providers that turns every opt-in #2428 group on.
|
|
const OPT_IN_ON = { eox: { enabled: true }, osmfr: { enabled: true }, openfreemap: { enabled: true },
|
|
versatiles: { enabled: true }, hillshade: { enabled: true } };
|
|
const OPT_IN_IDS = ['eox-s2-2025', 'eox-s2-2016', 'eox-terrain-light', 'osmfr-hot', 'osmfr-cyclosm', 'osmfr-gray', 'osmfr-gray-dark',
|
|
'openfreemap-liberty', 'openfreemap-bright', 'openfreemap-positron', 'openfreemap-dark', 'openfreemap-fiord',
|
|
'versatiles-colorful', 'versatiles-muted', 'versatiles-gray', 'versatiles-colorful-dark', 'versatiles-gray-dark'];
|
|
|
|
async function newPage(browser, { theme, provider, overlays, custom, planner, providers } = {}) {
|
|
const context = await browser.newContext({ viewport: { width: 1280, height: 800 }, serviceWorkers: 'block' });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(15000);
|
|
const errors = [], warnings = [];
|
|
page.on('pageerror', e => errors.push(String(e && e.message || e)));
|
|
page.on('console', m => { if (m.type() === 'warning') warnings.push(m.text()); });
|
|
await MH.installCollectors(page);
|
|
await MH.installTileStub(page, {
|
|
mode: 'stub', baseUrl: BASE,
|
|
extraHosts: [{ key: 'e2e-custom', kind: 'raster', test: new RegExp(CUSTOM_HOST.replace(/\./g, '\\.')) }],
|
|
});
|
|
await MH.presetStorage(page, { theme: theme || 'light', provider: provider || 'auto', overlays });
|
|
// Rewrite map.tiles.custom / planner in the client config.
|
|
await page.route('**/api/config/client', async (route) => {
|
|
const res = await route.fetch();
|
|
const json = await res.json();
|
|
json.map = json.map || {};
|
|
json.map.tiles = Object.assign({}, json.map.tiles || {});
|
|
if (providers !== null) json.map.tiles.providers = Object.assign({}, json.map.tiles.providers || {}, providers || OPT_IN_ON);
|
|
if (custom) json.map.tiles.custom = custom;
|
|
if (planner) json.planner = { enabled: true, defaultRangeKm: 30, newAntennaM: 10, existingAntennaM: 20, maxAreaKm: 100, nodeMarginKm: 20, maxLegKm: 100 };
|
|
await route.fulfill({ response: res, json });
|
|
});
|
|
const requests = [];
|
|
page.on('request', r => requests.push(r.url()));
|
|
return { context, page, errors, warnings, requests };
|
|
}
|
|
|
|
async function gotoMap(page, hash) {
|
|
await page.goto(`${BASE}/#/${hash || 'map'}`, { waitUntil: 'domcontentloaded' });
|
|
await page.waitForSelector('.leaflet-control-layers', { state: 'attached' });
|
|
await page.waitForSelector('.leaflet-tile-pane .leaflet-tile-loaded', { timeout: 15000 });
|
|
}
|
|
|
|
async function pick(page, id) {
|
|
const ctl = page.locator('.leaflet-control-layers').first();
|
|
await ctl.hover();
|
|
await page.locator(`label[data-tile-id="${id}"] input`).click();
|
|
}
|
|
async function pickOverlay(page, id) {
|
|
await page.locator('.leaflet-control-layers').first().hover();
|
|
await page.locator(`label[data-tile-overlay-id="${id}"] input`).click();
|
|
}
|
|
const paneFilter = (page) => page.evaluate(() => {
|
|
const p = document.querySelector('.leaflet-tile-pane');
|
|
return p ? (p.style.filter || getComputedStyle(p).filter || '') : null;
|
|
});
|
|
const norm = (f) => (f === 'none' ? '' : f);
|
|
const tileKeys = (page) => page.$$eval('.leaflet-tile-pane img.leaflet-tile', els => els.map(e => e.src));
|
|
|
|
async function waitFilter(page, pred, what) {
|
|
await page.waitForFunction((src) => {
|
|
const p = document.querySelector('.leaflet-tile-pane');
|
|
const f = p ? (p.style.filter || getComputedStyle(p).filter || '') : '';
|
|
return new Function('f', 'return ' + src)(f === 'none' ? '' : f);
|
|
}, pred, { timeout: 8000 }).catch(() => { throw new Error('timeout waiting for ' + what); });
|
|
}
|
|
|
|
async function run() {
|
|
const browser = await chromium.launch({
|
|
headless: true,
|
|
executablePath: process.env.CHROMIUM_PATH || undefined,
|
|
args: ['--no-sandbox', '--disable-dev-shm-usage'],
|
|
});
|
|
console.log(`\nMap providers E2E against ${BASE}\n`);
|
|
let vectorBranch = 'n/a';
|
|
try {
|
|
// ── 1. Picker structure (light + dark) ──────────────────────────────
|
|
for (const theme of ['light', 'dark']) {
|
|
const c = await newPage(browser, { theme });
|
|
try {
|
|
await gotoMap(c.page);
|
|
await MH.waitForTiles(c.page, { timeout: 15000 });
|
|
await test(`1 ${theme}: Auto first, headings in order, ids registered`, async () => {
|
|
await c.page.locator('.leaflet-control-layers').first().hover();
|
|
const first = await c.page.$eval('.leaflet-control-layers-base label', l => l.getAttribute('data-tile-id') + '|' + l.textContent.trim());
|
|
assert(first.startsWith('__auto__') && first.endsWith('Auto'), 'first entry: ' + first);
|
|
const heads = await c.page.$$eval('.leaflet-control-layers .mc-tile-group-heading', els => els.map(e => e.textContent));
|
|
assert(JSON.stringify(heads) === JSON.stringify(['Street', 'Topographic', 'Satellite', 'Overlays']), 'headings: ' + heads);
|
|
const ids = await c.page.$$eval('.leaflet-control-layers-base label[data-tile-id]', els => els.map(e => e.getAttribute('data-tile-id')));
|
|
const reg = new Set((await MH.listProviders(c.page)).map(p => p.id));
|
|
const bad = ids.filter(i => i !== '__auto__' && !reg.has(i));
|
|
assert(ids.length > 5 && bad.length === 0, 'unregistered ids: ' + bad);
|
|
});
|
|
await test(`1 ${theme}: no external request leaked, no page errors`, async () => {
|
|
const log = MH.getRequestLog(c.page);
|
|
assert(log.external.length === 0, 'external: ' + JSON.stringify(log.external.slice(0, 3)));
|
|
assert(log.failed.length === 0, 'failed: ' + JSON.stringify(log.failed.slice(0, 3)));
|
|
assert(c.errors.length === 0, 'page errors: ' + c.errors);
|
|
});
|
|
} finally { await c.context.close(); }
|
|
}
|
|
|
|
// ── 2. Gray raster and satellite filters ────────────────────────────
|
|
for (const [theme, id] of [['light', 'osmfr-gray'], ['dark', 'osmfr-gray-dark']]) {
|
|
const c = await newPage(browser, { theme });
|
|
try {
|
|
await gotoMap(c.page);
|
|
await test(`2 ${theme}: ${id} applies a grayscale filter`, async () => {
|
|
await pick(c.page, id);
|
|
await waitFilter(c.page, "f.indexOf('grayscale(') >= 0", 'grayscale filter');
|
|
await c.page.waitForFunction(() => Array.from(document.querySelectorAll('.leaflet-tile-pane img.leaflet-tile')).some(i => /osmfr/.test(i.src)));
|
|
assert(/grayscale\(/.test(await paneFilter(c.page)), 'filter: ' + await paneFilter(c.page));
|
|
});
|
|
if (theme === 'dark') {
|
|
await test('2 dark: satellite eox-s2-2025 is never inverted', async () => {
|
|
await pick(c.page, 'eox-s2-2025');
|
|
await waitFilter(c.page, "f === ''", 'empty filter');
|
|
await c.page.waitForFunction(() => Array.from(document.querySelectorAll('.leaflet-tile-pane img.leaflet-tile')).some(i => /eox/.test(i.src)));
|
|
assert(norm(await paneFilter(c.page)) === '', 'filter: ' + await paneFilter(c.page));
|
|
});
|
|
}
|
|
assert(c.errors.length === 0, 'page errors: ' + c.errors);
|
|
} finally { await c.context.close(); }
|
|
}
|
|
|
|
// ── 3. Custom entries (valid + hostile) ─────────────────────────────
|
|
{
|
|
const c = await newPage(browser, { theme: 'light', custom: CUSTOM_ENTRIES });
|
|
try {
|
|
await gotoMap(c.page);
|
|
await test('3 valid custom entry lists under Satellite and renders from its host', async () => {
|
|
await c.page.locator('.leaflet-control-layers').first().hover();
|
|
const cat = await c.page.$eval('label[data-tile-id="custom-e2e-sat"]', l => {
|
|
const fs = l.closest('fieldset');
|
|
return fs ? fs.querySelector('legend').textContent : null;
|
|
});
|
|
assert(cat === 'Satellite', 'category: ' + cat);
|
|
const text = await c.page.$eval('label[data-tile-id="custom-e2e-sat"]', l => l.textContent.trim());
|
|
assert(text === 'E2E Custom Sat', 'label: ' + text);
|
|
await pick(c.page, 'custom-e2e-sat');
|
|
await c.page.waitForFunction((h) => Array.from(document.querySelectorAll('.leaflet-tile-pane img.leaflet-tile-loaded')).some(i => i.src.indexOf(h) >= 0), CUSTOM_HOST);
|
|
assert(MH.getRequestLog(c.page).counts['e2e-custom'] > 0, 'no request reached the custom host');
|
|
});
|
|
await test('3 hostile entry is absent, inert, and warned about once without its URL', async () => {
|
|
const n = await c.page.locator('label[data-tile-id="custom-evil"]').count();
|
|
assert(n === 0, 'hostile entry listed');
|
|
const x = await c.page.evaluate(() => window.__x);
|
|
assert(x === undefined, 'window.__x = ' + x);
|
|
assert(await c.page.locator('.leaflet-control-layers img[src="x"], .leaflet-control-attribution img').count() === 0, 'injected <img> present');
|
|
const w = c.warnings.filter(t => /evil/.test(t));
|
|
assert(w.length === 1, 'warnings naming evil: ' + JSON.stringify(c.warnings));
|
|
assert(!/javascript:|alert\(1\)|onerror/.test(w[0]), 'warning leaks URL/attribution: ' + w[0]);
|
|
assert(c.errors.length === 0, 'page errors: ' + c.errors);
|
|
});
|
|
} finally { await c.context.close(); }
|
|
}
|
|
|
|
// ── 4. Overlays: Hillshade ──────────────────────────────────────────
|
|
{
|
|
const c = await newPage(browser, { theme: 'light', planner: true });
|
|
try {
|
|
await gotoMap(c.page);
|
|
const overlayState = () => c.page.evaluate(() => {
|
|
const out = [];
|
|
document.querySelectorAll('.leaflet-container').forEach(m => {
|
|
const p = m.querySelector('.leaflet-mcOverlay-pane');
|
|
out.push({ canvases: p ? p.querySelectorAll('canvas.leaflet-tile').length : -1, box: m.querySelector('.leaflet-control-layers-overlays input:checked') !== null });
|
|
});
|
|
return out;
|
|
});
|
|
await test('4 ticking Hillshade mounts canvas tiles in mcOverlayPane and fetches terrarium', async () => {
|
|
await pickOverlay(c.page, 'hillshade');
|
|
await c.page.waitForFunction(() => { const p = document.querySelector('.leaflet-mcOverlay-pane'); return p && p.querySelectorAll('canvas.leaflet-tile').length > 0; });
|
|
assert((MH.getRequestLog(c.page).counts.terrarium || 0) > 0, 'no terrarium requests');
|
|
const ls = await c.page.evaluate(() => JSON.parse(localStorage.getItem('mc-tile-overlays') || '[]'));
|
|
assert(ls.indexOf('hillshade') >= 0, 'not persisted: ' + JSON.stringify(ls));
|
|
});
|
|
await test('4 overlay survives reload', async () => {
|
|
await c.page.reload({ waitUntil: 'domcontentloaded' });
|
|
await c.page.waitForSelector('.leaflet-control-layers', { state: 'attached' });
|
|
await c.page.waitForFunction(() => { const p = document.querySelector('.leaflet-mcOverlay-pane'); return p && p.querySelectorAll('canvas.leaflet-tile').length > 0; });
|
|
await c.page.locator('.leaflet-control-layers').first().hover();
|
|
assert(await c.page.locator('label[data-tile-overlay-id="hillshade"] input').isChecked(), 'checkbox not ticked');
|
|
});
|
|
await test('4 overlay is restored on the planner map', async () => {
|
|
await c.page.evaluate(() => { location.hash = '#/tools/planner'; });
|
|
await c.page.waitForFunction(() => document.querySelector('.leaflet-container') && /planner/.test(location.hash));
|
|
await c.page.waitForFunction(() => { const p = document.querySelector('.leaflet-mcOverlay-pane'); return p && p.querySelectorAll('canvas.leaflet-tile').length > 0; });
|
|
await c.page.locator('.leaflet-control-layers').first().hover();
|
|
assert(await c.page.locator('label[data-tile-overlay-id="hillshade"] input').isChecked(), 'planner checkbox not ticked');
|
|
});
|
|
await test('4 unticking removes it on the planner and on #/map', async () => {
|
|
await pickOverlay(c.page, 'hillshade');
|
|
await c.page.waitForFunction(() => { const p = document.querySelector('.leaflet-mcOverlay-pane'); return !p || p.querySelectorAll('canvas.leaflet-tile').length === 0; });
|
|
await c.page.evaluate(() => { location.hash = '#/map'; });
|
|
await c.page.waitForSelector('#leaflet-map .leaflet-control-layers', { state: 'attached' });
|
|
await c.page.waitForSelector('.leaflet-tile-pane .leaflet-tile-loaded');
|
|
const st = await overlayState();
|
|
assert(st.every(s => s.canvases <= 0 && !s.box), 'still present: ' + JSON.stringify(st));
|
|
const ls = await c.page.evaluate(() => JSON.parse(localStorage.getItem('mc-tile-overlays') || '[]'));
|
|
assert(ls.indexOf('hillshade') < 0, 'still persisted: ' + JSON.stringify(ls));
|
|
assert(c.errors.length === 0, 'page errors: ' + c.errors);
|
|
});
|
|
} finally { await c.context.close(); }
|
|
}
|
|
|
|
// ── 4b. Another tab's pick that lands mid-click is kept ─────────────
|
|
// Tab A's write is already in localStorage when tab B's picker click
|
|
// runs, but its 'storage' event has not arrived. The click must write
|
|
// once, keep A's overlay (stored, on the map, box ticked), and the next
|
|
// click must not remove it. Leaflet applies a click by walking every
|
|
// checkbox; a sync applied mid-click left A's box stale (or unticked it
|
|
// in the same walk) and the removal was written back to every tab.
|
|
{
|
|
const c = await newPage(browser, { theme: 'light' });
|
|
try {
|
|
await gotoMap(c.page);
|
|
const ids = await c.page.evaluate(() => Array.from(document.querySelectorAll('label[data-tile-overlay-id]')).map(l => l.getAttribute('data-tile-overlay-id')));
|
|
const other = ids.find(id => id !== 'hillshade');
|
|
await test('4b a pick from another tab that lands mid-click stays (one write per click)', async () => {
|
|
assert(ids.indexOf('hillshade') >= 0 && other, 'need hillshade and one more overlay: ' + ids.join(','));
|
|
await c.page.evaluate((o) => {
|
|
window.__ovWrites = 0;
|
|
const set = Storage.prototype.setItem;
|
|
Storage.prototype.setItem = function (k, v) { if (k === 'mc-tile-overlays') window.__ovWrites++; return set.call(this, k, v); };
|
|
// Tab A's write: in storage, no 'storage' event in this tab.
|
|
set.call(localStorage, 'mc-tile-overlays', JSON.stringify([o]));
|
|
}, other);
|
|
const state = () => c.page.evaluate((o) => {
|
|
const box = document.querySelector(`label[data-tile-overlay-id="${o}"] input`);
|
|
return { writes: window.__ovWrites, stored: JSON.parse(localStorage.getItem('mc-tile-overlays') || '[]'), box: !!(box && box.checked) };
|
|
}, other);
|
|
await pickOverlay(c.page, 'hillshade');
|
|
await c.page.waitForTimeout(300);
|
|
let st = await state();
|
|
assert(st.writes === 1, `first click wrote ${st.writes}x: ${JSON.stringify(st.stored)}`);
|
|
assert(st.stored.indexOf(other) >= 0 && st.stored.indexOf('hillshade') >= 0, 'after first click stored ' + JSON.stringify(st.stored));
|
|
assert(st.box, `${other} box not ticked after the first click`);
|
|
await pickOverlay(c.page, 'hillshade');
|
|
await c.page.waitForTimeout(300);
|
|
st = await state();
|
|
assert(st.writes === 2, `second click: ${st.writes} writes in total, want 2: ${JSON.stringify(st.stored)}`);
|
|
assert(st.stored.indexOf(other) >= 0 && st.stored.indexOf('hillshade') < 0, 'after second click stored ' + JSON.stringify(st.stored));
|
|
assert(st.box, `${other} box not ticked after the second click`);
|
|
assert(c.errors.length === 0, 'page errors: ' + c.errors);
|
|
});
|
|
} finally { await c.context.close(); }
|
|
}
|
|
|
|
// ── 5. Vector: lazy load, GL or raster fallback ─────────────────────
|
|
{
|
|
const c = await newPage(browser, { theme: 'light' });
|
|
try {
|
|
await gotoMap(c.page);
|
|
await test('5 vendor/maplibre-gl is not requested on page load', async () => {
|
|
const hit = c.requests.filter(u => /vendor\/maplibre-gl/.test(u));
|
|
assert(hit.length === 0, 'requested: ' + hit.slice(0, 3));
|
|
});
|
|
await test('5 openfreemap-liberty mounts a GL canvas or falls back to raster tiles', async () => {
|
|
await pick(c.page, 'openfreemap-liberty');
|
|
await c.page.waitForFunction(() => {
|
|
const pane = document.querySelector('.leaflet-tile-pane');
|
|
if (!pane) return false;
|
|
if (pane.querySelector('canvas.maplibregl-canvas')) return true;
|
|
return Array.from(pane.querySelectorAll('img.leaflet-tile-loaded')).some(i => /cartocdn/.test(i.src));
|
|
}, null, { timeout: 20000 });
|
|
const gl = await c.page.locator('.leaflet-tile-pane canvas.maplibregl-canvas').count();
|
|
vectorBranch = gl > 0 ? 'webgl-canvas' : 'raster-fallback';
|
|
assert(c.requests.some(u => /vendor\/maplibre-gl/.test(u)), 'maplibre never loaded');
|
|
assert(c.errors.length === 0, 'page errors: ' + c.errors);
|
|
});
|
|
await test('5 back to Auto removes the GL canvas', async () => {
|
|
await pick(c.page, '__auto__');
|
|
await c.page.waitForFunction(() => !document.querySelector('.leaflet-tile-pane canvas.maplibregl-canvas'));
|
|
await c.page.waitForFunction(() => Array.from(document.querySelectorAll('.leaflet-tile-pane img.leaflet-tile-loaded')).some(i => /cartocdn/.test(i.src)));
|
|
assert(c.errors.length === 0, 'page errors: ' + c.errors);
|
|
});
|
|
} finally { await c.context.close(); }
|
|
}
|
|
|
|
// ── 6. #/live: pick + theme flip + Auto keeps one picker / one group ─
|
|
{
|
|
const c = await newPage(browser, { theme: 'light' });
|
|
try {
|
|
await gotoMap(c.page, 'live');
|
|
await test('6 live: provider pick, theme flip and Auto leave one picker and one auto layer', async () => {
|
|
await pick(c.page, 'osmfr-hot');
|
|
await c.page.waitForFunction(() => Array.from(document.querySelectorAll('.leaflet-tile-pane img.leaflet-tile')).some(i => /openstreetmap\.fr/.test(i.src)));
|
|
await MH.setTheme(c.page, 'dark');
|
|
await MH.setTheme(c.page, 'light');
|
|
await pick(c.page, '__auto__');
|
|
await c.page.waitForFunction(() => Array.from(document.querySelectorAll('.leaflet-tile-pane img.leaflet-tile-loaded')).some(i => /cartocdn/.test(i.src)));
|
|
await MH.waitForTiles(c.page, { timeout: 15000 });
|
|
const r = await c.page.evaluate(() => {
|
|
const maps = window.__mcHarness.maps;
|
|
const m = maps[maps.length - 1];
|
|
let grids = 0;
|
|
m.eachLayer(l => { if (l instanceof L.GridLayer && l._url) grids++; });
|
|
return { pickers: document.querySelectorAll('.leaflet-control-layers').length, grids, containers: document.querySelectorAll('.leaflet-tile-pane > .leaflet-layer').length };
|
|
});
|
|
assert(r.pickers === 1, 'pickers: ' + r.pickers);
|
|
assert(r.grids === 1, 'tile layers on map: ' + r.grids);
|
|
assert(r.containers === 1, 'tile pane layers: ' + r.containers);
|
|
assert(c.errors.length === 0, 'page errors: ' + c.errors);
|
|
});
|
|
} finally { await c.context.close(); }
|
|
}
|
|
|
|
// ── 7. Saved pick (mc-tile-pinned) ──────────────────────────────────
|
|
const pinned = (page) => page.evaluate(() => localStorage.getItem('mc-tile-pinned'));
|
|
const radioOn = async (page, id) => {
|
|
await page.locator('.leaflet-control-layers').first().hover();
|
|
return page.locator(`label[data-tile-id="${id}"] input`).isChecked();
|
|
};
|
|
const reloadMap = async (page) => {
|
|
await page.reload({ waitUntil: 'domcontentloaded' });
|
|
await page.waitForSelector('.leaflet-control-layers', { state: 'attached' });
|
|
await page.waitForSelector('.leaflet-tile-pane .leaflet-tile-loaded', { timeout: 15000 });
|
|
};
|
|
const drawn = (page, re, scope) => page.waitForFunction(([src, sel]) =>
|
|
Array.from(document.querySelectorAll(sel + ' .leaflet-tile-pane img.leaflet-tile-loaded')).some(i => new RegExp(src).test(i.src)),
|
|
[re, scope || ''], { timeout: 15000 });
|
|
{
|
|
const c = await newPage(browser, { theme: 'light' });
|
|
try {
|
|
await gotoMap(c.page);
|
|
await test('7a picking a base map saves it, and a reload keeps it selected and drawn', async () => {
|
|
assert(await pinned(c.page) === null, 'pinned before any pick: ' + await pinned(c.page));
|
|
await pick(c.page, 'osmfr-hot');
|
|
await drawn(c.page, 'openstreetmap\\.fr/hot');
|
|
assert(await pinned(c.page) === 'osmfr-hot', 'mc-tile-pinned: ' + await pinned(c.page));
|
|
await reloadMap(c.page);
|
|
await drawn(c.page, 'openstreetmap\\.fr/hot');
|
|
assert(await radioOn(c.page, 'osmfr-hot'), 'osmfr-hot radio not selected after reload');
|
|
assert(!(await radioOn(c.page, '__auto__')), 'Auto still selected after reload');
|
|
assert(await c.page.locator('label[data-tile-id="osmfr-hot"]').count() === 1, 'label[data-tile-id] missing');
|
|
assert(!(await tileKeys(c.page)).some(u => /cartocdn/.test(u)), 'Auto (carto) tiles still on the map');
|
|
});
|
|
await test('7a the saved pick also shows on a page without a picker (node detail map)', async () => {
|
|
const pk = await c.page.evaluate(async () => {
|
|
const r = await fetch('/api/nodes?limit=200'); const j = await r.json();
|
|
const n = (j.nodes || []).find(x => x.lat && x.lon);
|
|
return n ? n.public_key : null;
|
|
});
|
|
assert(pk, 'the fixture has no node with a location');
|
|
await c.page.evaluate((k) => { location.hash = '#/nodes/' + k; }, pk);
|
|
await c.page.waitForSelector('#nodeFullMap .leaflet-tile-loaded', { timeout: 15000 });
|
|
assert(await c.page.locator('#nodeFullMap .leaflet-control-layers').count() === 0, 'the node map has a picker');
|
|
await drawn(c.page, 'openstreetmap\\.fr/hot', '#nodeFullMap');
|
|
});
|
|
await test('7a a pin that does not fit the theme is kept but not drawn on a picker-less page', async () => {
|
|
// osmfr-hot is a light map: in dark the node map shows the dark choice, the pick stays saved.
|
|
await MH.setTheme(c.page, 'dark');
|
|
await c.page.waitForFunction(() => Array.from(document.querySelectorAll('#nodeFullMap .leaflet-tile-pane img.leaflet-tile-loaded')).some(i => /cartocdn/.test(i.src)), null, { timeout: 15000 });
|
|
assert(await c.page.locator('#nodeFullMap .leaflet-tile-pane img[src*="openstreetmap.fr"]').count() === 0, 'light pin drawn in dark');
|
|
assert(await pinned(c.page) === 'osmfr-hot', 'pin was dropped: ' + await pinned(c.page));
|
|
assert(c.errors.length === 0, 'page errors: ' + c.errors);
|
|
});
|
|
} finally { await c.context.close(); }
|
|
}
|
|
{
|
|
const c = await newPage(browser, { theme: 'light' });
|
|
try {
|
|
await gotoMap(c.page);
|
|
await test('7b picking Auto clears the saved pick; a reload shows Auto selected', async () => {
|
|
await pick(c.page, 'osmfr-hot');
|
|
await drawn(c.page, 'openstreetmap\\.fr/hot');
|
|
assert(await pinned(c.page) === 'osmfr-hot', 'not saved');
|
|
await pick(c.page, '__auto__');
|
|
await drawn(c.page, 'cartocdn');
|
|
assert(await pinned(c.page) === null, 'key still there: ' + await pinned(c.page));
|
|
await reloadMap(c.page);
|
|
assert(await radioOn(c.page, '__auto__'), 'Auto not selected after reload');
|
|
assert(!(await radioOn(c.page, 'osmfr-hot')), 'osmfr-hot selected after reload');
|
|
assert(await pinned(c.page) === null, 'key came back after reload');
|
|
assert(c.errors.length === 0, 'page errors: ' + c.errors);
|
|
});
|
|
await test('7b a saved id that is not registered (junk) is ignored: Auto, no error', async () => {
|
|
await c.page.evaluate(() => localStorage.setItem('mc-tile-pinned', '<img src=x onerror=window.__x=1>'));
|
|
await reloadMap(c.page);
|
|
assert(await radioOn(c.page, '__auto__'), 'Auto not selected');
|
|
assert(await c.page.evaluate(() => window.__x) === undefined, 'junk was executed');
|
|
assert(c.errors.length === 0, 'page errors: ' + c.errors);
|
|
});
|
|
} finally { await c.context.close(); }
|
|
}
|
|
|
|
// ── 7c. Untouched config: the opt-in groups are not offered ─────────
|
|
{
|
|
const c = await newPage(browser, { theme: 'light', providers: null });
|
|
try {
|
|
await gotoMap(c.page);
|
|
await test('7c with no map.tiles.providers the picker lists none of the opt-in groups', async () => {
|
|
await c.page.locator('.leaflet-control-layers').first().hover();
|
|
const ids = await c.page.$$eval('.leaflet-control-layers label[data-tile-id], .leaflet-control-layers label[data-tile-overlay-id]',
|
|
els => els.map(e => e.getAttribute('data-tile-id') || e.getAttribute('data-tile-overlay-id')));
|
|
assert(ids.indexOf('carto-light') >= 0 && ids.indexOf('__auto__') >= 0, 'picker looks empty: ' + ids);
|
|
const leaked = ids.filter(i => OPT_IN_IDS.indexOf(i) >= 0 || /^(hillshade|eox-labels)/.test(i));
|
|
assert(leaked.length === 0, 'opt-in entries offered: ' + leaked);
|
|
const reg = (await MH.listProviders(c.page)).map(p => p.id);
|
|
assert(OPT_IN_IDS.every(i => reg.indexOf(i) < 0), 'registered: ' + reg.filter(i => OPT_IN_IDS.indexOf(i) >= 0));
|
|
assert(c.errors.length === 0, 'page errors: ' + c.errors);
|
|
});
|
|
} finally { await c.context.close(); }
|
|
}
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
const secs = ((Date.now() - T0) / 1000).toFixed(1);
|
|
console.log(`\nVector branch: ${vectorBranch}`);
|
|
console.log(`${passed} passed, ${failed} failed (${secs}s)`);
|
|
process.exit(failed > 0 ? 1 : 0);
|
|
}
|
|
|
|
run().catch(e => { console.error(e); process.exit(1); });
|