#!/usr/bin/env python3
"""Accept two real read-only downloads, never subsidy calculation or granting."""
import hashlib
import json
import subprocess
import sys
from pathlib import Path
import integrate_20261010 as tool
from integrate_20261011_batches46_48 import item

def verify():
    p = Path('/private/tmp/cdx-ai-hk-course-b.Kmdirn/review-s3-721-725/verify_review.py')
    assert hashlib.sha256(p.read_bytes()).hexdigest() == 'dc417b8a1b64c904b0b532fcedbf030e7d4795d5f399f5c459543986b613e250'
    r = json.loads(subprocess.check_output([sys.executable, '-B', str(p)]))
    assert r['offline'] and r['checks'] == 1458 and r['all_XLSX_cells'] == 416
    assert r['original_XLSX_HTTP'] == r['original_negative_HTTP'] == 8
    assert r['DB_HTTP_executed'] == 0 and r['fixture_new_rows_per_side'] == 4
    subprocess.check_call(['git', '-C', str(tool.source_root('store')), 'merge-base', '--is-ancestor', r['candidate'], 'develop_dameng'])

if __name__ == '__main__':
    audit = Path(__file__).with_name('integration-20261013-subsidy-download.json')
    assert not audit.exists(), 'Never replay main'
    report = tool.STORE + 'parallel-subsidy-download-20261013/ROOT_REVIEW.md'
    rows = [item('store', 'GET', '/p/consumeSubsidy/' + action, '', evidence=report,
        success_case='partial-evidence-real-four-sheet-XLSX-nongrantable-owned-batch',
        readback='tested-pass-complete-owned-batch-detail-anomaly-and-wallet-protection',
        parity='partial-evidence-all-52cells-types-values-format-hidden-sheet-formula-samples',
        missing_required='partial-evidence-empty-and-missing-batch-original-JSON-errors',
        risk='read-only-export-no-calculation-or-grant') for action in ['download', 'exportDetail']]
    tool.main(rows, audit, verify)
