#!/usr/bin/env python3
"""Record fixed approved leaf, retaining unrelated historical full-DTO difference."""
import hashlib
import json
import subprocess
from pathlib import Path
import integrate_20261010 as tool
from integrate_20261011_batches46_48 import item

HERE = Path(__file__).resolve().parent
ROOT = tool.ROOT.parent / 'worktrees/dm8-compat-20261012/private-prepay-harness/batch237-nonprinter-template-retest'
BASE = tool.STORE + 'parallel-equipment-template-audit-20261013/'


def verify():
    for name, sha in [('REPORT.md', '81273c4ef4e7dd24a9dce111057b0e54eeffb6d7b7ff6a5edb8a26f09b49a62d'),
                      ('verify_237_offline.php', '108e76718ddd0695950cc0082994c1bf062d24356ab446c91a3b5fbe02039b30')]:
        assert hashlib.sha256((ROOT / name).read_bytes()).hexdigest() == sha
    result = json.loads(subprocess.check_output(['/opt/homebrew/opt/php@7.4/bin/php', str(ROOT / 'verify_237_offline.php')]))
    assert result['checks'] == 85 and result['original_HTTP'] == {'B': 2, 'C': 2}
    raw = subprocess.check_output(['git', '-C', str(tool.source_root('store')), 'show', 'd167a25d0:application/p/logic/Equipment.php'])
    assert hashlib.sha256(raw).hexdigest() == '58b34ddb46fa1bf76c9846a191ab25880b893a0f8651473f2f515c27679a40c1'


if __name__ == '__main__':
    audit = HERE / 'integration-20261013-batch237.json'
    assert not audit.exists(), 'Never replay integration main'
    tool.main([
        item('store', 'POST', '/p/equipment/lists', BASE,
             success_case='partial-evidence-owned-type60-original-list-approved-template-fixed',
             parity='tested-fail-full-DTO-equality-historical-print-copies-B1-C2-remains-approved-template-leaf-fixed',
             cleanup='no-DML-entire-equipment-table-hash-unchanged-full-raw-private-worker-token-cleared'),
        item('store', 'POST', '/p/equipment/read', BASE, evidence_only=True)
    ], audit, verify)
