When I maintain signup telemetry around a first-party form using xCaptcha, I want analysts to see when an export is incomplete. A run can still contain plausible counts if a batch of events was lost upstream. The smallest example is a source that claims a completed batch of three events but delivers only the first and third.
Written with AI assistance. The Python example uses synthetic data and was checked locally.
Establish a scope and a completed range
The test models one app-owned stream that assigns consecutive positions inside a closed batch. The expected range comes from the producer’s completion record. It’s meaningful only if the producer promises contiguous positions. A database sequence with legitimate gaps is a different contract and shouldn’t be interpreted using this check.
I’d record the stream and batch separately in production. A replay of an event might be harmless if its content is identical, but it should never fill another position in the count. The fixture treats repeated positions as a data error so it can test the missing-position case clearly.
def missing_positions(delivered, count): positions = set(delivered) if len(delivered) != len(positions): raise ValueError("duplicate position") if any(not 1 <= n <= count for n in positions): raise ValueError("position outside batch") return sorted(set(range(1, count + 1)) - positions) assert missing_positions([3, 2, 1], 3) == [] assert missing_positions([], 0) == [] gap = missing_positions([3, 1], 3) assert gap == [2] print(f"Missing source positions: {gap}") The fixture prints Missing source positions: [2]. An analyst seeing an incomplete batch should know that ratios derived from it may be misleading. The event did not need to carry an email, verification token, or other field content for the system to detect the gap.
I’d test the completed batch, the missing position, and an awaiting-delivery state at the workflow level. An open batch can still gain events. Only the producer can confirm it closed, so let that fact determine when scheduling an investigation makes sense.
Further reading
Test a local form after a verification timeout.

