"""Independent real application test with deterministic fake provider.""" import json from pathlib import Path import sys import tempfile ROOT = Path('/home/xiaomo/multica_workspaces/hello-af23464d222e/hel-882-f72ebe62dddc/workdir') sys.path[:0] = [str(ROOT / 'CyberGril/src'), str(ROOT / 'CyberGril/tests')] from fastapi.testclient import TestClient from test_r4_api import r4_app from test_api import CREATE, turn, events with tempfile.TemporaryDirectory(prefix='hel874-api-review-', dir=ROOT) as td: app, provider = r4_app(Path(td), semantic='off') with TestClient(app) as client: assert client.post('/api/companion', json=CREATE).status_code == 201 guard = app.state.life.router.guard guard.config.daily_tokens = 1 guard.record(1, 'review_budget_already_used') used_before = guard.used calls_before = len(provider.calls) response = turn(client, '合成测试:额度用完后仍能发出请求吗') result = {'daily_tokens_limit': 1, 'used_before': used_before, 'used_after': guard.used, 'provider_requests_after_exhaustion': len(provider.calls)-calls_before, 'events': [e['t'] for e in events(response)], 'real_llm_requests': 0, 'real_embeddings': 0} (ROOT / 'HEL-874-api-independent.json').write_text(json.dumps(result, ensure_ascii=False, indent=2)) print(json.dumps(result, ensure_ascii=False, indent=2))