|
| 1 | +"""美股 get_news 路由:应透传上游(Yahoo)而非被东财关键词搜索截走;中文行业词才走东财。 |
| 2 | +
|
| 3 | +回归 bug:0.3.0 新闻分析师对美股 ticker(BABA)调 get_news,原逻辑只判 `not is_panwatch_routable`, |
| 4 | +把美股 ticker 也送进东财关键词搜索 → 搜不到 → 返回「未搜到」空结果,美股拿不到个股新闻。 |
| 5 | +修复:关键词新闻分支再加「含中文」闸,纯字母 ticker 落到上游透传。 |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +from src.agents.tradingagents import toolkit_adapter as tk |
| 11 | + |
| 12 | + |
| 13 | +def test_looks_like_cn_keyword_distinguishes_ticker_from_cn_query(): |
| 14 | + """纯字母美股 ticker 不算中文行业词;含中文(行业/主题)才算。""" |
| 15 | + assert tk._looks_like_cn_keyword("汽车行业") is True |
| 16 | + assert tk._looks_like_cn_keyword("新能源汽车") is True |
| 17 | + assert tk._looks_like_cn_keyword("BABA") is False |
| 18 | + assert tk._looks_like_cn_keyword("NVDA") is False |
| 19 | + assert tk._looks_like_cn_keyword("") is False |
| 20 | + |
| 21 | + |
| 22 | +def test_us_ticker_get_news_passes_through_to_upstream(monkeypatch): |
| 23 | + """美股 get_news(BABA)→ 走上游 vendor(Yahoo),不进东财关键词搜索。""" |
| 24 | + calls = {"keyword": 0, "upstream": 0} |
| 25 | + |
| 26 | + def fake_keyword(_sym): |
| 27 | + calls["keyword"] += 1 |
| 28 | + return "东财关键词新闻" |
| 29 | + |
| 30 | + def fake_upstream(_method, *_a, **_k): |
| 31 | + calls["upstream"] += 1 |
| 32 | + return "UPSTREAM YAHOO NEWS for BABA" |
| 33 | + |
| 34 | + monkeypatch.setattr(tk, "_serve_keyword_news", fake_keyword) |
| 35 | + monkeypatch.setattr(tk, "_real_route_to_vendor", fake_upstream) |
| 36 | + |
| 37 | + out = tk._patched_route_to_vendor("get_news", "BABA", "2026-06-15", "2026-06-22") |
| 38 | + |
| 39 | + assert calls["upstream"] == 1 |
| 40 | + assert calls["keyword"] == 0 |
| 41 | + assert "UPSTREAM" in str(out) |
| 42 | + |
| 43 | + |
| 44 | +def test_cn_keyword_get_news_goes_to_eastmoney(monkeypatch): |
| 45 | + """中文行业词(汽车行业)→ 走东财关键词搜索,不透传上游。""" |
| 46 | + calls = {"keyword": 0, "upstream": 0} |
| 47 | + |
| 48 | + def fake_keyword(_sym): |
| 49 | + calls["keyword"] += 1 |
| 50 | + return "东财搜到的行业新闻" |
| 51 | + |
| 52 | + def fake_upstream(_method, *_a, **_k): |
| 53 | + calls["upstream"] += 1 |
| 54 | + return "UPSTREAM" |
| 55 | + |
| 56 | + monkeypatch.setattr(tk, "_serve_keyword_news", fake_keyword) |
| 57 | + monkeypatch.setattr(tk, "_real_route_to_vendor", fake_upstream) |
| 58 | + |
| 59 | + out = tk._patched_route_to_vendor("get_news", "汽车行业", "2026-06-15", "2026-06-22") |
| 60 | + |
| 61 | + assert calls["keyword"] == 1 |
| 62 | + assert calls["upstream"] == 0 |
| 63 | + assert "行业新闻" in str(out) |
0 commit comments