fix: preserve strategy intent and recover accounts automatically

This commit is contained in:
AttilaNet
2026-11-11 19:37:15 +08:00
parent ccb945631d
commit 5c253d5cf9
26 changed files with 1628 additions and 236 deletions
+18 -4
View File
@@ -432,7 +432,7 @@ class WebIntegrationTests(unittest.TestCase):
point = next(point for point in dto["chart"]["series"] if point["id"] == "item:30005")
self.assertAlmostEqual(point["value"], .2)
def test_dto_egg_edit_autosaves_into_real_engine_plan_and_restart_stays_stopped(self):
def test_dto_egg_edit_autosaves_and_restart_preserves_explicit_execution_request(self):
config, row = self.hatch_config()
column = next(column for column in self.view("bag")["columns"] if column["key"] == "enabled")
self.assertEqual([row["id"] if part == "{id}" else part for part in column["edit"]["path"]], row["rule_path"] + ["enabled"])
@@ -454,7 +454,10 @@ class WebIntegrationTests(unittest.TestCase):
self.app.state.manager = self.manager
self.wait_idle()
self.assertEqual(self.config(), applied)
self.assertFalse(self.manager.status(self.account)["running"])
state = self.manager.status(self.account)
self.assertTrue(state["running"])
self.assertTrue(state["strategy_requested"])
self.assertFalse(state["manual_stop"])
self.assertFalse(self.manager._worker(self.account).engine.auto)
def test_same_species_config_and_catalog_overrides_are_independent_between_accounts(self):
@@ -541,7 +544,7 @@ class WebIntegrationTests(unittest.TestCase):
self.assertFalse(self.manager._worker(account).engine.auto)
self.assertEqual(client.writes, [])
def test_legacy_schema_one_import_is_a_job_and_never_starts_engine(self):
def test_legacy_schema_one_import_preserves_execution_request_without_inline_writes(self):
from ranch_assistant.model import Policy
from ranch_assistant.policy_io import portable_policy
@@ -555,10 +558,21 @@ class WebIntegrationTests(unittest.TestCase):
before = deepcopy(engine.snapshot.raw)
value = self.response(self.http.post(self.path("config/import"), json={"config": bundle}), 202)
self.job(value)
self.assertFalse(self.manager.status(self.account)["running"])
state = self.manager.status(self.account)
self.assertTrue(state["running"])
self.assertTrue(state["strategy_requested"])
self.assertFalse(state["manual_stop"])
self.assertFalse(engine.auto)
self.assertEqual(engine.snapshot.raw, before)
self.assertTrue(self.config()["config"]["policy"]["egg_rules"][row["id"]]["enabled"])
self.action("stop")
self.job(self.response(self.http.post(self.path("config/import"), json={"config": bundle}), 202))
state = self.manager.status(self.account)
self.assertFalse(state["running"])
self.assertFalse(state["strategy_requested"])
self.assertTrue(state["manual_stop"])
self.assertFalse(engine.auto)
self.assertEqual(engine.snapshot.raw, before)
exported = self.job(self.response(self.http.get(self.path("config/export")), 202))["result"]
self.assertEqual(exported["schema"], 2)
self.assertEqual(exported["format"], "ranch-helper-policies")