A conversion fixture can pass on Monday and fail on Friday without any payload or code change. If the rule reads the current time, the fixture is missing one of its inputs.
Time-sensitive checks need an explicit reference clock. Without one, an incident replay gradually stops reproducing the incident and starts answering a different question: whether the old event would be acceptable today.
Both questions can be useful. The test needs to say which one it asks and retain the inputs needed to reproduce its answer.
Separate historical validity from current sendability
Suppose a synthetic event occurred at 11:30 and the application evaluated it at noon. A historical replay should use noon as the reference time, even if the replay runs months later.
An operational check about sending that captured event now should use a current reference time. Its failure does not necessarily mean the historical decision was wrong.
Name the replay mode in the fixture. Store the event occurrence time, reference time, policy version and expected result together. Updating only the event timestamp to Date.now() may make a test pass while deleting the old behavior it was supposed to preserve.
Timestamp semantics also depend on the endpoint. Occurrence time, client send time and server receipt time are distinct fields in many event pipelines. Select the field that the policy actually evaluates before calculating its age.
Make the clock an argument
This complete Node.js example implements an application-owned one-hour window. It does not represent the ingestion window of Meta, Google, Segment or any other destination:
import assert from 'node:assert/strict';
function ageDecision({ eventMs, referenceMs, maxAgeMs }) {
if (![eventMs, referenceMs, maxAgeMs].every(Number.isSafeInteger) ||
maxAgeMs < 0) {
return { accepted: false, reason: 'invalid-input' };
}
const ageMs = referenceMs - eventMs;
if (!Number.isSafeInteger(ageMs)) {
return { accepted: false, reason: 'invalid-input' };
}
if (ageMs < 0) return { accepted: false, reason: 'future-event', ageMs };
if (ageMs > maxAgeMs) return { accepted: false, reason: 'too-old', ageMs };
return { accepted: true, reason: 'within-window', ageMs };
}
const referenceMs = Date.parse('2026-10-01T12:00:00Z');
const maxAgeMs = 60 * 60 * 1000;
const decide = eventMs => ageDecision({ eventMs, referenceMs, maxAgeMs });
assert.equal(decide(referenceMs - maxAgeMs).accepted, true);
assert.equal(decide(referenceMs - maxAgeMs - 1).reason, 'too-old');
assert.equal(decide(referenceMs + 1).reason, 'future-event');
assert.equal(decide(referenceMs).accepted, true);
assert.equal(decide(NaN).reason, 'invalid-input');
assert.equal(decide(String(referenceMs)).reason, 'invalid-input');
assert.equal(ageDecision({
eventMs: referenceMs - 30 * 60 * 1000,
referenceMs: referenceMs + 24 * maxAgeMs,
maxAgeMs
}).reason, 'too-old');
The exact-boundary assertions document an inclusive maximum age and a policy that rejects future-dated events. A different policy may allow a measured clock-skew tolerance, but that tolerance must be an explicit input with its own tests.
The function returns a reason instead of one unexplained false value. This prevents an invalid timestamp from being reported as merely too old.
Convert units before evaluating policy
Choose one unit for the age calculation and normalize inputs before calling the rule. Subtracting a microsecond event timestamp from a millisecond reference time can produce an enormous age with no parsing error.
Keep unit names in the fixture or schema. The local program uses eventMs, referenceMs and maxAgeMs so that the intended arithmetic is visible.
Reject invalid dates before subtraction. JavaScript's invalid date value propagates as NaN, and a loosely written comparison can behave differently from the failure classification you intended.
Also preserve precision decisions. If the event source was rounded to seconds, a test right on a millisecond cutoff may need to reflect that input precision rather than pretending the source measured more accurately.
Inject the clock through the real code path
A pure helper can be deterministic while the surrounding adapter still reads Date.now() and replaces an event field. Test the path that builds the actual payload and decision record.
Pass a clock dependency into the component that needs current time, or pass an already selected reference instant through the call. Avoid changing a process-wide clock when a narrow injected dependency is enough.
In an integration fixture, assert that multiple stages use the same intended reference. If each stage independently reads the clock, a boundary case can receive inconsistent treatment within one processing attempt.
Keep retry send times separate from the occurrence time. A retry may happen later while still representing the original purchase. Rewriting the occurrence time changes the event instead of explaining the delivery attempt.
Replay the rule and the payload independently
There are two useful upgrade tests. First, run the same event and reference time through old and new policy versions. That isolates rule changes.
Second, run the same policy against payloads produced by old and new adapter versions. That isolates transformations such as changed units or default timestamps.
Changing the payload, reference clock and policy in one test makes a changed outcome difficult to explain. Keep those dimensions explicit in the result.
For an incident record, preserve both the historical reference and a separate current-sendability result if operators need it. The report can then explain why the event was accepted earlier but should not be retried under today's conditions.
Keep local policy separate from destination behavior
The sample's one-hour cutoff is deliberately invented. Production rules need the current endpoint documentation, stream type and relevant ingestion settings.
A local age decision cannot prove that a destination will use the supplied occurrence time. The destination may apply its own validation or documented clock handling. Verify that behavior with controlled integration evidence when it matters to the incident.
I maintain Pixellint. Its captured-payload workflow offers a place to inspect conversion inputs. Whether you use that interface or your own harness, retain the reference time with the fixture so the replay continues to answer the question you intended.
Sources
Technical sources checked October 25, 2026. Drafted with AI; examples are synthetic unless explicitly stated otherwise.
Top comments (1)
The distinction between historical validity and current sendability is the part that clicked for me. A replay answering whether an old event would be acceptable today is a different question from whether it can be sent now, and mixing the two is how a fixture passes on Monday and fails on Friday. The other warning I will remember is the one about the pure helper being deterministic while the adapter still reads Date.now() and rewrites an event field — testing the helper alone would have given me false confidence. On retries, do you keep the original occurrence time in the payload and only move the send time, or does your adapter rewrite both?