Files
meshcore-analyzer/docs
0e23c24847 fix(scope-stats): report total and split unscoped by route (#2364) (#2368)
Fixes #2364.

## Problem

Since #1838, `GetScopeStats` folds every non-transport transmission
(FLOOD 1, DIRECT 2) into `summary.unscoped`, while `transportTotal` and
`scoped` still cover transport routes (0, 3) only. The documented
`transportTotal = scoped + unscoped` no longer holds, and a client
computing an unscoped share against `transportTotal` gets >100% (the
reporter shows `transportTotal 7620`, `unscoped 14320`).

## Fix — additive, no existing field changes value

`summary` gains:

| field | meaning |
|---|---|
| `total` | all observed transmissions, routes 0–3 (= `scoped +
unscoped`) |
| `unscopedTransport` | route 0/3 with Code1 = 0000 |
| `unscopedFlood` | route 1 — unscoped by protocol |
| `unscopedDirect` | route 2 — unscoped by protocol |

Invariants (now asserted in `TestGetScopeStats`):

```
transportTotal = scoped + unscopedTransport
unscoped       = unscopedTransport + unscopedFlood + unscopedDirect
total          = scoped + unscoped
```

The non-transport count query keeps its single scan; it just splits
route 1 vs 2 with `CASE`.

On the design question in the issue: rather than changing what
`unscoped` means (the Scopes tab and #1842 rely on it), the split lets a
rollout view use `unscopedFlood` directly: repeaters apply region
rejection to flood routes only (`isRouteFlood()` in
`examples/simple_repeater/MyMesh.cpp`), so DIRECT traffic is not subject
to flood-region filtering. `docs/api-spec.md` now says so, spells out
the route mapping, and notes that `timeSeries` is transport-only (its
`unscoped` matches `unscopedTransport`).

## Frontend

Scopes tab uses `summary.total` when present and shows `N transport, N
flood, N direct` on the Unscoped card; falls back unchanged for older
servers. The cards are built by `scopeSummaryCardsHtml(summary)`
(exposed as `window._analyticsScopeSummaryCardsHtml`).

## Tested

- `go vet ./...` (cmd/server) clean, `gofmt -l` clean
- `go test -run ScopeStats ./...` — pass (incl. extended
`TestGetScopeStats` and `/api/scope-stats` route test)
- `node --check public/analytics.js`;
`tests/unit/test-issue-1375-scope-stats-fetch.js`,
`test-issue-1979-scope-adverts-by-role.js` pass
- new `tests/unit/test-issue-2364-scope-summary-cards.js` (vm sandbox,
11 assertions: shares of `total`, route split, fallback for servers
without `total`/split, partial split, empty window); full `test-all.sh`
green

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: SaarMesh-Bot <300107934+SaarMesh-Bot@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-11-15 12:24:27 +01:00
..