# Fictional stable record sorting contract, revision 1

This teaching implementation accepts immutable tuples of zero through eight
records. Each record is an immutable pair `(key, tag)`. The key is an integer
from -2 through 2 inclusive, excluding booleans; tag is exactly `a`, `b` or `c`.
Records and keys may repeat. Tags are values, not unique identifiers. Equality
compares the complete pair. Inputs outside this domain are not specified or
tested. There is no floating point, NaN, locale, user comparator, object identity,
custom equality, I/O, concurrent state, unbounded input length or performance
requirement in this contract.

TREQ-SORT-01: Return an immutable tuple ordered by ascending key alone, retaining
every input record occurrence, including exact duplicates. Neither set equality
nor distinct-key equality is sufficient to establish record multiplicity.

TREQ-SORT-02: Preserve the input sequence of records within each equal-key group.
Stability is explicitly required for this sorter. It is not a requirement for
every sorting API or pure function. Identical record occurrences are not given
artificial separate identities; multiplicity accounts for their counts.

TREQ-SORT-03: The implementation boundary has no I/O or mutable global state.
Do not mutate the input. Repeated calls on equal inputs return equal values.
The implementation operates on local lists and returns a tuple of the original
immutable record values. Static source/call-graph review supports that boundary;
finite input-preservation and repeated-call tests do not prove purity generally.

Sorting again is idempotent for this contract because stable sorting an already
stably ordered sequence changes neither order nor multiplicity. Idempotence
alone is insufficient: always returning empty is idempotent too. Commutativity
and associativity are not required of this unary sorter. Total behavior is
observed only for the actual tested inputs, not proved over the whole domain.

The baseline drops exact duplicate values. The correction is stable insertion
sorting without the deduplication step. An empty-output implementation and an
equal-key reversal implementation are deliberate challenges to the properties.
The correction compares keys using <, never the complete `(key, tag)` pair.

The harness checks adjacent key order, Counter multiplicity over complete
records, and per-key subsequences. Stability is not assessed when multiplicity
already fails. Python's documented stable `sorted(..., key=...)` provides a
separate readable expected output; it does not call the insertion implementation.

Hypothesis generates values within this domain; it does not enumerate all inputs.
The test strategy uses no filter or assume and deliberately permits duplicates.
Generated search and shrinking, passing generated campaigns, and explicit
regression replay are distinct activities. No Proof CLI command, SMT solver,
formal proof, structural coverage measurement or production-system test is run.
