#!/usr/bin/env python3
"""Intake only the verified three-leaf User DTO repair; retain historical red."""
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-user1661/verify_independent.py'
    assert hashlib.sha256(p.read_bytes()).hexdigest() == '981f1b4b87d04b581b9b5bcda5b5a1e9126862451bcc431c9ae39a39e6aeb77f'
    result = json.loads(subprocess.check_output([sys.executable, '-B', str(p)]))
    assert result['passed'] and result['checks'] == 20356
    assert result['new_SQL'] == result['new_HTTP'] == 0
    assert result['old_1621_red_seal_unchanged']
    subprocess.check_call(['git', '-C', str(tool.source_root('store')), 'merge-base', '--is-ancestor',
                           '89dcb58610178e8c9c843665d68c4e123ec025be', 'develop_dameng'])

if __name__ == '__main__':
    audit = Path(__file__).with_name('integration-20261014-user1661.json')
    assert not audit.exists(), 'Never replay main'
    report = 'work/2026-09-28-smart-canteen-dm8-poc/matrix-integration/ROOT_USER1661_MERGE_20261014.md'
    rows = [item('store', 'POST', '/m/user/' + action, '', evidence=report,
        scope='owned-old-CDXPPREF-user-readonly-actual-DM-three-leaf-DTO-repair',
        success_case='partial-evidence-original-getuserinfo-three-leaf-format-fixed-assets-regression',
        readback='tested-pass-original-User40-native-types-values-nutrition0-config6-unchanged',
        parity='partial-evidence-original-MySQL-and-assets-unchanged-DM-only-three-approved-leaves',
        cleanup='zero-writes-old1621-red-retained-workers-stopped-local89dcb5861-no-business-push')
        for action in ('getuserinfo', 'assets')]
    tool.main(rows, audit, verify)
