Remove the must-haves the form dropped on 2026-10-03: the agent's must text, the judge's verdicts and the career cap they set, with migration 34 dropping their columns and the judge's format at 6 so every role is judged again

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-10-06 13:55:59 +02:00
1 parent 38c31c830b
commit 2159c7925f
19 files changed
+157 -365

No files matched your search

+13 -68
View File
@@ -7,18 +7,14 @@ to three strengths and gaps. A model's rating is an estimate, so the scale is
coarse. The total is `app.models.cv_score`, the three numbers under the
agent's `cv_*` weights times 10, so 0 to 100, worked out when a role is served
and not stored, so the weights are no part of `input_key`; it is what the
feed's CV match sorts by. The model also reports a verdict on each of the
agent's must-haves (one per line of its must text, numbered M1..Mn in the
prompt); it does not apply them. The rule is code's: a "broken" one makes
career count as at most `app.models.BROKEN_CAP` (4), when the role is
served. Culture and location are left out: the first is guessed from ad text,
the second is what the fetch gate does.
feed's CV match sorts by. Culture and location are left out: the first is
guessed from ad text, the second is what the fetch gate does.
The work is pairs, `(agent, role)`: an enabled agent with a CV, with or
without a prompt, and an open role in its cut (`scores.cut`, see `app.jobs.score`: the best by
fit, the best by CV closeness that those leave out, and the liked and saved)
with some text, that has no judgement yet, or one read from another CV,
prompts, languages, like, avoid or must text or role text than today's (`input_key`).
prompts, languages, like or avoid text or role text than today's (`input_key`).
The cut is the only selection: the pull judges it after extract and the
rescore that follows, so it reads the cut as recomputed. A pair is named by the composite key `"<agent_id>:<uid>"`,
which is what `desk.modeltask` hands round as a uid, so `desk/` is untouched.
@@ -51,9 +47,7 @@ from pipeline import NULL, RunContext, Task, job
from pipeline.task import Batch
from app.config import Config
from app.jobs import stages
from app.models import (
LANGUAGE_LEVELS, MUST_VERDICTS, Agent, CvLanguage, _language_name, cv_languages, must_lines,
)
from app.models import LANGUAGE_LEVELS, Agent, CvLanguage, _language_name, cv_languages
from app.storage import Store
#: How much of a posting goes in one item: summarise's 8000, since the
@@ -67,7 +61,8 @@ EXCERPT = 8000
#: career rubric reading both.
#: 4: the three numbers 0 to 10 rather than 0 to 100.
#: 5: the person's languages, read into skills.
FORMAT = 5
#: 6: no must-haves: the profile is the CV, languages, likes and dislikes.
FORMAT = 6
#: How many strengths and gaps are kept, and how long each may be.
MOST, LONGEST = 3, 300
@@ -76,9 +71,8 @@ SYSTEM = """You judge job postings for one person: how well each fits their CV a
Below the rules is the person: their CV, the languages they speak and how
well, what they want, what they like and what they do not like (the work,
the workplace, situations), and their must-haves and deal-breakers when they
gave any. Each item is one posting with a key, its title, company, place
and text. Answer one judgement per item.
the workplace, situations). Each item is one posting with a key, its title,
company, place and text. Answer one judgement per item.
Score three dimensions, each a whole number from 0 to 10:
- skills: 8-10 the core requirements are the person's primary skills; 6-7
@@ -99,16 +93,6 @@ Score three dimensions, each a whole number from 0 to 10:
whether the tasks and the setting would energise them, not only whether
they could do them.
Their must-haves and deal-breakers are numbered M1, M2 and so on. Give a
verdict on every one of them, in `musts`, for each item:
- "met": the posting text says it is met.
- "broken": only when the posting text clearly contradicts it.
- "unclear": the text does not say. Never infer from silence: a posting that
is silent on a must-have is "unclear", not "broken".
Judge a must-have by its own words, not by how well the role fits otherwise.
Answer musts as [] when there are none. The verdicts do not change the three
scores, which follow their rubrics; name a broken must-have as a gap.
Then 1 to 3 strengths and 1 to 3 gaps, each one short sentence grounded in
the posting text. State the gaps honestly: a prestigious role that fits
poorly scores low.
@@ -132,21 +116,8 @@ SCHEMA: dict[str, Any] = {
"career": {"type": "integer"},
"strengths": {"type": "array", "items": {"type": "string"}},
"gaps": {"type": "array", "items": {"type": "string"}},
"musts": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {"type": "string"},
"verdict": {"type": "string", "enum": list(MUST_VERDICTS)},
},
"required": ["id", "verdict"],
"additionalProperties": False,
},
},
},
"required": ["key", "skills", "experience", "career", "strengths", "gaps",
"musts"],
"required": ["key", "skills", "experience", "career", "strengths", "gaps"],
"additionalProperties": False,
},
},
@@ -187,11 +158,11 @@ def _text(row: Any) -> str:
def input_key(agent: Agent, text: str) -> str:
"""A hash of everything a judgement reads: the CV, the prompts, the
languages, the like, avoid and must texts, and the role's text as sent. A judgement stored
under another key is read again."""
languages, the like and avoid texts, and the role's text as sent. A judgement
stored under another key is read again."""
blob = json.dumps([FORMAT, agent.cv_text, [[p.name, p.text] for p in agent.prompts],
[[l.language, l.level] for l in agent.cv_languages],
agent.like_text, agent.avoid_text, agent.must_text, text], ensure_ascii=False)
agent.like_text, agent.avoid_text, text], ensure_ascii=False)
return hashlib.sha1(blob.encode()).hexdigest()[:16]
@@ -250,9 +221,6 @@ def system(agent: Agent) -> str:
if agent.avoid_text.strip():
parts.append("\n<dislikes title=\"what they do not like\">\n"
f"{agent.avoid_text.strip()}\n</dislikes>")
if musts := must_lines(agent.must_text):
lines = "\n".join(f"M{n}: {line}" for n, line in enumerate(musts, start=1))
parts.append(f"\n<must title=\"must-haves and deal-breakers\">\n{lines}\n</must>")
return "\n".join(parts)
@@ -300,25 +268,6 @@ def _lines(value: Any) -> list[str]:
return [line for line in found if line][:MOST]
def _musts(agent: Agent | None, value: Any) -> list[dict[str, str]]:
"""The verdicts on the agent's must-haves as they are stored: one
`{id, text, verdict}` per line of its must text, in order. A must-have
the model left out, or gave a verdict outside "met", "broken", "unclear",
is "unclear": nothing is broken by silence. An id that is not one of the
agent's is ignored, the first answer for an id counts."""
said: dict[str, str] = {}
for one in value if isinstance(value, list) else []:
if isinstance(one, dict):
said.setdefault(str(one.get("id") or "").strip().upper(),
str(one.get("verdict") or "").strip().lower())
found = []
for n, line in enumerate(must_lines(agent.must_text if agent else ""), start=1):
verdict = said.get(f"M{n}", "")
found.append({"id": f"M{n}", "text": line,
"verdict": verdict if verdict in MUST_VERDICTS else "unclear"})
return found
def apply_batch(store: Store, answer: dict[str, Any],
batch: dict[str, Any] | None = None,
config: Config | None = None) -> JudgeResult:
@@ -327,7 +276,6 @@ def apply_batch(store: Store, answer: dict[str, Any],
all three numbers; the pair stays waiting."""
keys: dict[str, str] = dict((batch or {}).get("keys") or {})
stats = JudgeResult()
agents: dict[int, Agent | None] = {}
for one in answer.get("judgements") or []:
key = str(one.get("key") or "")
pair = pair_of(key)
@@ -336,11 +284,8 @@ def apply_batch(store: Store, answer: dict[str, Any],
stats.rejected.append(key or "?")
continue
skills, experience, career = (int(m) for m in marks if m is not None)
if pair[0] not in agents:
agents[pair[0]] = store.agent(pair[0])
if not store.set_judgement(pair[0], pair[1], keys.pop(key), skills, experience, career,
_lines(one.get("strengths")), _lines(one.get("gaps")),
_musts(agents[pair[0]], one.get("musts"))):
_lines(one.get("strengths")), _lines(one.get("gaps"))):
stats.rejected.append(key)
continue
stats.judged += 1
+9 -62
View File
@@ -1008,79 +1008,30 @@ def language_flag(required: list[RoleLanguage],
return "", ""
#: What career counts as at most, on the judge's 0 to 10, when a posting
#: breaks one of the agent's must-haves: the foot of the rubric's 4-5 band,
#: a decent job that does not build toward the person's goals. The model
#: reports whether each must-have is met; this cap is applied in code, when a
#: role is served (`cv_score`, `Store.judgement`, `store._cv_sql`).
BROKEN_CAP = 4
#: A must-have's verdict, as the judge answers it.
MUST_VERDICTS = ("met", "broken", "unclear")
_BULLET = re.compile(r"^\s*(?:[-*\u2022]+|\(?\d+[.)])\s+")
def must_lines(text: str) -> list[str]:
"""The agent's must-haves text read as one must-have per line: a leading
bullet (`-`, `*`, `•`) or number (`1.`, `2)`) is dropped, so are empty
lines."""
found = []
for line in text.splitlines():
line = " ".join(_BULLET.sub("", line, count=1).split())
if line:
found.append(line)
return found
def capped_career(career: int, broken: int = 0) -> int:
"""`career` as it counts: at most `BROKEN_CAP` when any must-have is
broken."""
return min(career, BROKEN_CAP) if broken else career
def cv_score(skills: int, experience: int, career: int,
weights: Weights | None = None, broken: int = 0) -> float | None:
weights: Weights | None = None) -> float | None:
"""The one number of a CV match, 0 to 100 for sorting and display: the
judge's three numbers, each 0 to 10, averaged by the agent's
`cv_skills`, `cv_experience` and `cv_career` weights (30, 25 and 30 by
default), career as `capped_career` has it, times 10. None when all
three weights are 0."""
default), times 10. None when all three weights are 0."""
w = weights or Weights()
total = w.cv_skills + w.cv_experience + w.cv_career
if not total:
return None
career = capped_career(career, broken)
return round(10 * (w.cv_skills * skills + w.cv_experience * experience
+ w.cv_career * career) / total, 1)
class Must(Model):
"""One must-have of an agent as the judge read it against a role: its
`id` (`M1`, by line), the line's `text` and the `verdict`."""
id: str
text: str = ""
verdict: Literal["met", "broken", "unclear"] = "unclear"
class Judgement(Model):
"""What `judge` read of one role for one agent (`role_judgements`): the
three dimensions 0 to 10 as the model gave them, `cv_score`
(`cv_score`, 0 to 100) and 1 to 3 strengths and gaps grounded in the
posting.
`musts` is the verdict on each must-have and `broken` how many are
broken; any makes `career_capped` the lower of `career` and
`BROKEN_CAP`. `cv_score` and `career_capped` are not read from the
table: `Store.judgement` sets them from the agent's weights; `cv_score`
is None when all three are 0."""
posting. `cv_score` is not read from the table: `Store.judgement` sets
it from the agent's weights; it is None when all three are 0."""
skills: int
experience: int
career: int
career_capped: int | None = None
broken: int = 0
musts: Annotated[list[Must], BeforeValidator(lambda v: _json(v, "[]"))] = []
cv_score: float | None = None
strengths: JsonStrings = []
gaps: JsonStrings = []
@@ -1574,14 +1525,11 @@ class Agent(Model):
are the union over the enabled agents, and an agent with none means no
board is narrowed by words. They decide what is fetched, not what ranks.
`cv_text`, `cv_languages`, `like_text`, `avoid_text` and `must_text` are
what `judge` reads a role against: the CV, the languages it states with
a level, what the person likes and does not like (the work, the
workplace, situations; both feed the career score), and their
must-haves and deal-breakers (set through the API only, not on the
form; soft, read by the model only; a hard rule is a gate). An agent without
a CV is not judged, and one without languages flags none
(`language_flag`)."""
`cv_text`, `cv_languages`, `like_text` and `avoid_text` are what `judge`
reads a role against: the CV, the languages it states with a level, and
what the person likes and does not like (the work, the workplace,
situations; both feed the career score). An agent without a CV is not
judged, and one without languages flags none (`language_flag`)."""
id: int
name: str
@@ -1594,7 +1542,6 @@ class Agent(Model):
cv_languages: CvLanguages = []
like_text: str = ""
avoid_text: str = ""
must_text: str = ""
enabled: bool = True
created_at: str
+1 -4
View File
@@ -30,10 +30,7 @@
* text (typed, or read from a .md/.txt file by the browser), the languages it
* states as rows of a code and a level, and the two soft texts, what the
* person likes and what they do not like (the work, the workplace,
* situations), which the judge reads for the career score. The must-have text
* is no longer on the form: a save leaves `must_text` out, so the stored one
* is kept (it is set through the API, and still caps career at 4 in code
* when the judge reports one broken).
* situations), which the judge reads for the career score.
* Every save sends the CV, languages and the two texts, and the card's switch
* re-posts the row as the server gave it, so neither drops them.
*
-8
View File
@@ -978,14 +978,6 @@ body[data-reader="open"] .company-strip { display: none; }
.reader-cv .cv-total { margin: 0 0 .45rem; font-variant-numeric: tabular-nums; }
.reader-cv .cv-total b { font-size: 1.25rem; }
.reader-cv .cv-total span { display: inline-block; margin-left: .4rem; color: var(--dim); font-size: .88rem; }
/* The must-haves, one line each with its verdict's mark. */
.cv-musts { list-style: none; margin: 0 0 .55rem; padding: 0; font-size: .92rem; line-height: 1.4; }
.cv-musts li { display: flex; gap: .45rem; }
.cv-musts li + li { margin-top: .15rem; }
.cv-musts .mark { flex: none; width: 1rem; text-align: center; font-weight: 700; }
.cv-musts .must-met .mark { color: var(--good); }
.cv-musts .must-broken .mark { color: var(--error); }
.cv-musts .must-unclear .mark { color: var(--faint); }
.cv-lists { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem 1.2rem; }
.cv-lists ul { margin: 0; padding-left: 1.1rem; font-size: .92rem; line-height: 1.45; }
.cv-lists li + li { margin-top: .2rem; }
+4 -18
View File
@@ -1744,34 +1744,20 @@
try { return languageNames?.of(code) || code; } catch (err) { return code; }
}
const MUST_MARKS = { met: ["✓", "met"], broken: ["✗", "broken"], unclear: ["?", "unclear"] };
/* The agent's `judge` reading against its CV: the total and its three
numbers, each of 10, career as the server counted it (capped at 4 when a must-have
is broken, with what the model said), the must-haves with a verdict
each, then the strengths and gaps it named. A box as the summary is,
since it is the same kind of thing: a model's reading, not the posting. */
numbers, each of 10, then the strengths and gaps it named. A box as the
summary is, since it is the same kind of thing: a model's reading, not
the posting. */
function cvMatch(r) {
const j = r.judgement;
if (!j) return "";
const list = (items, none) => (items?.length
? `<ul>${items.map((x) => `<li>${esc(x)}</li>`).join("")}</ul>`
: `<p class="muted small">${none}</p>`);
const counted = j.career_capped ?? j.career;
const career = counted < j.career
? `career ${counted}/10 (capped: breaks a must-have; model said ${j.career}/10)`
: `career ${j.career}/10`;
const musts = Array.isArray(j.musts) && j.musts.length
? `<ul class="cv-musts">${j.musts.map((m) => {
const [mark, word] = MUST_MARKS[m.verdict] || MUST_MARKS.unclear;
return `<li class="must-${word}"><span class="mark" role="img"
aria-label="${word}" title="${word}">${mark}</span><span>${esc(m.text)}</span></li>`;
}).join("")}</ul>` : "";
return `<section class="reader-summary reader-cv">
<h2 class="reader-label">CV match</h2>
<p class="cv-total"><b>${Math.round(j.cv_score)}</b> of 100
<span>skills ${j.skills}/10 · experience ${j.experience}/10 · ${career}</span></p>
${musts}
<span>skills ${j.skills}/10 · experience ${j.experience}/10 · career ${j.career}/10</span></p>
<div class="cv-lists">
<div><h3 class="reader-label">Strengths</h3>${list(j.strengths, "None named.")}</div>
<div><h3 class="reader-label">Gaps</h3>${list(j.gaps, "None named.")}</div>
+28 -16
View File
@@ -328,9 +328,8 @@ END;
-- as JSON: a key it lacks means the `Limits` default. fetch_terms is a JSON
-- list of words that narrow what big boards send (app/jobs/reach.py); empty
-- means no narrowing. cv_text, cv_languages (a JSON list of {language,
-- level}), like_text (what they like: the work, the workplace, situations),
-- avoid_text (what they do not like) and must_text (must-haves and
-- deal-breakers, set through the API only) are what judge reads a role
-- level}), like_text (what they like: the work, the workplace, situations)
-- and avoid_text (what they do not like) are what judge reads a role
-- against; an agent with no CV is not judged.
CREATE TABLE IF NOT EXISTS agents (
id INTEGER PRIMARY KEY,
@@ -344,7 +343,6 @@ CREATE TABLE IF NOT EXISTS agents (
cv_text TEXT NOT NULL DEFAULT '',
cv_languages TEXT NOT NULL DEFAULT '[]',
avoid_text TEXT NOT NULL DEFAULT '',
must_text TEXT NOT NULL DEFAULT '',
like_text TEXT NOT NULL DEFAULT ''
);
@@ -435,11 +433,8 @@ CREATE TABLE IF NOT EXISTS agent_cv_vectors (
-- 100 until migration 33), cv_score their weighted total times 10 at the
-- default weights (not read: app.models.cv_score is worked out when a role
-- is served), strengths and gaps JSON lists. input_key
-- is a hash of the CV, prompts, avoid text and the role's text it read: a
-- different one is read again. musts is a JSON list of {id, text, verdict},
-- the model's verdict on each of the agent's must-haves (one per line of its
-- must text), broken how many are "broken": career counts as at most 4 then
-- (app.models.BROKEN_CAP), applied when the role is served. tries counts
-- is a hash of the CV, prompts, languages, like and avoid texts and the
-- role's text it read: a different one is read again. tries counts
-- replies that left the role without one since; at 3 it is given up until the agent is saved again. A
-- row with judged_at NULL holds only tries.
CREATE TABLE IF NOT EXISTS role_judgements (
@@ -451,8 +446,6 @@ CREATE TABLE IF NOT EXISTS role_judgements (
cv_score REAL,
strengths TEXT NOT NULL DEFAULT '[]',
gaps TEXT NOT NULL DEFAULT '[]',
musts TEXT NOT NULL DEFAULT '[]',
broken INTEGER NOT NULL DEFAULT 0,
input_key TEXT NOT NULL DEFAULT '',
tries INTEGER NOT NULL DEFAULT 0,
judged_at TEXT,
@@ -763,6 +756,10 @@ UPDATE roles SET seniority = COALESCE(NULLIF(seniority_model, ''),
# A Python step: JSON limits, and a count for the log.
(33, "the judge on 0 to 10: every judgement cleared to be made again, and summarise_top "
"50 becomes 30", lambda conn: _judge_out_of_ten(conn)),
# A Python step: it drops the columns only where they are there. The
# judge reads every role again (judge.FORMAT).
(34, "agents.must_text, role_judgements.musts and broken dropped: the profile is the "
"CV, languages, likes and dislikes", lambda conn: _drop_musts(conn)),
)
#: What a file created from `SCHEMA` today is already at.
@@ -1203,12 +1200,14 @@ def _judge_out_of_ten(conn: sqlite3.Connection) -> None:
old number is shown on the new scale. The rows stay, as rows of no
judgement, and the judge reads every pair again. An agent whose
`summarise_top` is 50, migration 32's default, takes 30, the new one.
Runs twice without harm."""
Runs twice without harm, also after migration 34 dropped the verdicts."""
columns = {r[1] for r in conn.execute("PRAGMA table_info(role_judgements)")}
verdicts = ", musts = '[]', broken = 0" if {"musts", "broken"} <= columns else ""
cleared = conn.execute(
"""UPDATE role_judgements
SET skills = NULL, experience = NULL, career = NULL, cv_score = NULL,
strengths = '[]', gaps = '[]', musts = '[]', broken = 0,
input_key = '', tries = 0, judged_at = NULL""").rowcount
f"""UPDATE role_judgements
SET skills = NULL, experience = NULL, career = NULL, cv_score = NULL,
strengths = '[]', gaps = '[]'{verdicts},
input_key = '', tries = 0, judged_at = NULL""").rowcount
lowered = conn.execute(
"""UPDATE agents SET limits = json_set(limits, '$.summarise_top', 30)
WHERE json_valid(limits) AND json_type(limits) = 'object'
@@ -1217,6 +1216,19 @@ def _judge_out_of_ten(conn: sqlite3.Connection) -> None:
"summarise_top 50 set to 30", cleared, lowered)
def _drop_musts(conn: sqlite3.Connection) -> None:
"""Migration 34's step: the must-haves are gone, the agent's text
(`agents.must_text`) and the judge's verdicts on it
(`role_judgements.musts`, `broken`), and with them the cap on career.
Runs twice without harm."""
for table, columns in (("agents", ("must_text",)),
("role_judgements", ("musts", "broken"))):
present = {r[1] for r in conn.execute(f"PRAGMA table_info({table})")}
for column in columns:
if column in present:
conn.execute(f"ALTER TABLE {table} DROP COLUMN {column}")
def _add_all_roles(conn: sqlite3.Connection) -> None:
"""Migration 21's step. The column; the tag for every company that is a
favourite of any agent, since favourite no longer widens what a pull
+20 -35
View File
@@ -11,7 +11,7 @@ from __future__ import annotations
import json
import sqlite3
from collections import Counter
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, Sequence
from collections.abc import Callable, Iterable, Iterator, MutableMapping, Sequence
from contextlib import closing, contextmanager
from datetime import UTC, datetime, timedelta
from pathlib import Path
@@ -26,7 +26,7 @@ from app.models import (
AFFINITY, HAND_REASONS, LEVELS, STATUSES, Agent, Application,
ApplicationEvent, Candidate, Company, CvLanguage, Gate, Judgement, Limits, Prompt, Role,
RoleCopy, RolePlace, RoleRow, SavedFilter, ScoredRole, cv_languages as normal_languages, cv_score,
BROKEN_CAP, capped_career, language_flag, role_languages,
language_flag, role_languages,
Subscription, Weights, check_prompts, company_fold, company_key, country_of, excerpt, place_key,
fetch_terms as normal_terms, host_word, iso_day, posted_at, posted_host, remote_of, title_key,
)
@@ -140,7 +140,7 @@ _VOTED_SCORE = ("MIN(1.0, s.score * CASE v.vote WHEN -1 THEN 0.5 "
_WITH_VOTES = "LEFT JOIN role_votes v ON v.uid = roles.uid AND v.agent_id = ?"
#: The agent's `judge` readings beside every role, the same way: `j.skills`,
#: `j.experience`, `j.career` and `j.broken` are NULL for a role not judged and with no
#: `j.experience` and `j.career` are NULL for a role not judged and with no
#: agent.
_WITH_JUDGEMENTS = ("LEFT JOIN role_judgements j ON j.uid = roles.uid AND j.agent_id = ? "
"AND j.judged_at IS NOT NULL")
@@ -150,19 +150,15 @@ _WITH_JUDGEMENTS = ("LEFT JOIN role_judgements j ON j.uid = roles.uid AND j.agen
def _cv_sql(weights: Weights | None) -> str:
"""`cv_score` as SQL for one agent's weights, 0 to 100 from the judge's
three numbers 0 to 10, unrounded (`app.models.cv_score` rounds it): NULL
for a role not judged, and for all three weights 0. Career
counts as at most `BROKEN_CAP` when the judgement holds a broken
must-have (`j.broken`), as `app.models.capped_career` has it. The
numbers are the model's validated, finite floats, so they are written in
rather than bound, the select's placeholders being then no concern."""
for a role not judged, and for all three weights 0. The weights are
validated, finite floats, so they are written in rather than bound, the
select's placeholders being then no concern."""
w = weights or Weights()
total = w.cv_skills + w.cv_experience + w.cv_career
if not total:
return "NULL"
career = (f"(CASE WHEN j.broken > 0 AND j.career > {BROKEN_CAP} THEN {BROKEN_CAP} "
"ELSE j.career END)")
return (f"(10.0 * ({w.cv_skills!r} * j.skills + {w.cv_experience!r} * j.experience "
f"+ {w.cv_career!r} * {career}) / {total!r})")
f"+ {w.cv_career!r} * j.career) / {total!r})")
def _by_cv(expression: str) -> str:
@@ -2021,33 +2017,28 @@ class Store:
def set_judgement(self, agent_id: int, uid: str, input_key: str, skills: int,
experience: int, career: int, strengths: Sequence[str],
gaps: Sequence[str], musts: Sequence[Mapping[str, str]] = ()) -> bool:
gaps: Sequence[str]) -> bool:
"""Store `judge`'s reading of one role for one agent, replacing the
one before: the three numbers as the model gave them, the verdict on
each of the agent's must-haves (`musts`, `{id, text, verdict}`) and how
many are broken, `cv_score` (`app.models.cv_score`, at the default
weights and with the cap: the table's column is not read, see
`judgement`) and its tries back at 0. False for an unknown role or
agent."""
broken = sum(1 for m in musts if m.get("verdict") == "broken")
one before: the three numbers as the model gave them, `cv_score`
(`app.models.cv_score`, at the default weights: the table's column is
not read, see `judgement`) and its tries back at 0. False for an
unknown role or agent."""
try:
with self.transaction() as conn:
conn.execute(
"""INSERT INTO role_judgements (uid, agent_id, skills, experience, career,
cv_score, strengths, gaps, musts, broken,
cv_score, strengths, gaps,
input_key, tries, judged_at)
VALUES (?,?,?,?,?,?,?,?,?,?,?,0,?)
VALUES (?,?,?,?,?,?,?,?,?,0,?)
ON CONFLICT(uid, agent_id) DO UPDATE SET
skills=excluded.skills, experience=excluded.experience,
career=excluded.career, cv_score=excluded.cv_score,
strengths=excluded.strengths, gaps=excluded.gaps,
musts=excluded.musts, broken=excluded.broken,
input_key=excluded.input_key, tries=0, judged_at=excluded.judged_at""",
(uid, agent_id, skills, experience, career,
cv_score(skills, experience, career, broken=broken),
cv_score(skills, experience, career),
json.dumps(list(strengths), ensure_ascii=False),
json.dumps(list(gaps), ensure_ascii=False),
json.dumps([dict(m) for m in musts], ensure_ascii=False), broken,
input_key, self.now()))
except sqlite3.IntegrityError:
return False
@@ -2075,8 +2066,7 @@ class Store:
def judgement(self, agent_id: int | None, uid: str) -> Judgement | None:
"""The agent's judgement of one role, None when it has none, its
`cv_score` the three numbers under the agent's weights as they are
now, not as stored, and `career_capped` the model's career as the
broken must-haves leave it (`BROKEN_CAP`)."""
now, not as stored."""
if agent_id is None:
return None
row = self._row("SELECT * FROM role_judgements WHERE agent_id = ? AND uid = ? "
@@ -2085,9 +2075,8 @@ class Store:
return None
found = Judgement.from_row(row)
agent = self.agent(agent_id)
found.career_capped = capped_career(found.career, found.broken)
found.cv_score = cv_score(found.skills, found.experience, found.career,
agent.weights if agent else None, found.broken)
agent.weights if agent else None)
return found
def set_article_text(self, uid: str, text: str) -> Role | None:
@@ -2209,14 +2198,13 @@ class Store:
cv_text: str | None = None,
cv_languages: Sequence[CvLanguage] | None = None,
avoid_text: str | None = None,
must_text: str | None = None,
like_text: str | None = None) -> Agent:
"""Create an agent, or with `agent_id` replace that one's fields and
prompts. Without `prompts`, a non-empty `intent` is its one prompt,
named after the agent. Without `fetch_terms` an update keeps the
stored ones and a new agent has none, so a caller that does not know
them (the CLI's prompt edit) loses none; `cv_text`, `cv_languages`,
`like_text`, `avoid_text` and `must_text` are kept the same way. A prompt whose text is
`like_text` and `avoid_text` are kept the same way. A prompt whose text is
unchanged keeps its cached vector, whatever its name or place, so an
edit re-embeds only the prompts it changed. A save gives every role
`judge` gave up on for the agent its tries back, since what it is
@@ -2237,7 +2225,6 @@ class Store:
(limits or Limits()).model_dump_json(), int(enabled), terms,
None if cv_text is None else cv_text.strip(), spoken,
None if avoid_text is None else avoid_text.strip(),
None if must_text is None else must_text.strip(),
None if like_text is None else like_text.strip())
try:
with self.transaction() as conn:
@@ -2245,10 +2232,9 @@ class Store:
agent_id = conn.execute(
"""INSERT INTO agents (name, gates, weights, limits, enabled,
fetch_terms, cv_text, cv_languages, avoid_text,
must_text, like_text, created_at)
like_text, created_at)
VALUES (?,?,?,?,?,COALESCE(?, '[]'),COALESCE(?, ''),
COALESCE(?, '[]'),COALESCE(?, ''),COALESCE(?, ''),
COALESCE(?, ''),?)""",
COALESCE(?, '[]'),COALESCE(?, ''),COALESCE(?, ''),?)""",
(*fields, self.now())).lastrowid
elif not conn.execute(
"""UPDATE agents SET name=?, gates=?, weights=?, limits=?, enabled=?,
@@ -2256,7 +2242,6 @@ class Store:
cv_text=COALESCE(?, cv_text),
cv_languages=COALESCE(?, cv_languages),
avoid_text=COALESCE(?, avoid_text),
must_text=COALESCE(?, must_text),
like_text=COALESCE(?, like_text)
WHERE id=?""",
(*fields, agent_id)).rowcount:
+2 -4
View File
@@ -1251,7 +1251,7 @@ class AgentBody(BaseModel):
it is stored as one prompt named after the agent. `fetch_terms` narrow
what big boards send (`app/jobs/reach.py`); `[]` narrows nothing, and
leaving the key out keeps an existing agent's. `cv_text`,
`cv_languages`, `like_text`, `avoid_text` and `must_text` are what `judge` reads a
`cv_languages`, `like_text` and `avoid_text` are what `judge` reads a
role against (`app/jobs/judge.py`), kept the same way when left out or
null."""
@@ -1267,7 +1267,6 @@ class AgentBody(BaseModel):
cv_languages: CvLanguages | None = None
like_text: str | None = None
avoid_text: str | None = None
must_text: str | None = None
enabled: bool = True
@@ -1307,8 +1306,7 @@ def save_agent(body: AgentBody, store: StoreDep, queue: QueueDep) -> Agent:
body.enabled, agent_id=body.id, limits=body.limits,
prompts=body.prompts, fetch_terms=body.fetch_terms,
cv_text=body.cv_text, cv_languages=body.cv_languages,
like_text=body.like_text, avoid_text=body.avoid_text,
must_text=body.must_text)
like_text=body.like_text, avoid_text=body.avoid_text)
except ValueError as exc:
raise HTTPException(409, str(exc)) from exc
except KeyError:
+2 -2
View File
@@ -148,7 +148,7 @@ def test_migration_20_seeds_an_old_file_and_leaves_collisions(tmp_path: Path) ->
"VALUES (?, ?, '', '')", (key, name))
conn.execute("PRAGMA user_version = 19")
reopened = Store(path)
assert reopened.migrations_applied == [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
assert reopened.migrations_applied == [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
assert reopened.duplicate_companies() == [("orsted", ["orsted", "ørsted"])]
assert len(reopened.companies()) == 3
@@ -186,7 +186,7 @@ def test_migration_21_tags_the_favourites_and_the_boards_that_read_all_roles(tmp
conn.execute("ALTER TABLE companies DROP COLUMN all_countries")
conn.execute("PRAGMA user_version = 20")
reopened = Store(path)
assert reopened.migrations_applied == [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
assert reopened.migrations_applied == [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
# The tag of 21 is All countries and All roles since 24.
tagged = {"mistral-ai": 1, "acme": 0, "black-forest-labs": 1, "liked": 0}
assert {c.key: c.all_roles for c in reopened.companies()} == tagged
+2 -34
View File
@@ -91,37 +91,6 @@ def test_best_cv_match_puts_the_judged_first_by_cv_score(
"order": "best"}).status_code == 422
def test_a_broken_must_have_caps_career_in_the_order_and_the_reader(
client: TestClient, store: Store) -> None:
owner, uid = setup(store)
# c: 9 on all three, but one must-have broken: career counts as 4.
musts = [{"id": "M1", "text": "Permanent", "verdict": "met"},
{"id": "M2", "text": "Remote", "verdict": "broken"}]
store.set_judgement(owner.id, uid["c"], "k", 9, 9, 9, [], [], musts)
capped = round(10 * (30 * 9 + 25 * 9 + 30 * 4) / 85, 1)
rows = client.get("/api/roles", params={"agent": owner.id, "order": "cv"}).json()["items"]
assert [(r["uid"], r["cv_score"]) for r in rows[:2]] == [(uid["c"], capped), (uid["b"], 60.0)]
# With career weighted up the capped value drops under b's 60.
store.save_agent("Data", prompts=owner.prompts, agent_id=owner.id, cv_text=owner.cv_text,
weights=Weights(cv_skills=0, cv_experience=0, cv_career=1))
rows = client.get("/api/roles", params={"agent": owner.id, "order": "cv"}).json()["items"]
assert [(r["uid"], r["cv_score"]) for r in rows[:2]] == [(uid["b"], 60.0), (uid["c"], 40.0)]
one = client.get(f"/api/roles/{uid['c']}", params={"agent": owner.id}).json()
j = one["judgement"]
assert (j["career"], j["career_capped"], j["broken"]) == (9, 4, 1)
assert j["musts"] == musts and one["cv_score"] == j["cv_score"] == 40.0
def test_a_met_or_unclear_must_have_leaves_career_as_the_model_gave_it(
client: TestClient, store: Store) -> None:
owner, uid = setup(store)
musts = [{"id": "M1", "text": "Permanent", "verdict": "met"},
{"id": "M2", "text": "Remote", "verdict": "unclear"}]
store.set_judgement(owner.id, uid["c"], "k", 9, 9, 9, [], [], musts)
j = client.get(f"/api/roles/{uid['c']}", params={"agent": owner.id}).json()["judgement"]
assert (j["career"], j["career_capped"], j["broken"], j["cv_score"]) == (9, 9, 0, 90.0)
def test_the_agents_weights_make_the_cv_score_at_read_time(
client: TestClient, store: Store) -> None:
owner, uid = setup(store)
@@ -218,15 +187,14 @@ def test_an_agent_without_languages_flags_nothing(client: TestClient, store: Sto
def test_the_cv_fields_round_trip_and_are_kept_when_left_out(client: TestClient) -> None:
body = {"name": "Data", "cv_text": "VP Data.", "like_text": "Teams.", "avoid_text": "Reporting.",
"must_text": "Permanent.",
"cv_languages": [{"language": "da", "level": "native"},
{"language": "EN", "level": "fluent"}]}
made = client.post("/api/agents", json=body).json()
assert made["cv_languages"] == [{"language": "da", "level": "native"},
{"language": "en", "level": "fluent"}]
kept = client.post("/api/agents", json={"id": made["id"], "name": "Data"}).json()
assert (kept["cv_text"], kept["like_text"], kept["avoid_text"], kept["must_text"]) == \
("VP Data.", "Teams.", "Reporting.", "Permanent.")
assert (kept["cv_text"], kept["like_text"], kept["avoid_text"]) == \
("VP Data.", "Teams.", "Reporting.")
assert len(kept["cv_languages"]) == 2
nulls = client.post("/api/agents", json={"id": made["id"], "name": "Data",
"cv_text": None, "cv_languages": None}).json()
+46 -42
View File
@@ -16,7 +16,7 @@ from pydantic import ValidationError
from app import prep
from app.config import Config
from app.jobs import extract
from app.models import CvLanguage, RoleLanguage, cv_score, iso_day, language_flag, must_lines
from app.models import CvLanguage, RoleLanguage, cv_score, iso_day, language_flag
from app.storage import Store
from desk import modeltask
from desk.models import Item
@@ -44,24 +44,21 @@ def test_an_agent_keeps_its_cv_fields_when_a_save_leaves_them_out(store: Store)
cv_languages=[CvLanguage(language="DA", level="native"),
CvLanguage(language="en", level="fluent"),
CvLanguage(language="da", level="basic")],
like_text=" Building teams. ", avoid_text="Pure reporting.",
must_text="Permanent contract.")
like_text=" Building teams. ", avoid_text="Pure reporting.")
assert made.cv_text == "VP Data."
assert [(lang.language, lang.level) for lang in made.cv_languages] == \
[("da", "native"), ("en", "fluent")]
assert (made.like_text, made.avoid_text, made.must_text) == \
("Building teams.", "Pure reporting.", "Permanent contract.")
assert (made.like_text, made.avoid_text) == ("Building teams.", "Pure reporting.")
kept = store.save_agent("Data", "data leadership", agent_id=made.id)
assert (kept.cv_text, kept.like_text, kept.avoid_text, kept.must_text) == \
("VP Data.", "Building teams.", "Pure reporting.", "Permanent contract.")
assert (kept.cv_text, kept.like_text, kept.avoid_text) == \
("VP Data.", "Building teams.", "Pure reporting.")
assert len(kept.cv_languages) == 2
cleared = store.save_agent("Data", "data leadership", agent_id=made.id, cv_text="",
cv_languages=[], like_text="", avoid_text="",
must_text="")
assert (cleared.cv_text, cleared.cv_languages, cleared.like_text, cleared.avoid_text,
cleared.must_text) == ("", [], "", "", "")
cv_languages=[], like_text="", avoid_text="")
assert (cleared.cv_text, cleared.cv_languages, cleared.like_text, cleared.avoid_text) == \
("", [], "", "")
def test_a_cv_language_is_a_code_and_a_level_of_the_ladder() -> None:
@@ -92,25 +89,24 @@ def test_v28_adds_the_cv_columns_and_the_host_deadline_and_runs_twice(tmp_path:
conn.execute("DROP TABLE role_judgements")
for column in ("languages_required", "deadline_host", "deadline_model", "deadline"):
conn.execute(f"ALTER TABLE roles DROP COLUMN {column}")
for column in ("cv_text", "cv_languages", "avoid_text", "must_text"):
for column in ("cv_text", "cv_languages", "avoid_text"):
conn.execute(f"ALTER TABLE agents DROP COLUMN {column}")
conn.execute("PRAGMA user_version = 27")
migrated = Store(path)
assert migrated.migrations_applied == [28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [28, 29, 30, 31, 32, 33, 34]
rows = {r["source_id"]: r for r in migrated._rows(
"SELECT source_id, languages_required, deadline_host, deadline FROM roles")}
assert (rows["a"]["deadline_host"], rows["a"]["deadline"]) == ("2026-10-18", None)
assert rows["a"]["languages_required"] is None and rows["b"]["deadline_host"] == ""
[data] = migrated.agents()
assert (data.cv_text, data.cv_languages, data.avoid_text, data.must_text) == \
("", [], "", "")
assert (data.cv_text, data.cv_languages, data.avoid_text) == ("", [], "")
prep.run(migrated, remap=True, dupes=False)
assert migrated.role(posting("a").uid).deadline == "2026-10-18"
with sqlite3.connect(path) as conn:
conn.execute("PRAGMA user_version = 27")
assert Store(path).migrations_applied == [28, 29, 30, 31, 32, 33]
assert Store(path).migrations_applied == [28, 29, 30, 31, 32, 33, 34]
# ---------------------------------------------------------------- deadline
@@ -231,7 +227,6 @@ def test_the_language_flag() -> None:
def test_the_cv_score_weighs_skills_and_career_above_experience() -> None:
assert cv_score(10, 10, 10) == 100.0
assert cv_score(8, 6, 4) == round(10 * (240 + 150 + 120) / 85, 1)
assert cv_score(8, 6, 9, broken=1) == cv_score(8, 6, 4)
def test_a_stored_language_list_survives_a_bad_entry(store: Store) -> None:
@@ -244,20 +239,36 @@ def test_a_stored_language_list_survives_a_bad_entry(store: Store) -> None:
assert [lang.language for lang in store.role(item.uid).languages_required] == ["da"]
def test_v29_adds_the_musts_and_broken_columns_and_runs_twice(tmp_path: Path) -> None:
path = tmp_path / "v28.db"
Store(path)
def test_v34_drops_the_must_haves_and_runs_twice(tmp_path: Path) -> None:
"""A file from before migration 34 holds the agent's must text and the
judge's verdicts on it; the columns go, the rest of the agent and the
judgement stay."""
path = tmp_path / "v33.db"
store = Store(path)
item = posting("1")
upsert(store, item)
agent = store.save_agent("Data", "data leadership", cv_text="CV.", like_text="Teams.")
assert store.set_judgement(agent.id, item.uid, "key", 8, 7, 9, ["Good."], ["Bad."])
with sqlite3.connect(path) as conn:
for column in ("musts", "broken"):
conn.execute(f"ALTER TABLE role_judgements DROP COLUMN {column}")
conn.execute("PRAGMA user_version = 28")
conn.execute("ALTER TABLE agents ADD COLUMN must_text TEXT NOT NULL DEFAULT ''")
conn.execute("ALTER TABLE role_judgements ADD COLUMN musts TEXT NOT NULL DEFAULT '[]'")
conn.execute("ALTER TABLE role_judgements ADD COLUMN broken INTEGER NOT NULL DEFAULT 0")
conn.execute("UPDATE agents SET must_text = 'Remote.'")
conn.execute("UPDATE role_judgements SET musts = ?, broken = 1",
(json.dumps([{"id": "M1", "text": "Remote.", "verdict": "broken"}]),))
conn.execute("PRAGMA user_version = 33")
assert Store(path).migrations_applied == [29, 30, 31, 32, 33]
with sqlite3.connect(path) as conn:
columns = {r[1] for r in conn.execute("PRAGMA table_info(role_judgements)")}
assert {"musts", "broken"} <= columns
conn.execute("PRAGMA user_version = 28")
assert Store(path).migrations_applied == [29, 30, 31, 32, 33]
for _ in range(2): # runs twice without harm
migrated = Store(path)
assert migrated.migrations_applied == [34]
with sqlite3.connect(path) as conn:
assert "must_text" not in {r[1] for r in conn.execute("PRAGMA table_info(agents)")}
assert not {"musts", "broken"} & {
r[1] for r in conn.execute("PRAGMA table_info(role_judgements)")}
conn.execute("PRAGMA user_version = 33")
assert migrated.agent(agent.id).like_text == "Teams." # type: ignore[union-attr]
found = migrated.judgement(agent.id, item.uid)
assert found is not None and (found.career, found.cv_score) == (9, cv_score(8, 7, 9))
def test_v30_adds_like_text_and_runs_twice(tmp_path: Path) -> None:
@@ -269,12 +280,12 @@ def test_v30_adds_like_text_and_runs_twice(tmp_path: Path) -> None:
migrated = Store(path)
assert migrated.migrations_applied == [30, 31, 32, 33]
assert migrated.migrations_applied == [30, 31, 32, 33, 34]
[data] = migrated.agents()
assert (data.like_text, data.avoid_text) == ("", "Reporting.")
with sqlite3.connect(path) as conn:
conn.execute("PRAGMA user_version = 29")
assert Store(path).migrations_applied == [30, 31, 32, 33]
assert Store(path).migrations_applied == [30, 31, 32, 33, 34]
def test_v33_clears_every_judgement_and_lowers_the_old_summarise_default(
@@ -290,8 +301,7 @@ def test_v33_clears_every_judgement_and_lowers_the_old_summarise_default(
old = store.save_agent("Old", "data leadership", cv_text="CV.")
own = store.save_agent("Own", "data leadership")
bare = store.save_agent("Bare", "data leadership")
musts = [{"id": "M1", "text": "Remote", "verdict": "broken"}]
assert store.set_judgement(old.id, item.uid, "key", 80, 70, 90, ["Good."], ["Bad."], musts)
assert store.set_judgement(old.id, item.uid, "key", 80, 70, 90, ["Good."], ["Bad."])
store.judge_missed([(own.id, item.uid)])
with sqlite3.connect(path) as conn:
conn.execute("UPDATE agents SET limits = json_set(limits, '$.summarise_top', 50) "
@@ -303,22 +313,16 @@ def test_v33_clears_every_judgement_and_lowers_the_old_summarise_default(
for _ in range(2): # runs twice without harm
migrated = Store(path)
assert migrated.migrations_applied == [33]
assert migrated.migrations_applied == [33, 34]
assert migrated.judgement(old.id, item.uid) is None
with sqlite3.connect(path) as conn:
rows = conn.execute(
"SELECT skills, experience, career, cv_score, strengths, gaps, musts, broken, "
"SELECT skills, experience, career, cv_score, strengths, gaps, "
"input_key, tries, judged_at FROM role_judgements").fetchall()
assert rows == [(None, None, None, None, "[]", "[]", "[]", 0, "", 0, None)] * 2
assert rows == [(None, None, None, None, "[]", "[]", "", 0, None)] * 2
conn.execute("PRAGMA user_version = 32")
assert {a.name: a.limits.summarise_top for a in migrated.agents()} == {
"Old": 30, "Own": 12, "Bare": 30}
with sqlite3.connect(path) as conn:
assert conn.execute("SELECT limits FROM agents WHERE id = ?",
(bare.id,)).fetchone() == ("{}",)
def test_the_musts_text_is_one_must_have_per_line() -> None:
assert must_lines("- A\n* B c\n\u2022 D\n1. E\n2) F\n \nG\n-H") == [
"A", "B c", "D", "E", "F", "G", "-H"]
assert must_lines("") == []
+1 -1
View File
@@ -282,7 +282,7 @@ def test_migration_31_adds_the_column_and_the_table_and_runs_twice(tmp_path: Pat
conn.execute("DROP TABLE agent_cv_vectors")
conn.execute("ALTER TABLE scores DROP COLUMN cv_fit")
conn.execute("PRAGMA user_version = 30")
assert Store(path).migrations_applied == [31, 32, 33]
assert Store(path).migrations_applied == [31, 32, 33, 34]
step = {v: s for v, _, s in MIGRATIONS}[31]
with sqlite3.connect(path) as conn:
assert callable(step)
+1 -1
View File
@@ -279,7 +279,7 @@ def test_a_v17_file_gains_dup_of_with_its_first_rebuild(tmp_path: Path) -> None:
migrated = Store(path)
assert migrated.migrations_applied == [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
assert dup_of(migrated) == {first.uid: None, second.uid: first.uid}
with sqlite3.connect(path) as conn:
assert conn.execute("SELECT 1 FROM sqlite_master WHERE name = 'idx_roles_dup_of'"
+1 -1
View File
@@ -520,7 +520,7 @@ def test_migration_23_gives_every_agent_no_terms(tmp_path: Path) -> None:
conn.execute("ALTER TABLE agents DROP COLUMN fetch_terms")
conn.execute("PRAGMA user_version = 22")
migrated = Store(path)
assert migrated.migrations_applied == [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
assert migrated.agents()[0].fetch_terms == []
+9 -51
View File
@@ -76,8 +76,7 @@ def config(tmp_path: Path) -> Config:
def hunter(store: Store, name: str = "Data", cv: str = CV, **kwargs: Any) -> Any:
return store.save_agent(name, prompts=[Prompt(name="AI lead", text="Head of AI")],
cv_text=cv, like_text="Building teams.",
avoid_text="Pure reporting.",
must_text="A permanent contract.", **kwargs)
avoid_text="Pure reporting.", **kwargs)
def ranked(store: Store, owner: Any, *ids: str) -> list[str]:
@@ -109,59 +108,18 @@ def test_a_run_writes_the_judgement_and_its_total(
assert item == {"key": f"{owner.id}:{uid}", "title": "Head of AI 1", "company": "Acme",
"place": "Copenhagen", "text": "Head of AI. Lead the data science team."}
[system] = model.systems
assert CV in system and "Pure reporting." in system and "A permanent contract." in system
assert "- AI lead: Head of AI" in system and "deal-breaker" in system
assert CV in system and "Pure reporting." in system
assert "- AI lead: Head of AI" in system
assert '<likes title="what they like: work, workplace, situations">\nBuilding teams.' \
in system
assert '<dislikes title="what they do not like">\nPure reporting.' in system
assert "<avoid" not in system
def test_the_musts_are_numbered_in_the_profile_and_stored_with_their_text(
store: Store, config: Config, monkeypatch: pytest.MonkeyPatch) -> None:
owner = hunter(store)
store.save_agent("Data", prompts=owner.prompts, agent_id=owner.id, cv_text=CV,
must_text="- Permanent contract\n\n * Remote two days\n3) Danish team\n")
[uid] = ranked(store, owner, "1")
def reply(items: list[dict[str, Any]]) -> list[dict[str, Any]]:
return [{**one, "career": 8, "musts": [
{"id": "M1", "verdict": "met"}, {"id": "M2", "verdict": "broken"},
{"id": "M9", "verdict": "broken"}, {"id": "M3", "verdict": "maybe"}]}
for one in judged(items)]
model = stub(monkeypatch, reply)
modeltask.run(judge.TASK, config, store)
[system] = model.systems
assert "M1: Permanent contract\nM2: Remote two days\nM3: Danish team" in system
found = store.judgement(owner.id, uid)
assert found is not None
assert [(m.id, m.text, m.verdict) for m in found.musts] == [
("M1", "Permanent contract", "met"), ("M2", "Remote two days", "broken"),
("M3", "Danish team", "unclear")]
assert (found.career, found.career_capped, found.broken) == (8, 4, 1)
assert found.cv_score == round(10 * (30 * 8 + 25 * 7 + 30 * 4) / 85, 1)
def test_a_must_the_model_left_out_is_unclear_and_nothing_is_broken_by_silence(
store: Store, config: Config, monkeypatch: pytest.MonkeyPatch) -> None:
owner = hunter(store)
[uid] = ranked(store, owner, "1")
stub(monkeypatch) # answers without any `musts`
modeltask.run(judge.TASK, config, store)
found = store.judgement(owner.id, uid)
assert found is not None
assert [(m.id, m.verdict) for m in found.musts] == [("M1", "unclear")]
assert (found.career, found.career_capped, found.broken) == (9, 9, 0)
def test_the_schema_requires_the_verdicts_and_the_prompt_leaves_the_cap_to_code() -> None:
def test_the_schema_asks_for_three_numbers_strengths_and_gaps() -> None:
item = judge.SCHEMA["properties"]["judgements"]["items"]
assert "musts" in item["required"]
verdict = item["properties"]["musts"]["items"]["properties"]["verdict"]
assert verdict["enum"] == ["met", "broken", "unclear"]
assert "career 0-3" not in judge.SYSTEM and "clearly contradicts" in judge.SYSTEM
assert item["required"] == ["key", "skills", "experience", "career", "strengths", "gaps"]
assert "must-have" not in judge.SYSTEM
assert "0 to 10" in judge.SYSTEM and "80-100" not in judge.SYSTEM
@@ -190,7 +148,7 @@ def test_what_the_person_likes_is_part_of_what_a_judgement_read(store: Store) ->
def hashlib_old_key(agent: Any, text: str) -> str:
blob = json.dumps([agent.cv_text, [[p.name, p.text] for p in agent.prompts],
agent.avoid_text, agent.must_text, text], ensure_ascii=False)
agent.avoid_text, text], ensure_ascii=False)
return hashlib.sha1(blob.encode()).hexdigest()[:16]
@@ -259,7 +217,7 @@ def test_a_judgement_is_read_again_only_when_what_it_read_changed(
with store.transaction() as conn:
conn.execute("UPDATE roles SET closed_at = NULL WHERE uid = ?", (uid,))
# The languages and the must text are part of what it read; the weights
# The languages and the dislikes are part of what it read; the weights
# are not.
store.save_agent("Data", prompts=owner.prompts, agent_id=owner.id,
weights=Weights(cv_skills=50))
@@ -270,7 +228,7 @@ def test_a_judgement_is_read_again_only_when_what_it_read_changed(
assert '<languages title="the languages they speak, and how well">\nDanish native' \
in judge.system(spoken)
store.save_agent("Data", prompts=owner.prompts, agent_id=owner.id,
must_text="Remote two days a week.")
avoid_text="Long commutes.")
assert judge.pending(store) == 1
assert store.judgement(owner.id, uid) is not None, "kept until the new one lands"
+1 -1
View File
@@ -122,7 +122,7 @@ def test_migration_24_splits_the_tag_and_moves_terms_off(tmp_path: Path) -> None
conn.execute("UPDATE companies SET all_roles=1 WHERE key='mistral-ai'")
conn.execute("PRAGMA user_version = 23")
migrated = Store(path)
assert migrated.migrations_applied == [24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
flags = {c.key: (c.all_countries, c.all_roles) for c in migrated.companies()}
assert flags == {"mistral-ai": (1, 1), "acme": (0, 1), "plain": (0, 0)}
params = {s.target: s.params for s in migrated.subscriptions(source="ats")}
+1 -1
View File
@@ -316,7 +316,7 @@ def test_migration_22_fills_the_host_words_from_raw(tmp_path: Path) -> None:
migrated = Store(path)
assert migrated.migrations_applied == [22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
one = row(migrated, "1")
assert (one["seniority_host"], one["employment_host"], one["remote_host"],
one["country_host"]) == ("senior", "full_time", "true", "DK")
+2 -2
View File
@@ -534,7 +534,7 @@ def test_migration_27_keeps_an_older_readers_remote_as_the_hosts_word(tmp_path:
migrated = Store(path)
assert migrated.migrations_applied == [27, 28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [27, 28, 29, 30, 31, 32, 33, 34]
assert migrated.gazetteer().anywhere is not None
row = migrated._row("SELECT remote_host, remote_model, remote_where_model FROM roles "
"WHERE uid = ?", (board,))
@@ -544,7 +544,7 @@ def test_migration_27_keeps_an_older_readers_remote_as_the_hosts_word(tmp_path:
assert area(migrated, search.uid) == ("", "")
with sqlite3.connect(path) as conn:
conn.execute("PRAGMA user_version = 26")
assert Store(path).migrations_applied == [27, 28, 29, 30, 31, 32, 33]
assert Store(path).migrations_applied == [27, 28, 29, 30, 31, 32, 33, 34]
def test_a_role_waits_for_extract_until_it_was_asked_where(store: Store) -> None:
+14 -14
View File
@@ -71,7 +71,7 @@ def test_schema_creates_on_an_empty_file(tmp_path: Path) -> None:
"application_events", "agents", "scores", "state"} <= tables
assert "idx_roles_cluster" in indexes
assert store.migrations_applied == []
assert LATEST == 33
assert LATEST == 34
# A second open finds it current and applies nothing.
assert Store(path).migrations_applied == []
@@ -169,8 +169,8 @@ def test_a_v1_file_migrates_to_the_shape_a_new_file_has(tmp_path: Path) -> None:
conn.execute(f"ALTER TABLE companies DROP COLUMN {column}")
for table in ("vectors", "role_tags", "agent_companies", "role_votes"):
conn.execute(f"DROP TABLE {table}")
for column in ("musts", "broken"): # v29
conn.execute(f"ALTER TABLE role_judgements DROP COLUMN {column}")
# The must-have columns v28 and v29 added and v34 drops are not in a
# fresh file either.
conn.execute("ALTER TABLE agents DROP COLUMN like_text") # v30
conn.execute("PRAGMA user_version = 1")
@@ -191,7 +191,7 @@ def test_a_v14_file_gains_the_watchlist_columns_and_leaves_companies_unrated(
migrated = Store(path)
assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
acme = migrated.company("acme")
assert acme is not None
assert (acme.ats, acme.careers_url) == ("teamtailor", "https://a.example")
@@ -396,7 +396,7 @@ def test_v14_makes_each_intent_the_agents_one_prompt_with_its_vector(tmp_path: P
migrated = Store(path)
assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
assert migrated.agent(backend.id).prompts == [ # type: ignore[union-attr]
Prompt(name="Backend", text="python backend")]
assert migrated.agent(blank.id).prompts == [] # type: ignore[union-attr]
@@ -420,7 +420,7 @@ def test_v16_gives_a_company_no_reason_and_keeps_its_row(tmp_path: Path) -> None
migrated = Store(path)
assert migrated.migrations_applied == [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
acme = migrated.company("acme")
assert acme is not None
assert (acme.careers_url, acme.notes, acme.hand_reason) == (
@@ -449,7 +449,7 @@ def test_v17_folds_every_place_and_levels_the_titles_extract_has_not_read(
migrated = Store(path)
assert migrated.migrations_applied == [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
with sqlite3.connect(path) as conn:
rows = {uid: (fold, level) for uid, fold, level in conn.execute(
"SELECT uid, place_fold, seniority FROM roles")}
@@ -691,7 +691,7 @@ def test_v19_gives_every_role_its_places_and_splits_its_level(tmp_path: Path) ->
migrated = Store(path)
assert migrated.migrations_applied == [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
assert [p.name for p in migrated.role_places(joined.uid)] == ["Copenhagen", "Malmö"]
assert [p.name for p in migrated.role_places(detailed.uid)] == ["Aarhus"]
assert migrated.role_places(stated.uid) == []
@@ -733,7 +733,7 @@ def test_v25_clears_the_model_levels_the_ladder_splits_and_sets_the_level(
migrated = Store(path)
assert migrated.migrations_applied == [25, 26, 27, 28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
with sqlite3.connect(path) as conn:
found = {sid: rest for sid, *rest in conn.execute(
"SELECT source_id, seniority_model, seniority_stated, seniority_title, seniority "
@@ -751,12 +751,12 @@ def test_v26_adds_posting_url_empty_and_runs_twice_without_harm(tmp_path: Path)
migrated = Store(path)
assert migrated.migrations_applied == [26, 27, 28, 29, 30, 31, 32, 33]
assert migrated.migrations_applied == [26, 27, 28, 29, 30, 31, 32, 33, 34]
role = migrated.role(posting("a").uid)
assert role is not None and role.posting_url == ""
with sqlite3.connect(path) as conn:
conn.execute("PRAGMA user_version = 25") # the column is there already
assert Store(path).migrations_applied == [26, 27, 28, 29, 30, 31, 32, 33]
assert Store(path).migrations_applied == [26, 27, 28, 29, 30, 31, 32, 33, 34]
def test_a_pull_keeps_the_posting_url(store: Store) -> None:
@@ -1855,7 +1855,7 @@ def test_v32_resets_the_limits_drops_prefer_gates_and_renames_enrich(tmp_path: P
migrated = Store(path)
assert migrated.migrations_applied == [32, 33]
assert migrated.migrations_applied == [32, 33, 34]
by_name = {a.name: a for a in migrated.agents()}
assert by_name["Wolf"].limits == Limits() == by_name["Bare"].limits
assert [(g.field, g.mode) for g in by_name["Wolf"].gates] == [
@@ -1880,14 +1880,14 @@ def test_v32_runs_twice_and_keeps_limits_set_since(tmp_path: Path) -> None:
store = Store(path)
agent = store.save_agent("Wolf", limits=Limits(cut_fit_top=900))
_v31(path)
assert Store(path).migrations_applied == [32, 33]
assert Store(path).migrations_applied == [32, 33, 34]
assert Store(path).agent(agent.id).limits == Limits() # type: ignore[union-attr]
narrow = Limits(cut_fit_top=900, summarise_top=10)
store.save_agent("Wolf", agent_id=agent.id, limits=narrow)
with sqlite3.connect(path) as conn:
conn.execute("PRAGMA user_version = 31") # the columns are there already
again = Store(path)
assert again.migrations_applied == [32, 33]
assert again.migrations_applied == [32, 33, 34]
assert again.agent(agent.id).limits == narrow # type: ignore[union-attr]