Audit-First Tests for Realtime Trading Alerts

Resumen

Pixel shares an audit-first approach to testing realtime trading watchlists and notification preferences. The announcement explains how token identity, workspace access, notification scopes, and preference revisions should be verified in one deterministic transaction, with browser tests reserved for transport wiring.

DEV Community

Realtime Trading Watchlists: Audit Trails for Notification Preference Verification

Short answer: test the authorization decision and its audit record as one deterministic transaction, then use browser tests only to verify transport wiring. In an e-commerce-style shared workspace for a stock trading desk, “online” says who currently holds a permitted connection; it does not grant access to somebody else’s watchlist or notification settings. A logical event trace makes that distinction reproducible when CI timing is noisy. Start with an evidence contract, not a socket The useful artifact is an append-only decision record. For every presence transition or alert attempt, record the token subject, workspace, connection identifier, requested scope, symbol, preference revision, and outcome. This is the same discipline I apply to a payment ledger: a counter is a hint, while a record that can be reconciled is evidence. The client can send a workspace name and a symbol, but those values are claims. The server derives the principal from a signed token and checks the token's workspace and scopes. Give a trader presence:read for desk-7; grant watchlist:notify separately. A second tab may be online in that workspace while still being denied an alert. That is a policy result, not a network race. One sentence is enough. Keep the record schema boring and stable. A revision is incremented whenever a symbol preference changes, and the revision travels with the alert event. A consumer can then reject an old event after reconnect without comparing wall-clock timestamps or guessing which callback arrived first. What does an audit-first test prove about realtime notification preferences? It proves four facts independently: the connection belongs to the token subject, the subject is in the requested workspace, the token has the notification scope, and the event uses the currently authorized preference revision. Presence and delivery therefore have separate assertions. This is important for a shared stock trading watchlist, where exposing membership can be acceptable while exposing a private symbol alert is not. The pure model below is intentionally transport-neutral. WebSocket and WebRTC adapters can call it after parsing an event; the model itself has no sleeps, goroutines, or browser state. Its small surface also makes a failed property test readable. package watchlist

import "testing"

type Token struct {
Subject string
Workspace string
Scopes map[string]bool
}

type Preference struct {
Enabled bool
Revision uint64
}

type Decision struct {
Subject string
Workspace string
Symbol string
Revision uint64
Allowed bool
}

type Desk struct {
preferences map[string]Preference
presence map[string]string
decisions []Decision
}

func NewDesk() *Desk {
return &Desk{
preferences: map[string]Preference{},
presence: map[string]string{},
}
}

func (d *Desk) SetPreference(symbol string, enabled bool) uint64 {
p := d.preferences[symbol]
p.Enabled = enabled
p.Revision++
d.preferences[symbol] = p
return p.Revision
}

func (d *Desk) Connect(t Token, connectionID string) bool {
allowed := t.Workspace == "desk-7" && t.Scopes["presence:read"]
if allowed {
d.presence[t.Subject] = connectionID
}
d.decisions = append(d.decisions, Decision{Subject: t.Subject, Workspace: t.Workspace, Allowed: allowed})
return allowed
}

func (d *Desk) AuthorizeAlert(t Token, symbol string) bool {
p, exists := d.preferences[symbol]
allowed := t.Workspace == "desk-7" && t.Scopes["watchlist:notify"] && exists && p.Enabled
d.decisions = append(d.decisions, Decision{Subject: t.Subject, Workspace: t.Workspace, Symbol: symbol, Revision: p.Revision, Allowed: allowed})
return allowed
}

func TestPresenceDoesNotImplyAlertAccess(t testing.T) {
d := NewDesk()
d.SetPreference("ACME", true)
observer := Token{Subject: "u2", Workspace: "desk-7", Scopes: map[string]bool{"presence:read": true}}
if !d.Connect(o...
Audit-First Tests for Realtime Trading Alerts
Powered by Readybot.io*

Lo último de Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …