"""Synthetic bring-up behavior; no model, Stage, or QA claims.""" import inspect import json import os from pathlib import Path import sys import tempfile import unittest from unittest.mock import patch sys.path.insert(0, str(Path(__file__).resolve().parents[1])) import runner as r class BringupTests(unittest.TestCase): def test_profile_naturally_completes_after_120_simulated_seconds(self): with tempfile.TemporaryDirectory() as d: # Advance the monotonic clock while exercising a real child process. import time clock = time.monotonic start = clock() pulses = [] def elapsed(): return clock() + (121 if pulses else 0) script = 'import time,json;time.sleep(.1);print(json.dumps({"type":"result","exit_code":0,"text":"complete"}))' with patch.object(r.time, 'monotonic', side_effect=elapsed): answer, _ = r.execute([sys.executable,'-c',script], '', dict(os.environ), Path(d), lambda:pulses.append(True), None, heartbeat_seconds=.02) self.assertEqual(answer, 'complete') self.assertTrue(pulses) self.assertLess(clock()-start, 2) self.assertIsNone(inspect.signature(r.run).parameters['total_seconds'].default) self.assertIsNone(inspect.signature(r.run).parameters['process_seconds'].default) class ModelPolicyTests(unittest.TestCase): def test_all_registered_plus_blog_qa_preserve_private_config_bytes(self): import installer policy=json.loads((Path(installer.__file__).parent/'model-policy.json').read_text()) self.assertEqual(len(set(policy['profiles'])),29) with tempfile.TemporaryDirectory() as d: home=Path(d) registered=set(policy['profiles'])-set(policy['additionalProfiles']) (home/policy['registry']).write_text('departments:\n'+''.join(' d%d: {profile: %s, status: active}\n' % (i,p) for i,p in enumerate(sorted(registered)))) original='model:\n default: old\n provider: custom\n base_url: https://private.invalid/v1\n api_key: SECRET\nagent:\n max_turns: 8\n run_budget_seconds: 90\nplatforms:\n telegram:\n allow_from: [123]\n' for p in policy['profiles']: path=home/'profiles'/p/'config.yaml';path.parent.mkdir(parents=True);path.write_text(original);path.chmod(0o600) (path.parent/'.env').write_text('PRIVATE=unchanged') self.assertEqual(installer.configure_models(home),29) for p in policy['profiles']: path=home/'profiles'/p/'config.yaml' self.assertEqual(path.read_text(),original.replace('default: old','default: Canina-content').replace('max_turns: 8','max_turns: 0').replace('run_budget_seconds: 90','run_budget_seconds: 0')) self.assertEqual(path.stat().st_mode & 0o777,0o600) self.assertEqual((path.parent/'.env').read_text(),'PRIVATE=unchanged') first=home/'profiles'/policy['profiles'][0]/'config.yaml' first.unlink(); first.symlink_to(home/'private.yaml') (home/'private.yaml').write_text(original) with self.assertRaises(ValueError): installer.configure_models(home) self.assertEqual((home/'private.yaml').read_text(), original) (home/policy['registry']).write_text('departments:\n stranger: {profile: canina-stranger-worker}\n') with self.assertRaises(ValueError): installer.configure_models(home) if __name__ == '__main__': unittest.main()