Files
2026-05-27 23:29:53 +01:00

4.5 KiB
Raw Permalink Blame History

Tasks — @suaveplan/api-ws-bun

Every checkbox MUST reflect work actually done in this change.

0. Pre-flight (non-negotiable)

  • 0.1 Confirm clean working tree (git status reports nothing) and no in-flight worktrees with uncommitted work (git worktree list then git status in 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.md matches find packages -maxdepth 3 -name package.json count. Drift here means a prior change archived without regenerating the manifest.

1. Spec authoring

  • 1.1 Read design doc §11 end-to-end
  • 1.2 Read umbrella Stage 7 acceptance
  • 1.3 Read design doc §14 open questions (reconnect event-buffer storage)
  • 1.4 Read openspec/AGENTS.md Sections 13 and 14
  • 1.5 Draft proposal.md
  • 1.6 Draft specs/api-ws-bun/spec.md
  • 1.7 Every requirement carries a **Verified by:** line

2. Implementation

  • 2.1 Scaffold packages/api/api-ws-bun/
  • 2.2 src/options/options.ts — BunWsEngineOptions Zod schema
  • 2.3 src/engine/bun-ws-engine.ts — createBunWsEngine(opts)
  • 2.4 src/handshake/handshake.ts — pipeline steps 1–7 wiring; principal freezing
  • 2.5 src/registry/connection-registry.ts — tenant-indexed registry; cross-tenant fan-out gate
  • 2.6 src/backpressure/backpressure.ts — maxQueuedMessages enforcement; BACKPRESSURE_EVICTED close frame
  • 2.7 src/heartbeat/heartbeat.ts — ping/pong schedule; missed-pong-limit drop
  • 2.8 src/limits/tenant-cap.ts — maxConnectionsPerTenant enforcement at handshake
  • 2.9 src/reconnect/reconnect-token.ts — HMAC token issue/validate via @suaveplan/crypto-hash
  • 2.10 src/reconnect/event-buffer.ts — strategy "auto" resolves to broker-backed when wired, in-memory otherwise
  • 2.11 src/subscription/subscription-bus.ts — conn.subscribe(topic, { tenant?, filter? }) + bus.broadcast fan-out
  • 2.12 src/principal/principal-expiry.ts — emit connection.principal_expired on mid-connection token expiry
  • 2.13 src/instruments/instruments.ts — every OTel instrument from §11.7
  • 2.14 src/error-codes.ts — 10 WS_BUN_* codes
  • 2.15 ./testing subpath — re-export runWsEngineConformance bound to factory
  • 2.16 src/index.ts — explicit named re-exports

3. Tests

  • 3.1 Unit tests, every it(...) { timeout: 5000 }
  • 3.2 Conformance test runs runWsEngineConformance
  • 3.3 Heartbeat test uses FakeClock ({ timeout: 5000 })
  • 3.4 Reconnect-token test pins issue + validate + expiry + replay-rejection
  • 3.5 Event-buffer strategy test pins broker-when-Redis / memory-otherwise default
  • 3.6 End-to-end test against real Bun.serve ({ timeout: 30000 })
  • 3.7 All tests import from @suaveplan/testing/runner

4. Documentation

  • 4.1 Sibling .md per implementation file
  • 4.2 README.md with ## Modules; document defaults table (maxQueuedMessages, heartbeatMs, missedPongLimit, reconnectTokenTtlMs, reconnectEventBufferStrategy)

5. Pre-archive verification

  • 5.1 bun run check — 0/0/0
  • 5.2 bunx turbo lint typecheck test --filter=@suaveplan/api-ws-bun — green
  • 5.3 bunx turbo test:coverage --filter=@suaveplan/api-ws-bun — 100/100/100/100
  • 5.4 bun scripts/openspec-conformance.ts @suaveplan/api-ws-bun — exit 0
  • 5.5 bunx turbo build --filter=@suaveplan/api-ws-bun — green

6. Pre-archive 7-row checklist

  • 6.1 Generics on Connection<TPrincipal>; expectTypeOf on literal-type claims
  • 6.2 Zod schemas at every config boundary; reconnect-token payload schema'd
  • 6.3 Every WS_BUN_* code thrown by a production path
  • 6.4 Strict-mode tested (heartbeat on vs off; cross-tenant fan-out capability gate on vs off)
  • 6.5 OTel instruments asserted against in-memory MeterProvider
  • 6.6 Lifecycle dedup: re-onConnect after reconnect-resume does not re-mint state — uses resumed subscription set
  • 6.7 No retroactive tick

7. Archive

  • 7.1 Fold spec delta into openspec/specs/api-ws-bun/spec.md
  • 7.2 Move to openspec/archive/<yyyy-mm-dd>-api-ws-bun/
  • 7.3 Tick Stage-7 row in umbrella tasks
  • 7.4 Refresh MANIFEST.md