5.4 KiB
5.4 KiB
Tasks — @suaveplan/api-sse-bun
Every checkbox MUST reflect work actually done in this change.
0. Pre-flight (non-negotiable)
- 0.1 Confirm clean working tree (
git statusreports nothing) and no in-flight worktrees with uncommitted work (git worktree listthengit statusin each) - 0.2 If any worktrees exist under
.claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against. - 0.3 Confirm the package set in
MANIFEST.mdmatchesfind packages -maxdepth 3 -name package.jsoncount. Drift here means a prior change archived without regenerating the manifest.
1. Spec authoring
- 1.1 Read design doc §11.5, §11.6, §11.7
- 1.2 Read umbrella Stage 7 acceptance
- 1.3 Read sibling
openspec/changes/api-ws-bun/andopenspec/changes/api-ws-broker-redis/for broker integration - 1.4 Read
openspec/AGENTS.mdSections 13 and 14 - 1.5 Draft
proposal.md - 1.6 Draft
specs/api-sse-bun/spec.md - 1.7 Every requirement carries a
**Verified by:**line
2. Implementation
- 2.1 Scaffold
packages/api-stack/api/api-sse-bun/ - 2.2
src/options/options.ts—BunSseEngineOptionsZod schema - 2.3
src/engine/bun-sse-engine.ts—createBunSseEngine(opts) - 2.4
src/stream/sse-stream.ts— SSE framing (id:,event:,data:,retry:,:keepalivecomments) - 2.5
src/handshake/handshake.ts— pipeline steps 1–7 wiring; principal freeze - 2.6
src/last-event-id/last-event-id.ts— parseLast-Event-Idheader; consult event buffer - 2.7
src/event-buffer/event-buffer.ts— in-memory ring buffer; delegate to broker when wired - 2.8
src/keep-alive/keep-alive.ts—keepAliveCommentMsscheduler - 2.9
src/limits/tenant-cap.ts—maxConnectionsPerTenantenforcement - 2.10
src/compression/compression.ts— gzip stream when client accepts; emitContent-Encoding: gzip - 2.11
src/subscription/subscription-bus.ts— registers against the shared subscription bus - 2.12
src/instruments/instruments.ts—sse.*OTel instruments per §11.7 + this package's extensions - 2.13
src/error-codes/error-codes.ts— 10SSE_BUN_*codes - 2.14
./testingsubpath — re-exportrunSseEngineConformancebound to factory - 2.15
src/index.ts— explicit named re-exports
3. Tests
- 3.1 Unit tests, every
it(...){ timeout: 5000 } - 3.2 Conformance test runs
runSseEngineConformance - 3.3 Keep-alive test uses injectable
schedule(FakeClock-style) and asserts cadence - 3.4 Last-Event-Id replay test pins replay-before-live ordering
- 3.5 End-to-end test against real
Bun.serve({ timeout: 30000 }) — gracefully skips under non-Bun runtimes (vitest+node) sinceBun.serveis the only transport; the in-process handshake suite drives the sameReadableStreampath. - 3.6 Multi-host fan-out test against real Redis broker — deferred to
api-ws-broker-rediskeystone (the broker package is the natural owner of the integration); the engine's broker-backed event buffer is unit-tested with a realSseBrokerimplementation in this package. - 3.7 All tests import from
@suaveplan/testing/runner
4. Documentation
- 4.1 Sibling
.mdper implementation file (13/13 = 100%) - 4.2
README.mdwith## Modules; document defaults table and explain SSE's "no client→server channel, no acks" boundary vs WS
5. Pre-archive verification
- 5.1
bun run check— 0/0/0 - 5.2
bunx turbo lint typecheck test --filter=@suaveplan/api-sse-bun— green - 5.3
bunx turbo test:coverage --filter=@suaveplan/api-sse-bun— 100/100/100/100 (306 stmts, 102 branches, 73 funcs, 304 lines) - 5.4
bun scripts/openspec-conformance.ts packages/api-stack/api/api-sse-bun— exit 0 - 5.5
bunx turbo build --filter=@suaveplan/api-sse-bun— green
6. Pre-archive 7-row checklist
- 6.1 Generics on engine surface (
BunSseEngine.activeConnectionsisReadonlyMap<string, ActiveConnection>); literal-type claims pinned viaas constonSSE_BUN_CODES. - 6.2 Zod schemas on options (
resolveOptionsstrict-parses every primitive knob); subscription payloads carry the typedSseEventschema from@suaveplan/api-sse. - 6.3 Every
SSE_BUN_*code thrown by a production path (HANDSHAKE_REJECTED, TENANT_CAP_EXCEEDED, BUFFER_MISS, EVENT_TOO_LARGE, LAST_EVENT_ID_INVALID, COMPRESSION_FAILED, STREAM_INTERRUPTED, PRINCIPAL_EXPIRED, BROKER_UNAVAILABLE, INVALID_TOPIC) — the registry-name-vs-throw audit is part of the conformance run. - 6.4 Strict-mode tested (compression on vs off; broker wired vs in-memory event buffer)
- 6.5 OTel instruments asserted against fake
MeterProvider(src/instruments/instruments.test.ts) - 6.6 Lifecycle dedup: reconnect with same
Last-Event-Iddoes not re-deliver already-delivered events — partially verified (replay test pins replay-before-live ordering); explicit "no double-delivery on reconnect" race is deferred to a later integration suite that owns the multi-host fan-out path. - 6.7 No retroactive tick
7. Archive
- 7.1 Fold spec delta into
openspec/specs/api-sse-bun/spec.md - 7.2 Move to
openspec/archive/<yyyy-mm-dd>-api-sse-bun/ - 7.3 Tick Stage-7 row in umbrella tasks
- 7.4 Refresh
MANIFEST.md