fix(hub): preserve key monitors when enrich_monitor returns partial payload
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""hub /api/hub/monitor:enrich 局部返回时须保留 keys。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from hub_bridge import build_hub_monitor_payload # noqa: E402
|
||||
|
||||
|
||||
class TestHubMonitorPayload(unittest.TestCase):
|
||||
def test_partial_enrich_keeps_keys(self):
|
||||
keys = [{"id": 7, "symbol": "BTC/USDT"}]
|
||||
orders = [{"id": 1}]
|
||||
trends = [{"id": 9, "symbol": "ETH/USDT"}]
|
||||
rolls = []
|
||||
|
||||
def enrich_only_trends(**_kw):
|
||||
return {"trends": [{"id": 9, "add_count": 2}]}
|
||||
|
||||
out = build_hub_monitor_payload(
|
||||
keys=keys,
|
||||
orders=orders,
|
||||
trends=trends,
|
||||
rolls=rolls,
|
||||
enrich=enrich_only_trends,
|
||||
)
|
||||
self.assertTrue(out["ok"])
|
||||
self.assertEqual(out["keys"], keys)
|
||||
self.assertEqual(out["orders"], orders)
|
||||
self.assertEqual(out["rolls"], rolls)
|
||||
self.assertEqual(out["trends"][0]["add_count"], 2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user