Files
meshcore-analyzer/test-path-inspector-e2e.js
T
Kpa-clawbot 54f7f9d35b feat: path-prefix candidate inspector with map view (#944) (#945)
## feat: path-prefix candidate inspector with map view (#944)

Implements the locked spec from #944: a beam-search-based path prefix
inspector that enumerates candidate full-pubkey paths from short hex
prefixes and scores them.

### Server (`cmd/server/path_inspect.go`)

- **`POST /api/paths/inspect`** — accepts 1-64 hex prefixes (1-3 bytes,
uniform length per request)
- Beam search (width 20) over cached `prefixMap` + `NeighborGraph`
- Per-hop scoring: edge weight (35%), GPS plausibility (20%), recency
(15%), prefix selectivity (30%)
- Geometric mean aggregation with 0.05 floor per hop
- Speculative threshold: score < 0.7
- Score cache: 30s TTL, keyed by (prefixes, observer, window)
- Cold-start: synchronous NeighborGraph rebuild with 2s hard timeout →
503 `{retry:true}`
- Body limit: 4096 bytes via `http.MaxBytesReader`
- Zero SQL queries in handler hot path
- Request validation: rejects empty, odd-length, >3 bytes, mixed
lengths, >64 hops

### Frontend (`public/path-inspector.js`)

- New page under Tools route with input field (comma/space separated hex
prefixes)
- Client-side validation with error feedback
- Results table: rank, score (color-coded speculative), path names,
per-hop evidence (collapsed)
- "Show on Map" button calls `drawPacketRoute` (one path at a time,
clears prior)
- Deep link: `#/tools/path-inspector?prefixes=2c,a1,f4`

### Nav reorganization

- `Traces` nav item renamed to `Tools`
- Backward-compat: `#/traces/<hash>` redirects to `#/tools/trace/<hash>`
- Tools sub-routing dispatches to traces or path-inspector

### Store changes

- Added `LastSeen time.Time` to `nodeInfo` struct, populated from
`nodes.last_seen`
- Added `inspectMu` + `inspectCache` fields to `PacketStore`

### Tests

- **Go unit tests** (`path_inspect_test.go`): scoreHop components, beam
width cap, speculative flag, all validation error cases, valid request
integration
- **Frontend tests** (`test-path-inspector.js`): parse
comma/space/mixed, validation (empty, odd, >3 bytes, mixed lengths,
invalid hex, valid)
- Anti-tautology gate verified: removing beam pruning fails width test;
removing validation fails reject tests

### CSS

- `--path-inspector-speculative` variable in both themes (amber, WCAG AA
on both dark/light backgrounds)
- All colors via CSS variables (no hardcoded hex in production code)

Closes #944

---------

Co-authored-by: you <you@example.com>
2026-04-30 23:28:16 -07:00

88 lines
3.7 KiB
JavaScript

// E2E tests for Path Inspector (spec §5 — Playwright).
// Run: npx playwright test test-path-inspector-e2e.js
// Requires: running server on BASE_URL (default http://localhost:3000).
'use strict';
const { test, expect } = require('@playwright/test');
const BASE_URL = process.env.BASE_URL || 'http://localhost:3000';
test.describe('Path Inspector — Map Side Pane (spec §2.7)', () => {
test('side pane present and collapsed by default', async ({ page }) => {
await page.goto(`${BASE_URL}/#/map`);
const pane = page.locator('#mapSidePane');
await expect(pane).toBeVisible();
await expect(pane).not.toHaveClass(/expanded/);
});
test('click toggle expands the pane', async ({ page }) => {
await page.goto(`${BASE_URL}/#/map`);
await page.click('#mapPaneToggle');
const pane = page.locator('#mapSidePane');
await expect(pane).toHaveClass(/expanded/);
});
test('submit valid prefixes renders candidates within 1s', async ({ page }) => {
await page.goto(`${BASE_URL}/#/map`);
await page.click('#mapPaneToggle');
await page.fill('#mapPiInput', '2c,a1,f4');
await page.click('#mapPiSubmit');
// Wait for results or error (both indicate API round-trip complete).
await expect(page.locator('#mapPiResults table, #mapPiResults .no-results, #mapPiError')).toBeVisible({ timeout: 1000 });
});
test('Show on Map button draws polyline on map', async ({ page }) => {
await page.goto(`${BASE_URL}/#/map`);
await page.click('#mapPaneToggle');
await page.fill('#mapPiInput', '2c,a1');
await page.click('#mapPiSubmit');
// Wait for results.
const btn = page.locator('#mapPiResults button[data-idx="0"]');
await btn.waitFor({ timeout: 2000 });
await btn.click();
// Check that route layer has SVG polyline paths drawn.
const svg = page.locator('#leaflet-map .leaflet-overlay-pane svg path');
await expect(svg.first()).toBeVisible({ timeout: 2000 });
});
test('switching candidate clears prior polyline', async ({ page }) => {
await page.goto(`${BASE_URL}/#/map`);
await page.click('#mapPaneToggle');
await page.fill('#mapPiInput', '2c,a1');
await page.click('#mapPiSubmit');
const btn0 = page.locator('#mapPiResults button[data-idx="0"]');
await btn0.waitFor({ timeout: 2000 });
await btn0.click();
// Click second candidate if available.
const btn1 = page.locator('#mapPiResults button[data-idx="1"]');
if (await btn1.isVisible()) {
await btn1.click();
// Prior route should be cleared — only one polyline group visible.
}
});
});
test.describe('Path Inspector — Standalone Page', () => {
test('deep link auto-fills and runs', async ({ page }) => {
await page.goto(`${BASE_URL}/#/tools/path-inspector?prefixes=2c,a1,f4`);
const input = page.locator('#path-inspector-input');
await expect(input).toHaveValue('2c,a1,f4');
// Should auto-submit and show results or error.
await expect(page.locator('#path-inspector-results table, #path-inspector-results .no-results, #path-inspector-error')).toBeVisible({ timeout: 2000 });
});
test('old #/traces/<hash> redirects to #/tools/trace/<hash>', async ({ page }) => {
await page.goto(`${BASE_URL}/#/traces/abc123`);
await page.waitForTimeout(500);
expect(page.url()).toContain('#/tools/trace/abc123');
});
});
test.describe('Path Inspector — Tools Landing (spec §2.8)', () => {
test('Tools nav shows landing with both entries', async ({ page }) => {
await page.goto(`${BASE_URL}/#/tools`);
await expect(page.locator('.tools-landing')).toBeVisible();
await expect(page.locator('a[href="#/tools/path-inspector"]')).toBeVisible();
await expect(page.locator('a[href*="#/tools/trace"]')).toBeVisible();
});
});