返回 last30days-skill
test_plan_source_deduplication.py
根目录 / tests / test_plan_source_deduplication.py
1 """One search per source and subquery, even if the plan repeats a source."""
2
3 from collections import Counter
4 from unittest.mock import patch
5
6 from lib import pipeline
7
8
9 def test_external_plan_deduplicates_sources_without_losing_distinct_queries():
10 plan = {
11 "intent": "opinion",
12 "freshness_mode": "balanced_recent",
13 "cluster_mode": "debate",
14 "subqueries": [
15 {
16 "label": "backup",
17 "search_query": "SQLite backup",
18 "ranking_query": "SQLite backup reviews",
19 "sources": ["hackernews", "youtube", "youtube", "hackernews"],
20 },
21 {
22 "label": "restore",
23 "search_query": "SQLite restore",
24 "ranking_query": "SQLite restore reviews",
25 "sources": ["youtube"],
26 },
27 ],
28 }
29 with patch.object(pipeline, "_retrieve_stream", return_value=([], {})) as retrieve:
30 report = pipeline.run(
31 topic="SQLite backups and recovery",
32 config={},
33 mock=True,
34 web_backend="none",
35 depth="default",
36 requested_sources=["hackernews", "youtube"],
37 external_plan=plan,
38 )
39
40 assert Counter(
41 (call.kwargs["source"], call.kwargs["subquery"].search_query)
42 for call in retrieve.call_args_list
43 if call.kwargs["subquery"].label in {"backup", "restore"}
44 ) == {
45 ("hackernews", "SQLite backup"): 1,
46 ("youtube", "SQLite backup"): 1,
47 ("youtube", "SQLite restore"): 1,
48 }
49 assert [subquery.sources for subquery in report.query_plan.subqueries] == [
50 ["hackernews", "youtube"],
51 ["youtube"],
52 ]
53
53 lines PYTHON