#!/usr/bin/env python3
"""Register observed underscore mobile URLs; do not relabel unobserved aliases."""
import hashlib
import json
import subprocess
import sys
from pathlib import Path
import integrate_20261010 as tool
from integrate_20261011_batches46_48 import item

REPORT = tool.STORE + 'parallel-menu-write-float-20261013/ROOT_REVIEW.md'
PRIVATE = tool.ROOT.parent / 'worktrees/dm8-compat-20261012/private-prepay-harness'

def verify():
    original = Path('/Users/wiscourper/Documents/workspace/local/dm8-independent-20261013/session-store-nutrition/verify-writes-472-479.py')
    independent = PRIVATE / 'review-s1-writes472-479/verify_independent.py'
    assert hashlib.sha256(original.read_bytes()).hexdigest() == '2db9627f39d2dd774b65ce93ace328ac5a3f78e03ee4a5d2ac4e51158c773fa7'
    assert hashlib.sha256(independent.read_bytes()).hexdigest() == '8eccbd2e65381071ff40ad2594a046b8978fa21eba6afba2e7a8e01f286a0349'
    a = json.loads(subprocess.check_output([sys.executable, '-B', str(original)]))
    b = json.loads(subprocess.check_output([sys.executable, '-B', str(independent)]))
    assert a['offline'] and a['checks'] == 62268 and a['baseline_physical_reds_and_log_red_preserved']
    assert b['passed'] and b['checks'] == 601 and b['original_business_HTTP'] == 24
    assert b['new_HTTP'] == b['new_DB'] == 0
    subprocess.check_call(['git', '-C', str(tool.source_root('store')), 'merge-base', '--is-ancestor', 'bf4c78b163effa0c72e422cabd1c49c260c26762', 'develop_dameng'])

if __name__ == '__main__':
    audit = Path(__file__).with_name('integration-20261013-menu-writes.json')
    assert not audit.exists(), 'Never replay main'
    rows = [item('store', 'POST', '/p/datemenu/' + action, '', evidence=REPORT, evidence_only=True)
            for action in ['editmenu', 'getmenuinfo']]
    for action, line in [('submitmenu', 60), ('editnumber', 119), ('delmenu', 90)]:
        rows.append(item('store', 'POST', '/m/date_menu/' + action, '', evidence=REPORT,
            register_new_runtime_key=True, runtime_observed_method='POST',
            runtime_inventory_scope='controller-direct-http-observed', runtime_direct_http_proof=REPORT,
            runtime_controller_source='application/m/controller/DateMenu.php:' + str(line) + ' actual-original-POST-no-client-usage-claim',
            success_case='partial-evidence-own-mobile-menu-write-original-contract-and-native-FLOAT-storage',
            readback='tested-pass-complete-owned-native-rows-and-original-transaction-closure',
            parity='partial-evidence-full-JSON-and-binary32-promoted-values-original-MySQL-unchanged'))
    tool.main(rows, audit, verify)
