Spaces:
Sleeping
Sleeping
Download src/tests/runtime/test_logistics_budget.py from dellweb3/VibeCoding: direct link, hf CLI and curl.
- Browser
- Download file 3.93 kB
-
https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/tests/runtime/test_logistics_budget.py
- Command line
-
hf download hf://spaces/dellweb3/VibeCoding/src/tests/runtime/test_logistics_budget.py
-
curl -L -o test_logistics_budget.py https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/tests/runtime/test_logistics_budget.py
3.93 kB
| """Fixed logistics requirement, synthetic budget arithmetic and atomic approval API.""" | |
| import unittest | |
| from types import SimpleNamespace | |
| from src.modules.orchestrator.budget_approval import propose | |
| REQUIREMENT='帮我开发一个物流管理的程序,作为物流公司,能够检索到当前订单的状态,并根据实际的物流进行状态调整。' | |
| class ProposalTests(unittest.TestCase): | |
| def test_stage_shortage_requests_one_fixed_increment(self): | |
| run,check,calls=self.fixture() | |
| check.update(input_bound=35295,model_context_limit=None,model='deepseek-v4-flash-0731') | |
| p,error=propose(run,check,calls,1000) | |
| self.assertIsNone(error);self.assertEqual(p['stage_limit'],44000) | |
| self.assertEqual(p['stage_delta'],12000);self.assertEqual(p['task_limit'],132000) | |
| self.assertEqual(p['task_remaining'],92148);self.assertFalse(p['model_context_limit_verified']) | |
| def fixture(self): | |
| run={'id':'logistics','request':{'requirement':REQUIREMENT},'snapshot':{'snapshot_digest':'fixed'}, | |
| 'cursor':8,'repairs':1,'repair_pending':True,'outputs':{},'budget':{'max_tokens':120000,'max_model_calls':6}} | |
| calls=[{'id':i,'state':'settled','charged':n,'reservation':n} for i,n in enumerate((10000,10000,7852))] | |
| check={'stage':'repair','model':'simulated-logistics-model','stage_limit':32000,'input_bound':42000,'output_target':12288, | |
| 'minimum_output':128,'estimator':'utf8-byte-upper-bound-v1','safety_tokens':512, | |
| 'model_context_limit':200000,'rejection':['STAGE_CONTEXT_BUDGET_EXCEEDED','stage only']} | |
| return run,check,calls | |
| def test_stage_shortage_is_not_total_shortage_or_account_balance(self): | |
| run,check,calls=self.fixture();p,error=propose(run,check,calls,1000) | |
| self.assertIsNone(error);self.assertEqual(p['stage_limit'],44000);self.assertEqual(p['stage_delta'],12000) | |
| self.assertEqual(p['task_limit'],132000);self.assertEqual(p['task_delta'],12000) | |
| self.assertEqual(p['task_remaining'],92148);self.assertEqual(p['adjustment'],'stage_and_task') | |
| self.assertEqual(p['model'],'simulated-logistics-model');self.assertIsNone(p['currency_estimate']) | |
| self.assertEqual(p['provider_balance'],'not_verified') | |
| def test_total_budget_adjustment_is_explicit_and_accounted(self): | |
| run,check,calls=self.fixture();run['budget']['max_tokens']=30000 | |
| p,error=propose(run,check,calls,1000) | |
| self.assertIsNone(error);self.assertEqual(p['task_limit'],42000);self.assertEqual(p['task_delta'],12000) | |
| self.assertEqual(p['output_reservation'],0) # Approval never promises the next call fits. | |
| self.assertEqual(p['adjustment'],'stage_and_task') | |
| def test_hard_window_rejects_or_caps_output_without_raising_window(self): | |
| run,check,calls=self.fixture() | |
| p,error=propose(run,check,calls,1000,SimpleNamespace(model='model',context_window=40000)) | |
| self.assertIsNone(p);self.assertEqual(error,'MODEL_CONTEXT_LIMIT_EXCEEDED') | |
| p,error=propose(run,check,calls,1000,SimpleNamespace(model='model',context_window=45000)) | |
| self.assertIsNone(error);self.assertEqual(p['output_reservation'],2000) | |
| self.assertEqual(p['stage_limit'],44000) | |
| def test_unknown_call_and_nonbudget_error_are_not_approvable(self): | |
| run,check,calls=self.fixture();calls[-1].update(state='unknown',charged=None) | |
| self.assertEqual(propose(run,check,calls,1000)[1],'MODEL_RESULT_UNKNOWN') | |
| calls[-1].update(state='settled',charged=7852) | |
| for code in ['MODEL_CONTEXT_LIMIT_EXCEEDED','MODEL_QUOTA_REJECTED','JAVA_TEST_FAILED','SANDBOX_CAPACITY_EXCEEDED']: | |
| check['rejection']=[code,'not a budget adjustment'] | |
| self.assertEqual(propose(run,check,calls,1000)[1],'BUDGET_NOT_ADJUSTABLE') | |
| if __name__=='__main__':unittest.main() | |