#!/usr/bin/env python3
"""Six terminal nutrition reads; per-source oracle, not natural value equality."""
import hashlib
import json
from pathlib import Path
import subprocess
import sys
import integrate_20261010 as tool

BASE=tool.AI+'parallel-ai-terminal-analysis-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['status']=='PASS' and r['unique_GET_methods']==6 and r['actual_native_HTTP']==32
    assert r['candidate_regression_assertions_passed']==72 and r['DML']==0
    assert r['MySQL_original_seven_complete_bodies_unchanged'] and not r['natural_business_values_cross_compared']
    subprocess.run([sys.executable,str(tool.ROOT/BASE/'test_compare.py')],check=True,capture_output=True)
    m=tool.load(BASE+'manifest.json')
    for path,sha in m['final_actual_private_and_main_sha256'].items():
        assert hashlib.sha256((tool.ROOT.parent/'zhctproject/ai_api'/path).read_bytes()).hexdigest()==sha
    for path,sha in m['files'].items():
        assert hashlib.sha256((tool.ROOT/BASE/path).read_bytes()).hexdigest()==sha
    for lane in ['B','C']:
        r=tool.load(BASE+'resource-cleanup-'+lane+'.json')
        assert r['business_DML']==r['business_fixtures_created']==r['business_cache_files']==0
        assert r['natural_original_rows_unchanged'] and r['tokens_cache_reclaimed']
        assert r['raw_CLI_secret_artifacts_removed']>0 and r['no_external_file_OSS_device_queue_calls']
        assert 'retained' in r['worker']  # Explicit authorized task-level transfer, not false shutdown.

def specs():
    return [dict(repo='ai_api',method='GET',path='/terminal/analysis.Analysis/'+action,
        module='设备端营养分析只读',terminal='terminal-controller-default-dispatch-no-client-source-claim',
        role='private-normal-terminal-auth-tenant',risk='readonly',
        scope='ai-primary-eight-original-source-tables-readonly-same-lane-full-oracle',
        evidence=BASE+'REPORT.md',request_type='GET-query',
        parity='partial-evidence-typed-full-original-projection-and-formula-per-lane-B-seven-complete-bodies-unchanged',
        cleanup='zero-DML-natural-consumed-source-unchanged-token-cache-reclaimed-task-workers-master-transferred',
        boundary_empty_min_max='partial-evidence-ready-nonempty-meal-vitamin1-2-C-dietary-recommend-empty-limitation-open')
        for action in ['supply','dishesType','dietary','vitamin','dietaryFiber','cookingMethod']]

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