Decompose architecture into atomic, dependency-ordered tasks
19 tasks covering core testing, Redis hardening, WebSocket client/server adapters, Worker adapter, and final review gates. Iroh adapters are tracked as a deferred placeholder blocked on the @alkdev/iroh fork. Phases: core validation → Redis hardening → review gate → WebSocket adapters → review gate → Worker adapter → review gate → final validation.
This commit is contained in:
55
tasks/009-websocket-server-tests.md
Normal file
55
tasks/009-websocket-server-tests.md
Normal file
@@ -0,0 +1,55 @@
|
||||
---
|
||||
id: websocket-server-tests
|
||||
name: Write tests for WebSocket server event target adapter
|
||||
status: pending
|
||||
depends_on: [websocket-server-adapter, websocket-client-tests]
|
||||
scope: moderate
|
||||
risk: medium
|
||||
impact: component
|
||||
level: implementation
|
||||
---
|
||||
|
||||
## Description
|
||||
|
||||
Write tests for `createWebSocketServerEventTarget`. This requires mocking multiple WebSocket connections and simulating the fan-out behavior.
|
||||
|
||||
Test scenarios from the architecture doc:
|
||||
1. Topic-based fan-out — dispatchEvent sends only to connections subscribed to that event type
|
||||
2. Subscription protocol — `__subscribe`/`__unsubscribe` control events correctly update the subscription map
|
||||
3. Incoming aggregation — messages from any spoke dispatch to local listeners
|
||||
4. Connection add/remove — new connections are tracked, disconnections clean up all subscriptions
|
||||
5. Backpressure disconnect — slow consumers exceeding threshold are disconnected
|
||||
6. Backpressure callback — `onBackpressure` is called before disconnecting
|
||||
7. Direct messaging — events dispatched to `"direct:${spokeId}"` reach only the target spoke
|
||||
8. Mixed topology — server adapter and client adapters can communicate bidirectionally
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] `test/event-target-websocket-server.test.ts` exists and passes
|
||||
- [ ] Mock strategy for multiple WebSocket connections established
|
||||
- [ ] Test: `addConnection`/`removeConnection` track connections correctly
|
||||
- [ ] Test: `__subscribe` control event adds connection to topic's subscriber set
|
||||
- [ ] Test: `__unsubscribe` control event removes connection from topic's subscriber set
|
||||
- [ ] Test: `dispatchEvent` sends only to connections subscribed to that topic
|
||||
- [ ] Test: connections NOT subscribed to a topic do NOT receive events for that topic
|
||||
- [ ] Test: malformed JSON from spokes is silently ignored
|
||||
- [ ] Test: invalid `__subscribe` with empty/malformed topic is ignored
|
||||
- [ ] Test: backpressure threshold disconnect — connections exceeding `maxBufferedAmount` are closed with code 1013
|
||||
- [ ] Test: `onBackpressure` callback fires before disconnect
|
||||
- [ ] Test: `onConnection` callback receives spoke target and WebSocket
|
||||
- [ ] Test: `onDisconnection` callback fires on connection close
|
||||
- [ ] Test: `dispatchEvent` always returns `true`
|
||||
- [ ] Test: send failure (ws.send throws) removes connection and fires `onDisconnection`
|
||||
|
||||
## References
|
||||
|
||||
- docs/architecture/event-targets/websocket-server.md (Test Plan section)
|
||||
- src/event-target-websocket-server.ts
|
||||
|
||||
## Notes
|
||||
|
||||
> To be filled by implementation agent
|
||||
|
||||
## Summary
|
||||
|
||||
> To be filled on completion
|
||||
Reference in New Issue
Block a user