feat(01-01): enforce eight-cell scenario and native evidence completeness
This commit is contained in:
1 parent
cc4a5a3e92
commit
32a72654e8
5 files changed
+430
-22
No files matched your search
+26
-5
@@ -13,7 +13,8 @@ from pathlib import Path
|
||||
import sys
|
||||
|
||||
from fidelity_receipts import (identify_tree, identify_report, import_receipt,
|
||||
read_json, stage_original, validate_receipt)
|
||||
read_json, read_receipt, stage_original, validate_receipt,
|
||||
audit_receipt_tree, canonical_bytes, MAX_JSON_BYTES)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
@@ -32,8 +33,10 @@ def main(argv=None):
|
||||
imp.add_argument('--root', type=Path, required=True)
|
||||
imp.add_argument('--output', type=Path, required=True)
|
||||
validate = sub.add_parser('validate')
|
||||
validate.add_argument('receipt', type=Path)
|
||||
validate.add_argument('--root', type=Path, required=True)
|
||||
validate.add_argument('receipt', type=Path, nargs='?')
|
||||
validate.add_argument('--root', type=Path)
|
||||
validate.add_argument('--scenarios', type=Path)
|
||||
validate.add_argument('--receipts', type=Path)
|
||||
mode = validate.add_mutually_exclusive_group()
|
||||
mode.add_argument('--allow-open', action='store_true')
|
||||
mode.add_argument('--require-complete', action='store_true')
|
||||
@@ -48,13 +51,31 @@ def main(argv=None):
|
||||
elif args.command == 'import':
|
||||
result = import_receipt(args.receipt, args.root, args.output)
|
||||
else:
|
||||
result = validate_receipt(read_json(args.receipt), args.root)
|
||||
if args.scenarios:
|
||||
if args.receipt or args.root or not args.receipts:
|
||||
raise ValueError('Scenario validation requires --scenarios PATH --receipts ROOT')
|
||||
result = audit_receipt_tree(read_json(args.scenarios), args.receipts)
|
||||
print('Structural readiness: READY; acceptance: ' + ('COMPLETE' if result['complete'] else 'OPEN'))
|
||||
print('Accepted obligations: {accepted}/{required}'.format(**result))
|
||||
print('Missing case IDs: ' + ', '.join(result['missing_case_ids']))
|
||||
for key in ('missing_obligations', 'open_receipts', 'invalid'):
|
||||
for item in result[key]:
|
||||
print(key + ': ' + item)
|
||||
if result['invalid']:
|
||||
return 2
|
||||
return 1 if args.require_complete and not result['complete'] else 0
|
||||
if args.receipt is None or args.root is None or args.receipts:
|
||||
raise ValueError('Receipt validation requires RECEIPT --root ROOT')
|
||||
result = validate_receipt(read_receipt(args.receipt), args.root)
|
||||
print('Receipt {receipt_id}: {evidence_kind}, status={status}'.format(**result))
|
||||
print('Acceptance: ' + ('ACCEPTED' if result['accepted'] else 'OPEN'))
|
||||
for missing in result['missing_evidence']:
|
||||
print('Missing/open: ' + str(missing))
|
||||
return 1 if args.require_complete and not result['accepted'] else 0
|
||||
print(json.dumps(result, indent=2, allow_nan=False))
|
||||
data = canonical_bytes(result)
|
||||
if len(data) > MAX_JSON_BYTES:
|
||||
raise ValueError('Result JSON exceeds 4 MiB limit')
|
||||
print(data.decode(), end='')
|
||||
return 0
|
||||
except (ValueError, OSError, KeyError, TypeError) as error:
|
||||
print('Invalid fidelity evidence: ' + str(error), file=sys.stderr)
|
||||
|
||||
Reference in new issue
Block a user