feat(admin): add GET /admin/network-health endpoint - #753
Conversation
After each probe run, sign and store NIP-66 relay discovery and monitor announcement events from the monitor identity, bootstrap kind 0/10002 on first run, and persist via the parameterized replaceable event path. Fixes #696
Knex already parses jsonb event_tags as an array; JSON.parse on that value caused CI failures. Assert the d tag via the event_tags table instead.
🦋 Changeset detectedLatest commit: df0a802 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| router.get( | ||
| '/network-health', | ||
| adminRateLimitMiddleware, | ||
| adminAuthMiddleware, |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new controller unit test likely fails in isolation due to missing sinon-chai setup, and the NIP-66 bootstrap logic can skip bootstrapping on monitor key rotation and can choose an invalid target URL for the relay list.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
Adds an authenticated admin endpoint to expose the latest relay-probe snapshot (“network health”), and extends the relay monitor worker to publish/store NIP-66 events after probe runs (including one-time monitor identity bootstrap).
Changes:
- Add
GET /admin/network-health(admin-authenticated + admin rate-limited) returning the latest stored probe snapshot. - Publish NIP-66 kind
30166(relay discovery) and10166(monitor announcement) events after each probe run, including bootstrapping kind0/10002for the monitor identity. - Add unit/integration coverage for NIP-66 event building/publishing and the new admin route/controller.
| File | Description |
|---|---|
| test/unit/utils/nip66-events.spec.ts | Unit tests for NIP-66 event builders and URL normalization. |
| test/unit/routes/admin.spec.ts | Extends admin router tests to cover /network-health protection and middleware counts. |
| test/unit/controllers/admin/get-network-health-controller.spec.ts | Adds unit test coverage for the new controller (currently missing sinon-chai setup). |
| test/unit/app/relay-monitor-worker.spec.ts | Verifies the worker invokes the NIP-66 publisher after saving snapshots. |
| test/integration/features/nip-66/nip-66.feature.ts | Integration step definitions now validate that kind 30166 is persisted for the monitor identity. |
| test/integration/features/nip-66/nip-66.feature | Adds scenario asserting a probe run stores a kind 30166 event. |
| src/utils/nip66-events.ts | Implements NIP-66 event builders and relay URL normalization for d tag usage. |
| src/utils/monitor-identity.ts | Adds cached env-backed monitor private key accessor + reset for tests. |
| src/services/nip66-event-publisher.ts | Implements publishing/signing/upserting NIP-66 events and bootstrap logic. |
| src/routes/admin/index.ts | Registers GET /admin/network-health under existing admin auth + rate limiting. |
| src/factories/relay-monitor-worker-factory.ts | Wires DB + cache-backed NIP-66 publisher into the relay monitor worker. |
| src/factories/controllers/get-admin-network-health-controller-factory.ts | Factory to create the new controller backed by Redis snapshot store. |
| src/controllers/admin/get-network-health-controller.ts | Controller returning { snapshot } as JSON from snapshot store. |
| src/constants/base.ts | Adds event kind constants for NIP-66 kinds 10166 and 30166. |
| src/app/relay-monitor-worker.ts | Publishes NIP-66 events after snapshot save with error isolation. |
| .changeset/nip66-publish-events.md | Changeset entry for NIP-66 event publishing feature. |
| .changeset/admin-network-health-endpoint.md | Changeset entry for the new admin endpoint. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Merging as #764 got approved. |

Description
Adds GET /admin/network-health for authenticated admin clients.
Related Issue
Stacked on #741 and closes #697
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: