Add pinned CPU engine dependencies, retained interrupted-response history, provider admission, offline evaluation and isolated browser tooling. Record Phase 2 acceptance and Phase 3/4 preparation, bounded paid-test accounting and interruption incident findings. Human interruption acceptance, paired OpenAI evaluation and rollback remain pending.
72 lines
3.2 KiB
Python
72 lines
3.2 KiB
Python
"""Provider-free regression check for the cumulative native-test budget."""
|
|
import asyncio
|
|
import importlib.util
|
|
import json
|
|
from pathlib import Path
|
|
import shutil
|
|
from tempfile import TemporaryDirectory
|
|
|
|
import httpx
|
|
|
|
spec = importlib.util.spec_from_file_location('budget', Path(__file__).with_name('native-budget-transport.py'))
|
|
budget = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(budget)
|
|
|
|
async def check():
|
|
with TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
for model in ('google/gemini-3.8-flash-lite-tts','openai/whisper-large-v3'):
|
|
name = 'endpoints-'+model.replace('/','-')+'.json'
|
|
shutil.copyfile(Path('.local-s2s-build')/name, root/name)
|
|
prior = root/'prior.json'
|
|
prior.write_text(json.dumps(dict(reserved_usd='0.56', paid_attempts=4)))
|
|
calls = []
|
|
def upstream(request):
|
|
calls.append(request)
|
|
return httpx.Response(503)
|
|
guard = budget.BudgetTransport(root, prior, upstream=httpx.MockTransport(upstream))
|
|
request = lambda: httpx.Request('POST','https://openrouter.ai/api/v1/audio/speech',
|
|
json={'model': budget.MODELS['speech'],'voice':'Kore','response_format':'pcm','input':'سلام'})
|
|
for _ in range(2):
|
|
result = await guard.handle_async_request(request())
|
|
assert result.status_code == 503
|
|
try:
|
|
await guard.handle_async_request(request())
|
|
except ValueError:
|
|
pass
|
|
else:
|
|
raise AssertionError('third TTS admitted')
|
|
assert len(calls) == 2
|
|
assert guard.state['reserved_usd'] == '0.970'
|
|
assert json.loads(guard.path.read_text())['reserved_usd'] == '0.970'
|
|
try:
|
|
budget.BudgetTransport(root, prior)
|
|
except FileExistsError:
|
|
pass
|
|
else:
|
|
raise AssertionError('existing ledger overwritten')
|
|
guard.state['reserved_usd'] = '.999'
|
|
try:
|
|
await guard.handle_async_request(httpx.Request('POST','https://openrouter.ai/api/v1/chat/completions',
|
|
json={'model':budget.MODELS['completions'],'messages':[], 'max_tokens':128}))
|
|
except ValueError:
|
|
pass
|
|
else:
|
|
raise AssertionError('cumulative overflow admitted')
|
|
assert len(calls) == 2
|
|
for data in ({'model':'wrong','voice':'Kore','response_format':'pcm','input':'سلام'},
|
|
{'model':budget.MODELS['speech'],'voice':'Kore','response_format':'pcm','input':'x'*4097}):
|
|
try:
|
|
budget.validate_request(httpx.Request('POST','https://openrouter.ai/api/v1/audio/speech',json=data))
|
|
except ValueError:
|
|
pass
|
|
else:
|
|
raise AssertionError('invalid input admitted')
|
|
_, rewritten = budget.validate_request(httpx.Request('POST','https://openrouter.ai/api/v1/chat/completions',
|
|
json={'model':budget.MODELS['completions'],'max_tokens':128,'messages':[]}))
|
|
assert json.loads(rewritten.content)['provider']['allow_fallbacks'] is False
|
|
await guard.close_owned()
|
|
print('PASS: price bounds, failed-attempt persistence, two-attempt limit, cumulative overflow, exclusive ledger, input/model and LLM route caps')
|
|
|
|
asyncio.run(check())
|