Mock notify service
The in-memory notify fixture: its endpoints, the signature and time checks it enforces, scenarios and control endpoints.

The mock notify service stands in for the hosted notify service in tests. It verifies the same signed CBOR requests the app sends, keeps a per account inbox in memory, and sends no email and makes no remote writes.

File and mounting

One file: tools/mock-notify/routes.ts. It exports handle(req), which returns a Response, a promise of one, or null when the path is not its own. The local test server mounts it on 127.0.0.1:4790; everything lives under /activity/. Bun tests call handle in process or serve it on port 0.

Endpoints

Method and path

Purpose

GET /activity/hm/api/config

{registeredAccountUid, notifyServiceUrl} where notifyServiceUrl is <origin>/activity/hm/api/notify. The test server also answers /hm/api/config with this

POST /activity/hm/api/notify/notifications

The signed request endpoint, see below

POST /activity/reset

Body {"now": <ms>, "scenario": "<name>"}. Clears all inboxes and the POST counter, sets the mock clock (null means real time) and the scenario (default inbox)

POST /activity/time

Body {"now": <ms>}. Moves the mock clock so signed times stay inside the window after a test's clock +<ms>

POST /activity/posts

Body {"min": a, "max": b, "reset": true}. Answers {"posts": n} with 200 when a <= n <= b, else 409. reset zeroes the counter after reading it

POST /activity/verify

Marks every configured email verified, as if the person clicked the link

other /activity/*

404 {"error": "Not found"}

What a signed request must satisfy

request(req) (routes.ts L58-L123) decodes the CBOR body and checks, in order:

Check

Failure

Body is CBOR

400 Invalid CBOR

Only the fields action, limit, signer, time (plus actions for a mutation) besides sig

400 Unknown signed fields

signer is a 34 byte principal starting 0xed 0x01

400 Expected Ed25519 principal

time is finite and within 20000 ms of the mock clock, either side

401 Request time outside 20 second window

sig verifies over the CBOR of the map without sig

401 Invalid signature

limit is 400

400 Expected limit 400

action is get-notification-state or apply-notification-actions

400 Unknown action

The signature convention differs from the agents protocol, which signs with a zero filled sig field. A Bun test sends an agents style signature and expects 401 (activity.test.ts L112-L130); it also checks that exactly 20000 ms passes and 20001 ms fails. See Crypto: signed envelopes.

Mutations handled: mark-event-read, mark-all-read, set-config (email is trimmed and lower cased; a new address resets verification), resend-config-verification (only when expired), remove-config. Anything else is 400 Unknown mutation. Every successful request returns the full snapshot.

Initial inbox

The first request from an account creates its state (routes.ts L15-L56): three NewDocument events on the hyper.media home account, today (1 hour ago, Ana, reply), earlier (2 hours ago, Ben, mention) and yesterday (24 hours ago, Mina, site-doc-update), with earlier already read. That is why tests expect "2 unread".

Scenarios

Set through /activity/reset:

Scenario

Effect

inbox (default)

The three events, no email

empty

No notifications

pending

Email reader@example.com, verification sent

expired

Same, with verificationExpired: true

verified

Same, with verifiedTime set

failure

Every signed request answers 503 Notification service is temporarily unavailable.

wrong-account

The snapshot's accountId is another-account, which the client must refuse

thread

The today event carries commentId: fixture-root, and three extra routes exist on the fixture origin only: GET /api/Resource?id=hm://<site>/fixture-root (a comment "Configured server thread"), GET /api/Resource?id=hm://<site>/fixture-target (a document), and POST /api/PublishBlobs, which answers 409 Reply received by local fixture. "Never forward a publish."

The POST counter

posts counts signed POSTs since the last reset. The Contract test "a minute on the inbox signs one request" uses /activity/posts with {"min":1,"max":1} and {"max":0} to bound how often the app signs: one refresh per minute on the tab, none while another tab is shown (activity.test.contract L224-L277).

Who uses it

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime