#!/usr/bin/env python3
"""Only actual owned Grade/Plan configuration CRUD; no recharge/payment claim."""
from pathlib import Path
import subprocess
import sys
import integrate_20261010 as tool
E = tool.AI + 'parallel-ai-grade-recharge-config-20261010/'

def verify():
    for name in ['compare.py', 'test_compare.py']:
        subprocess.run([sys.executable, str(tool.ROOT / E / name)], check=True, capture_output=True)
    clean = tool.load(E + 'cleanup.json')
    assert not clean['all_same_named_ids_claimed_zero'] and not clean['natural_training_rows_deleted_or_modified']
    assert not clean['real_money_or_external_side_effects'] and not clean['original_services_stopped']
    for label, port in [('B', 18321), ('C', 18322)]:
        lane = clean[label]
        assert lane['fresh_pdo_two_owned_tables_zero'] and lane['natural_two_tables_full_sha_unchanged']
        assert lane['semantic_reference_columns_checked'] == 7 and lane['semantic_owned_references_zero']
        assert lane['file_tokens_absent'] and lane['private_cache_files_remaining'] == 0
        assert not lane[f'port_{port}_listening']

def targets():
    data = tool.load(E + 'comparison.json')
    assert data['http_pairs'] == 46 and data['independent_original_pairs'] == 20
    out = []
    for actual in data['actual_methods']:
        method, path = actual.split(' ', 1)
        grade = 'user.Grade' in path
        out.append(dict(repo='ai_api', method=method, path=path,
            module='会员等级配置' if grade else '充值套餐配置',
            terminal='设备端' if path.startswith('/terminal/') else 'PC端',
            role='private-owned-merchant-configuration', risk='read' if method == 'GET' else 'configuration-write',
            scope='ai-primary-own-user-grade-recharge-plan-only-no-account-money-mutation',
            evidence=E + 'REPORT.md', request_type='GET-query' if method == 'GET' else 'application/json-form-object-numeric-identifiers',
            parity='partial-evidence-46-pairs-full-wire-values-types-order-and-20-original-row-proofs',
            boundary_empty_min_max='partial-evidence-JSON-value-types-empty-pages-Chinese-quotes-stored-money-rounding',
            duplicate_retry='partial-evidence-duplicate-grade-weight-refused-and-owned-soft-delete'))
    assert len(out) == 18
    return out

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