Skip to main content

Behavior Preservation and Migration Contracts

Before editing, define the input domain, public observations, effects and excluded behavior. The kit preserves the following teaching contracts.

APIContract
invoice(lines,deadline,clock,sink)Integer deadline excluding bool, checked before effects. Write invoice\n, consume finite rows once, read clock once after all rows, then write total=N\n and return integer minor units.
Invoice rowsEach list/tuple has two nonnegative integers excluding bool: quantity and unit price in thousandths. Round each quantity×price to cents, half up; sum the rounded lines. Invalid row raises ValueError("line") after any existing header output.
Deadline policyClock returns integer excluding bool. If now < deadline, apply a 10% discount to the summed cents and round half up. Equality gets no discount. Invalid clock value raises ValueError("clock").
Invoice failuresPropagate iterator, clock and sink errors without retries. Header failure stops before row reads; input failure leaves the header and prevents the clock read. No external-write transaction or production billing guarantee.
eligible(checks)Finite iterable of conforming zero-argument callables. Return False at first truthy result, otherwise True. Preserve call order, laziness and exceptions; empty input returns True.
price_order(text,prices)String splits on whitespace into exactly two tokens, otherwise ValueError("order"). Lookup SKU first; then Python int(quantity,10); multiply by integer unit price. Negative quantities and Python integer-string forms retain baseline behavior. No new validation policy.
Grid(width,height)Positive integer dimensions excluding bool. Only the listed methods are supported API; storage attributes, object layout and reflection are excluded. Initially empty, independent instances.
Grid put/get and put_at/get_atOld (x,y) and new tuple-coordinate APIs share state. Coordinates are bounded integers excluding bool. Put accepts strings, returns None and overwrites; get returns string or None. Coordinate errors precede value errors. Invalid operations leave state unchanged.
send(key,payload,old,new,use_new)Nonempty string key, string payload, exact bool flag; reject invalid request before provider call. Call selected provider exactly once, return its result or propagate its exception. No automatic fallback, retry or global deduplication guarantee.

All examples are sequential. No concurrency, persistence, crash recovery, real payments or network delivery is implemented. Exception classes and explicit messages belong to the teaching contract; runtime tracebacks and private helper names do not. Conversion-error text is compared within the same Python runtime.

Cost and state boundaries​

Invoice processing streams input with constant auxiliary accumulation storage, excluding the caller's sink and input. Costs count arithmetic operations; Python integer bit costs grow with value size. The dictionary grid is a single-process model, not evidence for safe distributed dual writes. Published API removal needs supported-caller and compatibility evidence beyond passing current tests.

Use worked traces, guided labs and the assessment map. Keep approved repairs in a separate evidence lane.