Files
rag-technical-docs-assistant/docs/evaluation/local-s2s/check-phase4-browser-budget.py
T
11linear11 a94b8cd3ea feat(voice): implement local S2S retained history and provider selection
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.
2026-10-16 17:09:27 -04:00

28 lines
1.5 KiB
Python

import importlib.util,tempfile,shutil,json,asyncio
from pathlib import Path
import httpx
s=importlib.util.spec_from_file_location('guard','docs/evaluation/local-s2s/phase4-browser-budget.py');m=importlib.util.module_from_spec(s);s.loader.exec_module(m)
async def main():
with tempfile.TemporaryDirectory() as d:
p=Path(d)
for f in Path('.local-s2s-build/phase4-browser-paid').glob('*.json'):
if f.name!='browser-paid-ledger.json':shutil.copyfile(f,p/f.name)
calls=[]
def mock(r):calls.append(r);return httpx.Response(503)
g=m.BrowserBudget(p,upstream=httpx.MockTransport(mock))
assert g.state['maximum_cumulative_usd']=='0.774504399'
request=httpx.Request('POST','https://openrouter.ai/api/v1/audio/speech',json={'model':'google/gemini-3.8-flash-lite-tts','voice':'Kore','input':'سلام','response_format':'pcm'})
for _ in range(6):await g.handle_async_request(request)
try:await g.handle_async_request(request)
except ValueError:pass
else:raise AssertionError('quota bypass')
assert g.state['last_denial']=={'stage':'speech','reason':'attempt_limit','admitted_attempts':6}
assert len(calls)==6 and len(g.state['attempts'])==6
assert g.state['unknown_prior_reservations_usd']=='0.417'
try:m.BrowserBudget(p,upstream=httpx.MockTransport(mock))
except FileExistsError:pass
else:raise AssertionError('ledger overwritten')
await g.close_owned()
print('PASS: carried exposure, fresh exclusive ledger, failure reservations, six-attempt ceiling, current prices')
asyncio.run(main())