mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-11-22 03:17:04 +00:00
The repeater planner (#2391) gets a fourth tab, **Coverage**: put a marker where you are thinking of placing a repeater, set its antenna height, and see on the map who would hear it. It answers the siting question "what does a repeater reach if we put it here", with two layers: handheld users and other repeaters. ## What it shows - **Users layer:** the chance that a handheld at 1.5 m hears the site, in 4 bands (10-25%, 25-50%, 50-75%, 75% and up; below 10% is not painted). The chance comes from a distance curve `P(d) = 1 / (1 + exp((ln d - ln d50) / slope))`, fitted on drive-test receptions of 41 Belgian repeaters (d50 2.7 km, slope 0.30). Terrain only lowers a cell by 2 bands where a 1.5 m receiver sits deeper than 1 first-Fresnel radius under the terrain (`cmd/server/planner_viewshed.go:19-21`). Antenna height does not change the curve: in the drive tests, handheld reach barely changed between 1, 7 and 15 m. The panel says so in one line. - **Repeaters layer:** first-Fresnel clearance from the site to every cell, for a receiver at "Repeaters at" height (default `planner.existingAntennaM`). 3 classes: line of sight (clearance 0% or more), slightly blocked (-20% to 0%), blocked (not painted). Every known repeater within range gets its link computed with the existing planner link code, a dot in its class colour, a line for line of sight and slightly blocked, and an entry in a list. - **Compute button:** changing site, height or range moves the marker and updates the URL hash right away, and dims an existing result with an "Outdated" note. Only "Compute coverage" starts a job. A shared link that carries a site computes once on open. The planner has 1 heavy-job slot shared with Area and allows 6 jobs per minute per IP, so recomputing on every change would burn both. State is in the hash: `#/tools/planner?mode=coverage&site=51.06,4.41&h=10&rx=5&range=30&layer=repeaters`. This builds on the repeater planner @zfouts wrote in #2391: the terrain tiles, the first-Fresnel analysis, the link code, the job protocol and the Area module pattern are all reused here. Thanks for that work, it made this tab a small addition instead of a new subsystem. ## Why the Repeaters classes are not the route LOS verdicts The route verdicts (clear 100%+, clear60 60%+, marginal 0%+, blocked) almost never show on Shuttle Radar Topography Mission (SRTM) terrain at mast heights. At 10 m / 5 m, 30 km around Mechelen, 109 of 70,980 cells reach clear60 or clear. SRTM includes trees and roofs, so the line between 2 masts rarely clears 60% of the Fresnel zone. I checked the clearance against one Belgian repeater (28 m, receivers at 5 m) and the repeaters live data shows it actually hears: | Distance | Heard, clearance >= 0 | Heard, clearance < 0 | |---|---|---| | 0-10 km | 9 of 11 | none in range | | 10-20 km | 3 of 4 | 1 of 8 | | 20-30 km | 0 of 6 | 3 of 35 | | 30-60 km | 1 of 2 | 0 of 84 | Every link heard within 16 km had a clearance between 2% and 54%, so "marginal" is where working links live. The map classes follow that (`repeaterClass`, `cmd/server/planner_viewshed.go:75-89`). Chain, Relay and Area keep the shared verdicts; `losVerdict` is unchanged. This rests on 17 heard links from 1 repeater, which is why the -20% band is narrow and the panel says line of sight stops being enough beyond about 20 km. ## Server - `GET /api/planner/viewshed?site=&h=&rx=&range=` (`cmd/server/planner_api.go:603`, route `cmd/server/routes.go:393`). Same job protocol, result cache, rate limits and opt-in as the other planner endpoints: 404 while `planner.enabled` is false. - One byte per cell: low nibble Users class 1-5, high nibble Repeaters class 1-3, 0 for no data. The grid is about 300 x 300 at every range: 0.2 km cells up to 30 km, `range/150` above (`planner_viewshed.go:47`). - Links skip rooms, stale repeaters and a repeater within 100 m of the site (that is the site itself). They carry no `elev_m` profile. - `truncated` is true only when the 300-node cap may have dropped a repeater within range (`viewshedTruncated`, `planner_api.go:694`). - Tile cap: `Viewshed` in the planner tile limits, sized from the largest offered range (60 km). - New config: `planner.userReach.{d50Km,slope}` with a `_comment` in `config.example.json`. Bounds 0.2-50 km and 0.05-2. - No writes, no new `map[string]interface{}`; response types `PlannerViewshedResponse/Params/Link` in `planner_types.go`. ## Frontend - `public/planner-coverage.js` + `.css`, mounted like `planner-area.js`. `planner.js` gets a `MODULES` table (`public/planner.js:31`) so Area and Coverage share one enter/leave path. - Canvas raster in an `L.imageOverlay`; the layer switch repaints locally without a new request. Requests go through `fetchJob` / `CSApi`. - Colours are CSS variables `--pl-cov-user-2..5` and `--pl-cov-rep-1..3` in `:root` and both dark blocks of `style.css`; the Repeaters ones point at `--status-*`, so a theme that changes those changes the map. ## Performance The job is opt-in and runs in the existing planner job slot, never in a hot path. Measured on real SRTM tiles, local build, 304 Belgian repeaters: | Site | Range | Mast | Job time | |---|---|---|---| | Maasvallei (hilly) | 30 km | 10 m | 2.07 s | | Maasvallei | 30 km | 30 m | 2.57 s | | Maasvallei | 60 km | 10 m | 3.98 s | | Mechelen (flat) | 30 km | 10 m | 2.61 s | On a staging instance (ARM64, cold tile cache) a 30 km job took 6.8 s including the tile downloads. Response size at 60 km with 115 links: 239,942 bytes with link elevation profiles, 149,984 without (what this PR ships). `BenchmarkViewshedMaxLeg` covers the 60 km worst case on a synthetic terrain view. ## Verification - Go: 26 viewshed tests and benchmarks in `planner_viewshed_test.go`, `planner_api_test.go`, `planner_config_test.go` and `planner_tiles_test.go`, among them: flat terrain equals the plain curve and `analyzeLOS`, a ridge shadows only its far side, missing terrain is "no data", the `truncated` rule (proven to fail on the old rule), links without `elev_m`, the repeater at the site left out. `go test ./...` in `cmd/server` passes. - Frontend: `tests/unit/test-planner-coverage.js` (23 tests, in `test-all.sh`): grid decode, class-to-colour mapping, unpainted classes, hash round trip, no fetch on parameter change, 1 fetch per click, deep-link autorun once, stale responses ignored, link classes at the boundaries, escaped repeater names. - E2E: 5 Coverage cases in `tests/e2e/test-planner-e2e.js` (stubbed viewshed): click and compute, layer switch without a request, outdated then recompute, deep link, leaving the tab removes the overlay. Planner E2E 25/25 locally. - eslint 0 errors. Browser: light and dark theme, Users and Repeaters on flat, hilly and coastal sites, deep links, no console errors; also on a staging instance with live data. ## Not in this PR - The `--pl-cov-*` colours are not in the customizer's `THEME_CSS_MAP` yet. They follow `--status-*` for the Repeaters layer; the Users colours need their own entries (AGENTS.md rule 8, later milestone). - In Flanders the Users layer is close to a circle: 0.3% of cells differ from the plain curve around Mechelen, 42% in the Maasvallei, 64% in the Ardennes. The terrain correction is untested in hilly areas, the drive tests had no repeater there. - The Repeaters calibration uses 1 repeater. Other operators with drive tests or neighbour data can tighten it. - A link's class comes from `clearance_pct`, rounded to 0.1%, while the grid uses the raw clearance: within 0.05% of a bound a link can land 1 class off the cell under it. List, line and dot always agree with each other. - An OS dark-mode switch without the theme toggle does not repaint the overlay until the next compute, the same as the planner's tile layer. --------- Co-authored-by: zfouts <zachary.fouts@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
483 lines
25 KiB
JavaScript
483 lines
25 KiB
JavaScript
/**
|
|
* E2E: Repeater Planner page (#/tools/planner), all three modes.
|
|
*
|
|
* The fixture server does not enable the planner and has no terrain source, so
|
|
* the test stubs the network calls the page depends on:
|
|
* GET /api/config/client → real JSON plus a `planner` block
|
|
* GET /api/planner/profile → canned legs (flat, 900 m ridge)
|
|
* GET /api/planner/relay → job protocol: 202 then 200
|
|
* GET /api/planner/coverage → job protocol: 202 then 200, or an error
|
|
* GET /api/planner/viewshed → job protocol: 202 then 200 (small canned grid)
|
|
* Negative case: without the config stub the page shows its disabled state.
|
|
*
|
|
* Usage: BASE_URL=http://localhost:13581 node test-planner-e2e.js
|
|
*/
|
|
'use strict';
|
|
const { chromium } = require('playwright');
|
|
|
|
const BASE = process.env.BASE_URL || 'http://localhost:13581';
|
|
|
|
const PLANNER_CFG = {
|
|
defaultRangeKm: 30, rangesKm: [10, 15, 20, 30, 40, 50, 60], newAntennaM: 10, existingAntennaM: 5,
|
|
frequencyMhz: 910.525, kFactor: 1.3333, maxPoints: 16, maxLegKm: 100, maxAreaKm: 100, maxSites: 10,
|
|
minClearance: 0.6,
|
|
};
|
|
const XSS = '"><img src=x onerror=alert(1)>';
|
|
|
|
let passed = 0, failed = 0;
|
|
async function step(name, fn) {
|
|
try { await fn(); passed++; console.log(' ✓ ' + name); }
|
|
catch (e) { failed++; console.error(' ✗ ' + name + ': ' + e.message); }
|
|
}
|
|
function assert(c, m) { if (!c) throw new Error(m || 'assertion failed'); }
|
|
|
|
// A valley between two 100 m ends is comfortably clear; a 900 m ridge blocks.
|
|
function flat() { return Array.from({ length: 100 }, (_, i) => (i === 0 || i === 99 ? 100 : 0)); }
|
|
function ridge() { const a = flat(); for (let i = 45; i <= 55; i++) a[i] = 900; return a; }
|
|
|
|
const json = (status, body, headers) => ({
|
|
status, contentType: 'application/json', headers: headers || {}, body: JSON.stringify(body),
|
|
});
|
|
|
|
async function stubConfig(page) {
|
|
await page.route('**/api/config/client', async (route) => {
|
|
const resp = await route.fetch();
|
|
const j = await resp.json();
|
|
await route.fulfill({ response: resp, contentType: 'application/json', body: JSON.stringify(Object.assign({}, j, { planner: PLANNER_CFG })) });
|
|
});
|
|
}
|
|
|
|
// Stubs one planner endpoint with a response sequence (the last entry repeats).
|
|
// An entry may carry `gate`, a promise the response waits on, so the test can
|
|
// observe an in-flight state deterministically. Returns a live call record.
|
|
async function stubJob(page, pattern, seq) {
|
|
const rec = { count: 0, urls: [] };
|
|
await page.route(pattern, async (route) => {
|
|
const i = Math.min(rec.count, seq.length - 1);
|
|
rec.count++;
|
|
rec.urls.push(route.request().url());
|
|
const e = seq[i];
|
|
if (e.gate) await e.gate;
|
|
// fulfill may be a function of the request URL, for answers that echo it.
|
|
await route.fulfill(typeof e.fulfill === 'function' ? e.fulfill(route.request().url()) : e.fulfill);
|
|
});
|
|
return rec;
|
|
}
|
|
|
|
// Profile stub: one canned leg per consecutive point pair (cycling flat, ridge).
|
|
async function stubProfile(page, kinds) {
|
|
const rec = { count: 0, urls: [] };
|
|
await page.route('**/api/planner/profile*', async (route) => {
|
|
rec.count++;
|
|
const url = route.request().url();
|
|
rec.urls.push(url);
|
|
const n = new URL(url).searchParams.get('pts').split(',').length / 2;
|
|
const legs = [];
|
|
for (let i = 0; i < n - 1; i++) {
|
|
const kind = (kinds || ['flat', 'ridge'])[i % (kinds || ['flat', 'ridge']).length];
|
|
legs.push({ distance_km: 20 + i, elev_m: kind === 'ridge' ? ridge() : flat() });
|
|
}
|
|
await route.fulfill(json(200, { source: 'e2e-stub', legs }));
|
|
});
|
|
return rec;
|
|
}
|
|
|
|
function link(verdict, clearance, km, elev) {
|
|
return { distance_km: km, clearance_pct: clearance, verdict, worst_km: km / 2, obstruction_m: clearance < 0 ? 400 : 0, elev_m: elev };
|
|
}
|
|
|
|
function relayBody() {
|
|
const opt = (kind, name, lat, lon, a, b) => ({
|
|
kind, pubkey: kind === 'existing' ? 'ab'.repeat(32) : undefined, name, lat, lon, elev_m: 300, antenna_m: kind === 'existing' ? 5 : 10,
|
|
leg_a: a, leg_b: b, bottleneck_pct: Math.min(a.clearance_pct, b.clearance_pct),
|
|
});
|
|
const good = (km) => link('clear', 120, km, flat());
|
|
return {
|
|
source: 'e2e-stub',
|
|
direct: link('blocked', -999, 41.3, ridge()),
|
|
existing: [
|
|
opt('existing', XSS, 37.8, -122.2, good(20), good(20)),
|
|
opt('existing', 'Hilltop Relay', 37.75, -122.15, good(22), good(18)),
|
|
],
|
|
open: [
|
|
opt('open', '', 37.78, -122.18, good(21), good(19)),
|
|
opt('open', '', 37.76, -122.12, good(23), good(17)),
|
|
],
|
|
params: {}, warnings: ['terrain missing for 1 of 4 tiles (read as sea level)'],
|
|
};
|
|
}
|
|
|
|
function areaBody() {
|
|
const names = ['Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot', XSS, 'Golf'];
|
|
const nodes = names.map((name, i) => ({
|
|
pubkey: String(i).repeat(64).slice(0, 64), name, role: 'repeater',
|
|
lat: 30.1 + (i % 4) * 0.1, lon: -98.1 + Math.floor(i / 4) * 0.4 + (i >= 6 ? 0.2 : 0),
|
|
stale: false, in_area: true, component: i >= 6 ? 1 : 0,
|
|
}));
|
|
const sum = (c, l, iso, cut) => ({ repeaters: 8, components: c, largest_component: l, isolated: iso, cut_vertices: cut, stale_excluded: 0 });
|
|
return {
|
|
area: { s: 30, w: -98.2, n: 30.6, e: -97.6 },
|
|
params: { sites: 3, range_km: 30, hr: 10, he: 5, baseline: 'predicted', stale: false },
|
|
source: 'e2e-stub', status: 'improved',
|
|
baseline: sum(2, 6, 0, 1), final: sum(1, 8, 0, 1),
|
|
nodes,
|
|
edges: [{ a: 0, b: 1, class: 'solid', distance_km: 10, clearance_pct: 90 }, { a: 6, b: 7, class: 'marginal', distance_km: 9, clearance_pct: 50 },
|
|
{ a: 1, b: 2, class: 'marginal', distance_km: 8, clearance_pct: 40 }, { a: 2, b: 3, class: 'marginal', distance_km: 8, clearance_pct: 30 }],
|
|
sites: [{
|
|
step: 1, lat: 30.3, lon: -97.9, elev_m: 250, antenna_m: 10, reason: 'joins',
|
|
gain: { components_joined: 1, cut_vertices_removed: 0, repeaters_reached: 2 },
|
|
after: sum(1, 8, 0, 1),
|
|
links: [
|
|
{ node: 2, distance_km: 12, clearance_pct: 80, class: 'solid' },
|
|
{ node: 6, distance_km: 14, clearance_pct: 70, class: 'solid' },
|
|
],
|
|
joins_components: [1],
|
|
}],
|
|
warnings: [], truncated: false, computed_at: new Date().toISOString(),
|
|
};
|
|
}
|
|
|
|
// 4x4 grid, row 0 north; byte = users | repeaters << 4. params.site echoes
|
|
// the requested site rounded to 0.001°, as the server does.
|
|
function viewshedBody(url) {
|
|
const req = url ? new URL(url).searchParams.get('site') : null;
|
|
const [lat, lon] = req ? req.split(',').map((v) => Math.round(Number(v) * 1000) / 1000) : [30.3, -97.9];
|
|
const rows = 4, cols = 4;
|
|
const b = Buffer.alloc(rows * cols);
|
|
for (let i = 0; i < b.length; i++) b[i] = ((i % 5) + 1) | (((i % 4) + 1) << 4);
|
|
return {
|
|
source: 'e2e-stub',
|
|
params: { site: { lat, lon }, antenna_m: 10, rx_antenna_m: 5, range_km: 30, frequency_mhz: 910.525, k_factor: 1.3333, user_reach: { d50_km: 2.7, slope: 0.3 } },
|
|
bbox: [30.2, -98.0, 30.4, -97.8], rows, cols, cell_km: 5, cells: b.toString('base64'),
|
|
links: [
|
|
{ pubkey: 'aa'.repeat(32), name: 'Cov Alpha', lat: 30.25, lon: -97.95, link: { distance_km: 7, clearance_pct: 90, verdict: 'clear', worst_km: 3, obstruction_m: 0 } },
|
|
{ pubkey: 'bb'.repeat(32), name: 'Cov Bravo', lat: 30.35, lon: -97.85, link: { distance_km: 9, clearance_pct: -20, verdict: 'blocked', worst_km: 4, obstruction_m: 80 } },
|
|
],
|
|
warnings: [], truncated: false,
|
|
};
|
|
}
|
|
|
|
const job202 = (gate) => ({ gate, fulfill: json(202, { state: 'loading_terrain', progress: 0.4, retry_after_s: 1 }) });
|
|
|
|
(async () => {
|
|
const browser = await chromium.launch({
|
|
headless: true,
|
|
executablePath: process.env.CHROMIUM_PATH || undefined,
|
|
args: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'],
|
|
});
|
|
const ctx = await browser.newContext({ viewport: { width: 1400, height: 900 } });
|
|
const errors = [];
|
|
const dialogs = [];
|
|
|
|
// A fresh page per scenario: the planner keeps module-level caches and a
|
|
// hash-only navigation would not reload them.
|
|
async function newPage(withConfig) {
|
|
const page = await ctx.newPage();
|
|
page.setDefaultTimeout(15000);
|
|
page.on('pageerror', (e) => errors.push(e));
|
|
page.on('dialog', async (d) => { dialogs.push(d.message()); await d.dismiss(); });
|
|
if (withConfig) await stubConfig(page);
|
|
return page;
|
|
}
|
|
async function openPlanner(page, query) {
|
|
await page.goto(BASE + '/#/tools/planner' + (query || ''), { waitUntil: 'domcontentloaded' });
|
|
await page.waitForSelector('.mc-pl-page', { timeout: 15000 });
|
|
await page.waitForSelector('.leaflet-container', { timeout: 15000 });
|
|
}
|
|
|
|
console.log(`\n=== planner E2E against ${BASE} ===`);
|
|
|
|
// Real fixture coordinates for the chain / relay points.
|
|
const nr = await ctx.request.get(BASE + '/api/nodes?limit=2000');
|
|
const nodes = ((await nr.json()).nodes || []).filter(n => (n.role === 'repeater' || n.role === 'room') && typeof n.lat === 'number' && typeof n.lon === 'number' && n.lat && n.lon);
|
|
assert(nodes.length >= 3, 'fixture needs 3 positioned repeaters');
|
|
const P = nodes.slice(0, 3).map(n => [n.lat, n.lon]);
|
|
const pts = P.map(p => p.join(',')).join(',');
|
|
|
|
// ── Disabled ──
|
|
await step('no planner config: page shows the disabled message, Tools has no planner card', async () => {
|
|
const page = await newPage(false);
|
|
await page.goto(BASE + '/#/tools/planner', { waitUntil: 'domcontentloaded' });
|
|
await page.waitForSelector('.mc-pl-off-card');
|
|
const t = await page.locator('.mc-pl-off-card').textContent();
|
|
assert(/not enabled/i.test(t), 'text: ' + t);
|
|
assert(await page.locator('.mc-pl-map').count() === 0, 'map should not mount');
|
|
await page.goto(BASE + '/#/tools', { waitUntil: 'domcontentloaded' });
|
|
await page.waitForSelector('.tools-card');
|
|
assert(await page.locator('a[href="#/tools/planner"]').count() === 0, 'planner card should be absent');
|
|
await page.close();
|
|
});
|
|
|
|
// ── Tools card ──
|
|
await step('planner config: Tools landing shows a card linking to #/tools/planner', async () => {
|
|
const page = await newPage(true);
|
|
await page.goto(BASE + '/#/tools', { waitUntil: 'domcontentloaded' });
|
|
await page.waitForSelector('a.tools-card[href="#/tools/planner"]');
|
|
const t = await page.locator('a.tools-card[href="#/tools/planner"]').textContent();
|
|
assert(/Repeater Planner/.test(t), 'card text: ' + t);
|
|
await page.close();
|
|
});
|
|
|
|
// ── Chain ──
|
|
{
|
|
const page = await newPage(true);
|
|
const rec = await stubProfile(page);
|
|
await openPlanner(page, '?mode=chain&pts=' + pts);
|
|
await page.waitForSelector('[data-leg-open="1"].mc-los-tone-bad');
|
|
await page.waitForSelector('.mc-los-obstruction', { state: 'attached' });
|
|
|
|
await step('chain: exactly 1 profile request carrying the 3 points', async () => {
|
|
assert(rec.count === 1, 'expected 1 request, got ' + rec.count);
|
|
const nums = new URL(rec.urls[0]).searchParams.get('pts').split(',').map(Number);
|
|
assert(nums.length === 6, 'expected 6 numbers, got ' + nums.length);
|
|
});
|
|
|
|
await step('chain: 2 leg chips, good then bad', async () => {
|
|
const chips = await page.evaluate(() => [...document.querySelectorAll('[data-leg-open]')].map(b => ({ text: b.textContent.trim(), cls: b.className })));
|
|
assert(chips.length === 2, 'expected 2 chips, got ' + chips.length);
|
|
assert(/mc-los-tone-good/.test(chips[0].cls) && /clear/i.test(chips[0].text), 'chip 1: ' + JSON.stringify(chips[0]));
|
|
assert(/mc-los-tone-bad/.test(chips[1].cls) && /blocked/i.test(chips[1].text), 'chip 2: ' + JSON.stringify(chips[1]));
|
|
});
|
|
|
|
await step('chain: exactly 1 warning marker on the map', async () => {
|
|
const n = await page.locator('.mc-los-obstruction').count();
|
|
assert(n === 1, 'expected 1 marker, got ' + n);
|
|
});
|
|
|
|
await step('chain: blocked chip opens a panel with an SVG; Escape closes it', async () => {
|
|
await page.locator('[data-leg-open="1"]').click();
|
|
await page.waitForSelector('.mc-los-panel svg.mc-los-svg');
|
|
assert(/Terrain rises/.test(await page.locator('.mc-los-panel .mc-los-obst').textContent()), 'obstruction text missing');
|
|
await page.keyboard.press('Escape');
|
|
await page.waitForFunction(() => !document.querySelector('.mc-los-panel'));
|
|
});
|
|
|
|
await step('chain: editing an antenna re-analyses with no new request', async () => {
|
|
const title = () => page.locator('[data-leg-open="1"]').getAttribute('title');
|
|
const before = await title();
|
|
await page.locator('input[data-h="1"]').fill('60');
|
|
await page.waitForFunction((b) => document.querySelector('[data-leg-open="1"]').title !== b, before);
|
|
assert(rec.count === 1, 'profile requests: ' + rec.count);
|
|
assert(/mc-los-tone-/.test(await page.locator('[data-leg-open="1"]').getAttribute('class')), 'chip lost its verdict');
|
|
});
|
|
await page.close();
|
|
}
|
|
|
|
// ── Relay ──
|
|
{
|
|
const page = await newPage(true);
|
|
let open;
|
|
const gate = new Promise((r) => { open = r; });
|
|
const rec = await stubJob(page, '**/api/planner/relay*', [job202(), { gate, fulfill: json(200, relayBody()) }]);
|
|
const prof = await stubProfile(page);
|
|
await openPlanner(page, '?mode=relay&a=' + P[0].join(',') + '&b=' + P[1].join(','));
|
|
|
|
await step('relay: progress UI shows while the job runs (202 then 200)', async () => {
|
|
try {
|
|
// The 2nd poll is held on the gate, so the 202 state stays observable.
|
|
await page.waitForFunction(() => /terrain/i.test((document.querySelector('[data-status="relay"] .mc-pl-progress-text') || {}).textContent || ''));
|
|
assert(await page.locator('[data-status="relay"] [role="progressbar"]').count() === 1, 'progress bar');
|
|
} finally { open(); }
|
|
await page.waitForSelector('.mc-pl-opts');
|
|
assert(rec.count === 2, 'relay requests: ' + rec.count);
|
|
});
|
|
|
|
await step('relay: direct card, 2 existing and 2 open options render', async () => {
|
|
assert(/Terrain blocks/.test(await page.locator('.mc-pl-direct .mc-pl-note').textContent()), 'direct note');
|
|
const sub = await page.locator('.mc-pl-direct .mc-pl-sub').textContent();
|
|
assert(sub.includes('terrain blocks the path') && !sub.includes('999'), 'direct link line: ' + sub);
|
|
const warn = await page.locator('.mc-pl-warnings').textContent();
|
|
assert(warn.includes('terrain missing for 1 of 4 tiles'), 'relay warning: ' + warn);
|
|
assert(await page.locator('[data-opt^="e"]').count() === 2, 'existing options');
|
|
assert(await page.locator('[data-opt^="o"]').count() === 2, 'open options');
|
|
assert(await page.locator('.mc-pl-cand').count() === 4, 'candidate markers');
|
|
});
|
|
|
|
await step('relay: selecting an option draws the route, opens two profiles, writes sel= to the URL', async () => {
|
|
await page.locator('[data-opt="o1"]').click();
|
|
await page.waitForSelector('.mc-los-panel .mc-pl-prof');
|
|
assert(await page.locator('.mc-los-panel .mc-pl-prof').count() === 2, 'expected 2 profiles');
|
|
assert(await page.locator('path.mc-pl-leg:not(.mc-pl-direct)').count() === 2, 'expected 2 route legs');
|
|
assert(/[?&]sel=o1(&|$)/.test(await page.evaluate(() => location.hash)), 'hash: ' + await page.evaluate(() => location.hash));
|
|
assert(prof.count === 0, 'profiles come from the relay result, not a request');
|
|
});
|
|
|
|
await step('relay XSS: a hostile node name renders as text', async () => {
|
|
const names = await page.locator('[data-opt="e1"] .mc-pl-name').textContent();
|
|
assert(names === XSS, 'name text: ' + names);
|
|
assert(await page.locator('img[src="x"]').count() === 0, 'injected <img> found');
|
|
});
|
|
await page.close();
|
|
}
|
|
|
|
// ── Area ──
|
|
{
|
|
const page = await newPage(true);
|
|
const cov = await stubJob(page, '**/api/planner/coverage*', [job202(), { fulfill: json(200, areaBody()) }]);
|
|
const prof = await stubProfile(page);
|
|
await openPlanner(page, '?mode=area&bbox=30.0,-98.2,30.6,-97.6');
|
|
|
|
await step('area: progress shown, then a summary table with clusters 2 -> 1', async () => {
|
|
await page.waitForSelector('.mc-pa-summary');
|
|
assert(cov.count === 2, 'coverage requests: ' + cov.count);
|
|
const row = await page.evaluate(() => {
|
|
const r = [...document.querySelectorAll('.mc-pa-summary tbody tr')].find(tr => /^Clusters$/.test(tr.querySelector('th').textContent));
|
|
return r ? [...r.querySelectorAll('td')].map(td => td.textContent.trim()) : null;
|
|
});
|
|
assert(row && row[0] === '2' && row[1] === '1', 'Clusters row: ' + JSON.stringify(row));
|
|
assert(/improve/i.test(await page.locator('.mc-pa-banner').textContent()), 'status banner');
|
|
});
|
|
|
|
await step('area: site card explains the join; numbered site marker on the map', async () => {
|
|
assert(await page.locator('.mc-pa-card').count() === 1, 'expected 1 site card');
|
|
const reason = await page.locator('.mc-pa-reason').textContent();
|
|
assert(/Joins/.test(reason), 'reason: ' + reason);
|
|
assert(await page.locator('.leaflet-marker-icon.mc-pa-site').count() === 1, 'site marker');
|
|
assert((await page.locator('.mc-pa-site span').textContent()).trim() === '1', 'site marker number');
|
|
});
|
|
|
|
await step('area: marginal links hidden by default, shown after toggling, marginal=1 in the hash', async () => {
|
|
const edges = () => page.locator('path.mc-pa-edge:not(.mc-pa-edge-marginal)').count();
|
|
const marg = () => page.locator('path.mc-pa-edge-marginal').count();
|
|
assert(await marg() === 0 && await edges() === 1, 'default edges: ' + await edges() + ' marginal: ' + await marg());
|
|
assert(await page.locator('[data-legend="marginal"]').isHidden(), 'legend marginal row hidden');
|
|
const before = cov.count;
|
|
await page.locator('[data-f="marginal"]').check();
|
|
assert(await marg() === 3, 'marginal edges shown: ' + await marg());
|
|
assert(await page.locator('[data-legend="marginal"]').isVisible(), 'legend marginal row visible');
|
|
assert(/[?&]marginal=1(&|$)/.test(await page.evaluate(() => location.hash)), 'hash: ' + await page.evaluate(() => location.hash));
|
|
assert(cov.count === before, 'toggle must not refetch');
|
|
await page.locator('[data-f="marginal"]').uncheck();
|
|
assert(await marg() === 0, 'hidden again');
|
|
});
|
|
|
|
await step('area: Show profiles triggers a profile request and opens the panel', async () => {
|
|
await page.locator('[data-act="profiles"][data-step="1"]').click();
|
|
await page.waitForSelector('.mc-los-panel svg.mc-los-svg');
|
|
assert(prof.count >= 1, 'profile requests: ' + prof.count);
|
|
});
|
|
|
|
await step('area XSS: a hostile node name renders as text', async () => {
|
|
const links = await page.locator('.mc-pa-links').textContent();
|
|
assert(links.includes(XSS), 'links text: ' + links);
|
|
assert(await page.locator('img[src="x"]').count() === 0, 'injected <img> found');
|
|
});
|
|
await page.close();
|
|
}
|
|
|
|
// ── Coverage ──
|
|
{
|
|
const page = await newPage(true);
|
|
const vs = await stubJob(page, '**/api/planner/viewshed*', [job202(), { fulfill: (url) => json(200, viewshedBody(url)) }]);
|
|
await openPlanner(page, '?mode=coverage');
|
|
const overlays = () => page.locator('img.leaflet-image-layer').count();
|
|
|
|
await step('coverage: map click requests a viewshed, overlay and legend appear', async () => {
|
|
assert(await overlays() === 0, 'overlay before click');
|
|
const box = await page.locator('.leaflet-container').boundingBox();
|
|
assert(await page.locator('[data-act="run"]').isDisabled(), 'Compute button enabled without a site');
|
|
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
|
|
await page.waitForSelector('path.mc-pl-cov-site');
|
|
await page.waitForTimeout(300);
|
|
assert(vs.count === 0, 'a map click fetched: ' + vs.count);
|
|
assert(await overlays() === 0, 'overlay before Compute');
|
|
await page.locator('[data-act="run"]').click();
|
|
await page.waitForSelector('img.leaflet-image-layer');
|
|
assert(vs.count === 2, 'viewshed requests (202 + 200): ' + vs.count);
|
|
assert(await page.locator('.mc-pl-cov-legend li').count() === 4, 'users legend rows');
|
|
assert(/[?&]site=/.test(await page.evaluate(() => location.hash)), 'site in hash');
|
|
});
|
|
|
|
await step('coverage: Repeaters layer lists links, no new viewshed request', async () => {
|
|
const before = vs.count;
|
|
assert(await page.locator('.mc-pl-cov-links').count() === 0, 'links list shown on Users layer');
|
|
assert(await page.locator('path.mc-pl-cov-link').count() === 0, 'map links drawn on Users layer');
|
|
await page.locator('[data-f="layer"][value="repeaters"]').check();
|
|
await page.waitForSelector('.mc-pl-cov-links li');
|
|
assert(await page.locator('.mc-pl-cov-links li').count() === 2, 'link rows');
|
|
assert(await page.locator('path.mc-pl-cov-link').count() === 2, 'map link lines');
|
|
await page.waitForTimeout(300);
|
|
assert(vs.count === before, 'layer switch refetched: ' + (vs.count - before));
|
|
assert(/[?&]layer=repeaters(&|$)/.test(await page.evaluate(() => location.hash)), 'layer in hash');
|
|
assert(await overlays() === 1, 'overlay kept');
|
|
});
|
|
|
|
await step('coverage: changing a parameter does not fetch, marks outdated; Compute refreshes', async () => {
|
|
const before = vs.count;
|
|
await page.locator('[data-f="h"]').fill('15');
|
|
await page.locator('[data-f="h"]').dispatchEvent('change');
|
|
await page.waitForSelector('[data-f="outdated"] .mc-pa-note');
|
|
await page.waitForTimeout(300);
|
|
assert(vs.count === before, 'parameter change refetched: ' + (vs.count - before));
|
|
assert(await overlays() === 1, 'overlay kept while outdated');
|
|
assert(await page.locator('path.mc-pl-cov-link').count() === 0, 'link lines shown while outdated');
|
|
assert(/[?&]h=15(&|$)/.test(await page.evaluate(() => location.hash)), 'h in hash');
|
|
await page.locator('[data-act="run"]').click();
|
|
await page.waitForFunction(() => !document.querySelector('[data-f="outdated"] .mc-pa-note'));
|
|
assert(vs.count === before + 1, 'Compute requests: ' + (vs.count - before));
|
|
assert(/[&?]h=15(&|$)/.test(vs.urls[vs.urls.length - 1]), 'latest h in request: ' + vs.urls[vs.urls.length - 1]);
|
|
await page.waitForSelector('path.mc-pl-cov-link');
|
|
});
|
|
|
|
await step('coverage: deep link restores site, Repeaters layer and overlay', async () => {
|
|
const hash = await page.evaluate(() => location.hash);
|
|
const m = hash.match(/[?&]site=([^&]+)/);
|
|
assert(m, 'no site in hash: ' + hash);
|
|
const p2 = await newPage(true);
|
|
const vs2 = await stubJob(p2, '**/api/planner/viewshed*', [{ fulfill: (url) => json(200, viewshedBody(url)) }]);
|
|
await openPlanner(p2, '?mode=coverage&site=' + m[1] + '&layer=repeaters');
|
|
await p2.waitForSelector('img.leaflet-image-layer');
|
|
await p2.waitForTimeout(300);
|
|
assert(vs2.count === 1, 'deep link computes once automatically: ' + vs2.count);
|
|
assert(await p2.locator('path.mc-pl-cov-site').count() === 1, 'site marker');
|
|
assert(await p2.locator('[data-f="layer"][value="repeaters"]').isChecked(), 'Repeaters selected');
|
|
await p2.waitForSelector('.mc-pl-cov-links li');
|
|
await p2.close();
|
|
});
|
|
|
|
await step('coverage: switching to Chain removes the overlay', async () => {
|
|
await page.locator('.mc-pl-tab[data-mode="chain"]').click();
|
|
await page.waitForFunction(() => document.querySelectorAll('img.leaflet-image-layer').length === 0);
|
|
assert(await overlays() === 0, 'overlay still present');
|
|
});
|
|
await page.close();
|
|
}
|
|
|
|
// ── Errors ──
|
|
await step('area error: 400 no_nodes_in_area shows a friendly message', async () => {
|
|
const page = await newPage(true);
|
|
await stubJob(page, '**/api/planner/coverage*', [{ fulfill: json(400, { error: 'no_nodes_in_area' }) }]);
|
|
await openPlanner(page, '?mode=area&bbox=30.0,-98.2,30.6,-97.6');
|
|
await page.waitForFunction(() => { const e = document.querySelector('[data-f="error"]'); return e && !e.hidden && e.textContent; });
|
|
const t = await page.locator('[data-f="error"]').textContent();
|
|
assert(/No known repeaters/.test(t), 'error text: ' + t);
|
|
assert(!/no_nodes_in_area/.test(t), 'raw error code leaked: ' + t);
|
|
await page.close();
|
|
});
|
|
|
|
await step('area error: 429 with Retry-After says to try again', async () => {
|
|
const page = await newPage(true);
|
|
await stubJob(page, '**/api/planner/coverage*', [{ fulfill: json(429, { error: 'rate_limited' }, { 'Retry-After': '7' }) }]);
|
|
await openPlanner(page, '?mode=area&bbox=30.0,-98.2,30.6,-97.6');
|
|
await page.waitForFunction(() => { const e = document.querySelector('[data-f="error"]'); return e && !e.hidden && e.textContent; });
|
|
const t = await page.locator('[data-f="error"]').textContent();
|
|
assert(/try again/i.test(t) && /7/.test(t), 'error text: ' + t);
|
|
await page.close();
|
|
});
|
|
|
|
// ── Cross-cutting ──
|
|
await step('no dialog fired (no XSS execution)', async () => {
|
|
assert(dialogs.length === 0, 'dialogs: ' + JSON.stringify(dialogs));
|
|
});
|
|
|
|
await step('no pageerror from planner*.js', async () => {
|
|
errors.forEach(e => console.log(' [pageerror]', e.message));
|
|
const ours = errors.filter(e => /planner[\w-]*\.js/.test(e.stack || '') || /MeshPlanner/.test(e.message));
|
|
assert(ours.length === 0, ours.map(e => e.message).join('; '));
|
|
});
|
|
|
|
await browser.close();
|
|
console.log(`\n${passed} passed, ${failed} failed`);
|
|
process.exit(failed ? 1 : 0);
|
|
})().catch((e) => { console.error(e); process.exit(1); });
|