Pdf Processor
The guard that tested my assumption instead of the code
TLDR
Writing hardcoded numeric assertions in regression guards (e.g. assertingexpectLinks: 0 on single-column documents) causes false test failures when algorithms correctly link paragraph continuations across page zone boundaries. Replacing brittle counts with property-based invariants (asserting that zero links touch digit-heavy table fragments) validates algorithmic correctness without locking tests to arbitrary totals.
| Guard Assertion Type | Assertion Logic | Resiliency to Valid System Improvements |
|---|---|---|
| Count-Based Assertion | expect(links.length).toBe(0) | Fragile (Fails when zone linkers improve) |
| Property-Based Invariant | links.every(l => !l.isDigitHeavy) | 100% reliable across feature updates |
Technical property invariant test assertion
// Property-Based Invariant Assertion for Paragraph Continuation Linkers
export function verifyContinuationLinkInvariants(detectedLinks) {
for (const link of detectedLinks) {
// Invariant 1: Continuation links must never connect numeric table debris
const hasDigitDebris = isDigitHeavy(link.prevFragment) || isDigitHeavy(link.nextFragment);
if (hasDigitDebris) {
throw new Error([InvariantViolation] Continuation link ${link.id} connects numeric table debris);
}
// Invariant 2: Linked fragments must share font family compatibility if (link.prevFragment.fontFamily !== link.nextFragment.fontFamily) { throw new Error([InvariantViolation] Font family mismatch across continuation link ${link.id}); } } return true; }
Rule of thumb: Assert structural property invariants rather than exact numeric result counts when testing heuristic extraction algorithms.
Read this post in the full Engineering Journal →