#!/usr/bin/env python3
"""Record four real shared-baseline failures; never convert them into passes."""
import json
from pathlib import Path
import subprocess
import sys
import integrate_20261010 as tool

BASE=tool.STORE+'parallel-store-train-unit-20261010/'

def verify():
    r=subprocess.run([sys.executable,str(tool.ROOT/BASE/'compare.py')],check=True,capture_output=True,text=True)
    r=json.loads(r.stdout)
    assert r['passed'] and r['business_interfaces_passed']==0 and all(r['evidence_consistency_only'].values())
    m=tool.load(BASE+'manifest.json')
    assert m['actual_HTTP']==24 and m['initialization_excluded_HTTP']==16 and m['properly_scoped_HTTP']==8
    assert m['positive_business_pass']==m['business_DML']==m['financial_DML']==m['DDL']==0
    assert m['CLI_scoped_assertions']['C']['failed']==3
    for path in ['application/p/controller/TrainUnit.php','application/p/logic/TrainUnit.php','application/model/TrainUnit.php']:
        assert not (tool.ROOT.parent/'zhctproject/store'/path).exists()
    r=tool.load(BASE+'resource-cleanup.json')
    assert r['business_token_raw_cache_CLI_reports_source_configs_source_tar_removed'] and r['natural_rows_deleted_or_rolled_back']==0
    for lane in ['B','C']:
        assert r[lane]['worker_absent'] and r[lane]['port_closed'] and r[lane]['runtime_removed']

def specs():
    out=[]
    for path in ['/p/trainunit/lists','/p/trainunit/info','/p/trainunit/allunit','/p/trainannex/lists']:
        is_annex='trainannex' in path
        reason='shared-original-missing-upload-time-and-file-size' if is_annex else 'shared-original-controller-absent-runtime-message-cause-C-not-confirmed'
        out.append(dict(repo='store',method='POST',path=path,module='训练档案原基线缺口',terminal='PC',
            role='approved-private-normal-real-actor',risk='readonly',
            scope='store-primary-readonly-fixed-annex-scope-and-actor-no-DML' if is_annex else 'dispatch-never-reaches-customer-business-rows-controller-absent',
            evidence=BASE+'REPORT.md',request_type='current-controller-form',
            mysql_state='tested-fail-'+reason,dm_state='tested-fail-'+reason,
            success_case='tested-fail-no-positive-business-case',
            mysql_readback='partial-evidence-source-actor-unchanged-on-failed-request',
            dm_readback='partial-evidence-source-actor-unchanged-on-failed-request',
            parity='not-accepted-shared-source-failure-not-DM-regression-claim-C-three-message-assertions-preserved',
            readback='partial-evidence-original-scope-and-actor-unchanged-no-success-write',
            cleanup='read-only-natural-scope-and-actor-unchanged-private-resources-released-task-master-transferred',
            boundary_empty_min_max='not-tested'))
    return out

if __name__=='__main__':
    audit=Path(__file__).with_name('integration-20261010-batch34.json')
    assert not audit.exists(),'Preserve original transition audit'
    tool.main(specs(),audit,verify)
