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 seed_vc import SeedVC,seed_vc_model from seed_vc_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='Seed-VC',model=dict(repo=REPO,file=ASSETS[0]['file'],kind='voice',runtime_metadata={'architecture':'seed_vc'})) self.a=SeedVC(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+ASSETS[0]['file']).encode()).hexdigest();folder=catalog.root/ident;folder.mkdir(parents=True) (folder/'model.pth').write_bytes(b'test');(folder/'entry.json').write_text(json.dumps(dict(repo=REPO,revision=MODEL_REVISION,file=ASSETS[0]['file'],kind='voice',size=4,sha256='b'*64,runtime_metadata={'architecture':'seed_vc'}))) profiles=Profiles(root/'profiles.json',catalog);profiles.save(dict(id=None,revision=0,name='Seed-VC Studio',api_id='seed-vc-singing',kind='voice',model_id=ident,parameters={})) profiles.seed_vc_blockers=lambda p:['Laufzeit fehlt'];self.assertFalse(profiles.status()['profiles'][0]['runnable']) profiles.seed_vc_blockers=lambda p:[];self.assertTrue(profiles.status()['profiles'][0]['runnable']) def test_rvc_recognition_does_not_guess_every_pth(self): self.assertTrue(seed_vc_model(self.profile['model']));self.assertFalse(seed_vc_model(dict(kind='voice',file=ASSETS[0]['file']))) result=assess(self.profile['model'],{'seed_vc':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),9) 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['file']).parts) self.assertEqual(len(RECIPE_HASH),64) def test_apply_profile_refuses_running_deck(self): from deploy.prepare_seed_vc import apply_profile with patch('deploy.prepare_seed_vc.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-seed-vc-web',image='athena-seed-vc-web:0.1.0-deck1',registry=None,application='seed-vc-web',labels={'io.athena-deck.managed':'true','io.athena-deck.role':'application','io.athena-deck.application':'seed-vc-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='seed-vc-web',unsupported=False,mounts=[dict(index=0,target='/run/secrets/seed-vc-bridge',read_only=True,deck_path='seed_vc-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()