Companion keeper: after a restart the panel opens the Companion that ran last if it is not running
- only in the watchdog's first 10 minutes, never another version, never during an upgrade - SC verified end to end; laptop SSH to the SC Macs; configs synced Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2581,3 +2581,38 @@ class TestSwitches(unittest.TestCase):
|
||||
errors = schema.validate(bad)[0]
|
||||
self.assertTrue(any("bypass.peers" in e for e in errors))
|
||||
self.assertTrue(any("nowhere" in e for e in errors))
|
||||
|
||||
|
||||
class TestCompanionKeeper(unittest.TestCase):
|
||||
"""After a restart the panel opens the Companion that ran last, and only then (Southcoast, 2026-10-21)."""
|
||||
|
||||
def setUp(self):
|
||||
self.engine = sp.Engine(CONFIG, os.path.join(tempfile.mkdtemp(), "state.json"))
|
||||
self.data = tempfile.mkdtemp()
|
||||
self.app = tempfile.mkdtemp(suffix=".app") # stands in for /Applications/Companion 5.0.7.app
|
||||
self.opened = []
|
||||
self.now = 1000.0
|
||||
self.running = self.app
|
||||
|
||||
def keeper(self):
|
||||
return sp.CompanionKeeper(self.engine, self.data, started=self.now, running=lambda: self.running,
|
||||
opener=self.opened.append)
|
||||
|
||||
def test_it_remembers_the_running_copy_and_opens_it_after_a_restart(self):
|
||||
self.keeper().check(self.now) # Companion running: remembered
|
||||
self.assertEqual(self.engine.state.get("companion_app"), self.app)
|
||||
self.running = None # the Mac restarted without Companion
|
||||
k = self.keeper()
|
||||
self.assertEqual(k.check(self.now + 30), self.app)
|
||||
self.assertEqual(k.check(self.now + 60), None) # not again straight away
|
||||
self.assertEqual(self.opened, [self.app])
|
||||
|
||||
def test_it_never_acts_later_on_or_during_an_upgrade_or_without_knowing_the_copy(self):
|
||||
k = self.keeper()
|
||||
self.running = None
|
||||
self.assertIsNone(k.check(self.now + 30)) # never seen one: no guessing
|
||||
self.engine.state.set("companion_app", self.app)
|
||||
self.assertIsNone(k.check(self.now + 700)) # someone quit it later on: left alone
|
||||
open(os.path.join(self.data, "companion-upgrading"), "w").write("x")
|
||||
self.assertIsNone(self.keeper().check(self.now + 30)) # an upgrade is going on
|
||||
self.assertEqual(self.opened, [])
|
||||
|
||||
Reference in New Issue
Block a user