#!/usr/bin/env python3
"""New Food marked CRUD closes four targeted date failures, not downstream sync."""
import hashlib
import json
from pathlib import Path
import subprocess
import integrate_20261010 as tool
from integrate_20261011_batches46_48 import item

BASE = tool.STORE + 'parallel-store-food-crud3-20261011/repaired-food-fixture2-20261011/'

def verify():
    script = Path(__file__).with_name('verify_food_fixed_readonly_20261011.mjs')
    r = json.loads(subprocess.run(['node', str(script)], check=True, capture_output=True, text=True).stdout)
    assert r['actual_FS_writes'] == r['SQL'] == r['HTTP'] == 0
    assert r['checks'] == 733 and r['sealed_assets'] == 189 and r['mutations'] == 5
    for lane, reads, cumulative in [('B', 118, 713), ('C', 159, 836)]:
        s = r['summary'][lane]
        assert s['HTTP'] == 8 and s['INSERT'] == s['UPDATE'] == s['DELETE'] == 1
        assert s['new_read'] == reads and s['cumulative'] == cumulative
        assert s['all_natural_batch_unchanged'] and s['own_row_deleted'] and s['own_resources_clean']
        assert s['AI_sync_NOT_TESTED'] and s['Tchef_sync_NOT_TESTED']
        assert r['dates'][lane]['actual_auto_update_time_advanced']
    pins = tool.load('work/2026-09-28-smart-canteen-dm8-poc/matrix-integration/STORE_APPLICATION_20261011_1034.json')
    assert len(pins) == 959
    for name, digest in pins.items():
        assert hashlib.sha256((tool.ROOT.parent / 'zhctproject/store/application' / name).read_bytes()).hexdigest() == digest

def targets():
    return [item('store', 'POST', '/p/food/' + action, BASE,
        request_type='application/json-string-add-number-update-original-mixed-PDO-binding',
        scope='customer-primary-own-Food62-CRUD-only-AI-transport-explicit-false-Tchef-process-isolated',
        risk='original-nutrition-numeric-input-and-date0-default-auto-update-contract',
        success_case='partial-evidence-new-marked-CRUD-all62-native-columns-date0-default-and-real-automatic-update',
        parity='partial-evidence-eight-whole-DTO-pairs-four-proven-environment-fields-only-mapped-after-native-date-proof',
        boundary_empty_min_max='partial-evidence-original-delete-detail-null-list-empty-old-edible0-contract-retained',
        cleanup='new-own-row-exact-approved-delete-natural-closure-source959-and-own-worker-auth-cache-released')
        for action in ['add', 'update', 'delete', 'readById', 'lists']]

if __name__ == '__main__':
    audit = Path(__file__).with_name('integration-20261011-batch91.json')
    assert not audit.exists(), 'Preserve original red and repaired transition audits'
    tool.main(targets(), audit, verify)
