#!/usr/bin/env python3
"""Procurement lifecycle evidence across the preserved red and repaired stages."""
import hashlib
import json
import subprocess
from pathlib import Path
import integrate_20261010 as tool
from integrate_20261011_batches46_48 import item

HERE=Path(__file__).resolve().parent
PRIVATE=Path('/Users/wiscourper/Documents/workspace/local/dm8-store-purchase-read3-20261012.L5dTYR')
BASE='work_store/apifox/2026-09-30-dm8-interface-acceptance/parallel-store-purchase-read3-20261012/'
REPORT=BASE+'ROOT_REVIEW_STAGE2_3.md'

def verify():
    for phase,name,pin in [('stage2','manifest-stage2.json','efc61935a984c2e347ff6b57dc8659a2256dc5fbabc327858f230d3570867f4c'),('stage3','manifest-core.json','2c483aedd2a9f8431d66ebe5db749c795857f1bc918481ed73a835055dccf3f1')]:
        assert hashlib.sha256((PRIVATE/phase/name).read_bytes()).hexdigest()==pin
    a=json.loads(subprocess.check_output(['node',str(PRIVATE/'stage2/audit-stage2.js'),'--readonly']))
    b=json.loads(subprocess.check_output(['node',str(PRIVATE/'stage3/audit-core.js'),'--readonly']))
    assert a['evidence_verified'] and not a['business_fully_passed'] and a['checks']==2766
    assert b['readonly'] and b['checks']==523 and b['assets']==196
    assert hashlib.sha256((tool.source_root('store')/'application/p/logic/Material.php').read_bytes()).hexdigest()=='dea975598c96ea27c69632b2cdbc44a1972ac7eb075b9cd06a848b1c464e143f'

def targets():
    out=[]
    for controller,actions in [('Supplier',['all','add','update','read']),('Material',['all','lists','add','update','read','del'])]:
        for action in actions:
            kw={}
            if action not in ['all','lists','del']:
                kw.update(from_repo='unreviewed',from_source='apifox-2026-05-08')
            if action=='del':
                kw.update(register_new_runtime_key=True,runtime_observed_method='POST',
                    runtime_inventory_scope='controller-direct-http-observed',runtime_direct_http_proof=REPORT,
                    runtime_controller_source='zhctproject/store/application/p/controller/Material.php:140')
            out.append(item('store','POST',f'/p/{controller}/{action}',BASE,evidence=REPORT,
                readback='partial-evidence-own-full-row-native-INSERT-UPDATE-and-selective-delete-or-independent-source-DTO',
                parity='partial-evidence-original-key-types-and-DATETIME0-own-values-creator-diff-is-real-actor-data',
                success_case='partial-evidence-owned-procurement-lifecycle-source-time-schema-fixed-scoped-regression',
                cleanup='owned-fixtures-and-stage3-workers-retained-stage2-unrelated-identity-drift-preserved',**kw))
    return out

if __name__=='__main__':
    audit=HERE/'integration-20261012-batch113.json';assert not audit.exists()
    tool.main(targets(),audit,verify)
