#!/usr/bin/env python3
"""Three nonempty physical-nutrition reads, one newly observed real PC route."""
import json
from pathlib import Path
import subprocess
import sys
import integrate_20261010 as tool
from integrate_20261011_batch72 import seal
from integrate_20261011_batches40_42 import sha
from integrate_20261011_batches46_48 import item

PARENT=tool.STORE+'parallel-store-onto-nutrition-read10-20261011/'
BASE=PARENT+'next-physical-regression/run6/'
def verify():
    root=tool.ROOT/BASE
    seal(root,'manifest.json','74c3729735bb3d48a3a796c7f1961d5a875108893695633264689c6760f12fd5',
        'd6a91d5bb08e3b565679b34651b8b5a69f736f946f16a4ce5e1bd5acd94dfd0e',57)
    manifest=tool.load(BASE+'manifest.json')
    assert len(manifest['prior_seals_unchanged'])==6
    for record in manifest['prior_seals_unchanged']:
        path=tool.ROOT/PARENT/record['manifest']
        previous=json.loads(path.read_text())
        seal(path.parent,path.name,record['file_sha256'],previous['seal_sha256'],record['files'])
    result=subprocess.run([sys.executable,'-B',str(root/'verify.py'),'--verify'],capture_output=True,text=True)
    assert result.returncode==0,result.stderr
    report=json.loads(result.stdout)
    assert report['assertions']==12024 and report['negative_cases']==8
    assert report['HTTP']==6 and report['DML']==report['DDL']==report['logs']==0
    assert report['native_execute']['B']['total']==16 and report['native_execute']['C']['total']==32
    assert report['preflight']['B']['total_attempts']==18 and report['preflight']['C']['total_attempts']==34
    assert report['phase_difference']['B']==[] and report['phase_difference']['C']=={'0':0,'2':1,'11':2,'13':3}
    source=tool.load(BASE+'source-lock.json');assert len(source)==959
    assert sha(root/'source-lock.json')=='49b1a564de5a93dcd0385659a3d79f2e92256970b7fd7cc0a1adb8d482ccdd57'
    for relative,digest in source.items():
        assert sha(tool.ROOT.parent/'zhctproject/store/application'/relative)==digest,relative
    for record in manifest['files']:
        assert sha(root/record['path'])==record['sha256']

def targets():
    result=[]
    for path in ['/m/nutrition/NutritionUseTimeGroup','/p/nutrition_scheme/getNutritionTime','/p/nutrition_template/info']:
        target=item('store','POST',path,BASE,
            risk='readonly-owned-nonempty-physical-nutrition-Group-Time-Template-Ext-no-log-or-business-write',
            parity='partial-three-complete-per-engine-DTO-oracles-12024-assertions-eight-mutations-legal-Set-ID-phase-shape-difference-retained',
            boundary_empty_min_max='partial-fixed-current-positive-product-and-template-Ext-no-large-random-recommendation-or-station-writes',
            cleanup='eleven-marked-rows-actor-config-physical-bits-unchanged-own-worker-ports-Auth-cache-cleaned')
        if path=='/p/nutrition_scheme/getNutritionTime':
            target.update(register_new_runtime_key=True,runtime_observed_method='POST',
                runtime_inventory_scope='controller-direct-http-observed',runtime_direct_http_proof=BASE+'REPORT.md',
                runtime_controller_source='application/p/controller/NutritionScheme.php:262 real App::run POST; current schemeAdd.vue caller in source review',
                runtime_client_source=PARENT+'next-physical-regression/SOURCE-REVIEW.md',terminal='PC端')
        else:target['evidence_only']=True
        result.append(target)
    return result

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