ci / tests (macos-latest, python 3.11) (push) Canceled after 0s
ci / tests (macos-latest, python 3.13) (push) Canceled after 0s
ci / tests (macos-latest, python 3.9) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.11) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.13) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.9) (push) Canceled after 0s
Contracts with a ladder of checks, an end-of-turn gate, retrospectives and shared lessons, time-to-delivery measurement, a library of 140 verification techniques and 20 recipes, personal data kept outside the clone, and releases with rollback. Standard library only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
3.2 KiB
3.2 KiB
id, title, answers, rung, section, languages, kinds, cost, detect, ran_here, verified
| id | title | answers | rung | section | languages | kinds | cost | detect | ran_here | verified |
|---|---|---|---|---|---|---|---|---|---|---|
| old-data-compatibility | Compatibility with data written by older and newer versions | Do files written by earlier versions still open to their recorded figures, and is data from a newer version reported as newer rather than corrupt? | 3 | many-inputs | any | migration, state-machine, money | medium | yes | ran |
Use when
- The program reads files, databases or journals that users keep across upgrades.
- You change a format, a schema or the rules for computing a stored figure.
- An old version may meet newer data (downgrade, shared folder, restored backup).
Do not use when
- You want sampled inputs: use
round-trip; this uses fixed fixtures.
Set up
- When a format version ships, write real data with that version and commit it
as
tests/fixtures/<version>/together withexpected.json, the figures the version itself computed. Never regenerate old fixtures with new code. - Keep a newer-format fixture (or fake one with a bumped format field).
Minimal example (Python)
import json, pathlib, tempfile
CURRENT = 2
def open_book(path):
data = json.loads(pathlib.Path(path).read_text()) # raises on garbage
v = data.get("format")
if v is None or not isinstance(v, int):
raise ValueError("corrupt: no format")
if v > CURRENT:
raise RuntimeError(f"newer: written by format {v}, this reader knows {CURRENT}")
return {"total": sum(data["cents"])} # v1 and v2 both store `cents`
def test_old_fixture_reopens_to_recorded_figures():
got = open_book("fixtures/v1/book.json")
assert got == json.load(open("fixtures/v1/expected.json"))
def test_newer_is_reported_as_newer_and_left_untouched():
p = pathlib.Path(tempfile.mkdtemp()) / "b.json"
p.write_text(json.dumps({"format": 3, "cents": [1]}))
before = p.read_bytes()
try:
open_book(p); assert False
except RuntimeError as e:
assert str(e).startswith("newer")
assert p.read_bytes() == before # never repaired or rewritten
def test_damage_is_still_corrupt():
p = pathlib.Path(tempfile.mkdtemp()) / "b.json"
p.write_text("{not json")
try:
open_book(p); assert False
except ValueError: pass
Run
python3 -m pytest -q test_compat.py
Passing looks like: 3 passed, exit 0. Failure shows which fixture gave other figures,
or a newer file reported as corrupt (or the reverse).
As a contract check
{"id": "old-data-compat", "claim": "v1 fixtures reopen to recorded figures; newer data is reported newer and untouched; damage stays corrupt", "kind": "migration", "rung": 3, "cmd": "python3 -m pytest -q test_compat.py", "expect": {"exit": 0, "stdout_contains": "3 passed"}, "tier": "deep", "timeout_s": 300}
What a pass does not prove
- Only the fixtures you have: keep one per released format.
- Expected figures come from the old version; never regenerate them to make a test pass.
- It does not show an upgrade is safe on real data: test the upgrade step on a copy.
- Check the check: edit a fixture's figure and see the test fail; bump a format number and see "newer" appear.