Spaces:
Sleeping
Sleeping
File size: 3,284 Bytes
5ca3c16 | 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 43 44 45 46 47 48 49 50 51 52 53 | """Business profiles bind only technical limits, not a purchase-specific UI."""
import unittest
from src.modules.execution.scenarios import business_app
from src.modules.harness.policy import Harness
from src.modules.skill.domain.models import SkillError
from src.modules.skill.packs.examples import framework_candidate
from src.modules.orchestrator.service import AgentRuntime
class RequirementBusinessTests(unittest.TestCase):
def setUp(self):
self.profile=framework_candidate().model_copy(update={'profile_id':business_app.PROFILE,
'allowed_paths':['src/main/','website/'],'state':'approved'}).model_dump()
self.harness=Harness(enabled=True,allow_qemu=True)
def test_model_can_supply_business_java_and_matching_html(self):
page='<html><style>body{color:blue}</style><h1>物流单</h1><script>window.zkRequest("GET","/api/app/list")</script></html>'
source=self.harness.files({'files':{business_app.JAVA:'class App {}',business_app.PAGE:page}},self.profile)
self.assertEqual(source['files'][business_app.PAGE],page)
self.assertEqual(source['files'][business_app.JAVA],'class App {}')
def test_generated_page_cannot_bypass_controlled_bridge(self):
page='<html><style></style><script>fetch("/api/admin")</script></html>'
with self.assertRaises(SkillError):
self.harness.files({'files':{business_app.JAVA:'class App {}',business_app.PAGE:page}},self.profile)
def test_recovery_reuses_original_design_without_model_call(self):
from unittest.mock import Mock
runtime=object.__new__(AgentRuntime);runtime.store=Mock();runtime.llm=Mock()
original={'summary':'物流单、查询与处理;其余为待确认假设'}
run={'id':'recovery','request':{'preserved_design':original}}
result=runtime._handle(None,run,{'operation_id':'AO04'}, {}, lambda:False)
self.assertEqual(result,{'design':original})
runtime.llm.generate.assert_not_called()
runtime.store.stage_event.assert_called_once()
def test_java_recovery_keeps_verified_original_page_and_cannot_bypass_file_gates(self):
page='<html><style></style><h1>物流单</h1><script>window.zkRequest("GET","/api/app/list")</script></html>'
run={'snapshot':{'framework':self.profile},'request':{'recovery_diagnostics':{'error':'JAVA_TEST_FAILED'},
'baseline':{'files':{business_app.JAVA:'old Java',business_app.PAGE:page}}}}
partial={'files':{business_app.JAVA:'fixed Java'}}
merged=AgentRuntime._candidate_patch(run,partial)
self.assertEqual(merged['files'],{business_app.JAVA:'fixed Java',business_app.PAGE:page})
self.harness.files(merged,self.profile)
del run['request']['recovery_diagnostics']
with self.assertRaises(SkillError):self.harness.files(AgentRuntime._candidate_patch(run,partial),self.profile)
run.update(repair_pending=True,release={'draft':{'graph':{'nodes':[{'id':'patch','operation_ref':'AO06@0.1.0'}]}}},
outputs={'patch':{'source':{'files':{business_app.JAVA:'old Java',business_app.PAGE:page}}}})
self.assertEqual(AgentRuntime._candidate_patch(run,partial)['files'][business_app.PAGE],page)
if __name__=='__main__':unittest.main()
|