#!/usr/bin/env python3
"""One new meal read plus C-only shared dependency evidence; not eight new methods."""
import hashlib
import json
from pathlib import Path
import subprocess
import sys
import integrate_20261010 as tool

BASE=tool.AI+'parallel-ai-terminal-meal-infos-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['new_unique_GET_methods']==1
    assert r['infos_native_HTTP']==5 and r['existing_Analysis_dependency_C_HTTP']==7 and r['actual_native_HTTP_total']==12
    assert r['DML']==0 and r['B_original_complete_body_unchanged'] and r['B_v2_native_not_repeated']
    assert r['C_final_v2_full_original_and_dependency_seven_passed'] and not r['cross_lane_natural_values_forced_equal']
    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_main_and_private_source_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+'infos-resource-cleanup-'+lane+'.json')
        assert r['business_DML']==r['cache_files']==0 and r['natural_rows_unchanged'] and r['tokens_cache_reclaimed']
        assert r['raw_CLI_secret_artifacts_removed']>0 and r['port_closed']

def specs():
    out=[dict(repo='ai_api',method='GET',path='/terminal/meal.Meal/infos',module='设备餐次菜品详情读取',
        terminal='terminal-controller-default-dispatch-no-client-source-claim',role='normal-private-terminal-tenant',risk='readonly',
        scope='ai-primary-meal-infos-dishes-three-tables-natural-readonly',evidence=BASE+'REPORT.md',request_type='GET-query',
        parity='partial-evidence-per-lane-complete-original-projection-B-full-body-unchanged-C-final-and-seven-consumers-green',
        cleanup='zero-DML-natural-consumed-source-unchanged-workers-ports-token-cache-reclaimed-master-to-root',
        boundary_empty_min_max='partial-evidence-natural-ready-one-and-seven-dishes-only-empty-loading-unverified')]
    for action in ['supply','dishesType','dietary','vitamin','dietaryFiber','cookingMethod']:
        out.append(dict(repo='ai_api',method='GET',path='/terminal/analysis.Analysis/'+action,
            module='营养分析新依赖C回归增强',terminal='terminal',role='normal-private-terminal-tenant',risk='readonly',
            scope='C-only-seven-shared-consumer-scenarios-new-MealModel-Service-B-v2-not-replayed',
            evidence=BASE+'REPORT.md',evidence_only=True))
    return out

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