"""Fresh spare adoption restores a namespace through the daemon's real link stack.""" from pathlib import Path import unittest from harness import Albedo, exclusive from inspect_support import Inspection from kernel_support import editable_daemon @exclusive class KernelSpareTests(unittest.TestCase): def test_unused_spares_end_on_stop_and_owner_death(self): with Albedo(prepare=lambda app: app.env.update(ALBEDO_INSPECT="1")) as app: probe = Inspection( app, Path(__file__).with_name("albedo_kernel_spare_probe.erl") ) self.assertTrue(probe.call_json("stop_json")["stopped"]) def test_stale_spare_is_cleaned_before_cold_fallback(self): def prepare(app): launcher, app.bundle = editable_daemon(app.root) app.env.update(ALBEDO_INSPECT="1", ALBEDO_DAEMON=str(launcher)) with Albedo(prepare=prepare) as app: session = app.session() probe = Inspection( app, Path(__file__).with_name("albedo_kernel_spare_probe.erl") ) changed = app.bundle / "albedo_bundle.py" result = probe.call_json( "run_json", f'[<<"{session}">>, <<"{app.workspace}">>, <<"{changed}">>]' ) self.assertEqual(result["recalled"]["status"], "ok", result) self.assertIn("SPARE_OK", result["recalled"]["output"]) def test_spare_is_single_use_and_restores_definitions(self): with Albedo(prepare=lambda app: app.env.update(ALBEDO_INSPECT="1")) as app: session = app.session() probe = Inspection( app, Path(__file__).with_name("albedo_kernel_spare_probe.erl") ) result = probe.call_json( "run_json", f'[<<"{session}">>, <<"{app.workspace}">>, <<>>]' ) self.assertEqual(result["recalled"]["status"], "ok", result) self.assertIn("SPARE_OK", result["recalled"]["output"]) self.assertEqual(result["live_work"], 0)