Skip to main content

Executable structural composition lab

For broader construction/copy/tree/proxy coverage, complete the core workshop inside original practice hours. This page remains the distinct SC extension.

This replaces the former two-hour quote-provider lab. The full extension is 18–26 hours; implementation and design evidence take 8–12 of those hours.

Download the lab archive, extract it and open structural-contracts. Use Python 3.10+ and its standard library; on Windows substitute py -3 for python3. No network calls or payment operations are involved.

python3 check.py starter

Initial NotImplementedError is intentional. Implement to_cents, retry, logged, build_quote and open_bundle from their docstrings and lessons. open_bundle must return a context manager; using contextmanager and ExitStack is encouraged. Choose functions or classes based on the contract; a class per wrapper is not required.

python3 run.py starter > results.json

Predict both wrapper traces first. Retain output and your own invalid-payload, exhausted-budget and partial-acquisition cases. After an attempt, compare reference.py and run python3 check.py reference. Checks include low decimal context precision, input bounds, all attempt budgets 1–5, exception identity, both wrapper orders and reverse-order cleanup.

Submit code, actual traces, a repaired failure, source/help record and a short decision note. Name which dependencies are borrowed and which scopes are owned, compare one rejected policy, and state the cost and missing guarantees. Reproduce a changed case unaided. Reuse this packet in the semester project and apply SC1–SC6.

The list-based logger assumes append succeeds. The context managers in fixtures do not suppress exceptions or fail during exit; arbitrary managers may. Finite checks do not establish real provider correctness, crash safety or concurrency guarantees.