Skip to content

feat(nodes): recommended scopes for where the node stands, info only (#1035 M2) - #1106

Draft
adminopenclaw8-sketch wants to merge 4 commits into
masterfrom
feat/1035-m2-node-page
Draft

adminopenclaw8-sketch wants to merge 4 commits into
masterfrom
feat/1035-m2-node-page

Conversation

@adminopenclaw8-sketch

Copy link
Copy Markdown
Collaborator

Relates to #1035

What

M2 of #1035 (plan "M2: node page" in the M0 report, owner decisions of 2026-12-02, M1 #1101 merged as 10a5f1da): the full node page of a repeater or room with an advertised position shows "Recommended scopes here (meshguide.dk)", an info-only section that sets what meshguide.dk recommends for where the node stands next to what the node has.

  • Endpoint GET /api/nodes/{pubkey}/scope-check (cmd/server/node_scope_check.go). It runs M1's engine as is (scopeguide.Recommend + Compare), with no copy of it. The response is a named struct (NodeScopeCheckResponse, embedding M1's Verdict) plus defaultConfirmedAt, listReportedAt and source (repo, pinned commit, meshguide.dk link). It reads one typed node row by primary key, so the new file has no map[string]interface{}.
  • Node side: the observed default scope (nodes.default_scope; '' means "cannot be decoded" here, NULL means none) and the configured allow-list (nodes.configured_scope, only when an observer reported it).
  • Not applicable: the answer carries notApplicable set to role (companion, sensor), position (no advertised position, 0,0 included; estimated positions are never used) or outside (in no DAGI postnummer, e.g. Sweden). The page shows nothing in these cases.
  • Gating and visibility: 404 for unknown, hidden or blacklisted nodes, and while dagi.enabled is off. Public, like the node page. Read-only (bug(db): vacuumOnStartup fails with SQLITE_BUSY when ingestor + server share DB (auto_vacuum migration #919 broken in single-container topology) Kpa-clawbot/CoreScope#1283).
  • Frontend public/node-scope-check.js: DOM built with textContent only.
    • Recommended chips: region scopes and dk/eu/europe, plus postal scopes only on Fyn and Sjælland, with a note explaining why there are none elsewhere.
    • The node's default scope and list in neutral wording ("Recommended, in the list", "Recommended, not in the list", "In the list, recommended elsewhere", "In the list, not a meshguide.dk scope").
    • A position disclaimer, and an https link to meshguide.dk/#/defaults/region-scopes with the pinned commit.
    • Deep link: #/nodes/{pk}?section=node-scope-check.
  • Request reuse: on a cold load the node page renders twice. This is existing behaviour; clock-skew is also fetched twice. The module therefore reuses its last answer, or the request still in flight, for 60 s. It holds one entry, and a failed request is dropped, so a view costs one request.
  • CSS: variables only, badge-scope chips, and a single column below 480 px.

Plan (no separate plan was posted, as the task asks)

  1. Go tests first (Fyn, Sjælland, Aarhus, København K group, Bornholm, no position, 0,0, companion, Malmö, hidden, blacklisted, DAGI off, pre-fix(ingestor): relay hops refresh last_seen only on a unique prefix (#897) #899 schema, compute budget), then the handler.
  2. Rendering unit tests in test-1035-node-scope-check.js (tests/fake-dom.js vm sandbox), then the module and the nodes.js wiring.
  3. An E2E on its own Go server with test-fixtures/seed-1035-scope-check-nodes.sql, at desktop and 375×560, light and dark. Registered in scripts/e2e-shards.json (shard 2, the lightest).

Choices made without asking (the smallest that changes no existing behaviour):

Performance

This is not a hot path: one request per node view, and nothing in ingest, WebSocket or render loops. TestScopeCheckComputeBudget asserts that buildNodeScopeCheck (DAGI lookup + Recommend + Compare) stays under 1 ms per call. It measured 2.9 µs/call over 5,000 calls (Apple M-series, without -race). BenchmarkNodeScopeCheck is included. Nothing scales with the number of nodes or packets, so the endpoint has no cache.

Config / customizer (rule 8)

The meshguide link URL and the roles checked are hard-coded constants, marked for #1035 M4, where the plan puts the customizer and config.

Tests

  • cd cmd/server && go test ./... passes; internal/scopeguide passes.
  • sh test-all.sh passes: 415/415.
  • node test-frontend-helpers.js passes: 746/746.
  • node test-1035-node-scope-check.js passes: 20/20.
  • test-issue-1035-m2-node-scope-check-e2e.js passes: 10/10 locally.
  • node scripts/run-go-server-shard.js --validate and node scripts/run-e2e-shard.js --validate both pass.
  • scripts/check-xss-sinks.sh --diff origin/master is clean.
  • .github/ is unchanged.

🤖 Generated with Claude Code

dborup and others added 2 commits December 3, 2026 04:35
…1035 M2)

GET /api/nodes/{pubkey}/scope-check sets a repeater's or room's own
scopes next to what meshguide.dk recommends for its advertised position,
through M1's engine (internal/scopeguide Recommend + Compare, unchanged):
one typed node-row read by primary key, one DAGI point lookup on the
in-memory index, a named response struct. 404 for unknown, hidden or
blacklisted nodes and while dagi.enabled is off.

The full node page shows it as "Recommended scopes here (meshguide.dk)"
(public/node-scope-check.js, textContent only): the recommended chips,
the node's default scope ("cannot be decoded" for an unnamed one) and the
observer-reported list in neutral wording, a meshguide.dk link, nothing for
companions or nodes without a position. ?section=node-scope-check deep
links to it. The page renders twice on a cold load, so the module reuses
the last answer for a minute: one request per node view.

Relates to #1035

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… M2)

CI's frontend lint (eslint no-undef, Kpa-clawbot#1342) rejects the bare global in the
node page template; the wiring test now pins the window. form.

Relates to #1035

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adminopenclaw8-sketch

Copy link
Copy Markdown
Collaborator Author

Rapport — CS-Macmini PR#1106 #1035 — head 1cd1db6

Status: #1035 M2 implemented as a draft. Every requirement has a red-before-green test, 29/29 mutants are killed, and all CI jobs are green on head 1cd1db6a.

Evidence tags: [T] = verified by a test or run, [A] = analysis from reading the code, [K] = known limitation or not verified.

Requirements

# Requirement Test (red → green) Mutants (all killed)
1 Endpoint GET /api/nodes/{pk}/scope-check uses M1's Recommend + Compare (no copy) and returns a named struct TestScopeCheckFyn (Odense: 5000, dk-fyn-odense, dk-fyn, dk5, dk5000, dk recommended, list listed/not-meshguide dk-kb, listReportedAt, source). Red: the package did not compile before the handler [T] G3 Postnummer→Kommune layer, G7 listReportedAt dropped [T]
2 Sjælland gets postal scopes TestScopeCheckSjaelland (Roskilde: 4000, dk-sjl, dk4000, default in_list, no report) [T] G4 list always "reported" [T]
3 Aarhus: region scopes + dk, no postal TestScopeCheckAarhusNoPostalAndUndecodedDefault [T] G2 undecoded never set [T]
4 Copenhagen K group TestScopeCheckCopenhagenKGroup (55.6805, 12.5860 → group 1050 "København K"). It was red first with 55.6761, 12.5683, which lies in 1550 V [T] G3 [T]
5 Bornholm TestScopeCheckBornholm (dk-bhm, 37xx, no postal; an empty reported list is still a report) [T] G4 [T]
6 No position / companion → nothing TestScopeCheckNotApplicable (NULL position, 0,0, companion → role, Malmö → outside) [T] G1 position never set, G10 0,0 counted as a position [T]
7 Default/list times, room TestScopeCheckRoomAndConfirmedDefault [T] G8 defaultConfirmedAt dropped [T]
8 Hidden / blacklisted / bad key → 404/400, upper-case key TestScopeCheckRejectsAndHides [T] G5 name-hide dropped, G9 no lower-casing, G11 blacklist dropped [T]
9 Gated by dagi.enabled TestScopeCheckGatedByDagi [T] G6 gate bypassed [T]
10 Works on a pre-#899 schema TestScopeCheckPreScopeSchema [T] — (the guard is covered by G4)
11 No new map[string]interface{} outside tests TestScopeCheckNoInterfaceMaps. Red against the first draft, which took GetNodeByPubkey's map; it now uses a typed row read [T] —
12 Cheap, cached data only TestScopeCheckComputeBudget: 2.9 µs per call, budget 1 ms; plus BenchmarkNodeScopeCheck [T] —
13 Rendering: chips, neutral wording, "cannot be decoded", postal note, empty/* list, link, nothing when not applicable test-1035-node-scope-check.js, 20 cases. Red: 2/20 pass without the module, 20/20 with it [T] J1 companion applies, J2 "cannot be decoded" text, J3 postal note, J8 status text swap, J11 0,0 as position, J13 not-meshguide line, J14 * note [T]
14 XSS: textContent only, https link only XSS case in the unit test; scripts/check-xss-sinks.sh --diff origin/master is clean [T] J5 non-https href, J12 innerHTML [T]
15 One request per view; stale answer dropped; deep link Unit tests: reuse, 60 s expiry, failed request not kept, late answer for another node, scroll [T] J4 no reuse, J6 stale guard, J7 no scroll, J9 failure kept, J10 never expires [T]
16 E2E at desktop and 375×560, light and dark test-issue-1035-m2-node-scope-check-e2e.js, 10 cases: Odense/Aarhus content, companion/no-position/Malmö give no card, one request per view, deep link, inside the screen, no sideways scroll, theme colours. 10/10 locally and in CI shard 2 [T] E1 phone single-column removed, E2 nodes.js mount broken, E3 note colour not --text-muted, E4 chips no-wrap/overflow [T]
17 CSS variables only Unit test scans the .scope-check rules and the module for colours [T] E3 [T]

Commands run locally [T]

  • cd cmd/server && go test ./...: ok (135 s).
  • internal/scopeguide: ok.
  • node test-frontend-helpers.js: 746/0.
  • sh test-all.sh: 415/415.
  • node scripts/run-go-server-shard.js --validate: ok.
  • node scripts/run-e2e-shard.js --validate: ok, 324 suites.
  • The new suite was added to shard 2, the lightest by the sum of meanSeconds.
  • test-issue-1055-m2-live-dagi-e2e.js was re-run (14/14) because its harness gained an optional seed argument.
  • ESLint (npx eslint public/*.js): 0 errors.

CI per job, head 1cd1db6a [T]

Job Result
Go Build & Test pass
Go Ingestor pass
Go Libraries & CLI pass
Go Server 1/3, 2/3, 3/3 pass
JavaScript Unit Tests & Lint pass
Script & Container Unit Checks pass
Validate Docker Image pass
Playwright E2E 1/3, 2/3, 3/3 pass (the new suite ran 10/10 in shard 2)
Verify E2E Shards & Coverage pass
Verify Go Test Assignments pass
Build & Publish Docker Image pass

First head 517391da:

Invariants

  • cmd/server stays read-only: the new code is one SELECT by primary key [A]. readonly_invariant_test.go passes [T].
  • No new map[string]interface{} outside tests [T].
  • .github/ is unchanged against master, so the fork guards are untouched [T]. A grep for the github.repository == 'Kpa-clawbot/CoreScope' guard gives 8 in deploy.yml and 1 in release-fast-path.yml, identical to master. The brief's 9 likely counts a different pattern [K].
  • cmd/server/go.mod and the Dockerfile now require and copy internal/scopeguide (Validate Docker Image passes) [T].

Choices made without asking

  • A new endpoint instead of new keys on the node-detail map (M0 §6) [A].
  • The postnummer comes from the DAGI index lookup on the row's own position: the same land-clipped index the membership snapshot uses, and fresher than the snapshot [A].
  • The card sits at the end of the node page, so the async fill does not shift anything above it [A].
  • The node page renders twice on a cold load. This is existing behaviour; clock-skew is also fetched twice. The module therefore reuses one answer for 60 s instead of changing nodes.js rendering [T].

Remaining

  • The DAGI credit is not shown in the card: DagiFilter.creditElement() returns null on the node page because its config is not loaded there. The module appends the credit when one is available [K]. Follow-up candidate for M3/M4.
  • The node's default scope still comes from the nodes.default_scope column, with no advert time. M0 §1 proposed reading the newest in-memory advert. M1 did not add that accessor, and M2 does not add it either [K].
  • The meshguide link URL and the role set are hard-coded, marked for the customizer and config in M4 (rule 8) [A].
  • The app was not checked against staging or prod, which the brief forbids. The browser check was local only: E2E screenshots at 1280×900 and 375×560, light and dark [T].

@dborup

dborup commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Review — CS-Minimax PR#1106 — head 1cd1db6

Dom: REQUEST CHANGES

An independent, read-only review of #1035 M2 against the M0 plan and the owner decisions of 2026-12-02. The wiring, API shape, layout, XSS handling and tests are solid. One owner decision (9, "cannot be decoded") is not met on real data, and the branch now conflicts with master.

Evidence tags: [T] = verified by a test or run, [A] = analysis from reading the code, [K] = known limitation or not verified.

Findings

# Severity Finding Evidence
F1 Must fix "Cannot be decoded" can never occur on real data, and nodes in that state are described wrongly. The handler treats nodes.default_scope = '' as "scoped, name cannot be decoded" (node_scope_check.go:122). The ingestor never writes '' to that column. Inference writes only when ScopeName != "" (shouldUpdateDefaultScope, cmd/ingestor/main.go:2095). UpdateNodeDefaultScope returns early on "". The confirmed path also drops a blank scope. Both are pinned as Kpa-clawbot#1534 regressions (main_test.go:1142, db_test.go:2944). The "scoped, unknown name" state lives in transmissions.scope_name = '' (scopeNameForDB, cmd/ingestor/db.go:2163), not in the node row. As a result: (a) owner decision 9 is unreachable on real data; only the hand-written '' in the Go seed and seed-1035-scope-check-nodes.sql reach it. (b) A repeater whose adverts carry a scope this instance cannot name shows either "no scoped flood advert seen", which is false, or an older decoded scope, which is stale. (c) A firmware-confirmed * ("no default region set") also shows "no scoped flood advert seen". [A] code paths cited; [T] the Kpa-clawbot#1534 tests exist and pass; [T] the e2e fixture has no default_scope column before migration, so nothing real seeds ''
F2 Must fix (mechanical) The branch conflicts with current master in scripts/e2e-shards.json: #1094 (984e99ea) appended test-issue-1023-m2-hidden-hops-e2e.js at the same place. GitHub reports mergeable: CONFLICTING. The fix is trivial: keep both entries. The green CI run is against the old base, so CI must run again after the rebase. [T] git merge-tree, gh pr view
F3 Should fix The DAGI credit depends on how the user reached the page. After a cold start → More → Nodes → tap a row, the card ends with the DAGI credit ("Indeholder data fra Klimadatastyrelsen, DAGI … CC BY 4.0"), because the Nodes list has loaded the DagiFilter config. On a cold deep link (#/nodes/{pk}?section=node-scope-check) the same card has no credit. The card always shows a DAGI-derived postnummer name ("8000 Aarhus C"), and M0 §5 asks for the credit wherever DAGI data shows. The PR's [K] says the credit is never there on the node page. In fact it is there on one route and missing on the other. [T] phone walkthrough (credit present), desktop deep link (credit absent, light and dark)
F4 Nit Two of my mutants survive: unanchoring the https check (/https:\/\//) and showing defaultConfirmedAt when the status is none. Both are test gaps. The link URL is a server constant today, so R3 is not exploitable now. [T] mutants R3, R4
F5 Nit The comment on nodeScopeRow still says "cast at the boundary from GetNodeByPubkey's map". It now reads a typed row. [A]
F6 Nit The undecoded line reads "cannot be decoded the scope name cannot be decoded on this instance": the chip and the sentence repeat each other. This is moot if F1 changes the wording. [T] screenshot
F7 Nit On an instance with dagi.enabled off, every repeater or room view still makes one /scope-check request that returns 404. This is harmless but avoidable from the client config. [A]

Suggested fix for F1 (read-only, cheap): take the node's default from its newest flood advert in transmissions (from_pubkey = ? AND payload_type = 4, flood route types, ORDER BY first_seen DESC LIMIT 1, served by idx_transmissions_from_pubkey), or from the in-memory store. scope_name NULL then means unscoped, '' means "cannot be decoded", and #x means x. This is the accessor M0 §1 asked for, and it also gives the advert time. If that is out of scope for M2, at least stop mapping '' to "undecoded" and word the NULL case honestly: "No default scope known: no advert with a scope this instance can name". In either case, the "undecoded" test should use a state the ingestor actually produces.

Note: M3 (#1107) builds on this helper (nodeScopeVerdict), so its defaultUndecoded count has the same problem. I built M3, and it will take the M2 fix.

Answers to the review points

  • M0 plan / owner decisions:
    • Info only, never "wrong": the wording is neutral throughout, with no status colours [T].
    • Postal scopes only on Fyn and Sjælland: Odense, Nyborg (with meshguide's dk42/dk53 water neighbours), Marstal, Svendborg, Langeland, Bogense, Sejerø and Møn get postal scopes. Aarhus, Copenhagen K/S, Frederiksberg, Bornholm, Læsø, Samsø, Anholt, Fanø, Padborg and Kruså get region scopes + dk only, with the note [T].
    • Repeaters and rooms only [T].
    • Unknown names "cannot be decoded": not met on real data (F1).
    • meshguide link: https, pinned commit shown [T].
  • One server-side helper: M2 has one helper. M3 (feat(analytics): a Location view in Scope Audit, info only (#1035 M3) #1107) refactors it into nodeScopeVerdict + nodeScopeSelect and uses it for both endpoints, with no copy of M1's engine [A, diff 1cd1db6a..1235ed81].
  • Borders and islands: probed 30 positions through buildNodeScopeCheck with the real DAGI index [T].
    • Correct: Flensburg and Helsingborg give outside; Padborg and Kruså give dk-sdk; Christiansø gives 3760 Gudhjem with se12/oresund and no dk-bhm, which follows meshguide's polygons.
    • Points just offshore (a harbour or pier, a GPS fix in the water, the Storebælt bridge) give outside, so the card silently does not show. This follows from the land-clipped index that M0 accepted [K].
  • No position, 0,0 and companions: no card and no request, or a hidden card for Malmö [T, unit + E2E].
  • API shape:
    • Named structs, with the Verdict embedded. No new map[string]interface{} outside tests [T].
    • Read-only: one SELECT by primary key [A]; readonly_invariant_test passes [T].
    • Hidden and blacklisted handling matches the node-detail endpoint [A].
    • Not cached server-side by design (≈3 µs + one PK read); the client reuses one answer for 60 s [A/T].
  • 375×560, 360×640 and desktop, light and dark:
    • Starting cold from Home, with real taps: I know what I'm doing → More → Nodes → search → tap the row → the full page.
    • Real touch swipes in the page area reach the card in 4–5 swipes. Inside the screen; no sideways scroll; no chip overflow; a single column; the meshguide link is not covered by the bottom nav after scrolling and opens a new tab; one /scope-check request per view [T].
    • No step is impossible. One pre-existing behaviour: a swipe that starts on the node map pans the map instead of the page.
    • Desktop 1280×900, dark: layout fine; the ?section= deep link scrolls to the card [T].
  • XSS: textContent only. check-xss-sinks.sh --diff is clean on the merged tree [T]. See F4 for the regex anchoring.
  • Fork guards: .github/ is unchanged; 9 in deploy.yml and 1 in release-fast-path.yml, the same as master. The report's count of "8" is off by one and harmless [T].
  • Housekeeping: no closing keywords; both commits by dborup <kontakt@meshview.dk>; no hardcoded colours [T].

Tests and mutants

These ran on the merged tree (origin/master 984e99ea + head, with the shards conflict resolved by keeping both entries) [T]:

My own mutants [T]:

Mutant Result
R1: client reuse cache ignores the pubkey (node B would get node A's answer) killed (unit)
R2: applies() drops rooms killed (unit)
R3: https check unanchored survived (F4)
R4: defaultConfirmedAt also set for status none survived (F4)
R5: listReportedAt set unconditionally survived; equivalent (configured_scope_at is NULL without a list)
R6: TrimSpace dropped in the undecoded test survived; equivalent (the ingestor never writes whitespace, and by F1 never '')

Not verified

  • Behaviour on real instance data, because staging and prod access were out of scope. F1 is shown from code and the ingestor's own regression tests, not from a live row [K].
  • The CI rerun after the rebase [K].
  • Red-before for the Go handler tests beyond "the package does not compile without the handler" [A].
  • iOS Safari itself: the phone runs used Chromium with touch emulation [K].
  • meshguide.dk itself: the popup was blocked in my runs; only the URL was checked [K].

dborup and others added 2 commits December 3, 2026 07:21
scripts/e2e-shards.json: keep both sides (#1094's
test-issue-1023-m2-hidden-hops-e2e.js and this branch's
test-issue-1035-m2-node-scope-check-e2e.js).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n a cold deep link (#1035 M2)

Review fix round for #1106 (CS-Minimax, head 1cd1db6).

F1: the ingestor never writes '' to nodes.default_scope
(shouldUpdateDefaultScope / UpdateNodeDefaultScope skip it, Kpa-clawbot#1534); an
undecodable scope lives in transmissions.scope_name ''. The check now
takes the default from, strongest first: the firmware's own report
(default_scope_confirmed_at, "*" = none), the node's newest flood advert
(route 0/1, payload 4, by ingest id; NULL = unscoped, '' = cannot be
decoded), nodes.default_scope (inferred from an older named advert), or
nothing. One probe of idx_transmissions_from_pubkey ("+" keeps the
planner off the payload_type index; pinned by a plan test). The response
gains defaultSource and defaultAdvertAt. An ingestor test pins the row
shape for a real undecodable transport-flood advert; the Go and E2E seeds
use that shape with default_scope NULL.

F3: the card waits for DagiFilter.enabled() (one config fetch per page
session), so a cold deep link shows the DAGI credit too; F7: DAGI off
makes no /scope-check request.
F4: unit tests kill R3 (unanchored https check) and R4 (confirmation time
outside the node's own report).
F5: nodeScopeRow comment. F6: "cannot be decoded" is said once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants