VibeCoding / src /tests /runtime /test_unlimited_usage.py
dellweb3's picture
sol6.1 ERP稳定版本
115b94d verified
Raw History Blame Contribute Delete
2.48 kB
"""Local opt-in removes usage caps, never unknown-outcome or model-window checks."""
import unittest
from pathlib import Path
from types import SimpleNamespace
from src.modules.llm_gateway.service import LLMGateway
from src.adapters.persistence.runtime_sqlite import RuntimeStore
from src.modules.skill.domain.models import SkillError
from src.tests.runtime.fixtures import workspace
class UnlimitedUsageTests(unittest.TestCase):
def preflight(self,window=None):
return LLMGateway.preflight([{'content':'system'},{'content':'x'*32000}],{},
{'request':{'budget_policy':{'mode':'unlimited-usage-v1'}},'budget':{'max_tokens':1}},
[{'charged':120001,'reservation':0}],32000,12288,SimpleNamespace(context_window=window),'repair')
def test_large_repair_gets_full_output_without_stage_or_task_cap(self):
output,check=self.preflight()
self.assertEqual(output,12288)
self.assertIsNone(check['rejection']);self.assertIsNone(check['task_limit'])
def test_model_window_is_still_enforced(self):
self.assertEqual(self.preflight(32000)[1]['rejection'][0],'MODEL_CONTEXT_LIMIT_EXCEEDED')
def test_accounting_exceeds_old_limits_and_unknown_still_blocks(self):
with workspace() as folder:
store=RuntimeStore(Path(folder)/'runtime.sqlite')
body={'id':'r','tenant_id':'t','owner_id':'u','status':'running','request':{'budget_policy':{'mode':'unlimited-usage-v1'}},'budget':{'max_tokens':1,'max_model_calls':1}}
store.create(body,'key',{})
for _ in range(8):
call=store.reserve('r','model',[],150000);store.settle(call,'settled',130000)
self.assertEqual(sum(c['charged'] for c in store.calls('r')),1040000)
call=store.reserve('r','model',[],150000);store.settle(call,'unknown')
with self.assertRaises(SkillError) as error:store.reserve('r','model',[],150000)
self.assertEqual(error.exception.code,'MODEL_RESULT_UNKNOWN')
def test_existing_tasks_keep_their_limits(self):
with workspace() as folder:
store=RuntimeStore(Path(folder)/'runtime.sqlite')
store.create({'id':'r','tenant_id':'t','owner_id':'u','status':'running','request':{},'budget':{'max_tokens':1,'max_model_calls':1}},'key',{})
with self.assertRaises(SkillError) as error:store.reserve('r','model',[],2)
self.assertEqual(error.exception.code,'TASK_TOKEN_BUDGET_EXCEEDED')