返回 last30days-skill
test_jobs_always.py
根目录 / tests / test_jobs_always.py
1 """The jobs lane runs without the host remembering to name it.
2
3 Evidence, four live runs on 2026-11-10 (v3.35.0):
4
5 - "Lyft", "McDonalds" and "Palmer Luckey": the host's ``--plan`` never named
6 ``jobs``, so the lane never ran. Lyft's Greenhouse board answers in 5 s.
7 - "Palmer Luckey": no company was resolved for him (Anduril is private, so
8 there is no ``--ticker``).
9 - "Anduril" with ``--official-site=anduril.com``: the careers page names no
10 hiring system, the slug ``anduril`` is a 404, and the board is
11 ``andurilindustries`` ("Anduril Industries", the name the site's own
12 structured data states).
13 - "Traeger": the careers page links ``/careers/board``, which links the
14 Greenhouse board ``traegergrills``.
15 """
16
17 from unittest.mock import patch
18
19 import pytest
20
21 import last30days as cli
22 from lib import http, jobs, pipeline, planner, schema, yahoo_finance
23
24 WINDOW = ("2026-10-12", "2026-11-11")
25
26
27 def plan_with(*source_lists):
28 return {
29 "intent": "opinion",
30 "freshness_mode": "balanced_recent",
31 "cluster_mode": "debate",
32 "subqueries": [
33 {"label": "primary" if not i else f"part-{i}", "search_query": "test topic",
34 "ranking_query": "test topic", "sources": sources, "weight": 1.0}
35 for i, sources in enumerate(source_lists)
36 ],
37 }
38
39
40 def _run_with_plan(topic, plan, *, config=None, depth="default", **kwargs):
41 with patch.object(pipeline, "_retrieve_stream", return_value=([], {})) as retrieve:
42 report = pipeline.run(
43 topic=topic, config=dict(config or {}), mock=True, web_backend="none",
44 depth=depth, external_plan=plan, **kwargs,
45 )
46 return report, {call.kwargs["source"] for call in retrieve.call_args_list}
47
48
49 def _planned(report):
50 """Subquery sources minus the installed lanes a mock run backfills."""
51 return [
52 [s for s in sq.sources if s not in planner.HOST_PLAN_BACKFILL_SOURCES]
53 for sq in report.query_plan.subqueries
54 ]
55
56
57 # --- Fix 1: the engine adds jobs to a host plan about a company ---
58
59
60 def test_company_signal_names_each_thing_that_makes_a_run_about_a_company():
61 usable = yahoo_finance.parse_host_tickers("LYFT:Lyft")
62 unusable = yahoo_finance.parse_host_tickers("LYFT")
63 assert "--official-site" in cli._company_signal({}, None, "lyft.com", [])
64 assert "--ticker" in cli._company_signal({}, usable, "", [])
65 assert "--company" in cli._company_signal({}, None, "", ["Anduril"])
66 assert "Nvidia" in cli._company_signal({"company": "Nvidia"}, None, "", [])
67 # A musician with no company, a concept, a ticker that could not be read.
68 assert cli._company_signal({}, None, "", []) == ""
69 assert cli._company_signal({}, unusable, "", []) == ""
70
71
72 @pytest.mark.parametrize("signal", ["--official-site", "--ticker", "--company", "the company Nvidia"])
73 def test_host_plan_about_a_company_gains_jobs_on_its_primary_subquery(signal, capsys):
74 report, fetched = _run_with_plan(
75 "Lyft", plan_with(["hackernews"], ["reddit"]), config={"_company_signal": signal},
76 )
77 assert _planned(report) == [["hackernews", "jobs"], ["reddit"]]
78 assert "jobs" in fetched
79 err = capsys.readouterr().err
80 assert "[Planner] Added jobs to primary" in err
81 assert signal in err
82 assert "EXCLUDE_SOURCES=jobs" in err
83
84
85 def test_host_plan_with_no_company_signal_does_not_gain_jobs(capsys):
86 report, fetched = _run_with_plan("Kanye West", plan_with(["hackernews"], ["reddit"]))
87 assert _planned(report) == [["hackernews"], ["reddit"]]
88 assert "jobs" not in fetched
89 assert "Added jobs" not in capsys.readouterr().err
90
91
92 def test_excluded_jobs_is_not_added_to_a_host_plan_about_a_company(capsys):
93 report, fetched = _run_with_plan(
94 "Lyft", plan_with(["hackernews"]),
95 config={"_company_signal": "--official-site", "EXCLUDE_SOURCES": "jobs"},
96 )
97 assert _planned(report)[0] == ["hackernews"]
98 assert "jobs" not in fetched
99 assert "Added jobs" not in capsys.readouterr().err
100
101
102 def test_search_list_without_jobs_still_runs_jobs_on_a_host_plan_about_a_company():
103 report, fetched = _run_with_plan(
104 "Lyft", plan_with(["hackernews"]), config={"_company_signal": "--official-site"},
105 requested_sources=["hackernews", "reddit"],
106 )
107 assert _planned(report)[0] == ["hackernews", "jobs"]
108 assert "jobs" in fetched
109
110
111 NIKE_SEARCH = ["reddit", "x", "youtube", "web"]
112
113
114 def test_search_list_that_would_drop_the_plans_jobs_keeps_it_and_says_so(capsys):
115 report, fetched = _run_with_plan(
116 "Nike", plan_with(["reddit", "jobs"], ["x", "youtube"]),
117 config={"_company_signal": "--official-site"}, requested_sources=NIKE_SEARCH,
118 )
119 assert _planned(report) == [["reddit", "jobs"], ["x", "youtube"]]
120 assert "jobs" in fetched
121 err = capsys.readouterr().err
122 assert err.count("--search would have dropped") == 1
123 assert "names jobs" in err
124 assert "EXCLUDE_SOURCES=jobs" in err
125
126
127 def test_excluded_jobs_stays_off_under_a_search_list_with_no_warning(capsys):
128 report, fetched = _run_with_plan(
129 "Nike", plan_with(["reddit", "jobs"], ["x"]),
130 config={"_company_signal": "--official-site", "EXCLUDE_SOURCES": "jobs"},
131 requested_sources=NIKE_SEARCH,
132 )
133 assert _planned(report) == [["reddit"], ["x"]]
134 assert "jobs" not in fetched
135 err = capsys.readouterr().err
136 assert "--search would have dropped" not in err
137 assert "--search dropped" not in err
138
139
140 def test_quick_run_under_a_search_list_does_not_gain_jobs(capsys):
141 _report, fetched = _run_with_plan(
142 "Nike", plan_with(["reddit", "jobs"]), config={"_company_signal": "--official-site"},
143 depth="quick", requested_sources=["reddit", "x"],
144 )
145 assert "jobs" not in fetched
146 # The quick run did lose the plan's jobs lane to --search, so it says so.
147 warnings = [line for line in capsys.readouterr().err.splitlines() if "--search dropped" in line]
148 assert len(warnings) == 1
149 assert "jobs" in warnings[0]
150
151
152 def test_search_list_on_a_run_with_no_company_signal_keeps_jobs_off():
153 _report, fetched = _run_with_plan(
154 "Kanye West", plan_with(["reddit"], ["x"]), requested_sources=["reddit", "x"],
155 )
156 assert "jobs" not in fetched
157
158
159 def test_engine_planned_company_run_under_a_search_list_runs_jobs():
160 with patch.object(pipeline, "_retrieve_stream", return_value=([], {})) as retrieve:
161 pipeline.run(
162 topic="Nike", config={"_company_signal": "--official-site"}, mock=True,
163 web_backend="none", depth="default", requested_sources=["reddit", "x"],
164 )
165 assert "jobs" in {call.kwargs["source"] for call in retrieve.call_args_list}
166
167
168 def test_past_window_jobs_skip_does_not_trigger_the_search_warning(capsys):
169 report, fetched = _run_with_plan(
170 "Nike", plan_with(["reddit", "jobs"]),
171 config={"_company_signal": "--official-site"},
172 requested_sources=["reddit", "x"], as_of_date="2025-01-31",
173 )
174 assert "jobs" not in fetched
175 assert report.source_status["jobs"].detail == pipeline.JOBS_PAST_WINDOW_SKIP
176 err = capsys.readouterr().err
177 assert "--search would have dropped" not in err
178 assert "--search dropped" not in err
179
180
181 def test_jobs_the_host_named_in_a_later_subquery_is_not_added_again(capsys):
182 report, _fetched = _run_with_plan(
183 "Lyft", plan_with(["hackernews"], ["reddit", "jobs"]),
184 config={"_company_signal": "--official-site"},
185 )
186 assert _planned(report) == [["hackernews"], ["reddit", "jobs"]]
187 assert "Added jobs" not in capsys.readouterr().err
188
189
190 def test_quick_host_plan_keeps_its_two_source_budget():
191 report, fetched = _run_with_plan(
192 "Lyft", plan_with(["hackernews"]), config={"_company_signal": "--official-site"},
193 depth="quick",
194 )
195 assert _planned(report)[0] == ["hackernews"]
196 assert "jobs" not in fetched
197
198
199 # --- Fix 2: --company ---
200
201
202 def test_company_flag_is_read_as_at_most_two_names(capsys):
203 assert cli._host_company_names("Anduril") == ["Anduril"]
204 assert cli._host_company_names(" Tesla ,SpaceX, ") == ["Tesla", "SpaceX"]
205 assert cli._host_company_names("") == []
206 assert cli._host_company_names("Tesla,SpaceX,Neuralink") == ["Tesla", "SpaceX"]
207 assert "Neuralink" in capsys.readouterr().err
208
209
210 def test_company_flag_feeds_the_jobs_lane_for_a_person_with_no_ticker():
211 assert cli._company_for_jobs({}, None, "Palmer Luckey", host_names=["Anduril"]) == {
212 "host_companies": ["Anduril"],
213 }
214 # The topic's own name is never one of them, and Wikidata's company stays.
215 assert cli._company_for_jobs({}, None, "Anduril", host_names=["Anduril"]) == {}
216 resolved = {"company": "Nvidia"}
217 assert cli._company_for_jobs(resolved, None, "Jensen Huang", host_names=["Other"]) == resolved
218
219
220 def test_company_flag_and_ticker_companies_are_one_list_without_repeats():
221 pairs = yahoo_finance.parse_host_tickers("TSLA:Tesla Inc.,SPCX:SpaceX")
222 assert cli._company_for_jobs({}, pairs, "Elon Musk", host_names=["Tesla", "xAI"]) == {
223 "host_companies": ["Tesla", "xAI", "SpaceX"],
224 }
225
226
227 def _run_lane(topic, company, search, config=None):
228 subquery = schema.SubQuery(label="primary", search_query=topic, ranking_query=topic, sources=["jobs"])
229 config = {"_company": company, **(config or {})}
230 with patch.object(jobs, "search_jobs", side_effect=search) as mock:
231 result = pipeline._retrieve_stream_impl(
232 topic=topic, subquery=subquery, source="jobs", config=config,
233 depth="default", date_range=WINDOW, runtime=None, mock=False,
234 web_backend="auto", raw_topic=topic,
235 )
236 return result, [call.args[0] for call in mock.call_args_list], mock
237
238
239 def test_person_with_a_host_company_gets_that_companys_board():
240 board = {"tier": "ats", "provider": "greenhouse", "company": "Anduril", "open_roles": 2}
241
242 def search(name, *_args, **_kwargs):
243 return ([{"id": "1"}, {"id": "2"}], dict(board)) if name == "Anduril" else ([], {"tier": "web"})
244
245 (items, artifact), names, _mock = _run_lane("Palmer Luckey", {"host_companies": ["Anduril"]}, search)
246 assert names == ["Palmer Luckey", "Anduril"]
247 assert len(items) == 2
248 assert artifact["board_of"] == "Anduril"
249
250
251 def test_two_host_companies_are_tried_in_order_and_the_first_board_wins():
252 def search(name, *_args, **_kwargs):
253 if name == "SpaceX":
254 return [{"id": "1"}], {"tier": "ats", "provider": "greenhouse", "open_roles": 1}
255 return [], {"tier": "web"}
256
257 (_items, artifact), names, _mock = _run_lane(
258 "Elon Musk", {"host_companies": ["Tesla", "SpaceX", "xAI"]}, search,
259 )
260 assert names == ["Elon Musk", "Tesla", "SpaceX"]
261 assert artifact["board_of"] == "SpaceX"
262
263
264 # --- Fix 3: --jobs-board ---
265
266
267 @pytest.mark.parametrize("url, expected", [
268 ("https://job-boards.greenhouse.io/andurilindustries", ("greenhouse", "andurilindustries")),
269 ("https://boards.greenhouse.io/lyft/jobs/8311413?gh_jid=8311413", ("greenhouse", "lyft")),
270 ("https://boards.greenhouse.io/embed/job_board?for=acme", ("greenhouse", "acme")),
271 ("job-boards.greenhouse.io/traegergrills", ("greenhouse", "traegergrills")),
272 ("https://jobs.lever.co/acme", ("lever", "acme")),
273 ("https://jobs.ashbyhq.com/acme", ("ashby", "acme")),
274 ("https://apply.workable.com/acme/", ("workable", "acme")),
275 ("https://jobs.smartrecruiters.com/AcmeCorporation", ("smartrecruiters", "AcmeCorporation")),
276 ("https://careers.smartrecruiters.com/AcmeCorporation", ("smartrecruiters", "AcmeCorporation")),
277 (
278 "https://nvidia.wd5.myworkdayjobs.com/en-US/NVIDIAExternalCareerSite",
279 ("workday", "nvidia.wd5/NVIDIAExternalCareerSite"),
280 ),
281 ("https://nvidia.wd5.myworkdayjobs.com/NVIDIAExternalCareerSite/job/JR1", ("workday", "nvidia.wd5/NVIDIAExternalCareerSite")),
282 ])
283 def test_board_url_gives_the_provider_and_slug_of_each_supported_system(url, expected):
284 assert jobs.parse_board_url(url) == expected
285
286
287 @pytest.mark.parametrize("url", [
288 "https://jobs.mcdonalds.com/",
289 "https://career41.sapsf.com/career?company=mcdonaldsc",
290 "https://www.anduril.com/open-roles",
291 # A supported system's name in the path or query of another host.
292 "https://example.com/?next=jobs.lever.co/acme",
293 "https://jobs.lever.co.example.com/acme",
294 "https://nvidia.wd5.myworkdayjobs.com/",
295 "not a url",
296 "",
297 ])
298 def test_url_that_is_not_a_supported_board_gives_nothing(url):
299 assert jobs.parse_board_url(url) == (None, None)
300
301
302 def _greenhouse(slug, company_name, count=3):
303 return {"jobs": [
304 {
305 "id": index, "title": f"Engineer {index}", "company_name": company_name,
306 "absolute_url": f"https://boards.greenhouse.io/{slug}/jobs/{index}",
307 "content": f"Build thing {index}.", "first_published": "2026-11-01T00:00:00Z",
308 }
309 for index in range(1, count + 1)
310 ]}
311
312
313 def _greenhouse_api(boards):
314 """``http.get`` for Greenhouse: the named boards answer, every other slug
315 and every other provider is a 404. The URLs asked are recorded."""
316 asked = []
317
318 def get(url, *_args, **_kwargs):
319 asked.append(url)
320 for slug, payload in boards.items():
321 if url == f"https://boards-api.greenhouse.io/v1/boards/{slug}/jobs":
322 return payload
323 if url == f"https://boards-api.greenhouse.io/v1/boards/{slug}":
324 return {"name": payload["jobs"][0]["company_name"]}
325 raise http.HTTPError("HTTP 404: Not Found", status_code=404)
326
327 return asked, get
328
329
330 ANDURIL_BOARD = "https://job-boards.greenhouse.io/andurilindustries"
331
332
333 def test_host_board_that_names_the_company_is_owned_and_gives_a_digest():
334 asked, get = _greenhouse_api({"andurilindustries": _greenhouse("andurilindustries", "Anduril Industries")})
335 with patch("lib.jobs.http.get_text", side_effect=AssertionError("no page is needed")), \
336 patch("lib.jobs.http.get", side_effect=get):
337 items, artifact = jobs.search_board_url(
338 ANDURIL_BOARD, ["Palmer Luckey", "Anduril"], WINDOW, {},
339 )
340 # The board's own record says whose it is before its job list is read.
341 assert asked == [
342 "https://boards-api.greenhouse.io/v1/boards/andurilindustries",
343 "https://boards-api.greenhouse.io/v1/boards/andurilindustries/jobs",
344 ]
345 assert len(items) == 3
346 assert artifact["tier"] == "ats"
347 assert artifact["found_via"] == "host"
348 assert artifact["owned"] is True
349 assert artifact["company"] == "Anduril"
350 assert artifact["board_company"] == "Anduril Industries"
351 assert artifact["open_roles"] == 3
352 assert artifact["digest"]["roles"]
353
354
355 def test_host_board_that_names_another_company_is_counted_with_no_digest(capsys):
356 _asked, get = _greenhouse_api({"andurilindustries": _greenhouse("andurilindustries", "Sgt. Pepper's Band")})
357 with patch("lib.jobs.http.get_text", return_value=None), \
358 patch("lib.jobs.http.get", side_effect=get):
359 items, artifact = jobs.search_board_url(
360 ANDURIL_BOARD, ["Palmer Luckey", "Anduril"], WINDOW, {},
361 )
362 assert len(items) == 3
363 assert artifact["open_roles"] == 3
364 assert artifact["owned"] is False
365 assert "digest" not in artifact
366 err = capsys.readouterr().err
367 assert "[Jobs] --jobs-board" in err
368 assert "Sgt. Pepper's Band" in err
369 assert "no digest" in err
370
371
372 def test_host_board_whose_name_only_starts_like_the_company_is_not_owned():
373 # "Metabase" is not "Meta": the company's name must be whole words.
374 _asked, get = _greenhouse_api({"metabase": _greenhouse("metabase", "Metabase")})
375 with patch("lib.jobs.http.get_text", return_value=None), \
376 patch("lib.jobs.http.get", side_effect=get):
377 _items, artifact = jobs.search_board_url(
378 "https://boards.greenhouse.io/metabase", ["Meta"], WINDOW, {},
379 )
380 assert artifact["owned"] is False
381
382
383 WORKDAY_URL = "https://acme.wd5.myworkdayjobs.com/en-US/AcmeCareers"
384
385
386 def _workday_board(token, *, deadline, **_kwargs):
387 rows = [
388 {
389 "id": f"JR{index}", "title": f"Engineer {index}", "provider": "workday",
390 "url": f"https://acme.wd5.myworkdayjobs.com/AcmeCareers/job/JR{index}",
391 "description": "", "date": None, "department": f"Team {index}", "location": "Austin",
392 }
393 for index in range(4)
394 ]
395 return rows, {"board_total": 4, "board_capped": False, "board_cut_short": False}
396
397
398 def test_host_board_with_no_name_of_its_own_is_owned_when_the_official_site_links_it():
399 pages = {"https://www.zenith.example/careers": f'<h2>Open roles</h2><a href="{WORKDAY_URL}">Jobs</a>'}
400 with patch("lib.jobs.http.get_text", side_effect=lambda url, **_k: pages.get(url)), \
401 patch.object(jobs, "search_workday_board", side_effect=_workday_board), \
402 patch.object(jobs, "fetch_workday_details", return_value=(0, 0)):
403 items, artifact = jobs.search_board_url(
404 WORKDAY_URL, ["Zenith"], WINDOW, {}, site="https://www.zenith.example",
405 )
406 assert len(items) == 4
407 assert artifact["found_via"] == "site"
408 assert artifact["owned"] is True
409 assert artifact["digest"]["roles"]
410
411
412 def test_host_board_with_no_name_that_the_official_site_does_not_link_is_not_owned(capsys):
413 pages = {"https://www.zenith.example/careers": "<h2>Open roles</h2>"}
414 with patch("lib.jobs.http.get_text", side_effect=lambda url, **_k: pages.get(url)), \
415 patch.object(jobs, "search_workday_board", side_effect=_workday_board):
416 items, artifact = jobs.search_board_url(
417 WORKDAY_URL, ["Zenith"], WINDOW, {}, site="https://www.zenith.example",
418 )
419 assert len(items) == 4
420 assert artifact["owned"] is False
421 assert "digest" not in artifact
422 assert "does not link" in capsys.readouterr().err
423
424
425 def test_host_board_whose_slug_is_the_companys_name_is_owned():
426 # Ashby, Lever, Workable and Workday state no company name: the board's
427 # own slug is the name it gives itself.
428 rows = [{"id": "1", "title": "Engineer", "provider": "lever", "url": "https://jobs.lever.co/acme/1",
429 "description": "Build.", "date": None, "department": "Eng", "location": "Austin"}]
430 with patch("lib.jobs.http.get_text", side_effect=AssertionError("no page is needed")), \
431 patch.object(jobs, "_fetch_ats", return_value=rows):
432 _items, artifact = jobs.search_board_url("https://jobs.lever.co/acme", ["Jane Doe", "Acme"], WINDOW, {})
433 assert artifact["owned"] is True
434 assert artifact["company"] == "Acme"
435
436
437 def test_unsupported_board_url_is_ignored_with_one_line_and_no_request(capsys):
438 with patch("lib.jobs.http.get_text", side_effect=AssertionError("nothing is fetched")), \
439 patch("lib.jobs.http.get", side_effect=AssertionError("nothing is fetched")):
440 assert jobs.search_board_url("https://jobs.mcdonalds.com/", ["McDonalds"], WINDOW, {}) == ([], {})
441 err = capsys.readouterr().err
442 assert err.count("[Jobs]") == 1
443 assert "--jobs-board ignored" in err
444 assert "jobs.mcdonalds.com" in err
445
446
447 def test_host_board_that_cannot_be_read_gives_nothing_and_says_so(capsys):
448 _asked, get = _greenhouse_api({})
449 with patch("lib.jobs.http.get", side_effect=get):
450 assert jobs.search_board_url(ANDURIL_BOARD, ["Anduril"], WINDOW, {}) == ([], {})
451 assert "--jobs-board" in capsys.readouterr().err
452
453
454 def test_owned_host_board_ends_the_lane_before_any_other_search():
455 board = {"tier": "ats", "provider": "greenhouse", "company": "Anduril", "owned": True, "open_roles": 3}
456 with patch.object(jobs, "search_board_url", return_value=([{"id": "1"}], dict(board))) as host:
457 (items, artifact), names, _mock = _run_lane(
458 "Palmer Luckey", {"host_companies": ["Anduril"]},
459 lambda *_a, **_k: pytest.fail("the lane already has its board"),
460 config={"_jobs_board": ANDURIL_BOARD},
461 )
462 assert host.call_args.args[:2] == (ANDURIL_BOARD, ["Palmer Luckey", "Anduril"])
463 assert names == []
464 assert len(items) == 1
465 assert artifact["board_of"] == "Anduril"
466
467
468 def test_unowned_host_board_is_kept_only_when_the_lane_finds_no_board_itself():
469 unowned = {"tier": "ats", "provider": "greenhouse", "company": "Palmer Luckey", "owned": False, "open_roles": 9}
470 found = {"tier": "ats", "provider": "ashby", "company": "Anduril", "owned": True, "open_roles": 2}
471
472 def nothing(*_args, **_kwargs):
473 return [], {"tier": "web"}
474
475 def anduril(name, *_args, **_kwargs):
476 return ([{"id": "a"}], dict(found)) if name == "Anduril" else ([], {"tier": "web"})
477
478 with patch.object(jobs, "search_board_url", return_value=([{"id": "1"}], dict(unowned))):
479 (_items, artifact), names, _mock = _run_lane(
480 "Palmer Luckey", {"host_companies": ["Anduril"]}, nothing,
481 config={"_jobs_board": ANDURIL_BOARD},
482 )
483 assert names == ["Palmer Luckey", "Anduril"]
484 assert artifact["open_roles"] == 9 and artifact["owned"] is False
485
486 (_items, artifact), _names, _mock = _run_lane(
487 "Palmer Luckey", {"host_companies": ["Anduril"]}, anduril,
488 config={"_jobs_board": ANDURIL_BOARD},
489 )
490 assert artifact["provider"] == "ashby"
491 assert artifact["board_of"] == "Anduril"
492
493
494 # --- Fix 4: boards the lane finds without the host ---
495
496 # www.anduril.com/careers on 2026-11-10: no hiring system is named (the job
497 # list is read from a search index by script). The page's structured data
498 # states the organization's name, and a social link carries the same token.
499 ANDURIL_CAREERS = """
500 <title>Careers | Anduril</title>
501 <meta property="og:site_name" content="Anduril">
502 <script type="application/ld+json">{"@context":"https://schema.org","@graph":[
503 {"@type":"WebPage","url":"https://www.anduril.com/careers","name":"Careers",
504 "isPartOf":{"@type":"WebSite","name":"Transforming US & allied military capabilities",
505 "publisher":{"@type":"Organization","name":"Anduril Industries","url":"https://www.anduril.com"}}}]}
506 </script>
507 <a href="https://www.facebook.com/andurilindustries/">Facebook</a>
508 <h2>Open Roles</h2>
509 """
510
511
512 def test_names_a_careers_page_states_for_its_organization_are_read():
513 assert jobs._stated_names(ANDURIL_CAREERS) == ["Anduril Industries", "Anduril"]
514 assert jobs._stated_names("<h1>Careers</h1>") == []
515
516
517 def test_board_under_the_name_the_official_site_states_is_found_and_owned():
518 asked, get = _greenhouse_api({"andurilindustries": _greenhouse("andurilindustries", "Anduril Industries")})
519 pages = {"https://anduril.com/careers": ANDURIL_CAREERS}
520 with patch("lib.jobs.http.get_text", side_effect=lambda url, **_k: pages.get(url)), \
521 patch("lib.jobs.http.get", side_effect=get):
522 items, artifact = jobs.search_jobs(
523 "Anduril", WINDOW, {}, web_backend="none", site="anduril.com",
524 )
525 # The company's own name is tried first; the site's name only after it.
526 assert asked[0] == "https://boards-api.greenhouse.io/v1/boards/anduril/jobs"
527 assert asked[-1] == "https://boards-api.greenhouse.io/v1/boards/andurilindustries/jobs"
528 assert len(items) == 3
529 assert artifact["tier"] == "ats"
530 assert artifact["board_token"] == "andurilindustries"
531 assert artifact["found_via"] == "site-name"
532 assert artifact["owned"] is True
533 assert artifact["digest"]["roles"]
534
535
536 def test_board_under_the_stated_name_must_state_that_name_itself():
537 # The slug the site's name gives belongs to someone else.
538 _asked, get = _greenhouse_api({"andurilindustries": _greenhouse("andurilindustries", "Anduril Bakery")})
539 pages = {"https://anduril.com/careers": ANDURIL_CAREERS}
540 with patch("lib.jobs.http.get_text", side_effect=lambda url, **_k: pages.get(url)), \
541 patch("lib.jobs.http.get", side_effect=get):
542 _items, artifact = jobs.search_jobs("Anduril", WINDOW, {}, web_backend="none", site="anduril.com")
543 assert artifact.get("owned") is not True
544 assert "digest" not in artifact
545
546
547 def test_stated_name_that_is_not_a_form_of_the_companys_is_not_probed():
548 page = ANDURIL_CAREERS.replace("Anduril Industries", "Hosting Partners").replace(
549 'content="Anduril"', 'content="Hosting Partners"',
550 )
551 asked, get = _greenhouse_api({"hostingpartners": _greenhouse("hostingpartners", "Hosting Partners")})
552 with patch("lib.jobs.http.get_text", side_effect=lambda url, **_k: page if url.endswith("/careers") else None), \
553 patch("lib.jobs.http.get", side_effect=get):
554 items, _artifact = jobs.search_jobs("Anduril", WINDOW, {}, web_backend="none", site="anduril.com")
555 assert items == []
556 assert not any("hostingpartners" in url for url in asked)
557
558
559 # www.traeger.com/careers on 2026-11-10 links its job list at /careers/board,
560 # and only that page links the Greenhouse postings.
561 TRAEGER_CAREERS = '<h2>Join our team</h2><a href="/careers">Careers</a><a href="/careers/board">See open positions</a>'
562 TRAEGER_BOARD = (
563 '<a href="https://job-boards.greenhouse.io/traegergrills/jobs/8311413">Finance Manager</a>'
564 )
565
566
567 def test_board_page_under_the_careers_page_is_followed_to_the_board():
568 asked, get = _greenhouse_api({"traegergrills": _greenhouse("traegergrills", "Traeger Grills")})
569 pages = {
570 "https://traeger.com/careers": TRAEGER_CAREERS,
571 "https://traeger.com/careers/board": TRAEGER_BOARD,
572 }
573 fetched = []
574
575 def get_text(url, **_kwargs):
576 fetched.append(url)
577 return pages.get(url)
578
579 with patch("lib.jobs.http.get_text", side_effect=get_text), \
580 patch("lib.jobs.http.get", side_effect=get):
581 items, artifact = jobs.search_jobs("Traeger", WINDOW, {}, web_backend="none", site="traeger.com")
582 assert fetched == ["https://traeger.com/careers", "https://traeger.com/careers/board"]
583 assert asked == ["https://boards-api.greenhouse.io/v1/boards/traegergrills/jobs"]
584 assert len(items) == 3
585 assert artifact["found_via"] == "site"
586 assert artifact["owned"] is True
587
588
589 # --- Fix 5: an official site that cannot be fetched ---
590
591
592 def test_official_site_that_refuses_the_request_still_gets_its_slug_probed():
593 # mcdonalds.com answers 403 to the engine: no page, so no careers link.
594 asked, get = _greenhouse_api({"lyft": _greenhouse("lyft", "Lyft")})
595 with patch("lib.jobs.http.get_text", return_value=None), \
596 patch("lib.jobs.http.get", side_effect=get):
597 items, artifact = jobs.search_jobs("Lyft", WINDOW, {}, web_backend="none", site="lyft.com")
598 assert asked == ["https://boards-api.greenhouse.io/v1/boards/lyft/jobs"]
599 assert len(items) == 3
600 assert artifact["owned"] is True
601 assert artifact["digest"]["roles"]
602
603
604 def test_official_site_that_refuses_the_request_does_not_stop_a_host_board():
605 _asked, get = _greenhouse_api({"lyft": _greenhouse("lyft", "Lyft")})
606 with patch("lib.jobs.http.get_text", return_value=None), \
607 patch("lib.jobs.http.get", side_effect=get):
608 items, artifact = jobs.search_board_url(
609 "https://boards.greenhouse.io/lyft", ["Lyft"], WINDOW, {}, site="lyft.com",
610 )
611 assert len(items) == 3
612 assert artifact["owned"] is True
613
614
615 # --- The flags exist and reach the run ---
616
617
618 def test_parser_takes_company_and_jobs_board():
619 args = cli.build_parser().parse_args([
620 "Palmer Luckey", "--company", "Anduril", "--jobs-board", ANDURIL_BOARD,
621 ])
622 assert args.company == "Anduril"
623 assert args.jobs_board == ANDURIL_BOARD
624
625
626 def test_company_and_jobs_board_are_part_of_what_a_cached_report_was_run_with():
627 args = cli.build_parser().parse_args([
628 "Palmer Luckey", "--company", "Anduril", "--jobs-board", ANDURIL_BOARD,
629 ])
630 options = cli._cache_research_options(args)
631 assert options["company"] == "Anduril"
632 assert options["jobs_board"] == ANDURIL_BOARD
633
634
635 # --- Review of PR #1410 ---
636
637 # Finding 1: --jobs-board alone starts the lane.
638
639
640 def test_jobs_board_alone_makes_the_run_about_a_company():
641 assert "--jobs-board" in cli._company_signal({}, None, "", [], jobs_board=ANDURIL_BOARD)
642 assert cli._company_signal({}, None, "", [], jobs_board=" ") == ""
643
644
645 # Finding 2: only a confirmed official site's stated name makes a board owned.
646
647 APEX_CAREERS = """
648 <script type="application/ld+json">{"@type":"Organization","name":"Apex Tool Group"}</script>
649 <h2>Open Roles</h2>
650 """
651
652
653 def test_name_stated_on_a_guessed_domain_finds_a_board_but_does_not_make_it_owned():
654 # apex.com is a guess from the name "Apex" and belongs to another business.
655 asked, get = _greenhouse_api({"apextoolgroup": _greenhouse("apextoolgroup", "Apex Tool Group")})
656 pages = {"https://apex.com/careers": APEX_CAREERS}
657 with patch("lib.jobs.http.get_text", side_effect=lambda url, **_k: pages.get(url)), \
658 patch("lib.jobs.http.get", side_effect=get):
659 items, artifact = jobs.search_jobs("Apex", WINDOW, {}, web_backend="none")
660 assert asked[-1] == "https://boards-api.greenhouse.io/v1/boards/apextoolgroup/jobs"
661 assert len(items) == 3
662 assert artifact["open_roles"] == 3
663 assert artifact["found_via"] == "slug-guess"
664 assert artifact["owned"] is False
665 assert "digest" not in artifact
666
667
668 def test_same_page_on_the_confirmed_official_site_makes_the_board_owned():
669 _asked, get = _greenhouse_api({"apextoolgroup": _greenhouse("apextoolgroup", "Apex Tool Group")})
670 pages = {"https://apex.com/careers": APEX_CAREERS}
671 with patch("lib.jobs.http.get_text", side_effect=lambda url, **_k: pages.get(url)), \
672 patch("lib.jobs.http.get", side_effect=get):
673 _items, artifact = jobs.search_jobs("Apex", WINDOW, {}, web_backend="none", site="apex.com")
674 assert artifact["found_via"] == "site-name"
675 assert artifact["owned"] is True
676
677
678 def test_each_host_company_gets_the_official_site_the_resolver_returns():
679 def resolve(name, *, listing=True, **_kwargs):
680 assert listing is False
681 if name == "Anduril":
682 return {"company": "Anduril Industries", "company_site": "https://www.anduril.com/"}
683 return {}
684
685 with patch.object(cli.company_resolve, "resolve_company", side_effect=resolve):
686 sites = cli._host_company_sites(["Anduril", "Nobody Inc"], mock=False, config={})
687 assert sites == {"Anduril": "https://www.anduril.com/"}
688 # No request on a mock run or with the jobs lane excluded.
689 assert cli._host_company_sites(["Anduril"], mock=True, config={}) == {}
690 assert cli._host_company_sites(["Anduril"], mock=False, config={"EXCLUDE_SOURCES": "jobs"}) == {}
691 assert cli._company_for_jobs(
692 {}, None, "Palmer Luckey", host_names=["Anduril"], host_sites=sites,
693 ) == {"host_companies": ["Anduril"], "host_company_sites": sites}
694
695
696 def test_host_company_is_searched_from_its_resolved_official_site():
697 seen = {}
698
699 def search(name, *_args, **kwargs):
700 seen[name] = kwargs.get("site", "")
701 return [], {"tier": "web"}
702
703 _run_lane(
704 "Palmer Luckey",
705 {"host_companies": ["Anduril", "Saronic"],
706 "host_company_sites": {"Anduril": "https://www.anduril.com/"}},
707 search,
708 )
709 assert seen == {"Palmer Luckey": "", "Anduril": "https://www.anduril.com/", "Saronic": ""}
710
711
712 # Finding 3: an unverified host board does not get the lane's whole budget.
713
714
715 def _workday_pages(total):
716 posted = []
717
718 def post(url, *, json_data, **_kwargs):
719 posted.append(json_data["offset"])
720 return {"total": total, "jobPostings": [
721 {"title": f"Engineer {json_data['offset'] + index}",
722 "externalPath": f"/job/JR{json_data['offset'] + index}"}
723 for index in range(min(20, total - json_data["offset"]))
724 ]}
725
726 return posted, post
727
728
729 def test_unowned_host_board_is_read_one_page_only(capsys):
730 posted, post = _workday_pages(2000)
731 with patch("lib.jobs.http.get_text", return_value=None), \
732 patch("lib.jobs.http.post", side_effect=post):
733 items, artifact = jobs.search_board_url(WORKDAY_URL, ["Zenith"], WINDOW, {})
734 assert posted == [0]
735 assert len(items) == 20
736 assert artifact["owned"] is False
737 assert artifact["open_roles_floor"] is True
738 assert "first page" in artifact["coverage_note"]
739 assert "no digest" in capsys.readouterr().err
740
741
742 def test_owned_host_board_is_read_in_full():
743 posted, post = _workday_pages(60)
744 pages = {"https://www.zenith.example/careers": f'<h2>Open roles</h2><a href="{WORKDAY_URL}">Jobs</a>'}
745 with patch("lib.jobs.http.get_text", side_effect=lambda url, **_k: pages.get(url)), \
746 patch("lib.jobs.http.post", side_effect=post), \
747 patch.object(jobs, "fetch_workday_details", return_value=(0, 0)):
748 items, artifact = jobs.search_board_url(
749 WORKDAY_URL, ["Zenith"], WINDOW, {}, site="https://www.zenith.example",
750 )
751 assert sorted(posted) == [0, 20, 40]
752 assert len(items) == 60
753 assert artifact["owned"] is True
754
755
756 def test_unowned_smartrecruiters_board_is_named_and_read_from_its_first_page():
757 asked = []
758
759 def get(url, *, params=None, **_kwargs):
760 asked.append(dict(params or {}))
761 return {"totalFound": 900, "content": [
762 {"id": str(index), "name": f"Cook {index}", "company": {"name": "Other Burgers"}}
763 for index in range(100)
764 ]}
765
766 with patch("lib.jobs.http.get_text", return_value=None), patch("lib.jobs.http.get", side_effect=get):
767 items, artifact = jobs.search_board_url(
768 "https://jobs.smartrecruiters.com/OtherBurgers", ["McDonalds"], WINDOW, {},
769 )
770 assert asked == [{"limit": "100"}]
771 assert len(items) == 100
772 assert artifact["owned"] is False and artifact["board_company"] == "Other Burgers"
773
774
775 def test_host_board_gets_a_share_of_the_budget_not_all_of_it():
776 seen = {}
777
778 def host(*_args, **kwargs):
779 seen.update(kwargs)
780 return [], {}
781
782 with patch.object(jobs, "search_board_url", side_effect=host):
783 _run_lane(
784 "Palmer Luckey", {"host_companies": ["Anduril"]}, lambda *_a, **_k: ([], {"tier": "web"}),
785 config={"_jobs_board": ANDURIL_BOARD},
786 )
787 # The board, the topic and one host company: a third each.
788 assert 0 < seen["discovery_seconds"] <= jobs.JOBS_BUDGET_SECONDS / 3 + 0.5
789
790
791 def test_owned_greenhouse_host_board_is_read_with_the_whole_budget_not_the_share():
792 # Anduril's job list is megabytes: read inside a 15 s share it timed out.
793 limits = []
794 budget = jobs.LaneBudget()
795
796 def get(url, *_args, **_kwargs):
797 limits.append((url.rsplit("/", 1)[-1], budget.step_deadline < budget.deadline))
798 if url.endswith("/jobs"):
799 return _greenhouse("andurilindustries", "Anduril Industries")
800 return {"name": "Anduril Industries"}
801
802 with patch("lib.jobs.http.get", side_effect=get):
803 _items, artifact = jobs.search_board_url(
804 ANDURIL_BOARD, ["Palmer Luckey", "Anduril"], WINDOW, {},
805 budget=budget, discovery_seconds=15,
806 )
807 assert artifact["owned"] is True
808 # The record is asked inside the share; the owned board's rows are not.
809 assert limits == [("andurilindustries", True), ("jobs", False)]
810
811
812 def test_unowned_greenhouse_host_board_is_read_inside_its_share():
813 limits = []
814 budget = jobs.LaneBudget()
815
816 def get(url, *_args, **_kwargs):
817 limits.append(budget.step_deadline < budget.deadline)
818 if url.endswith("/jobs"):
819 return _greenhouse("andurilindustries", "Other Co")
820 return {"name": "Other Co"}
821
822 with patch("lib.jobs.http.get", side_effect=get):
823 _items, artifact = jobs.search_board_url(
824 ANDURIL_BOARD, ["Anduril"], WINDOW, {}, budget=budget, discovery_seconds=15,
825 )
826 assert artifact["owned"] is False
827 assert limits == [True, True]
828 # The share is lifted again for whatever the lane does next.
829 assert budget.step_deadline == budget.deadline
830
831
832 def test_unowned_host_board_is_shown_under_the_name_it_states():
833 unowned = {"tier": "ats", "provider": "greenhouse", "company": "Palmer Luckey",
834 "board_company": "Anduril Industries", "owned": False, "open_roles": 9}
835 with patch.object(jobs, "search_board_url", return_value=([{"id": "1"}], dict(unowned))):
836 (_items, artifact), _names, _mock = _run_lane(
837 "Palmer Luckey", {}, lambda *_a, **_k: ([], {"tier": "web"}),
838 config={"_jobs_board": ANDURIL_BOARD},
839 )
840 assert artifact["board_of"] == "Anduril Industries"
841
842
843 # --- --company "Name:site": the host passes the company's official site ---
844
845
846 def test_company_entry_is_a_name_or_a_name_and_its_site():
847 assert cli._host_companies("Anduril") == [{"name": "Anduril", "site": ""}]
848 assert cli._host_companies("Anduril:anduril.com") == [
849 {"name": "Anduril", "site": "https://anduril.com/"},
850 ]
851 assert cli._host_companies(" Tesla : tesla.com , SpaceX:spacex.com ") == [
852 {"name": "Tesla", "site": "https://tesla.com/"},
853 {"name": "SpaceX", "site": "https://spacex.com/"},
854 ]
855 # A URL is a site too, normalized the way --official-site is.
856 assert cli._host_companies("Anduril:https://www.Anduril.com/careers?x=1") == [
857 {"name": "Anduril", "site": "https://www.anduril.com/"},
858 ]
859 assert cli._host_company_names("Tesla:tesla.com,SpaceX") == ["Tesla", "SpaceX"]
860 assert cli._host_companies("") == []
861
862
863 def test_company_entry_that_cannot_be_read_is_ignored_with_a_line(capsys):
864 # No name before the colon: nothing says whose site it is.
865 assert cli._host_companies(":anduril.com,SpaceX") == [{"name": "SpaceX", "site": ""}]
866 err = capsys.readouterr().err
867 assert "[Resolve] --company" in err and "anduril.com" in err
868 # A site that is not a domain: the name stands, without a site.
869 assert cli._host_companies("Anduril:not a site") == [{"name": "Anduril", "site": ""}]
870 err = capsys.readouterr().err
871 assert "[Resolve] --company" in err and "not a site" in err
872 # A third entry is one too many.
873 assert [c["name"] for c in cli._host_companies("A:a.com,B:b.com,C:c.com")] == ["A", "B"]
874 assert "C" in capsys.readouterr().err
875
876
877 def test_site_the_host_passed_is_used_without_asking_the_resolver():
878 def resolve(name, *, listing=True, **_kwargs):
879 assert name == "SpaceX", "a company that came with its site is not looked up"
880 return {"company": "SpaceX", "company_site": "https://www.spacex.com/"}
881
882 companies = cli._host_companies("Tesla:tesla.com,SpaceX")
883 with patch.object(cli.company_resolve, "resolve_company", side_effect=resolve):
884 sites = cli._host_company_sites(companies, mock=False, config={})
885 assert sites == {"Tesla": "https://tesla.com/", "SpaceX": "https://www.spacex.com/"}
886 # The host's own site needs no lookup, so a mock run keeps it.
887 assert cli._host_company_sites(companies, mock=True, config={}) == {"Tesla": "https://tesla.com/"}
888
889
890 def test_company_named_with_a_site_and_again_by_ticker_is_one_company_with_its_site():
891 pairs = yahoo_finance.parse_host_tickers("TSLA:Tesla Inc.,SPCX:SpaceX")
892 companies = cli._host_companies("Tesla:tesla.com,SpaceX:spacex.com")
893 sites = cli._host_company_sites(companies, mock=True, config={})
894 assert cli._company_for_jobs(
895 {}, pairs, "Elon Musk", host_names=[c["name"] for c in companies], host_sites=sites,
896 ) == {
897 "host_companies": ["Tesla", "SpaceX"],
898 "host_company_sites": {"Tesla": "https://tesla.com/", "SpaceX": "https://spacex.com/"},
899 }
900
901
902 def test_site_passed_for_the_topic_itself_is_the_topics_site():
903 companies = cli._host_companies("Anduril:anduril.com")
904 sites = cli._host_company_sites(companies, mock=True, config={})
905 assert cli._company_for_jobs(
906 {}, None, "Anduril", host_names=["Anduril"], host_sites=sites,
907 ) == {"topic_site": "https://anduril.com/"}
908 # --official-site, when given, stays the topic's site.
909 assert cli._company_for_jobs(
910 {}, None, "Anduril", official_site="anduril.io", host_names=["Anduril"], host_sites=sites,
911 ) == {"topic_site": "anduril.io"}
912
913
914 def _palmer_luckey_lane(company_flag):
915 """The real lane for "Palmer Luckey" with ``--company``: anduril.com's
916 careers page names no hiring system and states "Anduril Industries"."""
917 _asked, get = _greenhouse_api({"andurilindustries": _greenhouse("andurilindustries", "Anduril Industries")})
918 pages = {"https://anduril.com/careers": ANDURIL_CAREERS}
919 companies = cli._host_companies(company_flag)
920 with patch.object(cli.company_resolve, "resolve_company", return_value={}):
921 sites = cli._host_company_sites(companies, mock=False, config={})
922 company = cli._company_for_jobs(
923 {}, None, "Palmer Luckey", host_names=[c["name"] for c in companies], host_sites=sites,
924 )
925 subquery = schema.SubQuery(
926 label="primary", search_query="Palmer Luckey", ranking_query="Palmer Luckey", sources=["jobs"],
927 )
928 with patch("lib.jobs.http.get_text", side_effect=lambda url, **_k: pages.get(url)), \
929 patch("lib.jobs.http.get", side_effect=get):
930 return pipeline._retrieve_stream_impl(
931 topic="Palmer Luckey", subquery=subquery, source="jobs", config={"_company": company},
932 depth="default", date_range=WINDOW, runtime=None, mock=False,
933 web_backend="none", raw_topic="Palmer Luckey",
934 )
935
936
937 def test_person_whose_company_came_with_its_site_gets_a_digest():
938 items, artifact = _palmer_luckey_lane("Anduril:anduril.com")
939 assert len(items) == 3
940 assert artifact["found_via"] == "site-name"
941 assert artifact["owned"] is True
942 assert artifact["digest"]["roles"]
943 assert artifact["board_of"] == "Anduril"
944
945
946 def test_person_whose_company_came_with_no_site_gets_counts_only():
947 # Wikidata has no site for "Anduril", and the guessed anduril.com cannot vouch.
948 items, artifact = _palmer_luckey_lane("Anduril")
949 assert len(items) == 3
950 assert artifact["open_roles"] == 3
951 assert artifact["owned"] is False
952 assert "digest" not in artifact
953
954
955 # careers.google.com on 2026-11-10 links a PDF under /jobs/; read as a page
956 # it raised UnicodeDecodeError and the run printed "Jobs timeout".
957
958
959 def test_file_linked_from_a_careers_page_is_not_read_as_a_jobs_page():
960 landing = (
961 '<h2>Join our team</h2>'
962 '<a href="https://careers.acme.com/jobs/dist/legal/KnowYourRights.pdf">Rights</a>'
963 '<a href="https://careers.acme.com/jobs/results/">Search jobs</a>'
964 )
965 assert jobs._jobs_links(landing, "https://www.acme.com/careers") == [
966 "https://careers.acme.com/jobs/results/",
967 ]
968
969
970 def test_page_that_is_not_text_is_no_page_and_no_failure():
971 def get_text(url, **_kwargs):
972 if url.endswith("/careers"):
973 return '<h2>Join our team</h2><a href="/jobs/list">Jobs</a>'
974 raise UnicodeDecodeError("utf-8", b"\xe2", 0, 1, "invalid continuation byte")
975
976 with patch("lib.jobs.http.get_text", side_effect=get_text), \
977 patch("lib.jobs.http.get", side_effect=http.HTTPError("missing", status_code=404)), \
978 http.capture_failures() as failures:
979 items, artifact = jobs.search_jobs(
980 "Acme", WINDOW, {}, web_backend="none", site="https://www.acme.com",
981 )
982 assert items == [] and artifact["tier"] == "web"
983 assert failures == []
984
985
986 def test_first_page_with_no_reported_total_and_a_full_page_is_a_floor():
987 # The API left `totalFound` out: a full first page may not be the whole board.
988 def get(url, *, params=None, **_kwargs):
989 return {"content": [
990 {"id": str(index), "name": f"Cook {index}", "company": {"name": "Other Burgers"}}
991 for index in range(jobs.SMARTRECRUITERS_PAGE_SIZE)
992 ]}
993
994 with patch("lib.jobs.http.get", side_effect=get):
995 items, info = jobs.read_smartrecruiters_board("OtherBurgers", first_page_only=True)
996 assert len(items) == jobs.SMARTRECRUITERS_PAGE_SIZE
997 assert info["board_cut_short"] is True and info["board_first_page_only"] is True
998
999
1000 def test_first_page_with_no_reported_total_and_a_short_page_is_exact():
1001 def get(url, *, params=None, **_kwargs):
1002 return {"content": [{"id": "1", "name": "Cook", "company": {"name": "Other Burgers"}}]}
1003
1004 with patch("lib.jobs.http.get", side_effect=get):
1005 _items, info = jobs.read_smartrecruiters_board("OtherBurgers", first_page_only=True)
1006 assert info["board_cut_short"] is False
1007
1007 lines PYTHON