返回 last30days-skill
test_hiring_signals.py
根目录 / tests / test_hiring_signals.py
1 import unittest
2
3 from lib import hiring_signals, pipeline, schema
4
5
6 def job(title: str, body: str, department: str = "Engineering") -> schema.SourceItem:
7 return schema.SourceItem(
8 item_id=title,
9 source="jobs",
10 title=title,
11 body=body,
12 url=f"https://example.com/jobs/{title.replace(' ', '-').lower()}",
13 container=department,
14 published_at="2026-06-01",
15 date_confidence="high",
16 metadata={"department": department},
17 )
18
19
20 class HiringSignalsTests(unittest.TestCase):
21 def test_theme_keywords_match_whole_words_only(self):
22 themed = hiring_signals._theme_items([
23 job("JP-Technical Specialist", "Apple Retail store training and maintaining displays", "Apple Retail"),
24 job("Web Developer", "html and css", "Engineering"),
25 job("Staff Engineer, LLMs", "train large models", "Engineering"),
26 ])
27 ai = [item.title for item in themed.get("ai and machine learning", [])]
28 self.assertEqual(["Staff Engineer, LLMs"], ai)
29
30 def test_startup_cluster_surfaces_in_standard_mode(self):
31 items = [
32 job("Founding Enterprise Solutions Engineer", "SSO SOC 2 procurement enterprise", "Sales"),
33 job("Security Platform Engineer", "enterprise security audit admin", "Engineering"),
34 ]
35 summary = hiring_signals.analyze(items, explicit=False, topic="Listen Labs")
36 self.assertTrue(summary["include"])
37 self.assertEqual("startup", summary["company_size_tier"])
38 self.assertEqual("enterprise readiness", summary["signals"][0]["theme"])
39
40 def test_mega_cap_scattered_roles_do_not_surface_standard_mode(self):
41 items = [
42 job("Retail Associate", "store operations", "Retail"),
43 job("iOS Engineer", "mobile app", "Engineering"),
44 job("Finance Analyst", "planning", "Finance"),
45 ]
46 summary = hiring_signals.analyze(items, explicit=False, topic="Apple")
47 self.assertFalse(summary["include"])
48 self.assertEqual("mega-cap", summary["company_size_tier"])
49 self.assertIn("too diffuse", summary["omitted_reason"])
50
51 def test_fortune_500_customer_boilerplate_does_not_make_startup_large_enterprise(self):
52 items = [
53 job(
54 "Founding Enterprise Solutions Engineer",
55 "Help Fortune 500 customers adopt SSO, SOC 2, and procurement workflows.",
56 "Sales",
57 ),
58 job(
59 "Security Platform Engineer",
60 "Build enterprise security, audit, and admin workflows for Fortune 500 customers.",
61 "Engineering",
62 ),
63 ]
64 summary = hiring_signals.analyze(items, explicit=False, topic="Listen Labs")
65 self.assertEqual("startup", summary["company_size_tier"])
66 self.assertTrue(summary["include"])
67
68 def test_explicit_mode_keeps_low_confidence_signal(self):
69 items = [job("Customer Success Manager", "support enterprise customers", "Success")]
70 summary = hiring_signals.analyze(items, explicit=True, topic="Acme")
71 self.assertTrue(summary["include"])
72 self.assertEqual("low", summary["signals"][0]["confidence"])
73
74 def test_founding_specialized_role_surfaces_as_strategic_candidate(self):
75 # The exact 2026-06-15 miss: one strategic role amid many generic ones.
76 items = [
77 job("Software Engineer", "backend services", "Engineering"),
78 job("Software Engineer, Backend", "platform", "Engineering"),
79 job("Software Engineer, Frontend", "ui", "Engineering"),
80 job("Founding Research Scientist, Human Simulation", "simulate users", "Research"),
81 ]
82 summary = hiring_signals.analyze(items, explicit=True, topic="Listen Labs")
83 titles = [c["title"] for c in summary["strategic_candidates"]]
84 self.assertIn("Founding Research Scientist, Human Simulation", titles)
85 top = summary["strategic_candidates"][0]
86 self.assertEqual("Founding Research Scientist, Human Simulation", top["title"])
87 self.assertIn("founding", top["flags"])
88 self.assertIn("specialized", top["flags"])
89
90 def test_specialization_ignores_generic_level_qualifiers(self):
91 self.assertEqual("", hiring_signals._specialization("Engineer, Senior"))
92 self.assertEqual("Human Simulation", hiring_signals._specialization("Research Scientist, Human Simulation"))
93 self.assertEqual("Forward Deployed", hiring_signals._specialization("Engineer (Forward Deployed)"))
94
95 def test_new_geo_flag_for_rare_location(self):
96 def loc_job(title, location):
97 it = job(title, "work", "Engineering")
98 it.metadata["location"] = location
99 return it
100 items = [
101 loc_job("Engineer A", "San Francisco"),
102 loc_job("Engineer B", "San Francisco"),
103 loc_job("Engineer C", "San Francisco"),
104 loc_job("Growth Lead", "New York"),
105 ]
106 summary = hiring_signals.analyze(items, explicit=True, topic="Acme")
107 ny = [c for c in summary["strategic_candidates"] if c["location"] == "new york"]
108 self.assertTrue(ny)
109 self.assertIn("new-geo", ny[0]["flags"])
110
111 def _located(self, *rows):
112 items = []
113 for title, location in rows:
114 item = job(title, "work", "Engineering")
115 item.metadata["location"] = location
116 items.append(item)
117 return hiring_signals.analyze(items, explicit=True, topic="Acme")["strategic_candidates"]
118
119 def test_a_spelling_of_a_place_already_on_the_board_is_not_a_new_geography(self):
120 candidates = self._located(
121 ("Engineer A", "San Francisco"),
122 ("Engineer B", "San Francisco"),
123 ("Engineer C", "San Francisco"),
124 ("Engineer D", "Seattle"),
125 ("Engineer E", "Seattle, WA"),
126 )
127 self.assertFalse([c for c in candidates if "new-geo" in c["flags"]])
128
129 def test_a_title_tail_is_specialized_only_when_it_names_a_specialty(self):
130 candidates = self._located(
131 ("Engineer, Payments", "Seattle"),
132 ("Engineer, Seattle", "Seattle"),
133 ("Engineer, Multiple Teams", "Seattle"),
134 ("Engineer, Entry Level", "Seattle"),
135 )
136 flagged = {c["title"] for c in candidates if "specialized" in c["flags"]}
137 self.assertEqual({"Engineer, Payments"}, flagged)
138
139
140 # Company text a board repeats on every role, the way Microsoft's postings do.
141 BOILERPLATE = (
142 "Our team accelerates customer outcomes and business growth with AI-powered "
143 "solutions and cloud platforms. We design for security and data insights."
144 )
145 KEYWORD_THEMES = set(hiring_signals.THEME_KEYWORDS)
146
147
148 def board(*roles: tuple[str, str, str]) -> list[schema.SourceItem]:
149 """Postings that each open with BOILERPLATE, then the role's own text."""
150 return [job(title, f"{title}\n{department}\n{BOILERPLATE}\n{own}", department)
151 for title, own, department in roles]
152
153
154 def themes_of(themed: dict[str, list[schema.SourceItem]], title: str) -> set[str]:
155 return {theme for theme, items in themed.items() if any(i.title == title for i in items)}
156
157
158 class BoilerplateThemeTests(unittest.TestCase):
159 def test_role_matching_only_shared_boilerplate_is_unthemed(self):
160 themed = hiring_signals._theme_items(board(
161 ("Logistics Technician", "Move parts between sites.", "Operations"),
162 ("Paralegal", "Draft contracts.", "Legal"),
163 ("Facilities Coordinator", "Book rooms.", "Workplace"),
164 ("Product Designer", "Shape the editor.", "Studio"),
165 ))
166 for title in ("Logistics Technician", "Paralegal", "Facilities Coordinator"):
167 self.assertEqual(set(), themes_of(themed, title) & KEYWORD_THEMES, title)
168 self.assertEqual({"product expansion"}, themes_of(themed, "Product Designer") & KEYWORD_THEMES)
169 self.assertIn("operations", themed)
170
171 def test_role_unique_body_sentence_still_themes(self):
172 themed = hiring_signals._theme_items(board(
173 ("Software Engineer", "You will build LLM evaluation pipelines.", "Engineering"),
174 ("Paralegal", "Draft contracts.", "Legal"),
175 ("Facilities Coordinator", "Book rooms.", "Workplace"),
176 ))
177 self.assertEqual({"ai and machine learning"},
178 themes_of(themed, "Software Engineer") & KEYWORD_THEMES)
179
180 def test_boilerplate_needs_three_roles_before_it_is_removed(self):
181 themed = hiring_signals._theme_items(board(
182 ("Paralegal", "Draft contracts.", "Legal"),
183 ("Facilities Coordinator", "Book rooms.", "Workplace"),
184 ))
185 # Two roles sharing a sentence is not yet company text.
186 self.assertIn("ai and machine learning", themes_of(themed, "Paralegal"))
187
188 def test_title_match_outranks_body_match(self):
189 themed = hiring_signals._theme_items([
190 job("Software Engineer", "Software Engineer\nYou will tune ML ranking.", "Engineering"),
191 job("Machine Learning Engineer", "Machine Learning Engineer\nShip things.", "Engineering"),
192 job("Data Engineer", "Data Engineer\nKeep pipelines up.", "AI Platform"),
193 ])
194 self.assertEqual(
195 ["Machine Learning Engineer", "Data Engineer", "Software Engineer"],
196 [item.title for item in themed["ai and machine learning"]],
197 )
198
199 def test_generic_words_do_not_theme_a_logistics_technician(self):
200 themed = hiring_signals._theme_items([
201 job(
202 "Logistics Technician",
203 "Logistics Technician\nSupport warehouse growth, design shipping solutions on "
204 "our platform, and model activation insights for admin teams.",
205 "Operations",
206 ),
207 ])
208 self.assertEqual({"operations"}, set(themed))
209
210 def test_data_center_roles_are_infrastructure_not_data(self):
211 themed = hiring_signals._theme_items([
212 job("Data Center Program Manager", "Data Center Program Manager", "Operations"),
213 job("Data Analyst", "Data Analyst", "Finance"),
214 ])
215 self.assertEqual({"infrastructure and reliability"},
216 themes_of(themed, "Data Center Program Manager") & KEYWORD_THEMES)
217 self.assertEqual({"data and analytics"}, themes_of(themed, "Data Analyst") & KEYWORD_THEMES)
218
219
220 class DistinctEvidenceTests(unittest.TestCase):
221 def _items(self) -> list[schema.SourceItem]:
222 items = []
223 for prefix, department in (("Sales Lead", "Sales"), ("ML Engineer", "Research"),
224 ("Cloud Engineer", "Infra")):
225 items.extend(job(f"{prefix} {n}", f"{prefix} {n}", department) for n in range(3))
226 # Each of these matches all three themes on its title, and comes first.
227 shared = [job(f"Sales ML Cloud Architect {n}", "Sales ML Cloud Architect", "Office")
228 for n in range(2)]
229 return shared + items
230
231 def test_no_role_is_an_example_under_two_themes(self):
232 summary = hiring_signals.analyze(self._items(), explicit=True, topic="Acme")
233 by_theme = {s["theme"]: s for s in summary["signals"]}
234 self.assertTrue({"go-to-market", "ai and machine learning",
235 "infrastructure and reliability"} <= set(by_theme))
236 urls = [e["url"] for s in summary["signals"] for e in s["evidence"]]
237 self.assertEqual(len(urls), len(set(urls)))
238 for theme in ("go-to-market", "ai and machine learning", "infrastructure and reliability"):
239 self.assertTrue(by_theme[theme]["evidence"], theme)
240
241 def test_evidence_count_is_unchanged_by_dedup(self):
242 summary = hiring_signals.analyze(self._items(), explicit=True, topic="Acme")
243 by_theme = {s["theme"]: s for s in summary["signals"]}
244 for theme in ("go-to-market", "ai and machine learning", "infrastructure and reliability"):
245 self.assertEqual(5, by_theme[theme]["evidence_count"], theme)
246
247 def test_every_theme_gets_a_first_example_before_any_gets_a_second(self):
248 summary = hiring_signals.analyze(self._items(), explicit=True, topic="Acme")
249 firsts = [s["evidence"][0]["title"] for s in summary["signals"][:3]]
250 # The two all-theme roles go to the top two themes; the third takes its own.
251 self.assertEqual(2, sum(title.startswith("Sales ML Cloud Architect") for title in firsts))
252
253
254 class HiringSignalGateTests(unittest.TestCase):
255 def _bundle(self, items: list[schema.SourceItem]) -> schema.RetrievalBundle:
256 bundle = schema.RetrievalBundle()
257 bundle.add_items("primary", "jobs", items)
258 return bundle
259
260 def test_mega_cap_standard_run_with_real_concentration_passes_the_gate(self):
261 roles = [
262 (f"{level} Machine Learning Engineer, {area}", f"Train {area} models.", dept)
263 for level, area, dept in [
264 ("Senior", "Copilot", "Research"), ("Principal", "Azure AI", "AI Platform"),
265 ("Staff", "Bing", "Search"), ("Senior", "Speech", "Research"),
266 ("Principal", "Vision", "AI Platform"), ("Senior", "Ads", "Search"),
267 ("Staff", "Office", "Research"), ("Senior", "Gaming", "AI Platform"),
268 ("Principal", "Security", "Search"), ("Senior", "Health", "Research"),
269 ]
270 ] + [
271 ("Logistics Technician", "Move parts.", "Operations"),
272 ("Paralegal", "Draft contracts.", "Legal"),
273 ]
274 bundle = self._bundle(board(*roles))
275
276 summary = pipeline._apply_hiring_signal_gate(bundle, explicit=False, topic="Microsoft")
277
278 self.assertEqual("mega-cap", summary["company_size_tier"])
279 self.assertTrue(summary["include"])
280 self.assertEqual("ai and machine learning", summary["signals"][0]["theme"])
281 self.assertIn("jobs", bundle.items_by_source)
282 shown = [e["title"] for s in summary["signals"] for e in s["evidence"]]
283 self.assertNotIn("Logistics Technician", shown)
284
285 def test_mega_cap_board_themed_only_by_boilerplate_leaves_the_pool(self):
286 # Before boilerplate removal, every one of these themed as AI, go-to-market,
287 # infrastructure, product, enterprise and data.
288 roles = [(f"Technician {n}", f"Move parts in bay {n}.", f"Site {n}") for n in range(12)]
289 bundle = self._bundle(board(*roles))
290
291 summary = pipeline._apply_hiring_signal_gate(bundle, explicit=False, topic="Microsoft")
292
293 self.assertFalse(summary["include"])
294 self.assertNotIn("jobs", bundle.items_by_source)
295
296
297 if __name__ == "__main__":
298 unittest.main()
299
300
301 class GreenhouseParagraphsTest(unittest.TestCase):
302 """HTML paragraphs without ending punctuation still split company from role text."""
303
304 def test_unpunctuated_company_paragraph_themes_nothing(self):
305 from lib import jobs, normalize
306
307 roles = [
308 ("Logistics Technician", "Move parts between sites"),
309 ("Paralegal", "Draft contracts for review"),
310 ("Executive Chef", "Run the kitchen line"),
311 ("Office Coordinator", "Plan team events"),
312 ]
313 items = []
314 for index, (title, duty) in enumerate(roles):
315 raw = jobs._greenhouse_job_to_item({
316 "id": index + 1,
317 "title": title,
318 "absolute_url": f"https://boards.greenhouse.io/acme/jobs/{index + 1}",
319 "content": f"<p>We build cloud infrastructure</p><p>{duty}</p>",
320 "departments": [{"name": "Operations"}],
321 }, "acme")
322 items.append(normalize._normalize_jobs("jobs", raw, index, "2026-10-16", "2026-11-15"))
323
324 themed = hiring_signals._theme_items(items)
325
326 for title, _duty in roles:
327 self.assertNotIn("infrastructure and reliability", themes_of(themed, title))
328
329
330 def test_general_manager_titles_are_leadership():
331 from lib import hiring_signals
332 assert "leadership" in hiring_signals._title_flags("GM, NIKE Energy DOTSWOOSH")
333 assert "leadership" in hiring_signals._title_flags("General Manager, Prime Video")
334 assert "leadership" not in hiring_signals._title_flags("Program Manager, Payments")
335
335 lines PYTHON