This repository was archived by the owner on May 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_streetwear_flow.py
More file actions
216 lines (173 loc) · 10.1 KB
/
Copy pathtest_streetwear_flow.py
File metadata and controls
216 lines (173 loc) · 10.1 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
from __future__ import annotations
import json
import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from intelligence.cli import main
_FIXTURE_PATH = Path(__file__).resolve().parent / "fixtures" / "mediacrawler_streetwear_export.jsonl"
class DesignerStreetwearPackFlowTests(unittest.TestCase):
"""End-to-end tests for the designer_streetwear pack."""
def test_run_pack_streetwear_writes_all_outputs(self) -> None:
with TemporaryDirectory() as tmpdir:
exit_code = main(["run-pack", "designer_streetwear", "--output-dir", tmpdir])
self.assertEqual(exit_code, 0)
output_dir = Path(tmpdir)
for filename in (
"normalized_samples.json",
"scored_samples.json",
"report.json",
"report.md",
"report.html",
):
self.assertTrue((output_dir / filename).is_file(), filename)
normalized = json.loads((output_dir / "normalized_samples.json").read_text(encoding="utf-8"))
scored = json.loads((output_dir / "scored_samples.json").read_text(encoding="utf-8"))
report_json = json.loads((output_dir / "report.json").read_text(encoding="utf-8"))
report_md = (output_dir / "report.md").read_text(encoding="utf-8")
report_html = (output_dir / "report.html").read_text(encoding="utf-8")
self.assertEqual(len(normalized), 3)
self.assertEqual(normalized[0]["provenance"]["source"], "mediacrawler")
self.assertEqual(normalized[0]["provenance"]["source_id"], "sw-note-001")
self.assertEqual(len(scored), 3)
self.assertIn("weighted_score", scored[0])
self.assertIn("confidence", scored[0])
self.assertIn("classification", scored[0])
self.assertEqual(report_json["title"], "Designer Streetwear Pack Report")
self.assertIn("# Designer Streetwear Pack Report", report_md)
self.assertIn("## Evidence Buckets", report_md)
self.assertIn("Fixture Coverage", report_md)
self.assertIn("<html", report_html.lower())
def test_run_pack_streetwear_with_explicit_input(self) -> None:
with TemporaryDirectory() as tmpdir:
exit_code = main([
"run-pack", "designer_streetwear",
"--input", str(_FIXTURE_PATH),
"--output-dir", tmpdir,
])
self.assertEqual(exit_code, 0)
output_dir = Path(tmpdir)
report_md = (output_dir / "report.md").read_text(encoding="utf-8")
self.assertIn("Input Coverage", report_md)
self.assertNotIn("Fixture Coverage", report_md)
def test_streetwear_scores_relevant_higher_than_irrelevant(self) -> None:
"""Streetwear content should score higher than food content."""
with TemporaryDirectory() as tmpdir:
exit_code = main(["run-pack", "designer_streetwear", "--output-dir", tmpdir])
self.assertEqual(exit_code, 0)
scored = json.loads(
(Path(tmpdir) / "scored_samples.json").read_text(encoding="utf-8")
)
# sw-note-001 (layering, graphic, silhouette) and sw-note-002 (brand, bomber)
# should both score higher than sw-note-003 (food post)
self.assertGreater(scored[0]["weighted_score"], scored[2]["weighted_score"])
self.assertGreater(scored[1]["weighted_score"], scored[2]["weighted_score"])
def test_streetwear_report_title_is_pack_specific(self) -> None:
with TemporaryDirectory() as tmpdir:
exit_code = main(["run-pack", "designer_streetwear", "--output-dir", tmpdir])
self.assertEqual(exit_code, 0)
report_json = json.loads(
(Path(tmpdir) / "report.json").read_text(encoding="utf-8")
)
# Must NOT say "Jade"
self.assertNotIn("Jade", report_json["title"])
self.assertNotIn("jade", report_json["summary"].lower().split("from")[0])
def test_report_top_signal_is_highest_scored_sample(self) -> None:
"""Report summary should reflect the highest-scoring sample, not the first."""
with TemporaryDirectory() as tmpdir:
exit_code = main(["run-pack", "designer_streetwear", "--output-dir", tmpdir])
self.assertEqual(exit_code, 0)
scored = json.loads(
(Path(tmpdir) / "scored_samples.json").read_text(encoding="utf-8")
)
max_score = max(s["weighted_score"] for s in scored)
report_json = json.loads(
(Path(tmpdir) / "report.json").read_text(encoding="utf-8")
)
self.assertIn(f"{max_score:.2f}", report_json["summary"])
def test_empty_input_uses_pack_default_classification(self) -> None:
"""Empty input should use the pack's own default_classification, not jade's."""
with TemporaryDirectory() as tmpdir:
input_path = Path(tmpdir) / "empty.jsonl"
input_path.write_text("", encoding="utf-8")
outdir = Path(tmpdir) / "out"
exit_code = main([
"run-pack", "designer_streetwear",
"--input", str(input_path),
"--output-dir", str(outdir),
])
self.assertEqual(exit_code, 0)
report_md = (outdir / "report.md").read_text(encoding="utf-8")
# streetwear default is "noise", not jade's "avoid_for_now"
self.assertIn("noise", report_md)
self.assertNotIn("avoid_for_now", report_md)
def test_examples_directory_contains_streetwear_readme(self) -> None:
readme = Path(__file__).resolve().parents[1] / "examples" / "designer_streetwear" / "README.md"
self.assertTrue(readme.is_file())
self.assertIn("run-pack designer_streetwear", readme.read_text(encoding="utf-8"))
class StreetwearHeuristicTests(unittest.TestCase):
"""Tests for keyword coverage found during the pilot study."""
def _score_text(self, title: str, desc: str, tags: str) -> dict:
"""Build a sample, score it, and return the result dict."""
from intelligence.schema import CanonicalSample, CanonicalContent, CanonicalProvenance
from intelligence.workflows.streetwear_pack import _bucket_scores, _SCORING_CONFIG
from intelligence.scoring.engine import ScoringEngine
sample = CanonicalSample(
provenance=CanonicalProvenance(source="test", source_id="t-001"),
content=CanonicalContent(
text=desc,
title=title,
tags=tuple(t.strip() for t in tags.split(",") if t.strip()),
),
)
engine = ScoringEngine(_SCORING_CONFIG)
result = engine.score(_bucket_scores(sample))
return {
"bucket_scores": result.bucket_scores,
"weighted_score": result.weighted_score,
"confidence": result.confidence,
"classification": result.classification,
}
def test_straight_leg_triggers_silhouette(self) -> None:
result = self._score_text("直筒裤搭配", "直筒裤穿搭分享", "直筒裤")
self.assertGreater(result["bucket_scores"]["silhouette"], 0)
def test_chinese_mesh_triggers_material(self) -> None:
result = self._score_text("网眼拼接球鞋", "网眼面料透气", "球鞋")
self.assertGreater(result["bucket_scores"]["material"], 0)
def test_workwear_triggers_material(self) -> None:
result = self._score_text("工装裤搭配", "工装风穿搭", "工装")
self.assertGreater(result["bucket_scores"]["material"], 0)
def test_pure_noise_scores_zero(self) -> None:
result = self._score_text("今天吃了火锅", "和朋友聚餐", "美食,火锅")
self.assertEqual(result["weighted_score"], 0.0)
self.assertEqual(result["classification"], "noise")
class SharedWorkflowTests(unittest.TestCase):
"""Tests proving both packs exercise the same shared flow."""
def test_both_packs_produce_identical_output_structure(self) -> None:
"""Both packs should produce the same set of output files with matching top-level keys."""
with TemporaryDirectory() as tmpdir:
jade_dir = Path(tmpdir) / "jade"
sw_dir = Path(tmpdir) / "streetwear"
self.assertEqual(main(["run-pack", "jade", "--output-dir", str(jade_dir)]), 0)
self.assertEqual(main(["run-pack", "designer_streetwear", "--output-dir", str(sw_dir)]), 0)
for filename in ("normalized_samples.json", "scored_samples.json", "report.json"):
jade_data = json.loads((jade_dir / filename).read_text(encoding="utf-8"))
sw_data = json.loads((sw_dir / filename).read_text(encoding="utf-8"))
if isinstance(jade_data, list) and isinstance(sw_data, list):
# Both produce lists; check inner structure keys match if non-empty
if jade_data and sw_data:
self.assertEqual(sorted(jade_data[0].keys()), sorted(sw_data[0].keys()))
elif isinstance(jade_data, dict) and isinstance(sw_data, dict):
self.assertEqual(sorted(jade_data.keys()), sorted(sw_data.keys()))
def test_both_packs_share_normalized_sample_schema(self) -> None:
with TemporaryDirectory() as tmpdir:
jade_dir = Path(tmpdir) / "jade"
sw_dir = Path(tmpdir) / "streetwear"
main(["run-pack", "jade", "--output-dir", str(jade_dir)])
main(["run-pack", "designer_streetwear", "--output-dir", str(sw_dir)])
jade_sample = json.loads((jade_dir / "normalized_samples.json").read_text(encoding="utf-8"))[0]
sw_sample = json.loads((sw_dir / "normalized_samples.json").read_text(encoding="utf-8"))[0]
self.assertEqual(sorted(jade_sample.keys()), sorted(sw_sample.keys()))
self.assertEqual(sorted(jade_sample["provenance"].keys()), sorted(sw_sample["provenance"].keys()))
self.assertEqual(sorted(jade_sample["content"].keys()), sorted(sw_sample["content"].keys()))
if __name__ == "__main__":
unittest.main()