#!/usr/bin/env python3
"""Close the nine observed read DTO differences only after verified local merge."""
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 = tool.ROOT.parent / 'worktrees/dm8-compat-20261012/private-prepay-harness/review-subsidy1461/verify_independent.py'
    assert hashlib.sha256(p.read_bytes()).hexdigest() == 'a30deea6af3e4f197c6500a1d655d22a8d29a61ce9ad25fe86ae98db7318c5c2'
    r = json.loads(subprocess.check_output([sys.executable, '-B', str(p)]))
    assert r['passed'] and r['checks'] == 3037 and r['new_manifest_assets'] == 486
    assert r['old_red_assets'] == 479 and r['MySQL_golden_bytes'] == 100
    assert r['new_SQL_HTTP_business_CLI'] == r['writes'] == 0
    subprocess.check_call(['git', '-C', str(tool.source_root('store')), 'merge-base', '--is-ancestor', r['commit'], 'develop_dameng'])

if __name__ == '__main__':
    audit = Path(__file__).with_name('integration-20261014-subsidy1461.json')
    assert not audit.exists(), 'Never replay main'
    report = 'work/2026-09-28-smart-canteen-dm8-poc/matrix-integration/ROOT_SUBSIDY1461_MERGE_20261014.md'
    rows = [item('store', 'POST', '/api/subsidy/' + action, '', evidence=report,
        scope='owned-old-CDXPAY-original-two-DB-reads-DM-only-four-money-five-time-leaves',
        success_case='partial-evidence-nonempty-read-nine-DTO-differences-repaired-no-issuance',
        readback='tested-pass-full-batch28-detail15-grant17-Staff77-native-unchanged-actor6-config6x2-projections',
        parity='partial-evidence-MySQL-raw-except-trace-identical-DM-only-nine-approved-leaves-changed',
        cleanup='zero-new-rows-or-writes-old1401-red-sealed-workers-stopped')
        for action in ('detail', 'userList')]
    tool.main(rows, audit, verify)
