#!/usr/bin/env python3
"""One-time intake: two bounded health paths, two original common failures."""
import hashlib
import json
import subprocess
import sys
from pathlib import Path
import integrate_20261010 as tool
from integrate_20261011_batches46_48 import item

HERE = Path(__file__).resolve().parent
REVIEW = Path('/private/tmp/cdx-ai-hk-course-b.Kmdirn/review-s2-391-402/verify_review.py')
COMMIT = 'c441957b156a6651657fc3191f4088c25fe4a274'
REPORT = tool.AI + 'parallel-health-cached-20261013/ROOT_REVIEW.md'


def verify():
    assert hashlib.sha256(REVIEW.read_bytes()).hexdigest() == '5e74fc36fb085896ff4946293917ba75fc9fe12895a2455add26afec93f9bafe'
    result = json.loads(subprocess.check_output([sys.executable, '-B', str(REVIEW)]))
    assert result['verified_bounded_evidence'] and result['checks'] == 655
    assert result['author_verifier']['checks'] == 10084
    assert result['retained_HTTP_wires'] == 23 and result['candidate_HTTP'] == 14
    for path, digest in result['candidate_source']['files'].items():
        for revision in (COMMIT, 'develop_dameng'):
            data = subprocess.check_output(['git', '-C', str(tool.source_root('ai_api')), 'show', revision + ':' + path])
            assert hashlib.sha256(data).hexdigest() == digest
    subprocess.check_call(['git', '-C', str(tool.source_root('ai_api')), 'merge-base', '--is-ancestor', COMMIT, 'develop_dameng'])


if __name__ == '__main__':
    audit = HERE / 'integration-20261013-health-cached.json'
    assert not audit.exists(), 'Never replay main'
    rows = [item('ai_api', method, path, '', evidence=REPORT,
        success_case='partial-evidence-owned-cached-health-or-internal-type4-type5-replacement',
        readback='tested-pass-complete-native-rows-selected-soft-delete-new-row-and-nine-table-protection',
        parity='partial-evidence-raw-full-JSON-types-values-no-real-external-generation',
        cleanup='owned-marked-data-retained-private-workers-stopped-original-C394-missing-not-replayed')
        for method, path in [('GET', '/api/health.Suggestion/info'), ('POST', '/api/health.Suggestion/replace')]]
    for path in ['/api/Dishes/all', '/api/Dishes/skuInfo']:
        rows.append(item('ai_api', 'GET', path, '', evidence=REPORT,
            mysql_state='tested-fail-original-missing-method-or-import',
            dm_state='tested-fail-original-missing-method-or-import',
            success_case='failed-common-source-disconnection-not-a-DB-compatibility-pass',
            readback='partial-evidence-no-business-write', parity='failed-original-common-error-both-engines'))
    tool.main(rows, audit, verify)
