#!/usr/bin/env python3
"""Resolve original mixed-case Apifox key, not failed lowercase route alias."""
import hashlib
import json
import subprocess
import sys
from pathlib import Path
import integrate_20261010 as tool
from integrate_20261011_batches46_48 import item

HERE = Path(__file__).resolve().parent
REPORT = tool.STORE + 'parallel-cashout-list-20261013/ROOT_REVIEW.md'

def verify():
    path = Path('/private/tmp/cdx-ai-hk-course-b.Kmdirn/review-s3-525-527/verify_review.py')
    assert hashlib.sha256(path.read_bytes()).hexdigest() == 'fbe5503511f3574766c4721187d9521c5e98523ee711c8d64f61838c53d2ed9c'
    result = json.loads(subprocess.check_output([sys.executable, '-B', str(path)]))
    assert result['offline'] and result['checks'] == 1377
    assert result['original_business_reached'] == 10 and result['lowercase_route_failures'] == 2
    assert result['paths'] == {'/p/cashoutorder/list': 2, '/p/cashoutOrder/list': 10}
    subprocess.check_call(['git', '-C', str(tool.source_root('store')), 'merge-base', '--is-ancestor', result['commit'], 'develop_dameng'])

if __name__ == '__main__':
    audit = HERE / 'integration-20261013-cashout-list.json'
    assert not audit.exists(), 'Never replay main'
    # Exact original inventory label must be preserved despite normalized counting.
    for path, column in [(tool.COVERAGE, 'route_or_command'), (tool.CONTRACT, 'path')]:
        _, rows, _ = tool.read_csv(path)
        found = [r for r in rows if r['repo'] == 'unreviewed' and r['method'] == 'POST'
                 and tool.norm(r[column]) == '/p/cashoutorder/list']
        assert len(found) == 1 and found[0][column] == '/p/cashoutOrder/list'
    rows = [item('store', 'POST', '/p/cashoutOrder/list', '', evidence=REPORT,
        from_repo='unreviewed', from_source='apifox-2026-05-08',
        success_case='partial-evidence-exact-mixed-case-client-URL-only-lowercase-route-still-fails',
        readback='tested-pass-own-terminal-failed-cashout-full-source-wallet-preserved-zero-DML',
        parity='partial-evidence-row-money-string-DATETIME-seconds-SUM-original-numeric-types',
        boundary_empty_min_max='partial-evidence-own-page2-negative-page-date-exclusion-scope-overrides')]
    tool.main(rows, audit, verify)
