import copy,hashlib,json,tempfile,time,unittest from pathlib import Path from types import SimpleNamespace from unittest.mock import patch from test_applio import Tests as LeaseTests from xvc import XVC,xvc_model from xvc_runtime import ASSETS,REVISION,MODEL_REVISION,REPO,RECIPE_HASH from execution_setup import assess class Tests(LeaseTests): def setUp(self): super().setUp();self.a.stop() self.profile.update(name='X-VC',model=dict(repo=REPO,file='xvc.pt',kind='voice',runtime_metadata={'architecture':'xvc'})) self.a=XVC(Path(self.tmp.name),self.runtime,self.scheduler,self.profiles,lambda:self.active) self.a.settings={'device':'3060'} def test_real_profile_is_runnable_only_after_runtime_ready(self): from catalog import Catalog from profiles import Profiles root=Path(self.tmp.name);catalog=Catalog(root/'models');ident=hashlib.sha256((REPO+MODEL_REVISION+'xvc.pt').encode()).hexdigest();folder=catalog.root/ident;folder.mkdir(parents=True) (folder/'model.pt').write_bytes(b'test');(folder/'entry.json').write_text(json.dumps(dict(repo=REPO,revision=MODEL_REVISION,file='xvc.pt',kind='voice',size=4,sha256='b'*64,runtime_metadata={'architecture':'xvc'}))) profiles=Profiles(root/'profiles.json',catalog);profiles.save(dict(id=None,revision=0,name='X-VC Studio',api_id='xvc-studio',kind='voice',model_id=ident,parameters={})) profiles.xvc_blockers=lambda p:['Laufzeit fehlt'];self.assertFalse(profiles.status()['profiles'][0]['runnable']) profiles.xvc_blockers=lambda p:[];self.assertTrue(profiles.status()['profiles'][0]['runnable']) def test_rvc_recognition_does_not_guess_every_pth(self): self.assertTrue(xvc_model(self.profile['model']));self.assertFalse(xvc_model(dict(kind='voice',file='xvc.pt'))) result=assess(self.profile['model'],{'xvc':True});self.assertEqual(result['setup_steps'][1]['state'],'complete');self.assertEqual(result['components'],[]) def test_assets_have_fixed_verified_sources(self): self.assertEqual(len(ASSETS),10) for item in ASSETS: self.assertEqual(len(item['revision']),40);self.assertGreater(item['size'],0);self.assertTrue(item['sha256'] or item['git_sha1']) self.assertNotIn('..',Path(item['target']).parts) self.assertEqual(len(RECIPE_HASH),64) def test_apply_profile_refuses_running_deck(self): from deploy.prepare_xvc import apply_profile with patch('deploy.prepare_xvc.subprocess.run',return_value=SimpleNamespace(stdout=json.dumps([{'State':{'Running':True}}]))): with self.assertRaisesRegex(ValueError,'Deck läuft'):apply_profile(self.tmp.name) def test_container_backup_preserves_stopped_ui_and_rejects_unsafe_mount(self): from deploy.docker_backup import validate c=dict(name='athena-xvc-web',image='athena-xvc-web:0.1.0-deck1',registry=None,application='xvc-web',labels={'io.athena-deck.managed':'true','io.athena-deck.role':'application','io.athena-deck.application':'xvc-web'},env=[],entrypoint=None,cmd=None,user='65534:65534',uid=65534,workdir='/ui',network='host',ports={},restart='unless-stopped',memory=512*1024**2,nanocpus=10**9,running=False,build_recipe='xvc-web',unsupported=False,mounts=[dict(index=0,target='/run/secrets/xvc-bridge',read_only=True,deck_path='xvc-data/bridge-key',was_file=True,files={})]) self.assertFalse(validate(c)['running']);bad=copy.deepcopy(c);bad['mounts'][0]['read_only']=False with self.assertRaises(ValueError):validate(bad) if __name__=='__main__':unittest.main()