VibeCoding / src /tests /runtime /test_webapp_requirement.py
dellweb3's picture
Deploy verified conversational workbench and isolated Java application previews
5ca3c16 verified
Raw History Blame Contribute Delete
1.85 kB
"""The website is chosen by each request while the Java safety frame is fixed."""
import unittest
from src.modules.execution.scenarios import webapp
from src.modules.harness.policy import Harness
from src.modules.skill.domain.models import SkillError
from src.modules.skill.packs.examples import framework_candidate
class WebappRequirementTests(unittest.TestCase):
def setUp(self):
self.profile=framework_candidate().model_copy(update={
'profile_id':webapp.PROFILE,'allowed_paths':['src/main/','website/'],'state':'approved'}).model_dump()
self.harness=Harness(enabled=True,allow_qemu=True)
def test_different_business_pages_keep_same_framework_without_calculator_source(self):
pages=[
'<!doctype html><html><style>button{color:red}</style><button>扫雷</button><script>let mines=10;</script></html>',
'<!doctype html><html><style>button{color:blue}</style><button>翻牌配对</button><script>let pairs=8;</script></html>',
]
sources=[self.harness.files(webapp.prepare_patch({'files':{webapp.PAGE:page}}),self.profile) for page in pages]
self.assertNotEqual(sources[0]['source_digest'],sources[1]['source_digest'])
self.assertEqual(sources[0]['files'][webapp.JAVA],sources[1]['files'][webapp.JAVA])
self.assertEqual([s['files'][webapp.PAGE] for s in sources],pages)
def test_model_cannot_change_java_or_request_network_page(self):
with self.assertRaises(SkillError):
webapp.prepare_patch({'files':{webapp.PAGE:'<html></html>',webapp.JAVA:'bad'}})
page='<html><style>x{}</style><script>fetch("/api/admin")</script></html>'
with self.assertRaises(SkillError):
self.harness.files(webapp.prepare_patch({'files':{webapp.PAGE:page}}),self.profile)
if __name__=='__main__':unittest.main()