#!/usr/bin/env python3
"""Enhance one export, recover two User reads, retain true DTO incompatibility."""
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():
    base = tool.ROOT.parent / 'worktrees/dm8-compat-20261012/private-prepay-harness'
    for name, digest, counter, value in [
        ('review-staff1601/verify_independent.py', 'eee65bccd6711d03e192009f7f7c6e1f2bfff82fef48a7146318cc066bba630b', 'independent_checks', 4889),
        ('review-user1621/verify_independent.py', 'afb654576de7d23c44a3498e0d4f76b769f3aeb5145eb2aae8e4834f6dff307a', 'checks', 20265),
    ]:
        p = base / name
        assert hashlib.sha256(p.read_bytes()).hexdigest() == digest
        r = json.loads(subprocess.check_output([sys.executable, '-B', str(p)]))
        assert r['passed'] and r[counter] == value
        if 'staff' in name:
            assert r['new_SQL_HTTP_PHP_remote'] == r['original_writes'] == 0 and r['author_checks'] == 2103
        else:
            assert r['new_SQL'] == r['new_HTTP'] == r['business_execution'] == 0

if __name__ == '__main__':
    audit = Path(__file__).with_name('integration-20261014-staff1601-user1621.json')
    assert not audit.exists(), 'Never replay main'
    report = 'work/2026-09-28-smart-canteen-dm8-poc/matrix-integration/ROOT_1601_1621_ACCEPTANCE_20261014.md'
    rows = [item('store', 'GET', '/p/staff/export', '', evidence=report,
        scope='one-old-CDX762-person-original-XLS-authorized-three-field-association-readonly',
        success_case='partial-evidence-original-nonempty-one-person-export-all22-cells-typed',
        readback='tested-pass-three-old-owned-rows-and-exact-empty-wallet-card-unchanged-natural-association-summary-only',
        parity='partial-evidence-XLS-22cells-XF-equal-owned-name-dept-mapping-leading-zero-text-balances-implicit-blank',
        cleanup='zero-new-rows-old762-retained-private-worker-stopped-original-XLS-unchanged')]
    for action in ('assets', 'getuserinfo'):
        red = action == 'getuserinfo'
        rows.append(item('store', 'POST', '/m/user/' + action, '', evidence=report,
            from_repo='unreviewed', from_source='apifox-2026-05-08',
            scope='existing-exact-CDXPPREF-user40-columns-private-original-token-readonly-nutrition-count0',
            mysql_state='tested-pass', dm_state='tested-fail-money-types-and-zero-fraction-time-DTO' if red else 'tested-pass',
            success_case='failed-two-money-types-date-format-keep-fixture-salt-time-differences-separate' if red else 'partial-evidence-original-user-assets-query-static-points-coupon0',
            readback='tested-pass-full-own-User40-native-values-types-nutrition0-config6-projections-unchanged',
            parity='failed-DM-two-money-types-time-representation-original-dynamic-field-preserved' if red else 'partial-evidence-full9-JSON-paths-original-assets-equal-except-trace',
            cleanup='zero-writes-old-own-user-retained-private-workers-stopped-no-HTTP-replay'))
    tool.main(rows, audit, verify)
