-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathtest_generate_synthesis_inputs_v3.py
More file actions
123 lines (109 loc) · 4.11 KB
/
test_generate_synthesis_inputs_v3.py
File metadata and controls
123 lines (109 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import importlib.util
import json
import sys
import tempfile
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
from lib import schema
SCRIPT_PATH = Path(__file__).resolve().parents[1] / "scripts" / "generate-synthesis-inputs.py"
def load_module():
spec = importlib.util.spec_from_file_location("generate_synthesis_inputs", SCRIPT_PATH)
module = importlib.util.module_from_spec(spec)
assert spec and spec.loader
spec.loader.exec_module(module)
return module
class GenerateSynthesisInputsV3Tests(unittest.TestCase):
def test_main_uses_v3_report_deserializer(self):
module = load_module()
report = schema.Report(
topic="test topic",
range_from="2026-02-14",
range_to="2026-03-16",
generated_at="2026-03-16T00:00:00+00:00",
provider_runtime=schema.ProviderRuntime(
reasoning_provider="gemini",
planner_model="gemini-3.1-flash-lite-preview",
rerank_model="gemini-3.1-flash-lite-preview",
),
query_plan=schema.QueryPlan(
intent="breaking_news",
freshness_mode="strict_recent",
cluster_mode="story",
raw_topic="test topic",
subqueries=[
schema.SubQuery(
label="primary",
search_query="test topic",
ranking_query="What happened with test topic?",
sources=["grounding"],
)
],
source_weights={"grounding": 1.0},
),
clusters=[
schema.Cluster(
cluster_id="cluster-1",
title="Title",
candidate_ids=["c1"],
representative_ids=["c1"],
sources=["grounding"],
score=90.0,
)
],
ranked_candidates=[
schema.Candidate(
candidate_id="c1",
item_id="i1",
source="grounding",
sources=["grounding"],
title="Title",
url="https://example.com",
snippet="Snippet",
subquery_labels=["primary"],
native_ranks={"primary:grounding": 1},
local_relevance=0.8,
freshness=90,
engagement=None,
source_quality=1.0,
rrf_score=0.02,
rerank_score=91.0,
final_score=90.0,
source_items=[
schema.SourceItem(
item_id="i1",
source="grounding",
title="Title",
body="Body",
url="https://example.com",
published_at="2026-03-16",
)
],
)
],
items_by_source={
"grounding": [
schema.SourceItem(
item_id="i1",
source="grounding",
title="Title",
body="Body",
url="https://example.com",
)
]
},
errors_by_source={},
)
with tempfile.TemporaryDirectory() as tmp:
json_dir = Path(tmp) / "json"
compact_dir = Path(tmp) / "compact"
json_dir.mkdir()
(json_dir / "sample.json").write_text(json.dumps(schema.to_dict(report)))
module.JSON_DIR = json_dir
module.COMPACT_DIR = compact_dir
result = module.main()
self.assertEqual(0, result)
output = (compact_dir / "sample.md").read_text()
self.assertIn("# last30days v3.0.0: test topic", output)
if __name__ == "__main__":
unittest.main()