Spaces:
Sleeping
Sleeping
File size: 2,479 Bytes
115b94d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | """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')
|