"""Controlled HTTP/SOAP fault matrix; original client with existing mock transport."""
import hashlib
import importlib.metadata
import json
import sys
from decimal import Decimal
from pathlib import Path

project=Path.cwd()  # Reader adaptation: run from the pinned example directory.
sys.path[:0]=[str(project),str(project/'tests')]
import httpx
from test_ci_vendor_free import TransferFaultMapping, fault_reply

rows=[]
for status in (200,500,503):
    for side in ('Client','Server'):
        for code in (None,'100199','400001','999999'):
            authored=fault_reply(side,code)
            reply=httpx.Response(status,content=authored.content)
            client=TransferFaultMapping().client(reply)
            try:
                result=client.transfer(('1','D'),('2','S'),Decimal('5'))
            except Exception as error:
                result=type(error).__name__
            rows.append({'authoredHttpStatus':status,'authoredSoapSide':side,'authoredBusinessCode':code,'observedResult':result})
assert len(rows)==24
for row in rows:
    expected='refused' if row['authoredSoapSide']=='Client' or row['authoredBusinessCode'] in {'100199','400001'} else 'UnknownOutcome'
    assert row['observedResult']==expected,row
print(json.dumps({'sourceRevision':'b5a308ecd9acdc795ce56260ec81c21c879aa9c7',
 'clientSha256':hashlib.sha256((project/'silverlake_demo/client.py').read_bytes()).hexdigest(),
 'fixtureSourceSha256':hashlib.sha256((project/'tests/test_ci_vendor_free.py').read_bytes()).hexdigest(),
 'sdkVersion':importlib.metadata.version('rasa-pro'),
 'scope':'24 authored SOAP fault/HTTP status combinations through original client and existing StubContract/httpx.MockTransport; no physical server, actual vendor schema, bank, model or speech; not independent production observations',
 'rows':rows},indent=2))
