"""Actual pinned loader integration in fresh CPU subprocesses, no brain.""" import os from pathlib import Path import subprocess import sys import unittest class IsolationTests(unittest.TestCase): @classmethod def setUpClass(cls): server = Path('/data/digital-drosophila/models/male-cns-lif') cls.root = server if server.is_dir() else Path(__file__).resolve().parents[1] cls.model = cls.root / 'olfactory-conditioning-lab-v1' cls.helper = cls.root / 'wholebrain-plastic-interface-v1/overlay.py' assert cls.helper.is_file() def run_child(self, body): setup = ('import sys, pathlib, types\n' f'sys.path.insert(0,{str(self.model)!r})\n' f'helper=pathlib.Path({str(self.helper)!r})\n' 'import conditioning_epoch as E\n' 'c=E._load_source(pathlib.Path(E.__file__).parent / "runtime_continuation.py", E.SOURCE_PINS["runtime_continuation_source"], "continuation")\n' 'r=c.R\n') return subprocess.run([sys.executable, '-B', '-c', setup + body], env=dict(os.environ, CUDA_VISIBLE_DEVICES=''), capture_output=True, text=True, timeout=60) def test_fresh_E_uses_one_verified_helper_cache(self): result = self.run_child('a=r._load("phase4an_sealed_am_overlay",helper,r.AM_OVERLAY_SHA)\n' 'b=r._load("phase4an_sealed_am_overlay",helper,r.AM_OVERLAY_SHA)\n' 'assert a is b\nassert "runtime_light" not in sys.modules\nassert "torch" not in sys.modules\n') self.assertEqual(result.returncode, 0, result.stderr) def test_mixed_actual_loaders_reproduce_exact_failure(self): result = self.run_child('import runtime_light as ordinary\n' 'ordinary._load("phase4an_sealed_am_overlay",helper,ordinary.AM_OVERLAY_SHA)\n' 'r._load("phase4an_sealed_am_overlay",helper,r.AM_OVERLAY_SHA)\n') self.assertNotEqual(result.returncode, 0) self.assertIn('Existing unverified module binding: phase4an_sealed_am_overlay', result.stderr) def test_fake_preexisting_helper_is_still_rejected(self): result = self.run_child('sys.modules["phase4an_sealed_am_overlay"]=types.ModuleType("fake")\n' 'r._load("phase4an_sealed_am_overlay",helper,r.AM_OVERLAY_SHA)\n') self.assertNotEqual(result.returncode, 0) self.assertIn('Existing unverified module binding', result.stderr) def test_wrong_source_pin_is_still_rejected(self): result = self.run_child('r._load("phase4an_sealed_am_overlay",helper,"0"*64)\n') self.assertNotEqual(result.returncode, 0) self.assertIn('pin', result.stderr.lower()) if __name__ == '__main__': unittest.main()