返回 last30days-skill
jobs_signals_rule.py
根目录 / tests / jobs_signals_rule.py
1 """The decision rule for Jobs Page Secret Signals, written out as arithmetic.
2
3 The rule itself is prose in ``skills/last30days/references/hiring-signals.md``
4 and is applied by the model writing the report. This module restates only the
5 part that is arithmetic, so the labelled set in
6 ``tests/fixtures/jobs_signals_labelled.json`` can be checked against it:
7
8 - does a candidate signal qualify, given which of the four tests it meets;
9 - is the section written, and with how many signals, given a board's candidates
10 (a cluster of postings is one candidate);
11 - how may a qualifying signal be worded, given what the web check found.
12
13 It does NOT test whether a model finds the right signals in a digest or judges
14 the four tests correctly. Nothing here reads a digest. That needs live runs,
15 compared against the labels by a person. It is test support, not shipped code.
16 """
17
18 from __future__ import annotations
19
20 import re
21 from typing import Any
22
23 OUT_OF_CHARACTER, CONCRETE, HARD_TO_UNDO, BEARS_ON_STORY = 1, 2, 3, 4
24 MIN_SIGNALS = 1
25 MAX_SIGNALS = 2
26 # Postings that must share one concrete focus to count together as one signal.
27 MIN_CLUSTER_POSTINGS = 3
28 # Postings of a cluster cited in its paragraph, and sentences per paragraph.
29 CLUSTER_POSTINGS_CITED = 2
30 MAX_PARAGRAPH_SENTENCES = 2
31 # The longest optional quote from a posting.
32 MAX_QUOTE_WORDS = 12
33 LEAD_IN = "**Jobs Page Secret Signals** - "
34
35 _LINK = re.compile(r"\[[^\]]*\]\([^)]*\)")
36 _SENTENCE_BREAK = re.compile(r"(?<=[.!?])\s+(?=[{A-Z])")
37 _QUOTE = re.compile(r'"([^"]+)"')
38 _OVERCLAIM = re.compile(
39 r"\b(?:is|are) (?:building|developing|launching|shipping)\b"
40 r"|\bwill (?:ship|launch|release|sell|build)\b"
41 r"|\bhas decided\b|\bplans to\b",
42 re.IGNORECASE,
43 )
44
45
46 def qualifies(tests: list[int], postings: int = 1) -> bool:
47 """At least two of the first three tests, or the fourth.
48
49 A cluster (``postings`` sharing one concrete focus, three or more) also
50 qualifies when it is out of character: the shared focus is the concrete
51 thing it names.
52 """
53 met = set(tests)
54 if BEARS_ON_STORY in met or len(met & {OUT_OF_CHARACTER, CONCRETE, HARD_TO_UNDO}) >= 2:
55 return True
56 return postings >= MIN_CLUSTER_POSTINGS and OUT_OF_CHARACTER in met
57
58
59 def postings(candidate: dict[str, Any]) -> int:
60 """How many postings a candidate stands for: a cluster's, else one."""
61 return len(candidate.get("cluster") or []) or 1
62
63
64 def qualifying(candidates: list[dict[str, Any]]) -> list[dict[str, Any]]:
65 return [
66 candidate for candidate in candidates
67 if qualifies(candidate["tests"], postings(candidate))
68 ]
69
70
71 def max_section_paragraphs() -> int:
72 """The signal paragraphs (the lead-in runs into the first) and the closing line."""
73 return MAX_SIGNALS + 1
74
75
76 def section_present(
77 candidates: list[dict[str, Any]],
78 *,
79 hiring_signals_run: bool = False,
80 web_search: bool = True,
81 ) -> bool:
82 """One qualifying signal, on any run; never without web search."""
83 if not web_search:
84 return False
85 return len(qualifying(candidates)) >= MIN_SIGNALS
86
87
88 def signals_shown(candidates: list[dict[str, Any]], **run: bool) -> int:
89 """How many signal paragraphs the section has. Which two is the model's call."""
90 if not section_present(candidates, **run):
91 return 0
92 return min(len(qualifying(candidates)), MAX_SIGNALS)
93
94
95 def wording(candidate: dict[str, Any]) -> str:
96 """``public`` when already announced, ``unreported`` only when a check found nothing."""
97 if candidate["public"] is True:
98 return "public"
99 if candidate["public"] is False:
100 return "unreported"
101 return "check first"
102
103
104 def standout(candidate: dict[str, Any]) -> bool:
105 """May also be one KEY PATTERNS line: all of the first three tests, and checked unreported."""
106 return (
107 {OUT_OF_CHARACTER, CONCRETE, HARD_TO_UNDO} <= set(candidate["tests"])
108 and wording(candidate) == "unreported"
109 )
110
111
112 def sentences(paragraph: str) -> list[str]:
113 body = paragraph.removeprefix(LEAD_IN)
114 return [part for part in _SENTENCE_BREAK.split(body) if part]
115
116
117 def paragraph_ok(paragraph: str) -> bool:
118 """A signal paragraph in the plain-words shape: two sentences, the role linked,
119 any quote at most 12 words, and nothing worded as a plan."""
120 return (
121 len(sentences(paragraph)) == MAX_PARAGRAPH_SENTENCES
122 and bool(_LINK.search(paragraph))
123 and all(len(quote.split()) <= MAX_QUOTE_WORDS for quote in _QUOTE.findall(paragraph))
124 and not _OVERCLAIM.search(paragraph)
125 )
126
126 lines PYTHON