test(server): unit-test event-log ring buffer (#273 follow-up) #286

Merged
charles merged 1 commit from test/s11-event-log into main 2026-04-23 23:08:15 +00:00
Collaborator

PR #273 s11 extraction follow-up. Covers event-log.ts — the 50-entry in-memory ring buffer of TaskRecords.

Coverage (9 tests)

  • push + retrieve roundtrip (create + find same live object, idempotent getOrCreateRecord, pushEvent insertion order)
  • getTaskHistory ordering (newest-first via unshift) + returns live mutable buffer
  • Empty-buffer state (unknown-id lookup returns undefined; pushEvent on unknown id is a no-op)
  • 50-entry ring eviction (51st insert caps the buffer; findTaskRecord returns undefined after eviction)

Behaviour surprises worth knowing

  1. getOrCreateRecord is idempotent on id, not on content — second call ignores the supplied TaskRequest. Silent footgun for callers that change fields between enqueue + re-dispatch. Test pins this invariant.
  2. getTaskHistory() returns the live internal array, not a snapshot — mutations on subsequent inserts are visible through a previously-held reference. Registry lifecycle hooks rely on this.
  3. pushEvent silently drops events for unknown task ids (no throw, no log) but still fires broadcastSSE. An SSE subscriber can observe events for tasks with no record.
  4. No exported buffer-size constantMAX_TASK_HISTORY = 50 is module-private. MAX_EVENTS_PER_TASK = 500 IS exported but bounds per-task events, not the ring size. Test hard-codes 50 + documents the source.

Checks

  • bunx tsc --noEmit -p apps/server/tsconfig.json — EXIT=0
  • bun test apps/server/src/infrastructure/event-log.test.ts — 9/9 pass
  • Full suite: +9 passes, no regressions
PR #273 s11 extraction follow-up. Covers `event-log.ts` — the 50-entry in-memory ring buffer of `TaskRecord`s. ## Coverage (9 tests) - `push + retrieve` roundtrip (create + find same live object, idempotent `getOrCreateRecord`, `pushEvent` insertion order) - `getTaskHistory` ordering (newest-first via `unshift`) + returns live mutable buffer - Empty-buffer state (unknown-id lookup returns `undefined`; `pushEvent` on unknown id is a no-op) - 50-entry ring eviction (51st insert caps the buffer; `findTaskRecord` returns `undefined` after eviction) ## Behaviour surprises worth knowing 1. **`getOrCreateRecord` is idempotent on id, not on content** — second call ignores the supplied `TaskRequest`. Silent footgun for callers that change fields between enqueue + re-dispatch. Test pins this invariant. 2. **`getTaskHistory()` returns the live internal array**, not a snapshot — mutations on subsequent inserts are visible through a previously-held reference. Registry lifecycle hooks rely on this. 3. **`pushEvent` silently drops events for unknown task ids** (no throw, no log) but **still fires `broadcastSSE`**. An SSE subscriber can observe events for tasks with no record. 4. **No exported buffer-size constant** — `MAX_TASK_HISTORY = 50` is module-private. `MAX_EVENTS_PER_TASK = 500` IS exported but bounds per-task events, not the ring size. Test hard-codes 50 + documents the source. ## Checks - `bunx tsc --noEmit -p apps/server/tsconfig.json` — EXIT=0 - `bun test apps/server/src/infrastructure/event-log.test.ts` — 9/9 pass - Full suite: +9 passes, no regressions
test(server): unit-test event-log ring buffer (#273 follow-up)
All checks were successful
qa / qa (pull_request) Successful in 4m39s
qa / dockerfile (pull_request) Successful in 8s
4228d40fef
Add focused unit tests for apps/server/src/infrastructure/event-log.ts,
extracted from main.ts during S11 without dedicated coverage. Nine tests
cover the push/retrieve roundtrip, newest-first unshift ordering, empty-
buffer behaviour, and the 50-entry ring eviction (51st insert pops the
oldest, findTaskRecord returns undefined after eviction).

Uses Bun's test runner with no mock.module — each file runs in its own
process so the module-level taskHistory starts empty, and broadcastSSE
with zero subscribers is a harmless no-op.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
charles deleted branch test/s11-event-log 2026-04-23 23:08:16 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/claude-hooks!286
No description provided.