Allow authenticated resident handoff past composer availability guard

This commit is contained in:
firestar5683
2026-09-19 17:17:15 -07:00
parent 249eb88b3a
commit 89613c7c59
2 changed files with 29 additions and 2 deletions
+6 -2
View File
@@ -21,8 +21,12 @@ def check_available():
worker_state=json.loads((ROOT/'generated/ace_worker_state.json').read_text());profile=worker_state['profile']
except (OSError,ValueError,KeyError):raise SystemExit('ACE worker profile unavailable; restart preparation explicitly')
from generation_seed import configured_seed
if worker_state.get('generation_seed')!=configured_seed():raise SystemExit('Resident ACE seed differs; stop owned worker and prepare requested seed')
if profile!=selected_profile():raise SystemExit('Resident ACE profile differs; stop owned worker and prepare requested profile')
resident_handoff=False
if os.environ.get('ROADSCORE_RESIDENT')=='1' and os.environ.get('ROADSCORE_SEED_ORIGIN')!='judging-route':
try:resident_handoff=json.loads((ROOT/'generated/ace_initial.json').read_text()).get('resident_capable') is True
except (OSError,ValueError):pass
if not resident_handoff and worker_state.get('generation_seed')!=configured_seed():raise SystemExit('Resident ACE seed differs; stop owned worker and prepare requested seed')
if not resident_handoff and profile!=selected_profile():raise SystemExit('Resident ACE profile differs; stop owned worker and prepare requested profile')
return
lockpath=ROOT/'generated/gpu.lock'
if lockpath.exists():
@@ -0,0 +1,23 @@
import json, os, tempfile, unittest
from pathlib import Path
from unittest.mock import patch, Mock
import composer_choice as c
class ResidentHandoffTest(unittest.TestCase):
def check(self, optin, capable, judging=False):
with tempfile.TemporaryDirectory() as folder:
root=Path(folder); (root/'generated').mkdir()
(root/'generated/ace_worker_state.json').write_text(json.dumps({'profile':'prism','generation_seed':1}))
(root/'generated/ace_initial.json').write_text(json.dumps({'resident_capable':capable}))
command=Mock(); command.read_bytes.return_value=b'python /worker.py\0'
env={'ROADSCORE_COMPOSER':'ace','ROADSCORE_RESIDENT':optin,'ROADSCORE_SEED_ORIGIN':'judging-route' if judging else 'fresh-session'}
with patch.object(c,'ROOT',root),patch.object(c,'worker_path',return_value=Path('/worker.py')),patch.object(Path,'glob',return_value=[command]),patch.dict(os.environ,env),patch('generation_seed.configured_seed',return_value=2),patch('ace_profiles.selected',return_value='prism'):
c.check_available()
def test_opted_capable_reaches_authenticated_handoff(self):self.check('1',True)
def test_no_optin_rejects(self):
with self.assertRaises(SystemExit):self.check('0',True)
def test_nonresident_rejects(self):
with self.assertRaises(SystemExit):self.check('1',False)
def test_judging_rejects(self):
with self.assertRaises(SystemExit):self.check('1',True,True)
if __name__=='__main__':unittest.main()