#!/usr/bin/env python3
"""Eight Store getters: three partial business paths, five limited; no inflated pass."""
import hashlib
import json
from pathlib import Path
import stat
import subprocess
import integrate_20261010 as tool
from integrate_20261011_batches46_48 import item

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

def verify():
    root = tool.ROOT / BASE
    manifest = root / 'private/read8-manifest.json'
    assert hashlib.sha256(manifest.read_bytes()).hexdigest() == '904a4d2774127bbc77a55a37c2ab1f6eac1f6302f5108bdac47ac2c3d3734d73'
    frozen = json.loads(manifest.read_text())
    assert len(frozen['files']) == 237
    modes = 0
    for record in frozen['files']:
        relative = Path(record['path'])
        assert not relative.is_absolute() and '..' not in relative.parts
        p = root / relative
        assert p.is_file() and not p.is_symlink()
        raw = p.read_bytes()
        assert len(raw) == record['bytes'] and hashlib.sha256(raw).hexdigest() == record['sha256']
        if 'mode' in record:
            assert format(stat.S_IMODE(p.stat().st_mode), 'o') == record['mode'].removeprefix('0o')
            modes += 1
    assert modes == 226  # Eleven original manifest entries never froze mode.
    assert frozen['protection']['B_all_staff_unchanged'] is False
    assert frozen['protection']['B_unknown_delta'] == ['ydy_staff']
    assert frozen['protection']['C_same_tables'] == 17
    assert frozen['verifier']['checks'] == 164 and frozen['verifier']['mutations'] == 72
    for lane, http, reads in [('B', 13, 595), ('C', 12, 677)]:
        facts = frozen['facts'][lane]
        assert facts['actual_HTTP'] == http and facts['total_readonly'] == reads
        assert facts['new_DML'] == facts['new_DDL'] == 0 and facts['own_resources_clean']
    r = json.loads(subprocess.run(['node', str(root / 'food-date-root-runner-20261011/read8-root-readonly-recheck.js')], check=True, capture_output=True, text=True).stdout)
    assert r['writes'] == r['SQL'] == r['DB'] == 0 and r['immutable_artifacts_compared'] == 3

def targets():
    out = []
    for path in ['/p/role/getData', '/p/role/getDataCheked', '/p/user/dataPermissionInfo',
                 '/p/cater/aiImportTaskList', '/p/materialAnnex/lists',
                 '/p/employmentState/info', '/p/engineryIochemistry/lists', '/p/engineryIochemistry/info']:
        extra = dict(evidence=BASE + 'READ8_REPORT.md', request_type='application/json',
            scope='customer-primary-source-readonly-typed-projections-B-staff-global-drift-unattributed',
            parity='partial-evidence-per-side-whole-source-DTO-natural-snapshots-not-cross-value-equality',
            cleanup='workers-auth-cache-source-released-C17-and-B16-tables-stable-B-staff-drift-unattributed',
            risk='readonly-auth-and-source-data-contract',
            success_case='partial-evidence-original-nonempty-source-and-parameter-boundary-only')
        if path == '/p/role/getData':
            extra.update(mysql_state='partial-evidence-server-DTO-only-no-wire-native-client-timeout',
                success_case='partial-evidence-C-nonempty-B-server-only-DTO-not-end-to-end',
                performance='not-accepted-original-B500-and-client-timeout-no-third-replay')
        elif path in ['/p/materialAnnex/lists', '/p/employmentState/info', '/p/engineryIochemistry/lists', '/p/engineryIochemistry/info']:
            extra.update(mysql_state='partial-evidence-original-empty-or-not-found-only',
                dm_state='partial-evidence-original-empty-or-not-found-only',
                success_case='partial-evidence-empty-or-missing-parameter-contract-no-nonempty-business-sample',
                boundary_empty_min_max='partial-evidence-empty-array-or-null-or-absent-data-key-as-original')
        if path in ['/p/role/getDataCheked', '/p/user/dataPermissionInfo', '/p/engineryIochemistry/info']:
            extra['missing_required'] = 'partial-evidence-original-missing-parameter-envelope-and-data-key-contract'
        if '/role/' in path:
            extra['performance'] = 'not-accepted-large-tree-latency-and-B-staff-window-drift'
        out.append(item('store', 'POST', path, BASE, **extra))
    return out

if __name__ == '__main__':
    audit = Path(__file__).with_name('integration-20261011-batch89.json')
    assert not audit.exists(), 'Preserve one-time limited-evidence integration'
    tool.main(targets(), audit, verify)
