#!/usr/bin/env python3
"""Coupon schema red-to-green: upgrade two explicit failures only after real HTTP."""
from pathlib import Path
import integrate_20261010 as tool
E = tool.AI + 'parallel-ai-coupon-schema-align-20261010/http-retest/'

def verify():
    r = tool.load(E + 'results.json')
    assert r['status'] == 'pass' and r['pair_count'] == r['pair_pass'] == 16
    assert r['strict_full_response_pairs'] == 10 and r['strict_owned_row_pairs'] == 5
    assert r['cleanup_presence_pairs'] == 1
    for lane in ['B', 'C']:
        p = r['lanes'][lane]
        assert p['cases'] == p['source_pass'] == 16 and p['natural_before'] == p['natural_after']
        assert p['actors_unchanged'] and p['token_cleaned'] and p['external_attempts'] == 0
        assert p['cleanup'] == {'coupon': 1, 'user_coupon': 1}
        assert p['independent_remaining'] == {'coupon': 0, 'user_coupon': 0}
        assert p['http_writes'] == {'insert': 1, 'update': 1}
    clean = tool.load(E + 'ROOT_CLEANUP_POSTCHECK.json')
    for lane, port in [('B',18351), ('C',18352)]:
        assert clean[lane] == {f'port_{port}_listening': False, 'cache_files': 0, 'state_file_exists': False}
    meta = tool.load(tool.AI + 'parallel-ai-coupon-schema-align-20261010/INDEPENDENT_METADATA_POSTCHECK.json')
    assert meta['source_comments_match'] and len(meta['unsigned_constraints']) == 4
    assert all(c['status'] == 'ENABLED' and c['validated'] == 'VALIDATED' for c in meta['unsigned_constraints'])

def targets():
    return [dict(repo='ai_api', method=m, path=p, module='优惠券领取及列表', terminal='移动端',
        role='private-approved-synthetic-mobile-actor-owned-coupon', risk='read' if m=='GET' else 'coupon-write',
        scope='ai-primary-own-coupon-claim-real-transaction-store-actor-mapping-readonly',
        evidence=E+'REPORT.md', request_type='GET-query' if m=='GET' else 'application/x-www-form-urlencoded',
        parity='partial-evidence-16-pairs-10-full-responses-five-owned-rows-all-new-fields-source-verified',
        duplicate_retry='partial-evidence-repeat-receive-rejected-source-unchanged-and-zero-DML',
        boundary_empty_min_max='partial-evidence-NULL-zero-nonzero-ID-and-money-Chinese-JSON-32767-32768-byte-CLOB')
        for m,p in [('GET','/api/Coupon/list'),('GET','/api/MyCoupon/list'),('POST','/api/MyCoupon/receive')]]

if __name__ == '__main__':
    tool.main(targets(), Path(__file__).with_name('integration-20261010-batch12.json'), verify)
