Skip to content

The Drift Log · Certifying that code does something

Why Green Test Suites Fail to Prove Contract Invariants

12 November 2026 · 3 min read · 579 words · established

A crystal artifact under orange probe beams inside a test rig

Green test suites sample happy paths without proving invariants; contract certification requires explicit boundary and state-transition verification.

The Illusion of Exit Code 0

A green test suite guarantees one thing: the specific inputs written by a developer executed through the runtime without triggering an unhandled exception or a failing assertion. Nothing more.

Consider a ring buffer implementation designed to enforce bounded memory allocation:

class BoundedQueue<T> {
  private items: T[] = [];
  constructor(public readonly capacity: number) {}

  push(item: T): boolean {
    if (this.items.length >= this.capacity) {
      return false;
    }
    this.items.push(item);
    return true;
  }

  drain(): T[] {
    const batch = this.items;
    this.items = [];
    return batch;
  }
}

A standard test suite will instantiate the queue with a capacity of 3, push three items, assert that push returns false on the fourth, drain the queue, and assert that the length is zero. The test passes. CI turns green.

The contract invariant—that items.length never exceeds capacity under any series of operations across the object's lifecycle—remains unproven. Pass a floating-point number, a negative integer, or NaN into the constructor, and the boundary check fails silently. Mutate the array returned by drain() in an environment where references are shared, and the internal state is compromised.

The test proved that line coverage was achieved along a single happy path. It did not produce an executable proof of the contract.

Sampling vs. Verification

Unit tests are existential checks: they demonstrate that there exists at least one input $x$ for which the output $y$ satisfies an assertion. Contract invariants are universal statements: they assert that for all valid states and inputs, a property $P$ holds unconditionally.

Sampling five points on an input domain does not establish verification. When developers treat a green CI run as code certification, they conflate the absence of observed failures with the presence of correctness.

Real verification requires testing the boundaries of the input contract:

  1. Domain boundaries: Zero, negative values, integer limits, empty collections, and malformed structures.
  2. State transitions: Invariants that must survive arbitrary sequences of calls, not just setup -> action -> assert.
  3. Environmental fault injection: Dropped connections, full disks, and clock drift.

When a test harness cannot reach those edge states, asserting that the component is "tested" is dishonest. It creates false confidence that collapses the moment unmodelled inputs arrive in production.

Naming the Ladder Honestly

At SHPBL, we do not treat code as binary—either broken or complete. Our certification harness executes components against formal contracts and records one of four precise verdicts:

  • CERTIFIED: The component has been fully exercised against its contract boundaries, and its invariants hold under execution.
  • PROVISIONAL: The build is repeatable and byte-for-byte reproducible, but correctness across edge states has not yet been asserted.
  • INCONCLUSIVE: The harness hit an internal limit and could not fully exercise the input contract. This is recorded as a harness limitation, not an artifact defect.
  • FAILED: The component violated an invariant.

Our catalog is model-independent. Code is computed and owned outright, sealed with published checksums at our root of trust. If you want to see where your existing internal components sit on this ladder, start with a free repository evaluation.

Auditing Invariants on Monday

Do not write more unit tests that repeat the happy path. Pick one critical stateful component in your repository and audit its assertions:

  1. Extract the universal invariant. State it in plain text: "The balance never drops below zero," "Total capacity never exceeds $N$," or "Sequence numbers increase monotonically."
  2. Attack the constructor and public boundaries. Pass invalid, out-of-range, and boundary inputs directly into the interface without using your standard test fixtures.
  3. Separate your verdicts. If your existing test setup cannot exercise concurrent calls or memory constraints, mark that contract rung as inconclusive in your internal tracking rather than letting a shallow green suite mask the risk.

Keep reading

Next in the log

The Strategic Master Library · written and reviewed under the house's own epistemic rules: nothing claimed that we cannot show.