"""Offline synthetic-response reading exercise, not a schema validator or SDK.""" import json import re import sys OUTCOMES = {"established", "ambiguous", "no_match", "insufficient_evidence"} def summarise(response): data, receipt = response["data"], response["receipt"] outcome, units = data["outcome"], receipt["charged_units"] recovery = data["recovery"] if outcome not in OUTCOMES: raise ValueError("Unknown outcome: stop interpretation and check the contract") if not isinstance(units, str) or not re.fullmatch(r"0|[1-9][0-9]*", units): raise ValueError("Atomic units must remain canonical decimal strings") if recovery["automatic_retry_allowed"] is not False: raise ValueError("This exercise cannot authorise an automatic retry") return { "synthetic": True, "outcome": outcome, "entity_id": data["entity"]["subject"]["entity_id"] if outcome == "established" else None, "identity_assessment": data["identity_assessment"], "recovery": recovery, "receipt": {key: receipt[key] for key in ( "receipt_id", "operation_id", "charged_units", "unit", "unit_scale", "settlement" )}, } if __name__ == "__main__": with open(sys.argv[1], encoding="utf-8") as stream: responses = json.load(stream) print(json.dumps({name: summarise(value) for name, value in responses.items()}, indent=2))