#!/usr/bin/env python3
"""Close the observed amount representation failure only; retain original red evidence."""
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-subsidy1361/verify_independent.py'
    assert hashlib.sha256(p.read_bytes()).hexdigest() == '25debe8a392bdcdd0e922281b4b7502ef299dbf29e0dd67edce6f62bb18256ad'
    r = json.loads(subprocess.check_output([sys.executable, '-B', str(p)]))
    assert r['passed'] and r['checks'] == 86514 and r['new_SQL_HTTP_business_CLI'] == r['writes'] == 0
    assert r['old_red_sealed_files'] == 17269 and r['new_sealed_files'] == 17265
    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-subsidy1361.json')
    assert not audit.exists(), 'Never replay main'
    report = 'work/2026-09-28-smart-canteen-dm8-poc/matrix-integration/ROOT_SUBSIDY1361_MERGE_20261014.md'
    specs = [item('store', 'POST', '/api/subsidyRule/' + action, '', evidence=report,
        scope='owned-disabled-rule-original-read-Service-DM-only-money-DTO-format',
        success_case='partial-evidence-nonempty-original-read-money-type-fixed-zero-amount-fixture',
        readback='tested-pass-full17-owned-rule-actor6-config6-native-types-unchanged-no-write',
        parity='partial-evidence-full-raw-JSON-identical-except-fixture-identity-trace-money-repair',
        boundary_empty_min_max=('partial-evidence-original-page2-empty-current-page1-preserved' if action == 'list' else 'not-tested-live-missing-or-personnel-branch'),
        cleanup='old-disabled-rule-retained-no-fixture-replay-own-workers-stopped') for action in ('list', 'detail')]
    tool.main(specs, audit, verify)
