#!/usr/bin/env python3
"""Real menu copy paths; retains a committed-but-undelivered old MySQL attempt."""
import hashlib
import json
from pathlib import Path
import subprocess
import sys
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/stage3/meal-copy208-20261013')
BASE = 'work_store/apifox/2026-09-30-dm8-interface-acceptance/parallel-menu-copy-20261013/'


def verify():
    for name, digest in {
        'REPORT208.md': '00c0223f1b211765103405d223829ab45e2ed6577d13e62a088e9e3e50193917',
        'manifest208.json': '459b18dfee91482421ddabd7c9f060af5f997967b4c0276c2195560571d26c32',
        'verify208.py': 'a83b32b2590cf11a0a99a14fa1b9a5ca529cd6c0d347ff29923c2a58d3e9d1c5',
    }.items():
        assert hashlib.sha256((PRIVATE / name).read_bytes()).hexdigest() == digest
    v = json.loads(subprocess.check_output([sys.executable, '-B', str(PRIVATE / 'verify208.py')]))
    assert v['checks'] == 1320 and v['assets'] == 140
    assert v['old_B_commit_client_failure_retained'] and v['new_B_commit_client_closed']
    assert v['totals']['B']['HTTP'] == 5 and v['totals']['C']['HTTP'] == 3
    for lane, label, final in [('B', 'CM208', 'recovery-final208.json'), ('B', 'CM208B2', 'finishR208.json'), ('C', 'CM208', 'final208.json')]:
        root = PRIVATE / ('evidence-' + lane)
        r = json.loads((root / ('response-' + label + '.json')).read_text())
        f = json.loads((root / final).read_text())
        assert f['batch'][0]['id'] == int(r['ids']['batch_id'])
        assert f['batch'][0]['batch_no'] == r['ids']['batch_no']
        assert f['detail'][0]['batch_id'] == int(r['ids']['batch_id'])
        assert f['detail'][0]['recipe_uuid'] == r['ids']['recipe_uuid']
        assert f['own']['target_log'][0]['id'] == int(r['ids']['log_id'])


if __name__ == '__main__':
    audit = HERE / 'integration-20261013-batch208.json'
    assert not audit.exists(), 'Do not replay matrix integration'
    specs = [item('store', 'POST', '/p/bill/' + action, BASE,
        success_case='partial-evidence-original-owned-singleton-copy-empty-target-not-overwrite-or-concurrency',
        readback='tested-pass-original-recipes-batch-detail-log-full-rows-native-IDs-quantity-time-and-protected-source',
        parity='partial-evidence-real-client-wire-equal-typed-DTO-except-generated-identities-old-tool-failure-retained',
        cleanup='marked-business-records-retained-own-workers-token-cache-zero')
        for action in ('copy_menu', 'weekCopyPreview', 'weekCopyCommit')]
    tool.main(specs, audit, verify)
