#!/usr/bin/env python3
"""Existing GiftFlowList key: actual AI-engine date predicate and sum regression."""
import json
from pathlib import Path
import sys
import integrate_20261010 as tool
from integrate_20261011_batches40_42 import private_files, run, sha
from integrate_20261011_batches46_48 import item

BASE='work/2026-09-28-smart-canteen-dm8-poc/store-gift-date-filter-20261011/'
def verify():
    root=tool.ROOT/BASE/'private-evidence'
    assert sha(root/'manifest.json')=='7d6dc5f07713d8d69b15385cf3e7d9dfffb66dcacefeffe3a3d247a9560eaf26'
    records=tool.load(BASE+'private-evidence/manifest.json')['files'];assert len(records)==92
    private_files(root,{r['path']:r for r in records})
    for record in records:assert (root/record['path']).stat().st_size==record['bytes']
    result=json.loads(run(BASE,sys.executable,'verify.py'))
    assert result['passed'] and (result['HTTP_total'],result['successful_HTTP'],result['bootstrap_tool_HTTP500'])==(13,12,1)
    assert result['DML']==result['DDL']==0 and result['original_MySQL_date_failures']==3
    assert result['readonly_total']=={'B':134,'C':147}
    assert result['secret_original_response_deleted_irrecoverable']
    assert len(result['cases'])==12 and all(c['full_DTO_exact'] for c in result['cases'].values())
    run(BASE,sys.executable,'-m','unittest','discover','-p','test_verify.py')
    scan=tool.load(BASE+'secret-scan-summary.json');assert scan['passed']
    for lane,files in [('B',25),('C',16)]:
        assert scan['lanes'][lane]['matches']==0 and not scan['lanes'][lane]['secrets_persisted']
        c=tool.load(BASE+'cleanup.json')[lane]
        assert c['passed'] and c['port_closed'] and c['parent_alive_exact'] and c['DB_queries']==0
        assert c['raw_before']==c['raw_after'] and c['raw_after']['files']==files
        for target in ['private-request.json','auth-seed.json','auth-private.php','source.tgz']:
            assert c['removed'][target]==1
        assert c['removed']['source']>1000
    assert tool.load(BASE+'cleanup.json')['local_archive']['removed']
    assert sha(tool.ROOT.parent/'zhctproject/store/application/p/logic/AccountSetting.php')=='3cb6f3bea839149396b6b31f2c5d060e5d36057f9cfaad42b8b605b264e6e1cf'

if __name__=='__main__':
    audit=Path(__file__).with_name('integration-20261011-batch61.json')
    assert not audit.exists(),'Preserve original transition audit'
    targets=[item('store','POST','/p/accountSetting/giftFlowList',BASE,evidence_only=True,
        parity='partial-original-MySQL-date-bug-fixed-actual-AI-type-native-count-rows-two-SUM-boundaries-full-own-source-DM-byte-unchanged',
        boundary_empty_min_max='partial-include-two-pages-single-day-excluded-day-int-epoch-DM-datetime-and-existing-wide-reference')]
    tool.main(targets,audit,verify)
