Files
pubsub/tasks/003-redis-adapter-tests.md
glm-5.1 1306716897 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.
2026-05-08 05:50:43 +00:00

50 lines
2.2 KiB
Markdown

---
id: redis-adapter-tests
name: Write tests for Redis event target adapter
status: pending
depends_on: [core-pubsub-tests]
scope: moderate
risk: medium
impact: component
level: implementation
---
## Description
The Redis event target adapter (`event-target-redis.ts`) is implemented but has zero tests. The architecture doc lists 7 specific test scenarios. Tests need a running Redis instance or a mock. Since this is a dev dependency, we can use `ioredis-mock` or start a Redis container in CI. The test strategy needs to handle the Redis dependency.
The architecture specifies these test scenarios:
1. Publish path — dispatchEvent sends to Redis with correct channel and serialized envelope
2. Subscribe path — addEventListener subscribes to Redis, onMessage dispatches to local listeners
3. Unsubscribe — removeEventListener unsubscribes from Redis when no listeners remain for a topic
4. Topic scoping — type:id topics are correctly formed
5. Envelope serialization — full `{ type, id, payload }` round-trips through JSON
6. Multiple listeners — multiple listeners on same topic, single Redis subscribe
7. Error propagation — what happens on connection failure
Note: test 7 (error propagation) is partially blocked by the missing error handling in the current implementation (tracked in task `redis-channel-prefix-and-error-handling`). The test should exist but may need to be adjusted once error handling is added.
## Acceptance Criteria
- [ ] `test/event-target-redis.test.ts` exists and passes
- [ ] Test approach for Redis dependency is decided (mock, container, or ioredis-mock)
- [ ] Test: dispatchEvent publishes correct channel and serialized envelope
- [ ] Test: addEventListener subscribes to Redis and dispatches to local listeners
- [ ] Test: removeEventListener unsubscribes from Redis when no listeners remain
- [ ] Test: type:id topic scoping works correctly
- [ ] Test: EventEnvelope round-trips through JSON serialization
- [ ] Test: multiple listeners on same topic result in single Redis subscribe
- [ ] Test: custom serializer option works
## References
- docs/architecture/event-targets/redis.md
- src/event-target-redis.ts
## Notes
> To be filled by implementation agent
## Summary
> To be filled on completion