#!/usr/bin/env python3
"""Root-only ownership resolution and integration of two Store catalog GET-like POSTs."""
import hashlib
import json
from pathlib import Path
import subprocess
import sys

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-catalog-name-letter-actual-20261011.djaVOg')
EVIDENCE = 'work_store/apifox/2026-09-30-dm8-interface-acceptance/parallel-store-catalog-readonly-20261011/ROOT_REVIEW_CATALOG_READONLY_20261011.md'


def verify():
    assert (tool.ROOT / EVIDENCE).is_file()
    report = (PRIVATE / 'REPORT.md').read_bytes()
    assert hashlib.sha256(report).hexdigest() == '957bda005a7268e643e470ff92b493c92189e54e7548be2468565f9b8e56d8b9'
    manifest = (PRIVATE / 'manifest.json').read_bytes()
    assert hashlib.sha256(manifest).hexdigest() == '26231e8ac52f7821848357aa02dc57faacb306ae318be0602cd4bf4129421254'
    result = json.loads(subprocess.run(['node', str(PRIVATE / 'verify-final.js'), '--readonly'],
        check=True, capture_output=True, text=True).stdout)
    assert result == {'readonly': True, 'checks': 651, 'files': 106, 'all_sha_bytes_mode': True,
        'HTTP': 4, 'combined_new_reads': 129, 'DML': 0, 'no_full_dish_data': True}


def targets():
    base = EVIDENCE.rsplit('/ROOT_REVIEW', 1)[0] + '/'
    shared = dict(from_repo='unreviewed', from_source='apifox-2026-05-08',
        terminal='current-PC-catering-management-client', role='existing-marked-normal-admin-auth',
        request_type='actual-current-application-x-www-form-urlencoded-form',
        mysql_state='tested-pass', dm_state='tested-pass',
        readback='partial-evidence-original-SQL-success-actual-nonempty-fetch-and-own-database-full-typed-source-projection-equal',
        parity='partial-evidence-each-engine-response-exactly-matched-its-own-source; natural B/C snapshot values not compared',
        cleanup='no-business-writes-own-token-private-cache-worker-released-source-and-protected-dish-projections-unchanged',
        missing_required='not-tested', invalid_type='not-tested', duplicate_retry='not-applicable-read-only',
        performance='not-tested')
    return [
        item('store', 'POST', '/p/cater/allDishesName', base, **shared,
            risk='readonly-active-dish-name-catalog',
            scope='Store-primary-current-dish-source-per-own-engine-tenant-distribution-verified',
            evidence=EVIDENCE, success_case='partial-evidence-nonempty-name-as-value-and-label-source-projection-per-engine',
            boundary_empty_min_max='partial-evidence-current-nonempty-catalog-only-no-filter-or-order-contract'),
        item('store', 'POST', '/p/bill/getLetter', base, **shared,
            evidence=EVIDENCE, risk='readonly-type1-first-letter-dish-source',
            scope='Store-primary-dishes-where-is_del1-status1-type1-only-no-staff-food-or-recipe-branch',
            success_case='partial-evidence-nonempty-six-category-object-source-projection-per-engine',
            boundary_empty_min_max='partial-evidence-type1-current-snapshot-only-menu_date-not-filtered-and-other-types-unmeasured')]


if __name__ == '__main__':
    audit = HERE / 'integration-20261011-batch105.json'
    assert not audit.exists(), 'Preserve previous integration evidence'
    tool.main(targets(), audit, verify)
