feat: stabilize multi-region runtime sync and worker orchestration

This commit is contained in:
root
2026-04-27 15:48:12 +08:00
parent 7cbde2aa78
commit 215a364891
137 changed files with 31931 additions and 1943 deletions

View File

@@ -4,6 +4,9 @@ import unittest
from unittest.mock import patch
from app.api.routes.ops import (
ops_migration_execute,
ops_migration_preview,
ops_migration_source_profile,
ops_doctor_decision,
ops_go_live_bundle,
ops_go_live_review,
@@ -13,6 +16,39 @@ from app.api.routes.ops import (
class OpsApiRoutesTestCase(unittest.TestCase):
@patch("app.api.routes.ops.get_ops_migration_source_profile")
def test_migration_source_profile_route_returns_payload(self, mock_source_profile) -> None:
mock_source_profile.return_value = {"source_node": {"node_code": "overseas-control-01"}}
response = ops_migration_source_profile()
self.assertEqual(0, response.code)
self.assertEqual("overseas-control-01", response.data["source_node"]["node_code"])
mock_source_profile.assert_called_once_with()
@patch("app.api.routes.ops.preview_ops_migration")
def test_migration_preview_route_passes_payload(self, mock_preview_ops_migration) -> None:
mock_preview_ops_migration.return_value = (True, "ok", {"plan_steps": [{"key": "sync_env_files"}]})
payload = {"target_node_code": "node-a"}
response = ops_migration_preview(payload)
self.assertEqual(0, response.code)
self.assertEqual("sync_env_files", response.data["plan_steps"][0]["key"])
mock_preview_ops_migration.assert_called_once_with(payload)
@patch("app.api.routes.ops.execute_ops_migration")
def test_migration_execute_route_returns_error_payload(self, mock_execute_ops_migration) -> None:
mock_execute_ops_migration.return_value = (False, "failed", {"blocking_reasons": ["ssh missing"]})
payload = {"target_node_code": "node-a"}
response = ops_migration_execute(payload)
self.assertEqual(1, response.code)
self.assertEqual("failed", response.message)
self.assertEqual(["ssh missing"], response.data["blocking_reasons"])
mock_execute_ops_migration.assert_called_once_with(payload)
@patch("app.api.routes.ops.get_ops_go_live_signoff")
def test_go_live_signoff_route_uses_service_payload(self, mock_get_ops_go_live_signoff) -> None:
mock_get_ops_go_live_signoff.return_value = {