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

@@ -0,0 +1,62 @@
from __future__ import annotations
import unittest
from unittest.mock import patch
from app.services import detect_service
class DetectServiceRemoteLogsTests(unittest.TestCase):
@patch("app.services.detect_service.list_debug_events")
def test_build_remote_log_snapshot_from_debug_events_filters_to_active_job_identity(self, mock_list_debug_events) -> None:
mock_list_debug_events.return_value = {
"records": [
{
"id": 3,
"node_code": "mainland-controller-01-a",
"event_type": "worker_log",
"message": "旧任务日志",
"created_at": "2026-04-23 16:00:00",
"payload": {
"job_id": 10,
"job_code": "sync-overseas-10",
"cycle_token": "cycle-old",
"log_mode": "key",
},
},
{
"id": 4,
"node_code": "mainland-controller-01-a",
"event_type": "worker_log",
"message": "当前任务日志",
"created_at": "2026-04-23 16:01:00",
"payload": {
"job_id": 12,
"job_code": "sync-overseas-12",
"cycle_token": "cycle-12",
"log_mode": "key",
},
},
]
}
snapshot = detect_service._build_remote_log_snapshot_from_debug_events(
{
"job_id": 12,
"job_code": "sync-overseas-12",
"runtime_job_code": "sync-overseas-12",
"current_cycle_token": "cycle-12",
"node_stats": [{"node_code": "mainland-controller-01-a"}],
},
enabled=True,
mode="key",
limit=20,
)
self.assertEqual(1, snapshot["line_count"])
self.assertIn("当前任务日志", snapshot["lines"][0])
self.assertNotIn("旧任务日志", "\n".join(snapshot["lines"]))
if __name__ == "__main__":
unittest.main()