#!/usr/bin/env python3
"""One real activity-type read through original customer secondary DB connection."""
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
PRIVATE = Path('/Users/wiscourper/Documents/workspace/local/dm8-store-purchase-read3-20261012.L5dTYR/stage3/activity-types-read-20261012')
BASE = 'work_store/apifox/2026-09-30-dm8-interface-acceptance/parallel-activity-types-20261012/'


def verify():
    for name, digest in [
        ('manifest.json', '1873ae6146a1db86eb336791fd042c12add5d569338cdabfe8275f2d31744b48'),
        ('verify.js', '573cf8acfec905ae8046d3d967cf7231dc515c3cb16c7b8534f4cdd94af076a1'),
        ('REPORT.md', 'e2a86986f9a6ccb21a7556821154fefc65d20e19b8c2053469cf0a5e5bb572f6'),
    ]:
        assert hashlib.sha256((PRIVATE / name).read_bytes()).hexdigest() == digest
    r = json.loads(subprocess.check_output(['node', str(PRIVATE / 'verify.js'), '--readonly']))
    assert r['readonly'] and r['checks'] == 351 and r['assets'] == 27
    assert r['new_keys'] == ['POST /p/activity/types']
    for lane, native, secondary in [('B', 4, 2), ('C', 8, 4)]:
        e = r['sides'][lane]
        assert e['HTTP'] == 1 and e['rows'] == 1 and e['bytes'] == 75
        assert e['original_native'] == native and e['AI_native'] == secondary
        assert e['strict_source_match'] and e['source_stable'] and e['NoAI_restored']


if __name__ == '__main__':
    audit = HERE / 'integration-20261012-batch137.json'
    assert not audit.exists()
    specs = [item('store', 'POST', '/p/activity/types', BASE,
        from_repo='unreviewed', from_source='apifox-2026-05-08',
        scope='original-customer-AI-secondary-connection-only-activity-type-table-read',
        readback='tested-pass-nonempty-secondary-source-query-real-parent-fetch-and-identity',
        parity='partial-evidence-original-full-HTTP-hash-types-values-order-equal',
        cleanup='NoAI-placeholder-restored-no-business-writes-private-runtime-retained')]
    tool.main(specs, audit, verify)
