#!/usr/bin/env python3
"""Source ownership, one genuine mismatch and one static contract; no full pass."""
import hashlib
import json
import subprocess
import sys
from pathlib import Path
import integrate_20261010 as tool
from integrate_20261011_batches46_48 import item

REPORT = 'work/2026-09-28-smart-canteen-dm8-poc/matrix-integration/ROOT_READ1221_RESULT_20261014.md'

def verify():
    base = tool.ROOT.parent / 'worktrees/dm8-compat-20261012/private-prepay-harness'
    for name, sha, key, n in [
        ('root-read1221/verify1221.py', '6635913beb54f71c685d8ffb478f98167248aabc5e6adfb65ce07208fb983e66', 'checks', 20011),
        ('review-read1221/verify_independent.py', '3511e3e832d852cc86ff7099eefecc62ad381fcf14f2384c2d2045ae57134749', 'checks', 230),
    ]:
        p = base / name
        assert hashlib.sha256(p.read_bytes()).hexdigest() == sha
        r = json.loads(subprocess.check_output([sys.executable, '-B', str(p)]))
        assert r[key] == n and r['business_all_pass'] is False

if __name__ == '__main__':
    audit = Path(__file__).with_name('integration-20261014-read1221.json')
    assert not audit.exists(), 'Never replay main'
    shared = dict(evidence=REPORT, from_repo='unreviewed', from_source='apifox-2026-05-08',
                  cleanup='marked-owned-row-retained-private-workers-stopped')
    specs = [
        item('store', 'POST', '/p/Ai/lists', '', **shared,
             scope='owned-AiConversation-original-SELECT-COUNT-native-row',
             mysql_state='tested-pass', dm_state='tested-fail-time-format-and-versioned-extra-field',
             success_case='failed-nonempty-time-and-schema-output-mismatch',
             readback='tested-pass-native-owned-row-values-types-unchanged-difference-preserved',
             parity='failed-create_time-representation-and-content_file_ossurl1-schema-extra',
             boundary_empty_min_max='partial-evidence-original-empty-page2-total1'),
        item('store', 'POST', '/p/Material/unit', '', **shared,
             scope='no-db', mysql_state='partial-evidence-static-handler-39-units',
             dm_state='partial-evidence-static-handler-39-units',
             success_case='partial-evidence-static-39-unit-HTTP-contract-no-Material-business-DB',
             readback='not-applicable',
             parity='partial-evidence-exact-source-39-constants-complete-JSON-types-values'),
    ]
    tool.main(specs, audit, verify)
