#!/usr/bin/env python3
"""Root-only integration of Store saveDishLimits limited empty-scope branch."""
import hashlib
import json
from pathlib import Path
import subprocess

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-bill-empty-limit-actual-20261011.vSDylW')
EVIDENCE = 'work_store/apifox/2026-09-30-dm8-interface-acceptance/parallel-store-bill-empty-limit-20261011/ROOT_REVIEW_SAVE_DISH_LIMITS_20261011.md'


def verify():
    assert (tool.ROOT / EVIDENCE).is_file()
    result = json.loads(subprocess.run(['node', str(PRIVATE / 'verify-final.js'), '--readonly'],
        check=True, capture_output=True, text=True).stdout)
    assert result['readonly'] and result['checks'] == 459 and result['files'] == 137
    assert result['DML'] == 0 and result['B_business_SELECT'] == 0 and result['C_business_fetch0']
    manifest = (PRIVATE / 'manifest.json').read_bytes()
    assert hashlib.sha256(manifest).hexdigest() == 'ac113cffc256e4bf6c521a8b3145ed6d800e8b5e515b63c3118bf613ea3a4d07'


def targets():
    base = EVIDENCE.rsplit('/ROOT_REVIEW', 1)[0] + '/'
    return [item('store', 'POST', '/p/bill/saveDishLimits', base, evidence=EVIDENCE,
        from_source='current-PC-client-and-controller-route-source', terminal='PC-recipe-management',
        role='existing-marked-type0-operator-restaurant-scoped', risk='empty-future-recipe-scope-limited-negative',
        scope='store-primary-2099-02-11-marked-restaurant-recipes-only',
        request_type='original-urlencoded-form-three-fields-no-files',
        success_case='partial-evidence-DM-empty-scope-native-fetch0-B-tool-denied-SHOW-before-business-query',
        mysql_state='inconclusive-tool-metadata-denied-before-business-select',
        dm_state='tested-pass-negative-empty-recipe-map-before-transaction',
        readback='limited-DM-successful-original-four-column-SELECT-fetch-empty; B-business-SELECT-not-executed',
        parity='limited-one-engine-only-original-negative-envelope; no cross-engine business-result claim',
        cleanup='recipe-projection-marked-R-actor-config-unchanged-workers-token-cache-released',
        missing_required='not-tested', invalid_type='not-tested', duplicate_retry='not-tested',
        boundary_empty_min_max='limited-one-empty-future-menu-date-and-marked-restaurant-only', performance='not-tested')]


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