-
-
Notifications
You must be signed in to change notification settings - Fork 0
Tests Core
mchristegh edited this page Jul 14, 2026
·
1 revision
test-scripts/core-harness.js — the recording engine (lib/recorder-core.js): ring buffer, commands, incidents, events, and persistence policy (the file adapter itself is tested separately). The largest harness because the core carries the most behavioral contract. Everything time-dependent runs on an injected fake clock with manually-advanced fake timers, so deltas, cooldowns, and debounce are asserted exactly, and a fake in-memory persistence adapter counts every read/write/remove.
| Group | Why it exists |
|---|---|
| C1 — basic capture | The record format contract: monotonic seq, the delta chain (first record null, then exact gaps), source fields including port, and the stats shape. |
| C2 — ring eviction | At capacity the oldest record is evicted, wrapCount counts, and the wrapped event fires exactly once (the agreed throttle) — while seq keeps climbing despite eviction. |
| C3 — pause/resume | Paused captures are rejected and counted (droppedWhilePaused) — nothing invisible; redundant pauses are idempotent and emit no event spam but still report changed: false. |
| C4 — marks | Marks land on the tape in sequence position, work while paused (metadata, not traffic), count toward capacity, and do not reset the capture delta chain — a capture→mark→capture sequence shows the true gap between the real captures. |
| C5 — manual dump | The incident format contract: unique ids, trigger, context carried, stats identical in shape to query()'s, records copied not referenced — and dumping never clears the tape. An empty recording legally yields a zero-record incident ("the box was empty" is evidence). |
| C6 — cooldown | The full semantics: auto triggers suppressed within the window with a visible incidentSuppressed (carrying time remaining), manual dumps always fire and don't reset the clock, and expiry re-enables. |
| C7 — context truncation | An error dump must never produce a multi-MB incident because someone attached a huge message to node.error() — oversized contexts collapse to a flagged preview. |
| C8 — persistence debounce | Write-behind fires on the capture count or the time window, whichever first, with the counter and timer properly reset after each write — asserted against the fake adapter's write counts. |
| C9 — immediate writes | State-changing commands (clear, pause, resume, mark) persist instantly — losing a pause across a crash would misrepresent the recording. |
| C10 — restore round-trip | Close → downtime → reconstruct: records return flagged restored: true, seq continues monotonically, paused state survives, and new records are unflagged. The crash-survival story as a test. |
| C11 — corrupt persist files | Wrong formatVersion, throwing reads, malformed fields: all warn and start fresh — a bad file must never block the recorder's construction. |
| C12 — detach semantics | The redeploy-vs-delete distinction: last detach with removed: false final-writes the file; with removed: true it removes it. Also proves the refcounting (not-last detach does neither). |
| C13 — clear semantics |
clear empties records and resets counters but preserves seqCounter (monotonic forever) and re-arms the wrap event throttle. |
| C14 — write failures | A throwing persistence adapter surfaces an error and recording continues — and, subtly, emitting error with no listener attached must not crash (Node's EventEmitter would otherwise throw). |
| C15 — query & validation | The snapshot shape with its config echo, plus construction rejecting invalid store ids, capacities, and cooldowns, and summary capture mode flowing through to records. |
| C16 — incident meta | Environment metadata attaches to incidents (manual and auto) when injected via deps, is absent when not, and never leaks into query snapshots. |
Flight Recorder
Node Reference
Reference
Guides
Testing