Per-agent ranking: votes, affinity and a taste term; settings are three sub-tabs
Votes on roles and company affinity move to role_votes and agent_companies, one row per search agent, so two agents rank the same roles differently. The score gains taste, the cosine to mean(liked) - mean(passed) of the agent's votes, as newsdesk ranks articles. The API takes agent on roles, votes and companies and falls back to the default agent, the enabled one with the lowest id. Settings become Search agents (a list again, with New and Delete), Sources (job boards, company boards and runs with the message log, one section per plugin) and Account. Old paths answer 301 to their section. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
515d2250fc
commit
a0772519b3
28 files changed
+1461
-668
No files matched your search
@@ -15,9 +15,9 @@ uv run app serve # http://127.0.0.1:8790
|
||||
|
||||
`uv run app worker` drains the queue without the web app, and `uv run pytest` runs the app's tests and the copied modules' own. `config.yaml` is the committed default, with one starter agent and four Copenhagen searches on Jobindex; `config.example.yaml` documents every key, including the `summarise:` block below.
|
||||
|
||||
## Searches and companies
|
||||
## Sources: job boards and company boards
|
||||
|
||||
The Searches and Companies sub-tabs do all of this; the same actions exist on the command line:
|
||||
The Sources sub-tab does all of this; the same actions exist on the command line:
|
||||
|
||||
```bash
|
||||
uv run app searches add jobindex "Copenhagen golang" --q "golang go-udvikler" --area 1
|
||||
@@ -34,20 +34,19 @@ Two tabs, and a cog for settings.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Roles** | open roles, newest or by Best match, with filters, votes (▲ like ● neither way ▼ pass) and a Save button. A title opens the role's own read page |
|
||||
| **Roles** | open roles, newest or by Best match for one search agent, with filters, votes (▲ like ● neither way ▼ pass) and a Save button. A title opens the role's own read page |
|
||||
| **Applications** | the saved roles and their status, each change recorded as an event |
|
||||
|
||||
The cog opens `/settings`, one shell with six sub-tabs:
|
||||
The cog opens `/settings`, one shell with three sub-tabs:
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Ranking** | the one search agent the UI edits: intent, weights, and require/prefer gates behind an Advanced disclosure. Saving rescores it |
|
||||
| **Searches** | saved searches that find roles across companies (try, save, edit, remove) |
|
||||
| **Companies** | every company whose board is read, its open roles, and its affinity: hidden, neutral, liked, favourite; following a company and pruning boards by region live here too |
|
||||
| **Pulls** | a Pull now button and what is running, the pull schedule, and the extract/embed/score buttons behind a disclosure |
|
||||
| **Messages** | everything the server said that nobody has cleared |
|
||||
| **Search agents** | the list of agents the Roles tab ranks by, and the form for one: name, intent, weights, and require/prefer gates behind an Advanced disclosure. Saving rescores; deleting one takes its votes, liked companies and scores with it |
|
||||
| **Sources** | one page, one section per plugin: job boards (queries on Jobindex or Adzuna: try, save, edit, remove), company boards (every company whose board is read, its open roles and its affinity for the picked agent, following a company, pruning boards by region) and runs (Pull now, what is running, the schedule, one stage at a time, and the message log) |
|
||||
| **Account** | the password, sessions and passkeys. Open on loopback, locked on anything else |
|
||||
|
||||
Likes, hidden companies and votes belong to a search agent, not to the account: two agents rank the same roles differently, and one may hide a company the other favours. An agent also learns from votes: its `taste` weight scores a role by how close it is to the roles the agent liked minus the ones it passed.
|
||||
|
||||
A role's read page, `/roles/{uid}`, shows the full posting: the same vote and Save controls, the company's own affinity, and the summary when there is one. A search role's posting is a teaser; its page offers a Fetch button that scrapes the original listing once and stores the text. A Summarise button asks for a short summary of that one role; `config.yaml`'s `summarise:` block turns summarising on for the pull itself, bounded to the top `per_agent` roles of each agent so the cost stays flat.
|
||||
|
||||
## Docs
|
||||
|
||||
+3
-2
@@ -258,8 +258,9 @@ def seed_companies(store: Store, path: str) -> dict[str, int]:
|
||||
file=sys.stderr)
|
||||
skipped += 1
|
||||
continue
|
||||
store.add_company(name, key=key, affinity=int(row.get("affinity", 0)),
|
||||
careers_url=row.get("careers_url", ""))
|
||||
# A seed's `affinity` is not read: affinity is per agent now, and a
|
||||
# seed has no agent to set it for.
|
||||
store.add_company(name, key=key, careers_url=row.get("careers_url", ""))
|
||||
host, _, _slug = board.partition(":")
|
||||
try:
|
||||
store.add_subscription("ats", board, label=name, company=name, board=host)
|
||||
|
||||
+55
-20
@@ -10,13 +10,19 @@ good for a given search. For each agent:
|
||||
the roles this agent scores in this run: the closest is 1,
|
||||
the farthest 0, a lone role 1
|
||||
recency 0.5 ** (days since first_seen / 14)
|
||||
affinity (companies.affinity + 1) / 3
|
||||
affinity (the agent's affinity for the company + 1) / 3
|
||||
taste cos(role vector, liked direction), min-max scaled like fit,
|
||||
where the direction is mean(liked vectors) - mean(passed vectors)
|
||||
over this agent's votes; with only likes it is the liked mean,
|
||||
with only passes the negated passed mean; no votes, no term
|
||||
|
||||
Every term is 0..1. The score is the weighted sum over the sum of the weights
|
||||
(the agent's three and its prefer gates'), so it stays 0..1. A favourite
|
||||
company (`affinity = 2`) skips the gates and is floored at 0.9; a muted one
|
||||
(`-1`) is not scored at all. A role with no vector is scored without `fit`,
|
||||
unless `fit` is all there is, when it is gated as "no vector".
|
||||
(the agent's four and its prefer gates'), so it stays 0..1. A favourite
|
||||
company (`affinity = 2`) skips the gates and is floored at 0.9; a hidden one
|
||||
(`-1`) is not scored at all. A role with no vector is scored without `fit`
|
||||
and `taste`, unless `fit` is all there is, when it is gated as "no vector".
|
||||
An agent with no votes scores every role without `taste`; the direction is
|
||||
newsdesk's `centroid(liked) - centroid(disliked)`.
|
||||
|
||||
Recomputed in full on every run, and each agent's rows are replaced in one
|
||||
transaction: nothing is incremental, so nothing can drift.
|
||||
@@ -75,6 +81,24 @@ def cosine(role: np.ndarray, intent: np.ndarray) -> float:
|
||||
return float(np.dot(role, intent)) / norms
|
||||
|
||||
|
||||
def taste_direction(vectors: dict[str, np.ndarray],
|
||||
votes: dict[str, int]) -> np.ndarray | None:
|
||||
"""`mean(liked) - mean(passed)` over the voted roles that have a vector.
|
||||
A side with no votes is zero, so likes alone point at the liked mean and
|
||||
passes alone away from the passed mean. None when neither side has a
|
||||
vector: no votes, no direction. A neutral vote says nothing."""
|
||||
liked = [vectors[uid] for uid, vote in votes.items() if vote == 1 and uid in vectors]
|
||||
passed = [vectors[uid] for uid, vote in votes.items() if vote == -1 and uid in vectors]
|
||||
if not liked and not passed:
|
||||
return None
|
||||
direction = np.zeros_like(liked[0] if liked else passed[0], dtype=np.float64)
|
||||
if liked:
|
||||
direction += np.mean(liked, axis=0)
|
||||
if passed:
|
||||
direction -= np.mean(passed, axis=0)
|
||||
return direction
|
||||
|
||||
|
||||
def scale(cosines: dict[str, float]) -> dict[str, float]:
|
||||
"""Min-max to 0..1 across one agent's run, so `fit` ranks roles rather
|
||||
than stating a level.
|
||||
@@ -111,11 +135,12 @@ def failed_gates(candidate: Candidate, gates: Sequence[Gate]) -> list[str]:
|
||||
|
||||
|
||||
def score_one(candidate: Candidate, gates: Sequence[Gate], weights: Weights,
|
||||
fit: float | None, now: datetime, *,
|
||||
fit: float | None, now: datetime, *, taste: float | None = None,
|
||||
missing: str = "no vector") -> tuple[float, str]:
|
||||
"""One role for one agent: `(score, gated_reason)`. `fit` is already
|
||||
scaled to 0..1 (see `scale`), or None when the role or the intent has no
|
||||
vector; `missing` says which."""
|
||||
"""One role for one agent: `(score, gated_reason)`. `fit` and `taste` are
|
||||
already scaled to 0..1 (see `scale`), or None when there is nothing to
|
||||
measure: no role vector, no intent vector, no votes. A None term leaves
|
||||
the denominator; `missing` says why fit is out."""
|
||||
favourite = candidate.affinity == 2
|
||||
if failed := failed_gates(candidate, gates):
|
||||
return 0.0, ", ".join(failed)
|
||||
@@ -126,6 +151,8 @@ def score_one(candidate: Candidate, gates: Sequence[Gate], weights: Weights,
|
||||
for g, state in zip(gates, candidate.gates, strict=True) if g.mode == "prefer"]
|
||||
if fit is not None:
|
||||
terms.append((weights.fit, fit))
|
||||
if taste is not None:
|
||||
terms.append((weights.taste, taste))
|
||||
total = sum(w for w, _ in terms)
|
||||
if not total:
|
||||
if favourite:
|
||||
@@ -183,23 +210,31 @@ def _intent(store: Store, agent: Agent, model: str,
|
||||
|
||||
def score_agent(store: Store, agent: Agent, vectors: dict[str, np.ndarray],
|
||||
intent: np.ndarray | None, now: datetime) -> dict[str, int]:
|
||||
"""Two passes: the cosines of the roles this agent scores, then every
|
||||
score with fit scaled across them. A gated role is left out of the
|
||||
scaling, so a role that fails a require gate cannot stretch the range the
|
||||
ranked roles share."""
|
||||
candidates = store.score_candidates(agent.gates)
|
||||
"""Two passes: the cosines of the roles this agent scores, to its intent
|
||||
and to its taste direction, then every score with both scaled across
|
||||
them. A gated role is left out of the scaling, so a role that fails a
|
||||
require gate cannot stretch the range the ranked roles share. The voted
|
||||
roles are scored like any other; a liked one sits near the direction it
|
||||
helped make, which is what a like should do."""
|
||||
candidates = store.score_candidates(agent.id, agent.gates)
|
||||
direction = taste_direction(vectors, store.votes(agent.id))
|
||||
cosines: dict[str, float] = {}
|
||||
if intent is not None:
|
||||
for candidate in candidates:
|
||||
role_vec = vectors.get(candidate.uid)
|
||||
if role_vec is not None and not failed_gates(candidate, agent.gates):
|
||||
cosines[candidate.uid] = cosine(role_vec, intent)
|
||||
fits = scale(cosines)
|
||||
tastes: dict[str, float] = {}
|
||||
for candidate in candidates:
|
||||
role_vec = vectors.get(candidate.uid)
|
||||
if role_vec is None or failed_gates(candidate, agent.gates):
|
||||
continue
|
||||
if intent is not None:
|
||||
cosines[candidate.uid] = cosine(role_vec, intent)
|
||||
if direction is not None:
|
||||
tastes[candidate.uid] = cosine(role_vec, direction)
|
||||
fits, tastes = scale(cosines), scale(tastes)
|
||||
rows: list[tuple[str, float, str]] = []
|
||||
gated = 0
|
||||
for candidate in candidates:
|
||||
value, reason = score_one(
|
||||
candidate, agent.gates, agent.weights, fits.get(candidate.uid), now,
|
||||
taste=tastes.get(candidate.uid),
|
||||
missing="no vector" if intent is not None else "no intent vector")
|
||||
gated += bool(reason)
|
||||
rows.append((candidate.uid, round(value, 6), reason))
|
||||
|
||||
+9
-3
@@ -264,7 +264,8 @@ class Role(Model):
|
||||
raw: JsonDict = {}
|
||||
extracted_at: str | None = None
|
||||
created_at: str
|
||||
#: None unjudged, else -1 pass, 0 neutral, 1 like.
|
||||
#: The vote of the agent the role was read for (see `role_votes`): None
|
||||
#: unjudged, else -1 pass, 0 neutral, 1 like.
|
||||
vote: Literal[-1, 0, 1] | None = None
|
||||
voted_at: str | None = None
|
||||
summary: str = ""
|
||||
@@ -297,6 +298,9 @@ class ScoredRole(Role):
|
||||
|
||||
|
||||
class Company(Model):
|
||||
"""A row of `companies`, with `affinity` as the agent it was read for
|
||||
has it (see `agent_companies`); 0 when no agent was asked for."""
|
||||
|
||||
key: str
|
||||
name: str
|
||||
domain: str = ""
|
||||
@@ -377,6 +381,8 @@ class Weights(Model):
|
||||
fit: float = Field(0.6, ge=0)
|
||||
recency: float = Field(0.2, ge=0)
|
||||
affinity: float = Field(0.2, ge=0)
|
||||
#: Cosine to the liked-minus-passed direction of the agent's votes.
|
||||
taste: float = Field(0.2, ge=0)
|
||||
|
||||
|
||||
class Agent(Model):
|
||||
@@ -394,8 +400,8 @@ class Agent(Model):
|
||||
|
||||
class Candidate(Model):
|
||||
"""What scoring reads about one open role for one agent: when it was
|
||||
first seen, its company's affinity, and per gate `1` match, `0` no
|
||||
match, `-1` the column is empty."""
|
||||
first seen, its company's affinity for that agent, and per gate `1`
|
||||
match, `0` no match, `-1` the column is empty."""
|
||||
|
||||
uid: str
|
||||
first_seen: str
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
/* The Search agents page: what Best match on the Roles tab is measured
|
||||
* against, one agent at a time.
|
||||
*
|
||||
* The list is `/api/agents`; the form edits the agent picked from it, New
|
||||
* clears it, Delete removes it. Votes, liked companies and scores are the
|
||||
* agent's, so a delete takes them with it, and the confirm says so.
|
||||
*
|
||||
* Every request goes through `api()` from app.js, so a failure is one toast
|
||||
* carrying the server's own sentence.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const { api, count } = window;
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
|
||||
const DEFAULT_WEIGHTS = { fit: 0.6, recency: 0.2, affinity: 0.2, taste: 0.2 };
|
||||
|
||||
/** @type {object[]} every agent, as the server lists them */
|
||||
let agents = [];
|
||||
/** @type {object | null} the agent the form edits, null for a new one */
|
||||
let agent = null;
|
||||
|
||||
function byId(rows) {
|
||||
return [...rows].sort((a, b) => a.id - b.id);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- the list
|
||||
|
||||
function onSwitch(row) {
|
||||
const box = document.createElement("input");
|
||||
box.type = "checkbox";
|
||||
box.checked = Boolean(row.enabled);
|
||||
box.setAttribute("aria-label", `Enable ${row.name}`);
|
||||
box.addEventListener("change", async () => {
|
||||
box.disabled = true;
|
||||
try {
|
||||
const saved = await api("/api/agents", {
|
||||
method: "POST", body: Object.assign({}, row, { enabled: box.checked }),
|
||||
});
|
||||
Object.assign(row, saved);
|
||||
} catch (err) {
|
||||
box.checked = !box.checked;
|
||||
}
|
||||
box.disabled = false;
|
||||
render();
|
||||
});
|
||||
return box;
|
||||
}
|
||||
|
||||
function render() {
|
||||
const body = $("#agents-list");
|
||||
body.replaceChildren();
|
||||
for (const row of byId(agents)) {
|
||||
const div = document.createElement("div");
|
||||
div.className = "crow";
|
||||
if (!row.enabled) div.dataset.hidden = "true";
|
||||
if (agent && agent.id === row.id) div.dataset.current = "true";
|
||||
const name = document.createElement("span");
|
||||
name.className = "name";
|
||||
name.textContent = row.name;
|
||||
div.appendChild(name);
|
||||
div.appendChild(onSwitch(row));
|
||||
|
||||
const sub = document.createElement("span");
|
||||
sub.className = "sub";
|
||||
const w = Object.assign({}, DEFAULT_WEIGHTS, row.weights);
|
||||
sub.append(`fit ${w.fit} · newness ${w.recency} · companies ${w.affinity} · liked ${w.taste}`, " ");
|
||||
const edit = document.createElement("button");
|
||||
edit.type = "button";
|
||||
edit.className = "linky";
|
||||
edit.textContent = "Edit";
|
||||
edit.addEventListener("click", () => fill(row));
|
||||
const remove = document.createElement("button");
|
||||
remove.type = "button";
|
||||
remove.className = "linky";
|
||||
remove.textContent = "Delete";
|
||||
remove.addEventListener("click", () => removeAgent(row));
|
||||
sub.append(edit, " ", remove);
|
||||
div.appendChild(sub);
|
||||
body.appendChild(div);
|
||||
}
|
||||
$("#agents-count").textContent = agents.length
|
||||
? count(agents.length, "search agent")
|
||||
: "No search agents yet. Describe one below.";
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- the form
|
||||
|
||||
function fill(row) {
|
||||
agent = row;
|
||||
const weights = Object.assign({}, DEFAULT_WEIGHTS, row ? row.weights : {});
|
||||
$("#agent-form-title").textContent = row ? `Edit ${row.name}` : "New agent";
|
||||
$("#a-name").value = row ? row.name : "";
|
||||
$("#a-intent").value = row ? row.intent : "";
|
||||
$("#a-gates").value = JSON.stringify(row ? row.gates : [], null, 2);
|
||||
$("#a-fit").value = weights.fit;
|
||||
$("#a-recency").value = weights.recency;
|
||||
$("#a-affinity").value = weights.affinity;
|
||||
$("#a-taste").value = weights.taste;
|
||||
$("#a-delete").hidden = !row;
|
||||
$("#agent-status").textContent = "";
|
||||
render();
|
||||
if (row) $("#agent-form").scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
}
|
||||
|
||||
async function save(event) {
|
||||
event.preventDefault();
|
||||
const status = $("#agent-status");
|
||||
let gates;
|
||||
try {
|
||||
gates = JSON.parse($("#a-gates").value || "[]");
|
||||
} catch (err) {
|
||||
window.toast.error(`Gates are not valid JSON: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
const body = {
|
||||
name: $("#a-name").value.trim(),
|
||||
intent: $("#a-intent").value,
|
||||
gates,
|
||||
weights: {
|
||||
fit: Number($("#a-fit").value),
|
||||
recency: Number($("#a-recency").value),
|
||||
affinity: Number($("#a-affinity").value),
|
||||
taste: Number($("#a-taste").value),
|
||||
},
|
||||
// Saving an agent means it is wanted, so a new one starts on; the
|
||||
// list's checkbox is where an existing one is switched.
|
||||
enabled: agent ? agent.enabled : true,
|
||||
};
|
||||
if (agent) body.id = agent.id;
|
||||
const button = $("#agent-form button[type=submit]");
|
||||
button.disabled = true;
|
||||
let saved;
|
||||
try {
|
||||
saved = await api("/api/agents", { method: "POST", body });
|
||||
await load();
|
||||
} catch (err) {
|
||||
status.textContent = "";
|
||||
button.disabled = false;
|
||||
return;
|
||||
}
|
||||
agent = agents.find((a) => a.id === saved.id) || saved;
|
||||
$("#agent-form-title").textContent = `Edit ${agent.name}`;
|
||||
$("#a-delete").hidden = false;
|
||||
render();
|
||||
await rescore(status);
|
||||
button.disabled = false;
|
||||
}
|
||||
|
||||
async function removeAgent(row) {
|
||||
if (!window.confirm(`Delete ${row.name}? Its votes and liked companies go with it.`)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await api(`/api/agents/${row.id}`, { method: "DELETE" });
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
agents = agents.filter((a) => a.id !== row.id);
|
||||
if (agent && agent.id === row.id) fill(null);
|
||||
else render();
|
||||
}
|
||||
|
||||
// Start the `score` job and wait for it, so "Saved and scored" means the
|
||||
// Roles tab already orders by what was saved.
|
||||
async function rescore(status) {
|
||||
status.textContent = "Saved. Scoring…";
|
||||
let job;
|
||||
try {
|
||||
job = await api("/api/jobs", { method: "POST", body: { kind: "score", payload: {} } });
|
||||
} catch (err) {
|
||||
status.textContent = "Saved, but scoring did not start.";
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < 300; i += 1) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
let snapshot;
|
||||
try {
|
||||
snapshot = await api("/api/jobs");
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
const busy = [...snapshot.running, ...snapshot.queued].some((j) => j.id === job.id);
|
||||
if (busy) continue;
|
||||
const done = snapshot.recent.find((j) => j.id === job.id);
|
||||
if (done && done.state !== "done") {
|
||||
status.textContent = `Saved. Scoring ${done.state}.`;
|
||||
if (done.error) window.toast.error(`Scoring ${done.state}: ${done.error}`);
|
||||
return;
|
||||
}
|
||||
status.replaceChildren("Saved and scored. ");
|
||||
const link = document.createElement("a");
|
||||
link.href = `/?agent=${agent.id}`;
|
||||
link.textContent = "See the best matches";
|
||||
status.appendChild(link);
|
||||
return;
|
||||
}
|
||||
status.replaceChildren("Saved. Scoring is still running; ");
|
||||
const link = document.createElement("a");
|
||||
link.href = "/settings/sources#runs";
|
||||
link.textContent = "follow it under Runs";
|
||||
status.append(link, ".");
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- init
|
||||
|
||||
async function load() {
|
||||
agents = await api("/api/agents");
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
if (!$("#agents-list")) return;
|
||||
try {
|
||||
await load();
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
// The default agent, the enabled one with the lowest id, is what the
|
||||
// Roles tab and the company list fall back to, so it is what opens.
|
||||
const first = byId(agents).find((a) => a.enabled) || byId(agents)[0] || null;
|
||||
fill(first);
|
||||
$("#agent-form").addEventListener("submit", save);
|
||||
$("#a-new").addEventListener("click", () => fill(null));
|
||||
$("#a-delete").addEventListener("click", () => agent && removeAgent(agent));
|
||||
});
|
||||
})();
|
||||
+21
-5
@@ -124,6 +124,17 @@ a { color: var(--accent); }
|
||||
}
|
||||
.subtabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
|
||||
|
||||
/* The jump row under the sub-tabs on Sources: one link per section, since
|
||||
the page is three sections long. Each section clears the sticky bar when
|
||||
the anchor lands. */
|
||||
.jump { display: flex; gap: .25rem .75rem; flex-wrap: wrap; margin: -6px 0 10px; font-size: .9rem; }
|
||||
.jump a { color: var(--dim); text-decoration: none; }
|
||||
@media (hover: hover) {
|
||||
.jump a:hover { color: var(--fg); text-decoration: underline; }
|
||||
}
|
||||
section[id] { scroll-margin-top: calc(var(--header-h, 3.5rem) + .5rem); }
|
||||
.card h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
|
||||
|
||||
main {
|
||||
max-width: 62rem;
|
||||
margin: 0 auto;
|
||||
@@ -550,7 +561,7 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
|
||||
background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
|
||||
padding: .75rem 1rem;
|
||||
}
|
||||
.agent-form h2 { font-size: 1rem; margin: 0; }
|
||||
.agent-form h2, .agent-form h3 { font-size: 1rem; margin: 0; }
|
||||
.agent-form label { display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; }
|
||||
.agent-form label.inline { flex-direction: row; align-items: center; gap: .4rem; }
|
||||
.agent-form input[type="text"], .agent-form textarea, .agent-form input[type="number"] {
|
||||
@@ -568,7 +579,7 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
|
||||
.agent-form details[open] summary { margin-bottom: .5rem; }
|
||||
|
||||
/* ================================================================ */
|
||||
/* companies and sources — Settings' Companies and Searches pages, */
|
||||
/* companies and sources — the Sources page's sections, */
|
||||
/* static/companies.js and static/sources.js. Package B2's own */
|
||||
/* section; the rest of the file is not reflowed for it. */
|
||||
/* ================================================================ */
|
||||
@@ -576,6 +587,9 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
|
||||
.section { margin: 1.5rem 0 2rem; }
|
||||
.section > h2 { margin-bottom: .25rem; }
|
||||
.source-form { margin-top: 1rem; max-width: none; }
|
||||
/* The agent select on the filter row: a label beside its box, not above. */
|
||||
.filters label.inline { display: flex; align-items: center; gap: .4rem; font-size: .9rem; color: var(--dim); }
|
||||
.filters label.inline select { color: var(--fg); }
|
||||
/* `auto-fit` rather than a fixed count of columns: a row with fewer fields
|
||||
(Jobindex's Area, say, where Adzuna also needs Country and Place) simply
|
||||
leaves the boxes it does have at the same width instead of stretching one
|
||||
@@ -617,6 +631,8 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
|
||||
gap: .4rem; font-size: .8rem; color: var(--dim);
|
||||
}
|
||||
.srow[data-muted="true"], .crow[data-hidden="true"] { opacity: .6; }
|
||||
/* The agent the form is editing, on the Search agents list. */
|
||||
.crow[data-current="true"] .name { color: var(--accent); }
|
||||
|
||||
.linky {
|
||||
padding: 0; border: 0; background: none; font-size: .8rem;
|
||||
@@ -672,9 +688,9 @@ table.list select { padding: .25rem .4rem; }
|
||||
.top nav a { flex: 1 1 auto; text-align: center; padding: .6rem .4rem; white-space: nowrap; }
|
||||
.top nav a.icon { flex: 0 0 auto; justify-content: center; padding-inline: .7rem; }
|
||||
|
||||
/* Six sub-tabs are too many for one row, and a scrolling strip does not
|
||||
show that more are off the edge. They wrap, three to a row, as pills
|
||||
rather than the desktop's underlined row. */
|
||||
/* Three sub-tabs, one row of pills rather than the desktop's underlined
|
||||
row; they wrap if a label needs it, since a scrolling strip does not
|
||||
show that more are off the edge. */
|
||||
.subtabs { flex-wrap: wrap; border-bottom: none; gap: 6px; }
|
||||
.subtabs a {
|
||||
flex: 1 1 30%;
|
||||
|
||||
+12
-6
@@ -17,6 +17,10 @@
|
||||
* `count`, `cell`, `debounce`, and the company list with its affinity control
|
||||
* (`loadCompanies`, `companies`, `affinityControl`, `setAffinity`). One copy
|
||||
* each, since two copies of a helper is one of them being fixed.
|
||||
*
|
||||
* Affinity is per search agent. The three company helpers take the agent's
|
||||
* id as an optional last argument and send it along; a caller that passes
|
||||
* none gets the server's default agent, the enabled one with the lowest id.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
@@ -106,8 +110,9 @@
|
||||
Map, refilled in place, so a script holding it sees every reload. */
|
||||
const companies = new Map();
|
||||
|
||||
async function loadCompanies() {
|
||||
const rows = await api("/api/companies");
|
||||
async function loadCompanies(agent) {
|
||||
const query = agent == null ? "" : `?agent=${encodeURIComponent(agent)}`;
|
||||
const rows = await api(`/api/companies${query}`);
|
||||
companies.clear();
|
||||
for (const c of rows) companies.set(c.key, c);
|
||||
return companies;
|
||||
@@ -127,7 +132,7 @@
|
||||
/* `onChange` runs after the server accepted the change, so each page
|
||||
decides what a change means for it: the role list refetches, since a
|
||||
hidden company's roles come out of it, and the company list redraws. */
|
||||
function affinityControl(companyKey, current, onChange) {
|
||||
function affinityControl(companyKey, current, onChange, agent) {
|
||||
const span = document.createElement("span");
|
||||
span.className = "affinity";
|
||||
span.setAttribute("role", "group");
|
||||
@@ -142,18 +147,19 @@
|
||||
button.setAttribute("aria-label", level.label);
|
||||
button.setAttribute("aria-pressed", String(pressed));
|
||||
button.addEventListener("click", () =>
|
||||
setAffinity(companyKey, pressed ? 0 : level.value, onChange));
|
||||
setAffinity(companyKey, pressed ? 0 : level.value, onChange, agent));
|
||||
span.appendChild(button);
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
async function setAffinity(companyKey, affinity, onChange) {
|
||||
async function setAffinity(companyKey, affinity, onChange, agent) {
|
||||
if (!companyKey) return;
|
||||
const body = agent == null ? { affinity } : { affinity, agent };
|
||||
let updated;
|
||||
try {
|
||||
updated = await api(`/api/companies/${encodeURIComponent(companyKey)}/affinity`, {
|
||||
method: "POST", body: { affinity },
|
||||
method: "POST", body,
|
||||
});
|
||||
} catch (err) {
|
||||
return;
|
||||
|
||||
+55
-9
@@ -1,11 +1,17 @@
|
||||
/* The Companies page: every company, its board, its open roles, its
|
||||
* affinity, following a new one, and pruning boards with nothing open in a
|
||||
* region.
|
||||
/* The Company boards section of Sources: every company, its board, its open
|
||||
* roles, its affinity, following a new one, and pruning boards with nothing
|
||||
* open in a region.
|
||||
*
|
||||
* The list is app.js's shared company list (`/api/companies`), already
|
||||
* joined with each company's board subscription — its id and whether it is
|
||||
* on — so nothing here fetches `/api/sources` as well. The affinity buttons
|
||||
* are `affinityControl`, the same ones the Roles tab and the read page draw.
|
||||
*
|
||||
* Liked and hidden are per search agent, so the `#c-agent` select above the
|
||||
* list says whose the list shows and whose the buttons set. It opens on the
|
||||
* server's default, the enabled agent with the lowest id; with no agent at
|
||||
* all there is nothing to like, and the section says so instead of drawing
|
||||
* the buttons.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
@@ -13,6 +19,31 @@
|
||||
const { api, count, debounce, companies, loadCompanies, affinityControl } = window;
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
|
||||
/** @type {object[]} the search agents, by id */
|
||||
let agents = [];
|
||||
|
||||
/** The id in `#c-agent`, or null while there is no agent to pick. */
|
||||
function agentId() {
|
||||
const value = $("#c-agent").value;
|
||||
return value ? Number(value) : null;
|
||||
}
|
||||
|
||||
async function loadAgents() {
|
||||
agents = (await api("/api/agents")).sort((a, b) => a.id - b.id);
|
||||
const select = $("#c-agent");
|
||||
select.replaceChildren();
|
||||
for (const a of agents) {
|
||||
const option = document.createElement("option");
|
||||
option.value = String(a.id);
|
||||
option.textContent = a.name;
|
||||
select.appendChild(option);
|
||||
}
|
||||
const first = agents.find((a) => a.enabled) || agents[0];
|
||||
if (first) select.value = String(first.id);
|
||||
select.closest("label").hidden = !first;
|
||||
$("#c-no-agent").hidden = Boolean(first);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- the list
|
||||
|
||||
function subLine(company) {
|
||||
@@ -24,7 +55,7 @@
|
||||
badge.textContent = company.board;
|
||||
sub.appendChild(badge);
|
||||
} else {
|
||||
sub.append("from searches");
|
||||
sub.append("from job boards");
|
||||
}
|
||||
sub.append(` · ${count(company.open_roles, "open role")}`);
|
||||
return sub;
|
||||
@@ -88,7 +119,10 @@
|
||||
row.appendChild(link);
|
||||
const switchBox = onSwitch(company, render);
|
||||
if (switchBox) row.appendChild(switchBox);
|
||||
row.appendChild(affinityControl(company.key, company.affinity, async () => render()));
|
||||
const agent = agentId();
|
||||
if (agent != null) {
|
||||
row.appendChild(affinityControl(company.key, company.affinity, async () => render(), agent));
|
||||
}
|
||||
row.appendChild(subLine(company));
|
||||
body.appendChild(row);
|
||||
}
|
||||
@@ -111,7 +145,7 @@
|
||||
method: "POST",
|
||||
body: { board, name: $("#b-name").value.trim() },
|
||||
});
|
||||
await loadCompanies();
|
||||
await loadCompanies(agentId());
|
||||
render();
|
||||
$("#board-form").reset();
|
||||
status.textContent = `Following ${result.source.label}: `
|
||||
@@ -167,7 +201,7 @@
|
||||
+ `closed ${count(result.roles_closed, "role")}. ${result.boards_left} boards are on.`;
|
||||
$("#prune-list").replaceChildren();
|
||||
$("#p-apply").textContent = "Switch off these boards";
|
||||
await loadCompanies();
|
||||
await loadCompanies(agentId());
|
||||
render();
|
||||
} catch (err) {
|
||||
$("#p-apply").disabled = false;
|
||||
@@ -176,15 +210,27 @@
|
||||
|
||||
// -------------------------------------------------------------------- init
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
async function switchAgent() {
|
||||
try {
|
||||
await loadCompanies();
|
||||
await loadCompanies(agentId());
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
render();
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
if (!$("#companies-list")) return;
|
||||
try {
|
||||
await loadAgents();
|
||||
await loadCompanies(agentId());
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
render();
|
||||
$("#c-q").addEventListener("input", debounce(render, 150));
|
||||
$("#c-filter").addEventListener("change", render);
|
||||
$("#c-agent").addEventListener("change", switchAgent);
|
||||
$("#board-form").addEventListener("submit", addBoard);
|
||||
$("#prune-form").addEventListener("submit", previewPrune);
|
||||
$("#p-apply").addEventListener("click", applyPrune);
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/* The Pulls page: Pull now on top, one button per remaining kind under
|
||||
* "Run one stage".
|
||||
/* The Runs section of Sources: Pull now on top, one button per remaining
|
||||
* kind under "Run one stage".
|
||||
*
|
||||
* The list comes from `/api/jobs/kinds`, which is the registry, so a new
|
||||
* `@job` in `app/jobs.py` is a new button and this file is not edited --
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/* The Messages tab: the notice log as a table.
|
||||
/* The message log at the end of Sources' Runs section.
|
||||
*
|
||||
* `/api/notices` is the queue's own route (`pipeline/web/jobs.py`) -- the log
|
||||
* belongs to the queue, the wording belongs to the app, and this page is only
|
||||
* the reading of it. It redraws on `app:notice` so a failure that happens
|
||||
* while you are looking at this tab appears without a reload.
|
||||
* belongs to the queue, the wording belongs to the app, and this is only the
|
||||
* reading of it. It redraws on `app:notice` so a failure that happens while
|
||||
* you are looking at the page appears without a reload.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
/* The Ranking page: what Best match on the Roles tab is measured against.
|
||||
*
|
||||
* The UI shows one ranking. Underneath it is the first enabled search agent,
|
||||
* the oldest by id, since the `agents` table still holds as many as the CLI
|
||||
* or the config put there; this page edits that one and never lists, adds or
|
||||
* deletes. An empty table gets its first agent on the first save.
|
||||
*
|
||||
* Every request goes through `api()` from app.js, so a failure is one toast
|
||||
* carrying the server's own sentence.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const { api, count } = window;
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
|
||||
/** The name a ranking made here is saved under; the UI never shows it
|
||||
unless the CLI adds a second one. */
|
||||
const NEW_NAME = "My ranking";
|
||||
const DEFAULT_WEIGHTS = { fit: 0.6, recency: 0.2, affinity: 0.2 };
|
||||
|
||||
/** @type {object | null} the agent this page edits, null until one is saved */
|
||||
let agent = null;
|
||||
|
||||
/* The first enabled agent, else the first at all: editing it here means it
|
||||
is wanted, so a save switches it on. */
|
||||
function pick(agents) {
|
||||
const byId = [...agents].sort((a, b) => a.id - b.id);
|
||||
return byId.find((a) => a.enabled) || byId[0] || null;
|
||||
}
|
||||
|
||||
function fill(others) {
|
||||
$("#a-intent").value = agent ? agent.intent : "";
|
||||
$("#a-gates").value = JSON.stringify(agent ? agent.gates : [], null, 2);
|
||||
const weights = agent ? agent.weights : DEFAULT_WEIGHTS;
|
||||
$("#a-fit").value = weights.fit;
|
||||
$("#a-recency").value = weights.recency;
|
||||
$("#a-affinity").value = weights.affinity;
|
||||
const note = $("#ranking-others");
|
||||
note.hidden = !(agent && others > 0);
|
||||
if (!note.hidden) {
|
||||
note.textContent = `This edits "${agent.name}". ${count(others, "other ranking")} `
|
||||
+ "can be picked by name in the order menu on Roles.";
|
||||
}
|
||||
}
|
||||
|
||||
async function save(event) {
|
||||
event.preventDefault();
|
||||
const status = $("#ranking-status");
|
||||
let gates;
|
||||
try {
|
||||
gates = JSON.parse($("#a-gates").value || "[]");
|
||||
} catch (err) {
|
||||
window.toast.error(`Gates are not valid JSON: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
const body = {
|
||||
name: agent ? agent.name : NEW_NAME,
|
||||
intent: $("#a-intent").value,
|
||||
gates,
|
||||
weights: {
|
||||
fit: Number($("#a-fit").value),
|
||||
recency: Number($("#a-recency").value),
|
||||
affinity: Number($("#a-affinity").value),
|
||||
},
|
||||
enabled: true,
|
||||
};
|
||||
if (agent) body.id = agent.id;
|
||||
const button = $("#ranking-form button[type=submit]");
|
||||
button.disabled = true;
|
||||
try {
|
||||
agent = await api("/api/agents", { method: "POST", body });
|
||||
} catch (err) {
|
||||
status.textContent = "";
|
||||
button.disabled = false;
|
||||
return;
|
||||
}
|
||||
await rescore(status);
|
||||
button.disabled = false;
|
||||
}
|
||||
|
||||
// Start the `score` job and wait for it, so "Saved and scored" means the
|
||||
// Roles tab already orders by what was saved.
|
||||
async function rescore(status) {
|
||||
status.textContent = "Saved. Scoring…";
|
||||
let job;
|
||||
try {
|
||||
job = await api("/api/jobs", { method: "POST", body: { kind: "score", payload: {} } });
|
||||
} catch (err) {
|
||||
status.textContent = "Saved, but scoring did not start.";
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < 300; i += 1) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
let snapshot;
|
||||
try {
|
||||
snapshot = await api("/api/jobs");
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
const busy = [...snapshot.running, ...snapshot.queued].some((j) => j.id === job.id);
|
||||
if (busy) continue;
|
||||
const done = snapshot.recent.find((j) => j.id === job.id);
|
||||
if (done && done.state !== "done") {
|
||||
status.textContent = `Saved. Scoring ${done.state}.`;
|
||||
if (done.error) window.toast.error(`Scoring ${done.state}: ${done.error}`);
|
||||
return;
|
||||
}
|
||||
status.replaceChildren("Saved and scored. ");
|
||||
const link = document.createElement("a");
|
||||
link.href = `/?agent=${agent.id}`;
|
||||
link.textContent = "See the best matches";
|
||||
status.appendChild(link);
|
||||
return;
|
||||
}
|
||||
status.replaceChildren("Saved. Scoring is still running; ");
|
||||
const link = document.createElement("a");
|
||||
link.href = "/settings/pulls";
|
||||
link.textContent = "follow it under Pulls";
|
||||
status.append(link, ".");
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
let agents;
|
||||
try {
|
||||
agents = await api("/api/agents");
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
agent = pick(agents);
|
||||
fill(agents.filter((a) => a.enabled && (!agent || a.id !== agent.id)).length);
|
||||
$("#ranking-form").addEventListener("submit", save);
|
||||
});
|
||||
})();
|
||||
@@ -1,9 +1,11 @@
|
||||
/* The Searches page under Settings: saved searches only. Company boards and
|
||||
* the prune by region moved to Companies, since a board is a company's own,
|
||||
* not a search's.
|
||||
/* The Job boards section of Sources: one query on one board per row, on
|
||||
* Jobindex or Adzuna. The UI says "job board" for what the API and the CLI
|
||||
* call a search (`/api/searches`, `app searches`); company boards and the
|
||||
* prune by region are companies.js's section, since a board is a company's
|
||||
* own, not a query's.
|
||||
*
|
||||
* The list comes from `/api/sources`, and every action is a fetch through
|
||||
* `api()` from app.js, so a refusal (a search that finds nothing) is one
|
||||
* `api()` from app.js, so a refusal (a query that finds nothing) is one
|
||||
* toast with the server's own sentence. The catch blocks here only put a
|
||||
* control back.
|
||||
*/
|
||||
@@ -95,8 +97,8 @@
|
||||
}
|
||||
const open = data.searches.reduce((sum, s) => sum + s.open_roles, 0);
|
||||
$("#searches-count").textContent = data.searches.length
|
||||
? `${count(data.searches.length, "search", "searches")}, ${count(open, "open role")}`
|
||||
: "No searches yet. Add one below; the starter searches in config.yaml import on the first pull.";
|
||||
? `${count(data.searches.length, "job board")}, ${count(open, "open role")}`
|
||||
: "No job boards yet. Add one above; the starter ones in config.yaml import on the first pull.";
|
||||
}
|
||||
|
||||
function showProvider() {
|
||||
@@ -109,7 +111,7 @@
|
||||
|
||||
function fillSearchForm(source) {
|
||||
const p = (source && source.params) || {};
|
||||
$("#search-form-title").textContent = source ? `Edit ${source.label}` : "New search";
|
||||
$("#search-form-title").textContent = source ? `Edit ${source.label}` : "New job board";
|
||||
$("#s-provider").value = source ? source.provider : "jobindex";
|
||||
$("#s-name").value = source ? source.label : "";
|
||||
$("#s-name").readOnly = Boolean(source);
|
||||
|
||||
+60
-6
@@ -67,10 +67,6 @@ CREATE TABLE IF NOT EXISTS roles (
|
||||
-- Replies from extract that left this role unanswered. At GIVE_UP_AFTER it
|
||||
-- is no longer offered. A column, not raw, because every upsert rewrites raw.
|
||||
extract_tries INTEGER NOT NULL DEFAULT 0,
|
||||
-- The owner's judgement of the role: NULL unjudged, else -1 pass, 0
|
||||
-- neutral, 1 like. It moves the rank at read time and never hides a role.
|
||||
vote INTEGER CHECK (vote IN (-1, 0, 1)),
|
||||
voted_at TEXT,
|
||||
-- About 60 words from summarise, and when it wrote them.
|
||||
summary TEXT NOT NULL DEFAULT '',
|
||||
summarised_at TEXT,
|
||||
@@ -87,8 +83,6 @@ CREATE TABLE IF NOT EXISTS companies (
|
||||
key TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
domain TEXT NOT NULL DEFAULT '',
|
||||
-- -1 mute, 0 neutral, 1 interested, 2 favourite.
|
||||
affinity INTEGER NOT NULL DEFAULT 0 CHECK (affinity BETWEEN -1 AND 2),
|
||||
status TEXT NOT NULL DEFAULT 'researching',
|
||||
careers_url TEXT NOT NULL DEFAULT '',
|
||||
notes TEXT NOT NULL DEFAULT '',
|
||||
@@ -167,6 +161,29 @@ CREATE TABLE IF NOT EXISTS agents (
|
||||
intent_vec BLOB
|
||||
);
|
||||
|
||||
-- One agent's stance on a company: -1 hidden, 0 neutral, 1 liked, 2
|
||||
-- favourite. No row is 0, so the table holds only what somebody set. Per
|
||||
-- agent, because a company that is noise for one search is the target of
|
||||
-- another.
|
||||
CREATE TABLE IF NOT EXISTS agent_companies (
|
||||
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
company_key TEXT NOT NULL,
|
||||
affinity INTEGER NOT NULL CHECK (affinity BETWEEN -1 AND 2),
|
||||
updated_at TEXT NOT NULL,
|
||||
PRIMARY KEY (agent_id, company_key)
|
||||
);
|
||||
|
||||
-- One agent's judgement of a role: -1 pass, 0 neutral, 1 like. No row is
|
||||
-- unjudged. A vote moves the rank at read time, never hides a role, and its
|
||||
-- vectors shape the agent's taste direction in `score`.
|
||||
CREATE TABLE IF NOT EXISTS role_votes (
|
||||
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
uid TEXT NOT NULL REFERENCES roles(uid) ON DELETE CASCADE,
|
||||
vote INTEGER NOT NULL CHECK (vote IN (-1, 0, 1)),
|
||||
voted_at TEXT NOT NULL,
|
||||
PRIMARY KEY (agent_id, uid)
|
||||
);
|
||||
|
||||
-- A role is scored per agent. A gated role keeps its row, with the reason.
|
||||
CREATE TABLE IF NOT EXISTS scores (
|
||||
uid TEXT NOT NULL REFERENCES roles(uid) ON DELETE CASCADE,
|
||||
@@ -207,6 +224,7 @@ CREATE INDEX IF NOT EXISTS idx_roles_board ON roles(source, subscription_id
|
||||
CREATE INDEX IF NOT EXISTS idx_application_events
|
||||
ON application_events(application_id, at);
|
||||
CREATE INDEX IF NOT EXISTS idx_scores_agent ON scores(agent_id, score DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_role_votes_agent ON role_votes(agent_id, vote);
|
||||
CREATE INDEX IF NOT EXISTS idx_vectors_model ON vectors(model);
|
||||
"""
|
||||
|
||||
@@ -244,6 +262,42 @@ ALTER TABLE roles ADD COLUMN summary TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE roles ADD COLUMN summarised_at TEXT;
|
||||
ALTER TABLE roles ADD COLUMN article_text TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE roles ADD COLUMN article_at TEXT;
|
||||
"""),
|
||||
# Votes and affinities move from the role and company rows to one row per
|
||||
# agent. What was global goes to the default agent, the enabled one with
|
||||
# the lowest id (`Store.default_agent`); a file with something to move and
|
||||
# no agent gets one first, so nothing is lost. The columns are then
|
||||
# dropped, which SQLite has allowed since 3.35.
|
||||
(5, "agent_companies and role_votes: affinity and vote become per agent", """
|
||||
CREATE TABLE agent_companies (
|
||||
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
company_key TEXT NOT NULL,
|
||||
affinity INTEGER NOT NULL CHECK (affinity BETWEEN -1 AND 2),
|
||||
updated_at TEXT NOT NULL,
|
||||
PRIMARY KEY (agent_id, company_key)
|
||||
);
|
||||
CREATE TABLE role_votes (
|
||||
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
uid TEXT NOT NULL REFERENCES roles(uid) ON DELETE CASCADE,
|
||||
vote INTEGER NOT NULL CHECK (vote IN (-1, 0, 1)),
|
||||
voted_at TEXT NOT NULL,
|
||||
PRIMARY KEY (agent_id, uid)
|
||||
);
|
||||
INSERT INTO agents (name, intent, gates, weights, enabled, created_at)
|
||||
SELECT 'My ranking', '', '[]', '{}', 1, strftime('%Y-%m-%dT%H:%M:%S+00:00', 'now')
|
||||
WHERE NOT EXISTS (SELECT 1 FROM agents)
|
||||
AND (EXISTS (SELECT 1 FROM roles WHERE vote IS NOT NULL)
|
||||
OR EXISTS (SELECT 1 FROM companies WHERE affinity <> 0));
|
||||
INSERT INTO role_votes (agent_id, uid, vote, voted_at)
|
||||
SELECT (SELECT id FROM agents ORDER BY enabled DESC, id LIMIT 1), uid, vote,
|
||||
COALESCE(voted_at, strftime('%Y-%m-%dT%H:%M:%S+00:00', 'now'))
|
||||
FROM roles WHERE vote IS NOT NULL;
|
||||
INSERT INTO agent_companies (agent_id, company_key, affinity, updated_at)
|
||||
SELECT (SELECT id FROM agents ORDER BY enabled DESC, id LIMIT 1), key, affinity, updated_at
|
||||
FROM companies WHERE affinity <> 0;
|
||||
ALTER TABLE roles DROP COLUMN vote;
|
||||
ALTER TABLE roles DROP COLUMN voted_at;
|
||||
ALTER TABLE companies DROP COLUMN affinity;
|
||||
"""),
|
||||
)
|
||||
|
||||
|
||||
+156
-89
@@ -51,21 +51,29 @@ _EXTRACT_WAITING = (f"extracted_at IS NULL AND closed_at IS NULL "
|
||||
#: What a vote may be: 1 like, 0 neither way, -1 pass, None unjudged.
|
||||
VOTES = (-1, 0, 1, None)
|
||||
|
||||
#: The `judged` filter of `Store.roles`, as a `WHERE` on `roles.vote`. A
|
||||
#: neutral vote is judged, and is neither liked nor passed.
|
||||
#: The `judged` filter of `Store.roles`, as a `WHERE` on the agent's vote,
|
||||
#: joined as `v`. A neutral vote is judged, and is neither liked nor passed.
|
||||
JUDGED: dict[str, str] = {
|
||||
"liked": "roles.vote = 1",
|
||||
"unjudged": "roles.vote IS NULL",
|
||||
"passed": "roles.vote = -1",
|
||||
"liked": "v.vote = 1",
|
||||
"unjudged": "v.vote IS NULL",
|
||||
"passed": "v.vote = -1",
|
||||
}
|
||||
|
||||
#: A ranking's score as `Store.roles` serves and orders it: halved by a pass,
|
||||
#: lifted a fifth by a like, capped at 1. Applied at read time, so a vote
|
||||
#: moves the role at once and the stored score stays what `score` computed.
|
||||
_VOTED_SCORE = ("MIN(1.0, s.score * CASE roles.vote WHEN -1 THEN 0.5 "
|
||||
_VOTED_SCORE = ("MIN(1.0, s.score * CASE v.vote WHEN -1 THEN 0.5 "
|
||||
"WHEN 1 THEN 1.2 ELSE 1 END)")
|
||||
|
||||
_COMPANY_FIELDS = ("name", "domain", "affinity", "status", "careers_url", "notes")
|
||||
#: The agent's votes beside every role. With no agent the join matches
|
||||
#: nothing, so `vote` and `voted_at` are NULL: one query shape either way.
|
||||
_WITH_VOTES = "LEFT JOIN role_votes v ON v.uid = roles.uid AND v.agent_id = ?"
|
||||
|
||||
_COMPANY_FIELDS = ("name", "domain", "status", "careers_url", "notes")
|
||||
|
||||
#: A company as the store serves it: the row and the asked-for agent's affinity.
|
||||
_COMPANY_SELECT = """SELECT c.*, COALESCE(ac.affinity, 0) AS affinity FROM companies c
|
||||
LEFT JOIN agent_companies ac ON ac.company_key = c.key AND ac.agent_id = ?"""
|
||||
_SUBSCRIPTION_FIELDS = ("label", "company", "board", "params", "subscribed", "fetch",
|
||||
"show", "target_id")
|
||||
|
||||
@@ -280,89 +288,119 @@ class Store:
|
||||
f"ON CONFLICT(uid) DO UPDATE SET {', '.join(updates)}", row)
|
||||
return not existed
|
||||
|
||||
def role(self, uid: str) -> Role | None:
|
||||
row = self._row("SELECT * FROM roles WHERE uid=?", (uid,))
|
||||
def role(self, uid: str, agent_id: int | None = None) -> Role | None:
|
||||
"""One role, with `vote` and `voted_at` as `agent_id` judged it; None
|
||||
(unjudged) without an agent."""
|
||||
row = self._row(f"SELECT roles.*, v.vote, v.voted_at FROM roles {_WITH_VOTES} "
|
||||
"WHERE roles.uid=?", (agent_id, uid))
|
||||
return Role.from_row(row) if row else None
|
||||
|
||||
def set_vote(self, uid: str, value: int | None) -> Role:
|
||||
"""Judge one role: 1 like, 0 neither way, -1 pass, None unjudged again.
|
||||
Stamps `voted_at`, or clears it with the vote. A vote never hides a
|
||||
role; it moves it in a ranking (see `roles`). Raises ValueError for
|
||||
another value and KeyError for an unknown uid."""
|
||||
def set_vote(self, agent_id: int, uid: str, value: int | None) -> Role:
|
||||
"""One agent's judgement of one role: 1 like, 0 neither way, -1 pass,
|
||||
None unjudged again, which deletes the row. A vote never hides a
|
||||
role; it moves it in that agent's ranking (see `roles`) and shapes its
|
||||
taste direction (see `jobs/score.py`). Returns the role with this
|
||||
agent's vote. Raises ValueError for another value and KeyError for an
|
||||
unknown uid or agent."""
|
||||
if isinstance(value, bool) or value not in VOTES:
|
||||
raise ValueError(f"a vote is -1, 0 or 1, not {value!r}")
|
||||
stamp = None if value is None else self.now()
|
||||
if not self._write("UPDATE roles SET vote=?, voted_at=? WHERE uid=?",
|
||||
(value, stamp, uid)):
|
||||
raise KeyError(uid)
|
||||
role = self.role(uid)
|
||||
with self.transaction() as conn:
|
||||
self._known(conn, "roles", "uid", uid)
|
||||
self._known(conn, "agents", "id", agent_id)
|
||||
if value is None:
|
||||
conn.execute("DELETE FROM role_votes WHERE agent_id=? AND uid=?",
|
||||
(agent_id, uid))
|
||||
else:
|
||||
conn.execute(
|
||||
"""INSERT INTO role_votes (agent_id, uid, vote, voted_at) VALUES (?,?,?,?)
|
||||
ON CONFLICT(agent_id, uid) DO UPDATE
|
||||
SET vote=excluded.vote, voted_at=excluded.voted_at""",
|
||||
(agent_id, uid, value, self.now()))
|
||||
role = self.role(uid, agent_id)
|
||||
assert role is not None
|
||||
return role
|
||||
|
||||
def votes(self, agent_id: int) -> dict[str, int]:
|
||||
"""`uid -> vote` for one agent, open roles and closed alike: a closed
|
||||
role somebody liked still says what they like."""
|
||||
return {r["uid"]: int(r["vote"]) for r in self._rows(
|
||||
"SELECT uid, vote FROM role_votes WHERE agent_id=?", (agent_id,))}
|
||||
|
||||
@staticmethod
|
||||
def _known(conn: sqlite3.Connection, table: str, column: str, value: Any) -> None:
|
||||
"""KeyError unless the row exists: the caller's 404, rather than the
|
||||
foreign key's IntegrityError, which does not say which side is unknown."""
|
||||
if conn.execute(f"SELECT 1 FROM {table} WHERE {column}=?", (value,)).fetchone() is None:
|
||||
raise KeyError(value)
|
||||
|
||||
def roles(self, limit: int = 100, company: str | None = None,
|
||||
place: str | None = None, open_only: bool = True,
|
||||
q: str | None = None, function: str | None = None,
|
||||
remote: str | None = None, days: int | None = None,
|
||||
hide_muted: bool = False, agent: int | None = None,
|
||||
gated: bool = False, judged: str | None = None,
|
||||
offset: int = 0) -> list[ScoredRole]:
|
||||
by_score: bool = True, gated: bool = False,
|
||||
judged: str | None = None, offset: int = 0) -> list[ScoredRole]:
|
||||
"""Newest first by `first_seen`. `company` and `place` are
|
||||
case-insensitive substrings of the columns a board wrote — not the
|
||||
key, so a search does not have to know the exact slug a company folds
|
||||
to. `q` is matched word by word against `title`; a role must match
|
||||
every word. `function` and `remote` match a gate column exactly.
|
||||
`days` keeps only roles first seen within that many days of now.
|
||||
`judged` is a key of `JUDGED`: liked, unjudged or passed.
|
||||
|
||||
`hide_muted` excludes a muted company's roles before `limit` is
|
||||
applied, in SQL rather than after the fact: a company that has
|
||||
published a lot, all at once — a fresh board added, a re-pull that
|
||||
finally reached it — can otherwise fill the whole page with roles
|
||||
that then all turn out to be from the one company someone muted,
|
||||
leaving nothing to show for a default query that would otherwise
|
||||
have plenty.
|
||||
`agent` says whose votes, hidden companies and scores are meant. Each
|
||||
row carries that agent's `vote` and `voted_at`; `judged` (a key of
|
||||
`JUDGED`: liked, unjudged or passed) filters on them. `hide_muted`
|
||||
excludes the companies that agent hid, before `limit` is applied, in
|
||||
SQL rather than after the fact: a company that has published a lot,
|
||||
all at once — a fresh board added, a re-pull that finally reached
|
||||
it — can otherwise fill the whole page with roles that then all turn
|
||||
out to be from the one company someone hid, leaving nothing to show
|
||||
for a default query that would otherwise have plenty. With no agent
|
||||
every vote is None, nothing is hidden and `judged` reads as such.
|
||||
|
||||
`agent` orders by that agent's score instead, highest first, and
|
||||
carries `score` and `gated_reason` on each row. Only roles it has
|
||||
scored are listed, and a gated one only when `gated` is set. The score
|
||||
is the stored one moved by the role's vote (`_VOTED_SCORE`), so a vote
|
||||
shows in the order at once and needs no rescore.
|
||||
With `agent` and `by_score`, ordered by that agent's score instead,
|
||||
highest first, carrying `score` and `gated_reason` on each row. Only
|
||||
roles it has scored are listed, and a gated one only when `gated` is
|
||||
set. The score is the stored one moved by the agent's vote
|
||||
(`_VOTED_SCORE`), so a vote shows in the order at once and needs no
|
||||
rescore. With `by_score` off the order is newest, with the votes and
|
||||
no score.
|
||||
|
||||
`offset` skips that many rows of the same order, for the page that
|
||||
loads the next 60 as it is scrolled; `count_roles` is the total."""
|
||||
sql, params = self._roles_from(
|
||||
company=company, place=place, open_only=open_only, q=q, function=function,
|
||||
remote=remote, days=days, hide_muted=hide_muted, agent=agent, gated=gated,
|
||||
judged=judged)
|
||||
if agent is None:
|
||||
select = "SELECT roles.* "
|
||||
order = "roles.first_seen DESC, roles.uid"
|
||||
else:
|
||||
select = f"SELECT roles.*, {_VOTED_SCORE} AS score, s.gated_reason "
|
||||
order = "score DESC, roles.first_seen DESC, roles.uid"
|
||||
remote=remote, days=days, hide_muted=hide_muted, agent=agent,
|
||||
by_score=by_score, gated=gated, judged=judged)
|
||||
select = "SELECT roles.*, v.vote, v.voted_at"
|
||||
order = "roles.first_seen DESC, roles.uid"
|
||||
if agent is not None and by_score:
|
||||
select += f", {_VOTED_SCORE} AS score, s.gated_reason"
|
||||
order = "score DESC, " + order
|
||||
return [ScoredRole.from_row(r) for r in self._rows(
|
||||
f"{select}{sql} ORDER BY {order} LIMIT ? OFFSET ?", [*params, limit, offset])]
|
||||
f"{select} {sql} ORDER BY {order} LIMIT ? OFFSET ?", [*params, limit, offset])]
|
||||
|
||||
def count_roles(self, company: str | None = None, place: str | None = None,
|
||||
open_only: bool = True, q: str | None = None,
|
||||
function: str | None = None, remote: str | None = None,
|
||||
days: int | None = None, hide_muted: bool = False,
|
||||
agent: int | None = None, gated: bool = False,
|
||||
judged: str | None = None) -> int:
|
||||
agent: int | None = None, by_score: bool = True,
|
||||
gated: bool = False, judged: str | None = None) -> int:
|
||||
"""How many roles `roles` would list with the same filters and no limit."""
|
||||
sql, params = self._roles_from(
|
||||
company=company, place=place, open_only=open_only, q=q, function=function,
|
||||
remote=remote, days=days, hide_muted=hide_muted, agent=agent, gated=gated,
|
||||
judged=judged)
|
||||
remote=remote, days=days, hide_muted=hide_muted, agent=agent,
|
||||
by_score=by_score, gated=gated, judged=judged)
|
||||
row = self._row(f"SELECT COUNT(*) AS n {sql}", params)
|
||||
return int(row["n"]) if row else 0
|
||||
|
||||
def _roles_from(self, *, company: str | None, place: str | None, open_only: bool,
|
||||
q: str | None, function: str | None, remote: str | None,
|
||||
days: int | None, hide_muted: bool, agent: int | None,
|
||||
gated: bool, judged: str | None) -> tuple[str, list[Any]]:
|
||||
by_score: bool, gated: bool, judged: str | None) -> tuple[str, list[Any]]:
|
||||
"""The `FROM ... WHERE ...` that `roles` and `count_roles` share, with
|
||||
its parameters in order."""
|
||||
its parameters in order. The agent's votes are always joined as `v`
|
||||
(see `_WITH_VOTES`); its scores as `s` only when ordering by them."""
|
||||
where: list[str] = []
|
||||
params: list[Any] = []
|
||||
if company:
|
||||
@@ -389,14 +427,14 @@ class Store:
|
||||
where.append(JUDGED[judged])
|
||||
if open_only:
|
||||
where.append("closed_at IS NULL")
|
||||
if hide_muted:
|
||||
where.append("company_key NOT IN "
|
||||
"(SELECT key FROM companies WHERE affinity = -1)")
|
||||
joins: list[Any] = []
|
||||
if agent is None:
|
||||
sql = "FROM roles"
|
||||
else:
|
||||
sql = "FROM roles JOIN scores s ON s.uid = roles.uid AND s.agent_id = ?"
|
||||
if hide_muted and agent is not None:
|
||||
where.append("company_key NOT IN (SELECT company_key FROM agent_companies "
|
||||
"WHERE agent_id = ? AND affinity = -1)")
|
||||
params.append(agent)
|
||||
sql = f"FROM roles {_WITH_VOTES}"
|
||||
joins: list[Any] = [agent]
|
||||
if agent is not None and by_score:
|
||||
sql += " JOIN scores s ON s.uid = roles.uid AND s.agent_id = ?"
|
||||
joins.append(agent)
|
||||
if not gated:
|
||||
where.append("s.gated_reason = ''")
|
||||
@@ -520,8 +558,9 @@ class Store:
|
||||
"""The `WHERE` for a role `summarise` may be sent: no summary yet and
|
||||
some text to summarise. Given `uids`, those of them and nothing else,
|
||||
open or not and given up or not, because somebody asked for them.
|
||||
Otherwise open, not of a hidden company, not given up, and among the
|
||||
`per_agent` best ungated scores of an enabled agent."""
|
||||
Otherwise open, not given up, and among the `per_agent` best ungated
|
||||
scores of an enabled agent. A company an agent hid needs no clause:
|
||||
`score` writes no rows for it under that agent."""
|
||||
where = ["r.summary = ''",
|
||||
"(TRIM(r.article_text) <> '' OR TRIM(r.description) <> '')"]
|
||||
if uids is not None:
|
||||
@@ -529,7 +568,6 @@ class Store:
|
||||
return " AND ".join(where), [json.dumps(list(uids))]
|
||||
where += [
|
||||
"r.closed_at IS NULL",
|
||||
"r.company_key NOT IN (SELECT key FROM companies WHERE affinity = -1)",
|
||||
f"""NOT EXISTS (SELECT 1 FROM state
|
||||
WHERE key = '{self._SUMMARY_MISSED}' || r.uid
|
||||
AND CAST(value AS INTEGER) >= {GIVE_UP_AFTER})""",
|
||||
@@ -652,6 +690,12 @@ class Store:
|
||||
row = self._row("SELECT * FROM agents WHERE id=?", (agent_id,))
|
||||
return Agent.from_row(row) if row else None
|
||||
|
||||
def default_agent(self) -> Agent | None:
|
||||
"""The agent a vote or an affinity goes to when none is named: the
|
||||
enabled one with the lowest id, else the lowest id, else None."""
|
||||
row = self._row("SELECT * FROM agents ORDER BY enabled DESC, id LIMIT 1")
|
||||
return Agent.from_row(row) if row else None
|
||||
|
||||
def save_agent(self, name: str, intent: str = "", gates: Sequence[Gate] = (),
|
||||
weights: Weights | None = None, enabled: bool = True,
|
||||
agent_id: int | None = None) -> Agent:
|
||||
@@ -682,7 +726,7 @@ class Store:
|
||||
return found
|
||||
|
||||
def delete_agent(self, agent_id: int) -> bool:
|
||||
"""Its scores go with it, by the foreign key."""
|
||||
"""Its scores, votes and affinities go with it, by the foreign keys."""
|
||||
return self._write("DELETE FROM agents WHERE id=?", (agent_id,)) > 0
|
||||
|
||||
def intent_vector(self, agent_id: int, key: str) -> np.ndarray | None:
|
||||
@@ -699,11 +743,12 @@ class Store:
|
||||
|
||||
# --------------------------------------------------------------- scores
|
||||
|
||||
def score_candidates(self, gates: Sequence[Gate]) -> list[Candidate]:
|
||||
"""Every open role of a company that is not muted, with how it meets
|
||||
each gate: 1 match, 0 no match, -1 the column is empty. The gates are
|
||||
evaluated here, in SQL, so a `require` gate is the `WHERE` it reads
|
||||
as, written as a column so a gated role keeps its row and reason."""
|
||||
def score_candidates(self, agent_id: int, gates: Sequence[Gate]) -> list[Candidate]:
|
||||
"""Every open role of a company this agent has not hidden, with the
|
||||
agent's affinity for the company and how the role meets each gate: 1
|
||||
match, 0 no match, -1 the column is empty. The gates are evaluated
|
||||
here, in SQL, so a `require` gate is the `WHERE` it reads as, written
|
||||
as a column so a gated role keeps its row and reason."""
|
||||
columns: list[str] = []
|
||||
params: list[Any] = []
|
||||
for n, gate in enumerate(gates):
|
||||
@@ -712,12 +757,13 @@ class Store:
|
||||
f"CASE WHEN {empty} THEN -1 WHEN {match} THEN 1 ELSE 0 END AS g{n}")
|
||||
params += values
|
||||
select = ", ".join(["r.uid", "r.first_seen",
|
||||
"COALESCE(c.affinity, 0) AS affinity", *columns])
|
||||
"COALESCE(ac.affinity, 0) AS affinity", *columns])
|
||||
rows = self._rows(
|
||||
f"""SELECT {select} FROM roles r
|
||||
LEFT JOIN companies c ON c.key = r.company_key
|
||||
WHERE r.closed_at IS NULL AND COALESCE(c.affinity, 0) <> -1""",
|
||||
params)
|
||||
LEFT JOIN agent_companies ac
|
||||
ON ac.company_key = r.company_key AND ac.agent_id = ?
|
||||
WHERE r.closed_at IS NULL AND COALESCE(ac.affinity, 0) <> -1""",
|
||||
[*params, agent_id])
|
||||
return [Candidate(uid=r["uid"], first_seen=r["first_seen"],
|
||||
affinity=int(r["affinity"]),
|
||||
gates=[int(r[f"g{n}"]) for n in range(len(gates))])
|
||||
@@ -748,40 +794,61 @@ class Store:
|
||||
# ------------------------------------------------------------ companies
|
||||
|
||||
def add_company(self, name: str, *, key: str = "", domain: str = "",
|
||||
affinity: int = 0, status: str = "researching",
|
||||
careers_url: str = "", notes: str = "") -> Company:
|
||||
"""Raises ValueError on a key already taken or an affinity out of range."""
|
||||
status: str = "researching", careers_url: str = "",
|
||||
notes: str = "") -> Company:
|
||||
"""Raises ValueError on a key already taken."""
|
||||
name = name.strip()
|
||||
key = key or company_key(name)
|
||||
if not key:
|
||||
raise ValueError("a company needs a name")
|
||||
_check_affinity(affinity)
|
||||
stamp = self.now()
|
||||
try:
|
||||
self._write(
|
||||
"""INSERT INTO companies (key, name, domain, affinity, status,
|
||||
careers_url, notes, created_at, updated_at)
|
||||
VALUES (?,?,?,?,?,?,?,?,?)""",
|
||||
(key, name, domain, affinity, status, careers_url, notes, stamp, stamp))
|
||||
"""INSERT INTO companies (key, name, domain, status, careers_url, notes,
|
||||
created_at, updated_at)
|
||||
VALUES (?,?,?,?,?,?,?,?)""",
|
||||
(key, name, domain, status, careers_url, notes, stamp, stamp))
|
||||
except sqlite3.IntegrityError as exc:
|
||||
raise ValueError(f"company {key!r} already exists") from exc
|
||||
return self._company(key)
|
||||
|
||||
def company(self, key: str) -> Company | None:
|
||||
row = self._row("SELECT * FROM companies WHERE key=?", (key,))
|
||||
def company(self, key: str, agent_id: int | None = None) -> Company | None:
|
||||
"""One company, with `affinity` as `agent_id` set it; 0 without an agent."""
|
||||
row = self._row(f"{_COMPANY_SELECT} WHERE c.key=?", (agent_id, key))
|
||||
return Company.from_row(row) if row else None
|
||||
|
||||
def companies(self) -> list[Company]:
|
||||
return [Company.from_row(r)
|
||||
for r in self._rows("SELECT * FROM companies ORDER BY name COLLATE NOCASE")]
|
||||
def companies(self, agent_id: int | None = None) -> list[Company]:
|
||||
"""Every company by name, with `affinity` as `agent_id` set it."""
|
||||
return [Company.from_row(r) for r in self._rows(
|
||||
f"{_COMPANY_SELECT} ORDER BY c.name COLLATE NOCASE", (agent_id,))]
|
||||
|
||||
def set_affinity(self, agent_id: int, key: str, affinity: int) -> Company:
|
||||
"""One agent's stance on a company: -1 hidden, 0 neutral, 1 liked, 2
|
||||
favourite. 0 deletes the row, since no row means neutral. Returns the
|
||||
company with this agent's affinity. Raises ValueError for another
|
||||
value and KeyError for an unknown company or agent."""
|
||||
_check_affinity(affinity)
|
||||
with self.transaction() as conn:
|
||||
self._known(conn, "companies", "key", key)
|
||||
self._known(conn, "agents", "id", agent_id)
|
||||
if affinity == 0:
|
||||
conn.execute("DELETE FROM agent_companies WHERE agent_id=? AND company_key=?",
|
||||
(agent_id, key))
|
||||
else:
|
||||
conn.execute(
|
||||
"""INSERT INTO agent_companies (agent_id, company_key, affinity, updated_at)
|
||||
VALUES (?,?,?,?)
|
||||
ON CONFLICT(agent_id, company_key) DO UPDATE
|
||||
SET affinity=excluded.affinity, updated_at=excluded.updated_at""",
|
||||
(agent_id, key, affinity, self.now()))
|
||||
return self._company(key, agent_id)
|
||||
|
||||
def update_company(self, key: str, **fields: Any) -> Company:
|
||||
"""Change any of name, domain, affinity, status, careers_url, notes."""
|
||||
"""Change any of name, domain, status, careers_url, notes. Affinity is
|
||||
per agent: `set_affinity`."""
|
||||
unknown = set(fields) - set(_COMPANY_FIELDS)
|
||||
if unknown:
|
||||
raise ValueError(f"not a company field: {', '.join(sorted(unknown))}")
|
||||
if "affinity" in fields:
|
||||
_check_affinity(fields["affinity"])
|
||||
if fields:
|
||||
sets = ", ".join(f"{f}=?" for f in fields)
|
||||
changed = self._write(f"UPDATE companies SET {sets}, updated_at=? WHERE key=?",
|
||||
@@ -793,8 +860,8 @@ class Store:
|
||||
def remove_company(self, key: str) -> bool:
|
||||
return self._write("DELETE FROM companies WHERE key=?", (key,)) > 0
|
||||
|
||||
def _company(self, key: str) -> Company:
|
||||
found = self.company(key)
|
||||
def _company(self, key: str, agent_id: int | None = None) -> Company:
|
||||
found = self.company(key, agent_id)
|
||||
if found is None:
|
||||
raise KeyError(key)
|
||||
return found
|
||||
@@ -986,5 +1053,5 @@ def _check_status(status: str) -> None:
|
||||
|
||||
|
||||
def _check_affinity(affinity: Any) -> None:
|
||||
if not isinstance(affinity, int) or affinity not in AFFINITY:
|
||||
if isinstance(affinity, bool) or not isinstance(affinity, int) or affinity not in AFFINITY:
|
||||
raise ValueError(f"affinity is -1, 0, 1 or 2, not {affinity!r}")
|
||||
@@ -9,5 +9,5 @@
|
||||
the API does not. #}
|
||||
<p class="lede">{{ detail }}</p>
|
||||
|
||||
<p><a href="/">Back to the roles</a>, or <a href="/settings/messages">see what the server has been saying</a>.</p>
|
||||
<p><a href="/">Back to the roles</a>, or <a href="/settings/sources#messages">see what the server has been saying</a>.</p>
|
||||
{% endblock %}
|
||||
@@ -1,17 +1,24 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Ranking — roledesk{% endblock %}
|
||||
{% block title %}Search agents — roledesk{% endblock %}
|
||||
|
||||
{# One ranking in the UI, whatever the `agents` table holds: `static/ranking.js`
|
||||
edits the first enabled agent and makes one on the first save if there is
|
||||
none. No list, no New, no Delete. #}
|
||||
{# A list and a form: `static/agents.js` fills the list from `/api/agents`,
|
||||
the form edits the picked agent, New clears it, Delete removes it with its
|
||||
votes, liked companies and scores. #}
|
||||
{% block content %}
|
||||
<h1>Settings</h1>
|
||||
{% include "settings/_tabs.html" %}
|
||||
|
||||
<p class="lede">Describe the role you want. Best match on the Roles tab puts the postings closest to this first, and saving reorders them all.</p>
|
||||
<p class="lede">A search agent is what the Roles tab ranks by: describe the role, weigh the terms, and it scores every open role. Several agents rank the same roles differently, each with its own votes and liked companies; the order menu on Roles picks one.</p>
|
||||
|
||||
<form id="ranking-form" class="agent-form" autocomplete="off">
|
||||
<p id="ranking-others" class="count" hidden></p>
|
||||
<p id="agents-count" class="count" role="status"></p>
|
||||
<div id="agents-list" class="crows"></div>
|
||||
|
||||
<form id="agent-form" class="agent-form" autocomplete="off">
|
||||
<div class="row-between">
|
||||
<h2 id="agent-form-title">New agent</h2>
|
||||
<button type="button" id="a-new" class="secondary">New agent</button>
|
||||
</div>
|
||||
<label>Name <input type="text" id="a-name" required placeholder="My search"></label>
|
||||
<label>What you are looking for
|
||||
<textarea id="a-intent" rows="7" placeholder="Senior backend engineer. Python and Go services, PostgreSQL, APIs on Kubernetes. Wants ownership of production systems in a product company."></textarea>
|
||||
<span class="hint">A paragraph of your CV, or the role in your own words: the work, the stack, the level.</span></label>
|
||||
@@ -20,6 +27,7 @@
|
||||
<label>Fit to the text <input type="number" id="a-fit" min="0" step="0.05" value="0.6"></label>
|
||||
<label>Newness <input type="number" id="a-recency" min="0" step="0.05" value="0.2"></label>
|
||||
<label>Companies you like <input type="number" id="a-affinity" min="0" step="0.05" value="0.2"></label>
|
||||
<label>Roles you liked <input type="number" id="a-taste" min="0" step="0.05" value="0.2"></label>
|
||||
</fieldset>
|
||||
<details class="advanced">
|
||||
<summary>Advanced</summary>
|
||||
@@ -29,11 +37,12 @@
|
||||
</details>
|
||||
<div class="agent-actions">
|
||||
<button type="submit">Save and score</button>
|
||||
<button type="button" id="a-delete" class="secondary" hidden>Delete</button>
|
||||
</div>
|
||||
<p id="ranking-status" class="count" role="status"></p>
|
||||
<p id="agent-status" class="count" role="status"></p>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ asset('ranking.js') }}"></script>
|
||||
<script src="{{ asset('agents.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -1,66 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Companies — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Settings</h1>
|
||||
{% include "settings/_tabs.html" %}
|
||||
|
||||
<p class="lede">Every company roledesk has seen, and how many of its roles are open. Switching a board off stops reading it and closes its roles; hiding a company keeps reading it but leaves its roles out of the list and unscored, and favourite or like lifts one instead, in Best match.</p>
|
||||
|
||||
<form id="board-form" class="agent-form source-form" autocomplete="off">
|
||||
<h2>Follow a company</h2>
|
||||
<div class="form-row">
|
||||
<label>Host
|
||||
<select id="b-host">
|
||||
<option value="greenhouse">Greenhouse</option>
|
||||
<option value="lever">Lever</option>
|
||||
<option value="ashby">Ashby</option>
|
||||
<option value="workable">Workable</option>
|
||||
<option value="smartrecruiters">SmartRecruiters</option>
|
||||
<option value="recruitee">Recruitee</option>
|
||||
<option value="personio">Personio</option>
|
||||
</select></label>
|
||||
<label>Slug
|
||||
<input type="text" id="b-slug" required placeholder="acme" spellcheck="false">
|
||||
<span class="hint">The part after the host in the careers URL: boards.greenhouse.io/<strong>acme</strong>.</span></label>
|
||||
<label>Company <input type="text" id="b-name" required placeholder="Acme"></label>
|
||||
</div>
|
||||
<div class="agent-actions"><button type="submit">Follow</button></div>
|
||||
<p id="board-status" class="count" role="status"></p>
|
||||
</form>
|
||||
|
||||
<form class="filters" autocomplete="off" onsubmit="return false">
|
||||
<input type="search" id="c-q" placeholder="Filter by name or board" aria-label="Filter companies">
|
||||
<select id="c-filter" aria-label="Filter">
|
||||
<option value="">Any</option>
|
||||
<option value="favourite">Favourite</option>
|
||||
<option value="liked">Liked</option>
|
||||
<option value="hidden">Hidden</option>
|
||||
<option value="on">On</option>
|
||||
<option value="off">Off</option>
|
||||
</select>
|
||||
</form>
|
||||
|
||||
<p id="companies-count" class="count" role="status"></p>
|
||||
<div id="companies-list" class="crows"></div>
|
||||
|
||||
<details class="section prune">
|
||||
<summary>Switch off boards with no roles in a region</summary>
|
||||
<p class="lede">A board none of whose open roles is in the region is switched off; a board whose roles name no country is kept.</p>
|
||||
<form id="prune-form" class="agent-form source-form" autocomplete="off">
|
||||
<label>Region
|
||||
<input type="text" id="p-region" value="europe" spellcheck="false">
|
||||
<span class="hint"><code>europe</code>, or country codes such as <code>DK,SE,NO,EU</code>. EU is a role open anywhere in Europe.</span></label>
|
||||
<div class="agent-actions">
|
||||
<button type="submit" class="secondary">Preview</button>
|
||||
<button type="button" id="p-apply" disabled>Switch off these boards</button>
|
||||
</div>
|
||||
<p id="prune-status" class="count" role="status"></p>
|
||||
<ul id="prune-list" class="sample"></ul>
|
||||
</form>
|
||||
</details>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ asset('companies.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -1,21 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Messages — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Settings</h1>
|
||||
{% include "settings/_tabs.html" %}
|
||||
|
||||
<p class="lede">What the server said that nobody has cleared, newest first. A message goes when you clear it, or a fortnight after it was last said.</p>
|
||||
|
||||
<section class="card">
|
||||
<div class="row-between">
|
||||
<h2>The log</h2>
|
||||
<button type="button" id="clear-all" class="secondary">Clear all</button>
|
||||
</div>
|
||||
<div id="notices"><span class="muted">loading…</span></div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ asset('messages.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -1,46 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Pulls — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Settings</h1>
|
||||
{% include "settings/_tabs.html" %}
|
||||
|
||||
<p class="lede">Every 6 hours roledesk reads every board and search, then fills in what each posting says, embeds and scores. Change the cadence below.</p>
|
||||
|
||||
<section class="card">
|
||||
<div class="row-between">
|
||||
<h2>What is running</h2>
|
||||
<button type="button" id="pull-now" class="secondary">Pull now</button>
|
||||
</div>
|
||||
{# The heading and the idle line are the app's: the element takes up no
|
||||
space while the queue is idle — that is its `idle="hide"` default, and a
|
||||
strip that is always there is furniture — and a card with nothing in it
|
||||
and nothing above it reads as something that failed to load. The element
|
||||
and its script are the queue's own, served by its own router — see
|
||||
pipeline/web/static/jobs.js. #}
|
||||
<p class="muted small" id="idle">Nothing at the moment.</p>
|
||||
<script type="module" src="/_jobs/jobs.js"></script>
|
||||
<desk-jobs></desk-jobs>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
{# The element and its script are the scheduler's own, served by its own
|
||||
router — see pipeline/web/static/schedules.js. A cadence is typed as
|
||||
`every 15m`, `every 6h`, `daily at 06:00` or `weekly mon 07:00`; its add
|
||||
row's placeholder shows two. #}
|
||||
<h2>Schedule</h2>
|
||||
<script type="module" src="/_jobs/schedules.js"></script>
|
||||
<desk-schedules></desk-schedules>
|
||||
</section>
|
||||
|
||||
<details class="stage">
|
||||
<summary>Run one stage</summary>
|
||||
<div id="kinds" class="buttons">
|
||||
<span class="muted">loading…</span>
|
||||
</div>
|
||||
</details>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ asset('jobs.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -1,54 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Searches — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Settings</h1>
|
||||
{% include "settings/_tabs.html" %}
|
||||
|
||||
<p class="lede">Saved searches find roles at any company, on Jobindex or Adzuna. Switching one off closes its roles until you switch it back on.</p>
|
||||
|
||||
<form id="search-form" class="agent-form source-form" autocomplete="off">
|
||||
<h2 id="search-form-title">New search</h2>
|
||||
<div class="form-row">
|
||||
<label>Board
|
||||
<select id="s-provider">
|
||||
<option value="jobindex">Jobindex (Denmark)</option>
|
||||
<option value="adzuna">Adzuna (UK and EU)</option>
|
||||
</select></label>
|
||||
<label>Name <input type="text" id="s-name" required placeholder="Copenhagen backend"></label>
|
||||
</div>
|
||||
<label>Query
|
||||
<input type="text" id="s-q" required spellcheck="false">
|
||||
<span class="hint" data-provider="jobindex">Jobindex syntax: words are OR, <code>"a b"</code> is a phrase, <code>+word</code> is required.</span>
|
||||
<span class="hint" data-provider="adzuna" hidden>Every word must appear.</span></label>
|
||||
<div class="form-row">
|
||||
<label data-provider="jobindex">Area
|
||||
<select id="s-area">
|
||||
{% for value, label in areas %}<option value="{{ value }}"{% if value == 1 %} selected{% endif %}>{{ label }}</option>{% endfor %}
|
||||
</select></label>
|
||||
<label data-provider="adzuna" hidden>Country
|
||||
<select id="s-country">
|
||||
{% for value, label in countries %}<option value="{{ value }}">{{ label }}</option>{% endfor %}
|
||||
</select></label>
|
||||
<label data-provider="adzuna" hidden>Place <input type="text" id="s-where" placeholder="Berlin"></label>
|
||||
<label>Pages
|
||||
<input type="number" id="s-pages" min="1" max="10" value="10">
|
||||
<span class="hint">per pull, up to 10</span></label>
|
||||
</div>
|
||||
<p id="adzuna-key" class="note" hidden>No Adzuna key is set. Get a free one at developer.adzuna.com and set <code>ADZUNA_APP_ID</code> and <code>ADZUNA_APP_KEY</code> before starting the app.</p>
|
||||
<div class="agent-actions">
|
||||
<button type="button" id="s-try" class="secondary">Try it</button>
|
||||
<button type="submit">Save</button>
|
||||
<button type="button" id="s-new" class="secondary">New</button>
|
||||
</div>
|
||||
<p id="search-status" class="count" role="status"></p>
|
||||
<ol id="search-sample" class="sample"></ol>
|
||||
</form>
|
||||
|
||||
<p id="searches-count" class="count" role="status"></p>
|
||||
<div id="searches-list" class="srows"></div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ asset('sources.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,176 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Sources — roledesk{% endblock %}
|
||||
|
||||
{# One page, three sections, one per plugin: the `search` plugin's job board
|
||||
queries, the `ats` plugin's company boards, and the runs that read both,
|
||||
with the message log at the end. Each section keeps the element ids it had
|
||||
as a page of its own, so its script (sources.js, companies.js, jobs.js,
|
||||
messages.js) is unchanged and finds its root or does nothing. #}
|
||||
{% block content %}
|
||||
<h1>Settings</h1>
|
||||
{% include "settings/_tabs.html" %}
|
||||
|
||||
<p class="lede">Sources are where roles come from: queries on job boards that span companies, and the boards of the companies you follow. Each section is one plugin; the runs read them all.</p>
|
||||
|
||||
<nav class="jump" aria-label="Sections">
|
||||
<a href="#job-boards">Job boards</a>
|
||||
<a href="#company-boards">Company boards</a>
|
||||
<a href="#runs">Runs</a>
|
||||
</nav>
|
||||
|
||||
<section class="card" id="job-boards">
|
||||
<h2>Job boards</h2>
|
||||
<p class="lede">A query on Jobindex or Adzuna finds roles at any company. Switching one off closes its roles until you switch it back on.</p>
|
||||
|
||||
<form id="search-form" class="agent-form source-form" autocomplete="off">
|
||||
<h3 id="search-form-title">New job board</h3>
|
||||
<div class="form-row">
|
||||
<label>Board
|
||||
<select id="s-provider">
|
||||
<option value="jobindex">Jobindex (Denmark)</option>
|
||||
<option value="adzuna">Adzuna (UK and EU)</option>
|
||||
</select></label>
|
||||
<label>Name <input type="text" id="s-name" required placeholder="Copenhagen backend"></label>
|
||||
</div>
|
||||
<label>Query
|
||||
<input type="text" id="s-q" required spellcheck="false">
|
||||
<span class="hint" data-provider="jobindex">Jobindex syntax: words are OR, <code>"a b"</code> is a phrase, <code>+word</code> is required.</span>
|
||||
<span class="hint" data-provider="adzuna" hidden>Every word must appear.</span></label>
|
||||
<div class="form-row">
|
||||
<label data-provider="jobindex">Area
|
||||
<select id="s-area">
|
||||
{% for value, label in areas %}<option value="{{ value }}"{% if value == 1 %} selected{% endif %}>{{ label }}</option>{% endfor %}
|
||||
</select></label>
|
||||
<label data-provider="adzuna" hidden>Country
|
||||
<select id="s-country">
|
||||
{% for value, label in countries %}<option value="{{ value }}">{{ label }}</option>{% endfor %}
|
||||
</select></label>
|
||||
<label data-provider="adzuna" hidden>Place <input type="text" id="s-where" placeholder="Berlin"></label>
|
||||
<label>Pages
|
||||
<input type="number" id="s-pages" min="1" max="10" value="10">
|
||||
<span class="hint">per pull, up to 10</span></label>
|
||||
</div>
|
||||
<p id="adzuna-key" class="note" hidden>No Adzuna key is set. Get a free one at developer.adzuna.com and set <code>ADZUNA_APP_ID</code> and <code>ADZUNA_APP_KEY</code> before starting the app.</p>
|
||||
<div class="agent-actions">
|
||||
<button type="button" id="s-try" class="secondary">Try it</button>
|
||||
<button type="submit">Save</button>
|
||||
<button type="button" id="s-new" class="secondary">New</button>
|
||||
</div>
|
||||
<p id="search-status" class="count" role="status"></p>
|
||||
<ol id="search-sample" class="sample"></ol>
|
||||
</form>
|
||||
|
||||
<p id="searches-count" class="count" role="status"></p>
|
||||
<div id="searches-list" class="srows"></div>
|
||||
</section>
|
||||
|
||||
<section class="card" id="company-boards">
|
||||
<h2>Company boards</h2>
|
||||
<p class="lede">Every company roledesk has seen, and how many of its roles are open. Switching a board off stops reading it and closes its roles; hiding a company keeps reading it but leaves its roles out of the list and unscored, and favourite or like lifts one instead, in Best match.</p>
|
||||
|
||||
<form id="board-form" class="agent-form source-form" autocomplete="off">
|
||||
<h3>Follow a company</h3>
|
||||
<div class="form-row">
|
||||
<label>Host
|
||||
<select id="b-host">
|
||||
<option value="greenhouse">Greenhouse</option>
|
||||
<option value="lever">Lever</option>
|
||||
<option value="ashby">Ashby</option>
|
||||
<option value="workable">Workable</option>
|
||||
<option value="smartrecruiters">SmartRecruiters</option>
|
||||
<option value="recruitee">Recruitee</option>
|
||||
<option value="personio">Personio</option>
|
||||
</select></label>
|
||||
<label>Slug
|
||||
<input type="text" id="b-slug" required placeholder="acme" spellcheck="false">
|
||||
<span class="hint">The part after the host in the careers URL: boards.greenhouse.io/<strong>acme</strong>.</span></label>
|
||||
<label>Company <input type="text" id="b-name" required placeholder="Acme"></label>
|
||||
</div>
|
||||
<div class="agent-actions"><button type="submit">Follow</button></div>
|
||||
<p id="board-status" class="count" role="status"></p>
|
||||
</form>
|
||||
|
||||
<form class="filters" autocomplete="off" onsubmit="return false">
|
||||
<input type="search" id="c-q" placeholder="Filter by name or board" aria-label="Filter companies">
|
||||
<select id="c-filter" aria-label="Filter">
|
||||
<option value="">Any</option>
|
||||
<option value="favourite">Favourite</option>
|
||||
<option value="liked">Liked</option>
|
||||
<option value="hidden">Hidden</option>
|
||||
<option value="on">On</option>
|
||||
<option value="off">Off</option>
|
||||
</select>
|
||||
{# Liked and hidden are per search agent: this picks whose the list shows
|
||||
and whose the buttons set. companies.js fills it from /api/agents. #}
|
||||
<label class="inline">Liked and hidden for <select id="c-agent" aria-label="Search agent"></select></label>
|
||||
</form>
|
||||
<p id="c-no-agent" class="note" hidden>Liking a company needs a search agent. Add one under <a href="/settings/agents">Search agents</a>.</p>
|
||||
|
||||
<p id="companies-count" class="count" role="status"></p>
|
||||
<div id="companies-list" class="crows"></div>
|
||||
|
||||
<details class="prune">
|
||||
<summary>Switch off boards with no roles in a region</summary>
|
||||
<p class="lede">A board none of whose open roles is in the region is switched off; a board whose roles name no country is kept.</p>
|
||||
<form id="prune-form" class="agent-form source-form" autocomplete="off">
|
||||
<label>Region
|
||||
<input type="text" id="p-region" value="europe" spellcheck="false">
|
||||
<span class="hint"><code>europe</code>, or country codes such as <code>DK,SE,NO,EU</code>. EU is a role open anywhere in Europe.</span></label>
|
||||
<div class="agent-actions">
|
||||
<button type="submit" class="secondary">Preview</button>
|
||||
<button type="button" id="p-apply" disabled>Switch off these boards</button>
|
||||
</div>
|
||||
<p id="prune-status" class="count" role="status"></p>
|
||||
<ul id="prune-list" class="sample"></ul>
|
||||
</form>
|
||||
</details>
|
||||
</section>
|
||||
|
||||
<section class="card" id="runs">
|
||||
<div class="row-between">
|
||||
<h2>Runs</h2>
|
||||
<button type="button" id="pull-now" class="secondary">Pull now</button>
|
||||
</div>
|
||||
<p class="lede">Every 6 hours the pull reads every board, then extract fills in what each posting says, embed and score rank them, and summarise writes the summaries. Change the cadence below.</p>
|
||||
|
||||
<h3>What is running</h3>
|
||||
{# The heading and the idle line are the app's: the element takes up no
|
||||
space while the queue is idle — that is its `idle="hide"` default, and a
|
||||
strip that is always there is furniture — and a heading with nothing
|
||||
under it reads as something that failed to load. The element and its
|
||||
script are the queue's own, served by its own router — see
|
||||
pipeline/web/static/jobs.js. #}
|
||||
<p class="muted small" id="idle">Nothing at the moment.</p>
|
||||
<script type="module" src="/_jobs/jobs.js"></script>
|
||||
<desk-jobs></desk-jobs>
|
||||
|
||||
{# The element and its script are the scheduler's own, served by its own
|
||||
router — see pipeline/web/static/schedules.js. A cadence is typed as
|
||||
`every 15m`, `every 6h`, `daily at 06:00` or `weekly mon 07:00`; its add
|
||||
row's placeholder shows two. #}
|
||||
<h3>Schedule</h3>
|
||||
<script type="module" src="/_jobs/schedules.js"></script>
|
||||
<desk-schedules></desk-schedules>
|
||||
|
||||
<details class="stage">
|
||||
<summary>Run one stage</summary>
|
||||
<div id="kinds" class="buttons">
|
||||
<span class="muted">loading…</span>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<div class="row-between" id="messages">
|
||||
<h3>Messages</h3>
|
||||
<button type="button" id="clear-all" class="secondary">Clear all</button>
|
||||
</div>
|
||||
<p class="lede">What the server said that nobody has cleared, newest first. A message goes when you clear it, or a fortnight after it was last said.</p>
|
||||
<div id="notices"><span class="muted">loading…</span></div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ asset('sources.js') }}"></script>
|
||||
<script src="{{ asset('companies.js') }}"></script>
|
||||
<script src="{{ asset('jobs.js') }}"></script>
|
||||
<script src="{{ asset('messages.js') }}"></script>
|
||||
{% endblock %}
|
||||
+68
-24
@@ -28,16 +28,42 @@ from pipeline.web import QueueDep
|
||||
router = APIRouter(prefix="/api", tags=["roledesk"])
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ agent
|
||||
|
||||
def _agent_id(store: Store, agent: int | None) -> int | None:
|
||||
"""The agent a request means: the one named (404 when unknown), else the
|
||||
default (`Store.default_agent`), else None when there is no agent at all."""
|
||||
if agent is not None:
|
||||
if store.agent(agent) is None:
|
||||
raise HTTPException(404, f"no such agent: {agent}")
|
||||
return agent
|
||||
found = store.default_agent()
|
||||
return found.id if found else None
|
||||
|
||||
|
||||
def _agent_or_default(store: Store, agent: int | None) -> Agent:
|
||||
"""`_agent_id` for a write, which has to land somewhere: 422 when no
|
||||
agent exists yet."""
|
||||
agent_id = _agent_id(store, agent)
|
||||
found = store.agent(agent_id) if agent_id is not None else None
|
||||
if found is None:
|
||||
raise HTTPException(422, "No search agent exists yet. Add one under Settings.")
|
||||
return found
|
||||
|
||||
|
||||
# ------------------------------------------------------------------- roles
|
||||
|
||||
class VoteBody(BaseModel):
|
||||
value: Literal[-1, 0, 1]
|
||||
#: Whose vote; the default agent when absent.
|
||||
agent: int | None = None
|
||||
|
||||
|
||||
@router.get("/roles/{uid}")
|
||||
def get_role(uid: str, store: StoreDep) -> Role:
|
||||
"""One role, open or closed, for the read page."""
|
||||
role = store.role(uid)
|
||||
def get_role(uid: str, store: StoreDep, agent: int | None = None) -> Role:
|
||||
"""One role, open or closed, for the read page, with `agent`'s vote (the
|
||||
default agent's when absent; None when there is no agent)."""
|
||||
role = store.role(uid, _agent_id(store, agent))
|
||||
if role is None:
|
||||
raise HTTPException(404, f"no such role: {uid}")
|
||||
return role
|
||||
@@ -45,19 +71,23 @@ def get_role(uid: str, store: StoreDep) -> Role:
|
||||
|
||||
@router.post("/roles/{uid}/vote")
|
||||
def vote_role(uid: str, body: VoteBody, store: StoreDep) -> Role:
|
||||
"""1 like, 0 neither way, -1 pass. The role stays listed either way; the
|
||||
vote moves it in a ranking, see `Store.roles`."""
|
||||
"""1 like, 0 neither way, -1 pass, for `body.agent` or the default agent.
|
||||
The role stays listed either way; the vote moves it in that agent's
|
||||
ranking, see `Store.roles`, and shapes its taste at the next `score`."""
|
||||
owner = _agent_or_default(store, body.agent)
|
||||
try:
|
||||
return store.set_vote(uid, body.value)
|
||||
return store.set_vote(owner.id, uid, body.value)
|
||||
except KeyError:
|
||||
raise HTTPException(404, f"no such role: {uid}") from None
|
||||
|
||||
|
||||
@router.delete("/roles/{uid}/vote")
|
||||
def unvote_role(uid: str, store: StoreDep) -> Role:
|
||||
"""Unjudged again: what pressing the stance a role already has does."""
|
||||
def unvote_role(uid: str, store: StoreDep, agent: int | None = None) -> Role:
|
||||
"""Unjudged again for `agent` or the default agent: what pressing the
|
||||
stance a role already has does."""
|
||||
owner = _agent_or_default(store, agent)
|
||||
try:
|
||||
return store.set_vote(uid, None)
|
||||
return store.set_vote(owner.id, uid, None)
|
||||
except KeyError:
|
||||
raise HTTPException(404, f"no such role: {uid}") from None
|
||||
|
||||
@@ -80,25 +110,31 @@ def list_roles(
|
||||
days: int | None = None,
|
||||
show_muted: bool = False,
|
||||
agent: int | None = None,
|
||||
order: Literal["score", "newest"] = "score",
|
||||
gated: bool = False,
|
||||
judged: Literal["", "liked", "unjudged", "passed"] = "",
|
||||
offset: Annotated[int, Query(ge=0)] = 0,
|
||||
limit: Annotated[int, Query(ge=1, le=1000)] = 60,
|
||||
) -> RolesPage:
|
||||
"""Open roles, newest first, `limit` of them from `offset`, with the
|
||||
total. See `Store.roles` for what each filter does.
|
||||
"""Open roles, `limit` of them from `offset`, with the total. See
|
||||
`Store.roles` for what each filter does.
|
||||
|
||||
A muted company's roles are left out unless `show_muted` is set. With
|
||||
`agent`, ordered by that agent's score moved by the role's vote, and
|
||||
carrying `score` and `gated_reason`; a gated role only with `gated=1`.
|
||||
`judged` keeps the liked, the unjudged or the passed."""
|
||||
if agent is not None and store.agent(agent) is None:
|
||||
raise HTTPException(404, f"no such agent: {agent}")
|
||||
`agent` says whose votes, hidden companies and scores are meant. Each
|
||||
role carries that agent's `vote`; a company it hid is left out unless
|
||||
`show_muted` is set; `judged` keeps the liked, the unjudged or the
|
||||
passed. With `order=score` (the default) the roles are the ones that
|
||||
agent scored, best first, carrying `score` and `gated_reason`, a gated
|
||||
one only with `gated=1`; with `order=newest` every open role, newest
|
||||
first, with no score. Without `agent` the default agent's votes and
|
||||
hidden companies apply, the order is newest and there is no score; with
|
||||
no agent at all, every vote is None and nothing is hidden."""
|
||||
agent_id = _agent_id(store, agent)
|
||||
by_score = agent is not None and order == "score"
|
||||
filters: dict[str, Any] = {
|
||||
"q": q or None, "company": company or None, "place": place or None,
|
||||
"function": function or None, "remote": remote or None, "days": days,
|
||||
"hide_muted": not show_muted, "agent": agent, "gated": gated,
|
||||
"judged": judged or None}
|
||||
"hide_muted": not show_muted, "agent": agent_id, "by_score": by_score,
|
||||
"gated": gated, "judged": judged or None}
|
||||
return RolesPage(items=store.roles(limit=limit, offset=offset, **filters),
|
||||
total=store.count_roles(**filters))
|
||||
|
||||
@@ -200,11 +236,13 @@ def _company_boards(store: Store) -> dict[str, tuple[int, str, bool]]:
|
||||
|
||||
|
||||
@router.get("/companies")
|
||||
def list_companies(store: StoreDep) -> list[CompanyOut]:
|
||||
def list_companies(store: StoreDep, agent: int | None = None) -> list[CompanyOut]:
|
||||
"""Every company, with `affinity` as `agent` (the default agent when
|
||||
absent) has it; 0 throughout when there is no agent."""
|
||||
boards = _company_boards(store)
|
||||
counts = store.open_role_counts()
|
||||
out = []
|
||||
for c in store.companies():
|
||||
for c in store.companies(_agent_id(store, agent)):
|
||||
sub_id, host, on = boards.get(c.key, (None, "", None))
|
||||
out.append(CompanyOut(key=c.key, name=c.name, board=host,
|
||||
subscription_id=sub_id, on=on, affinity=c.affinity,
|
||||
@@ -214,16 +252,21 @@ def list_companies(store: StoreDep) -> list[CompanyOut]:
|
||||
|
||||
class AffinityBody(BaseModel):
|
||||
affinity: int
|
||||
#: Whose affinity; the default agent when absent.
|
||||
agent: int | None = None
|
||||
|
||||
|
||||
@router.post("/companies/{key}/affinity")
|
||||
def set_affinity(key: str, body: AffinityBody, store: StoreDep, queue: QueueDep) -> Company:
|
||||
"""A change here is not seen in Best match until `score` has run: the
|
||||
queue dedupes to a live job of that kind, so several clicks are one run."""
|
||||
"""-1 hidden, 0 neutral, 1 liked, 2 favourite, for `body.agent` or the
|
||||
default agent. A change here is not seen in Best match until `score` has
|
||||
run: the queue dedupes to a live job of that kind, so several clicks are
|
||||
one run."""
|
||||
if body.affinity not in AFFINITY:
|
||||
raise HTTPException(422, "affinity is -1, 0, 1 or 2")
|
||||
owner = _agent_or_default(store, body.agent)
|
||||
try:
|
||||
company = store.update_company(key, affinity=body.affinity)
|
||||
company = store.set_affinity(owner.id, key, body.affinity)
|
||||
except KeyError:
|
||||
raise HTTPException(404, f"no such company: {key}") from None
|
||||
queue.enqueue("score")
|
||||
@@ -482,6 +525,7 @@ def save_agent(body: AgentBody, store: StoreDep) -> Agent:
|
||||
|
||||
@router.delete("/agents/{agent_id}", status_code=204)
|
||||
def delete_agent(agent_id: int, store: StoreDep) -> Response:
|
||||
"""Its scores, votes and affinities go with it."""
|
||||
if not store.delete_agent(agent_id):
|
||||
raise HTTPException(404, f"no such agent: {agent_id}")
|
||||
return Response(status_code=204)
|
||||
+46
-47
@@ -1,26 +1,32 @@
|
||||
"""The pages: two tabs, a cog, and six settings pages behind it.
|
||||
"""The pages: two tabs, a cog, and three settings pages behind it.
|
||||
|
||||
`TABS` is the top bar, Roles and Applications, and `SETTINGS` is the row of
|
||||
sub-tabs under the cog at `/settings/<name>`: the setup pages first (Ranking,
|
||||
Searches, Companies), the system ones after (Pulls, Messages, Account).
|
||||
sub-tabs under the cog at `/settings/<name>`: Search agents, Sources, Account.
|
||||
`base.html` renders the first, `settings/_tabs.html` the second, every page
|
||||
marks itself active by its own `path`, and adding one is one entry here plus
|
||||
one template. `/settings` itself is Ranking.
|
||||
one template. `/settings` itself is Search agents.
|
||||
|
||||
Every page is a shell. Each is filled and driven by its own script under
|
||||
`static/` from the JSON routes in `web/api.py`; Pulls and Account are shells
|
||||
around the modules' own elements. What the server renders is only what a
|
||||
select needs to offer, so the options cannot drift from what the store
|
||||
accepts.
|
||||
`static/` from the JSON routes in `web/api.py`; the Runs section of Sources
|
||||
and the Account page are shells around the modules' own elements. What the
|
||||
server renders is only what a select needs to offer, so the options cannot
|
||||
drift from what the store accepts.
|
||||
|
||||
The pages that were tabs before the settings shell (`/agents`, `/companies`,
|
||||
`/sources`, `/jobs`, `/schedules`, `/messages`, `/account`) answer 301 to
|
||||
their new place, query string kept, so a bookmark still lands.
|
||||
Sources is one page in three sections, one per plugin: job boards (the
|
||||
`search` plugin's queries), company boards (`ats`) and the runs that read
|
||||
them, with the message log at the end. Its scripts are the ones the sections
|
||||
had as pages of their own, each guarding on its own root element.
|
||||
|
||||
Every path a page has had before (`/agents`, `/companies`, `/sources`,
|
||||
`/jobs`, `/schedules`, `/messages`, `/account`, and the six sub-tabs the
|
||||
settings shell started with) answers 301 to its place now, query string
|
||||
kept, so a bookmark still lands. A merged page's old path lands on its
|
||||
section's anchor.
|
||||
|
||||
`FUNCTIONS` is `plugins.ats`'s, not `app`'s: the nine job functions are the
|
||||
classifier's vocabulary, and this reaches `plugins/` the same way `app.cli`
|
||||
does, since a plugin is app-agnostic and never reaches back into `app`. The
|
||||
Jobindex areas and Adzuna countries on the Searches page come from
|
||||
Jobindex areas and Adzuna countries on the Sources page come from
|
||||
`plugins.search` for the same reason.
|
||||
"""
|
||||
|
||||
@@ -64,22 +70,25 @@ TABS: tuple[Tab, ...] = (
|
||||
|
||||
#: The sub-tabs under the cog, in order; `settings/_tabs.html` renders them.
|
||||
SETTINGS: tuple[Tab, ...] = (
|
||||
Tab("/settings/ranking", "Ranking", "settings/ranking.html"),
|
||||
Tab("/settings/searches", "Searches", "settings/searches.html"),
|
||||
Tab("/settings/companies", "Companies", "settings/companies.html"),
|
||||
Tab("/settings/pulls", "Pulls", "settings/pulls.html"),
|
||||
Tab("/settings/messages", "Messages", "settings/messages.html"),
|
||||
Tab("/settings/agents", "Search agents", "settings/agents.html"),
|
||||
Tab("/settings/sources", "Sources", "settings/sources.html"),
|
||||
Tab("/settings/account", "Account", "settings/account.html"),
|
||||
)
|
||||
|
||||
#: Where each page that used to be a tab lives now.
|
||||
#: Where each page that used to be a tab or a sub-tab lives now. The fragment
|
||||
#: is the section on the merged page; a browser keeps it across the 301.
|
||||
MOVED: dict[str, str] = {
|
||||
"/agents": "/settings/ranking",
|
||||
"/companies": "/settings/companies",
|
||||
"/sources": "/settings/searches",
|
||||
"/jobs": "/settings/pulls",
|
||||
"/schedules": "/settings/pulls",
|
||||
"/messages": "/settings/messages",
|
||||
"/agents": "/settings/agents",
|
||||
"/settings/ranking": "/settings/agents",
|
||||
"/companies": "/settings/sources#company-boards",
|
||||
"/settings/companies": "/settings/sources#company-boards",
|
||||
"/sources": "/settings/sources#job-boards",
|
||||
"/settings/searches": "/settings/sources#job-boards",
|
||||
"/jobs": "/settings/sources#runs",
|
||||
"/schedules": "/settings/sources#runs",
|
||||
"/settings/pulls": "/settings/sources#runs",
|
||||
"/messages": "/settings/sources#messages",
|
||||
"/settings/messages": "/settings/sources#messages",
|
||||
"/account": "/settings/account",
|
||||
}
|
||||
|
||||
@@ -142,42 +151,32 @@ def settings() -> RedirectResponse:
|
||||
return RedirectResponse(SETTINGS[0].path, status_code=302)
|
||||
|
||||
|
||||
@router.get("/settings/ranking", response_class=HTMLResponse)
|
||||
def ranking(request: Request) -> HTMLResponse:
|
||||
return page(request, "settings/ranking.html")
|
||||
@router.get("/settings/agents", response_class=HTMLResponse)
|
||||
def agents(request: Request) -> HTMLResponse:
|
||||
return page(request, "settings/agents.html")
|
||||
|
||||
|
||||
@router.get("/settings/searches", response_class=HTMLResponse)
|
||||
def searches(request: Request) -> HTMLResponse:
|
||||
return page(request, "settings/searches.html", areas=AREA_OPTIONS,
|
||||
@router.get("/settings/sources", response_class=HTMLResponse)
|
||||
def sources(request: Request) -> HTMLResponse:
|
||||
return page(request, "settings/sources.html", areas=AREA_OPTIONS,
|
||||
countries=COUNTRY_OPTIONS)
|
||||
|
||||
|
||||
@router.get("/settings/companies", response_class=HTMLResponse)
|
||||
def companies(request: Request) -> HTMLResponse:
|
||||
return page(request, "settings/companies.html")
|
||||
|
||||
|
||||
@router.get("/settings/pulls", response_class=HTMLResponse)
|
||||
def pulls(request: Request) -> HTMLResponse:
|
||||
return page(request, "settings/pulls.html")
|
||||
|
||||
|
||||
@router.get("/settings/messages", response_class=HTMLResponse)
|
||||
def messages(request: Request) -> HTMLResponse:
|
||||
return page(request, "settings/messages.html")
|
||||
|
||||
|
||||
@router.get("/settings/account", response_class=HTMLResponse)
|
||||
def account(request: Request) -> HTMLResponse:
|
||||
return page(request, "settings/account.html")
|
||||
|
||||
|
||||
def _moved(to: str) -> Callable[[Request], RedirectResponse]:
|
||||
"""A 301 to `to`, carrying the query string, so `/agents?x=1` keeps it."""
|
||||
"""A 301 to `to`, carrying the query string, so `/agents?x=1` keeps it.
|
||||
The query goes before `to`'s fragment, if it has one, or the browser
|
||||
would read `#runs?x=1` as one fragment."""
|
||||
path, _, fragment = to.partition("#")
|
||||
def redirect(request: Request) -> RedirectResponse:
|
||||
query = request.url.query
|
||||
return RedirectResponse(f"{to}?{query}" if query else to, status_code=301)
|
||||
target = f"{path}?{query}" if query else path
|
||||
return RedirectResponse(f"{target}#{fragment}" if fragment else target,
|
||||
status_code=301)
|
||||
return redirect
|
||||
|
||||
|
||||
|
||||
+6
-6
@@ -81,12 +81,12 @@ sources: {}
|
||||
# Starter search agents, imported once into an empty `agents` table. Each gate
|
||||
# is {field, values, mode: require|prefer, weight}; fields are place, country,
|
||||
# remote, seniority, function, salary_min, currency, permit, languages and
|
||||
# company. weights default to {fit: 0.6, recency: 0.2, affinity: 0.2}. A
|
||||
# country is an ISO code, filled from the board's location line; EU is a role
|
||||
# open anywhere in Europe.
|
||||
# The UI edits the first enabled one as "the ranking"; with more than one, the
|
||||
# order menu on Roles lists them by name. Two more, beside the starter in
|
||||
# config.yaml:
|
||||
# company. weights default to {fit: 0.6, recency: 0.2, affinity: 0.2, taste:
|
||||
# 0.2}; taste is how close a role is to the ones the agent liked minus the
|
||||
# ones it passed. A country is an ISO code, filled from the board's location
|
||||
# line; EU is a role open anywhere in Europe.
|
||||
# The Search agents sub-tab lists and edits them; the order menu on Roles
|
||||
# picks one by name. Two more, beside the starter in config.yaml:
|
||||
agents: []
|
||||
# - name: Remote from Europe
|
||||
# intent: >-
|
||||
|
||||
+10
-6
@@ -60,7 +60,7 @@ What was decided for roledesk and the one reason for each. The longer reasoning
|
||||
|
||||
**Workable's shape is confirmed, not a populated example.** Every slug tried during the build returned the documented empty `{"total": 0, "results": []}` before Cloudflare rate-limited the session, so the parser follows Workable's published job object. Recheck it against a live board with open roles the next time the plugin is touched.
|
||||
|
||||
**`pull` is a job that starts the cascade, on a default schedule of every 6h.** A schedule enqueues a job kind and a cascade is started by one, so the `pull` job only asks for the chain; declared beside it in `app/jobs/cascade.py`, the schedule is a starting point that an edit on the Schedules tab overrides for good. `pull` is not also a task, which would draw two buttons on the Jobs tab.
|
||||
**`pull` is a job that starts the cascade, on a default schedule of every 6h.** A schedule enqueues a job kind and a cascade is started by one, so the `pull` job only asks for the chain; declared beside it in `app/jobs/cascade.py`, the schedule is a starting point that an edit under Runs overrides for good. `pull` is not also a task, which would draw two buttons under Runs.
|
||||
|
||||
## Ranking
|
||||
|
||||
@@ -98,7 +98,15 @@ What was decided for roledesk and the one reason for each. The longer reasoning
|
||||
|
||||
**Two tabs and a cog.** `TABS` in `app/web/pages.py` becomes Roles and Applications; the other six pages (Agents, Companies, Sources, Jobs, Schedules, Messages, Account) move behind a settings cog at `/settings/<name>`, because nine tabs wrapped to three rows on a phone and six of them were setup or system pages. The old paths answer 301 to their new place, query string kept, so a bookmark or a `?agent=` link still lands.
|
||||
|
||||
**One ranking in the UI, while the `agents` table keeps every row.** The owner read "search agent" as something that searches a board, which is what a saved search does, so `/settings/ranking` edits only the first enabled agent and creates one when the table is empty. Code, API, CLI and config keep `agent`, and nothing is migrated.
|
||||
**Settings are three sub-tabs: Search agents, Sources, Account.** Six sub-tabs were three setup pages and three system pages for two things, what the app ranks by and where roles come from, so each is one page now and Account stays its own. The old paths answer 301 to the section they became.
|
||||
|
||||
**Sources is one page, one section per plugin.** Job boards are the `search` plugin's queries, company boards are `ats`'s, and the runs that read both end the page with the message log. A source's section says which plugin it is, and following a company, hiding it and switching its board off are one list. The UI says "job board" for what the API and CLI call a search, since "search agent" already means something else.
|
||||
|
||||
**Search agents are back in the UI as a list.** One person may run several: their own hunt, and one that monitors roles for someone else, each with its own intent and gates. The list has New and Delete; a delete takes the agent's votes, liked companies and scores with it.
|
||||
|
||||
**Affinity and votes are per agent.** A company hidden for one hunt may be a favourite for another, and a vote says what one agent should learn from, so both carry the agent id, and the Roles tab and the company list ask for one agent's. Without an agent id the API uses the default agent, the enabled one with the lowest id, so the CLI and older callers keep working.
|
||||
|
||||
**`taste` is the liked-minus-passed centroid, as in newsdesk.** An agent's votes become one vector, the mean of the liked roles' embeddings minus the mean of the passed ones', and a role's taste term is its cosine to that vector, weighted beside fit, recency and affinity. It is the one term an agent learns rather than is told, and it costs no model call.
|
||||
|
||||
**Roles are a feed with a read page, not links out.** `GET /roles/{uid}` renders the posting inside the app instead of sending the reader to the board, because 29,194 of 29,196 open board roles already have a `description` averaging 6,300 characters, and a search role's short teaser is worth reading in place before deciding whether to fetch the rest.
|
||||
|
||||
@@ -106,16 +114,12 @@ What was decided for roledesk and the one reason for each. The longer reasoning
|
||||
|
||||
**"Hidden" is the word the UI uses for affinity -1; the code keeps `mute` and `hide_muted`.** Renaming the columns would touch every reader of `agents` and `companies` for no behavioural gain, so only the toggle's title, the filter label and the dimmed row say "hidden" in the UI.
|
||||
|
||||
**Companies, following a board and pruning boards by region merge into one settings page.** A company's affinity used to live on Companies while following its board and pruning boards by region lived on Sources, so acting on one company took two tabs; now Companies is one list with the follow form on top and the prune behind a details below it.
|
||||
|
||||
**A company affinity change enqueues `score`.** `POST /api/companies/{key}/affinity` queues the `score` job right after the update, deduped to a live run of the same kind so ten clicks are one pass. Otherwise an affinity change is invisible in Best match until the next 6-hourly pull, and an unmuted company's roles have no score rows at all until then, so they are missing from that order entirely.
|
||||
|
||||
**A search role's posting text is fetched on demand, not in the pull.** `POST /api/roles/{uid}/text` scrapes `original_url` only when the read page asks for it, because following Jobindex's redirect for every role during a pull would count as a click in Jobindex's own statistics; one click for a posting somebody actually opened is fair.
|
||||
|
||||
**Summarising is bounded to the top `per_agent` roles of each agent, and off by default.** The pull's `summarise` stage only considers roles with no summary yet that are in the top `summarise.per_agent` (default 30) of an enabled agent's scores, so the cost stays flat whatever the backlog of open roles is. `summarise.enabled: false` matches `extract`'s own default; the read page's Summarise button asks for one role's summary either way.
|
||||
|
||||
**Jobs and Schedules merge into one Pulls sub-tab.** Both named the same thing from two angles, what is running now and when it runs next, so splitting them was two tabs for one job kind.
|
||||
|
||||
**The schedules element's narrow layout is fixed upstream, in `../boilerplate`.** `<desk-schedules>` is a shadow root the app cannot lay out from outside, and `pipeline/` is a downstream copy refreshed with `git archive`, so a fix landing only in roledesk would be reverted by the next refresh.
|
||||
|
||||
**The phone CSS is copied from health and news, not written from scratch.** Both apps have already been through several rounds of phone fixes, and the comments in their `app.css` say what each rule avoids, so adapting their fragments keeps those fixes rather than rediscovering the same edge cases, such as iOS zooming on a 16px input or a card losing width to a side gutter.
|
||||
|
||||
+86
-3
@@ -179,9 +179,10 @@ def test_a_prefer_gate_adds_its_weight_to_the_score(
|
||||
|
||||
def test_a_favourite_skips_the_gates_and_is_floored(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
store.add_company("Fave", affinity=2)
|
||||
store.add_company("Fave")
|
||||
fave = role(store, "1", company="Fave", place="Munich")
|
||||
agent = store.save_agent("Berlin", "", [Gate(field="place", values=["Berlin"])])
|
||||
store.set_affinity(agent.id, "fave", 2)
|
||||
|
||||
run(config, store, score.run_score)
|
||||
|
||||
@@ -189,17 +190,21 @@ def test_a_favourite_skips_the_gates_and_is_floored(
|
||||
assert reason == "" and value >= 0.9
|
||||
|
||||
|
||||
def test_a_muted_company_is_never_scored(
|
||||
def test_a_hidden_company_is_never_scored_for_the_agent_that_hid_it(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
store.add_company("Muted", affinity=-1)
|
||||
store.add_company("Muted")
|
||||
muted = role(store, "1", company="Muted")
|
||||
kept = role(store, "2")
|
||||
agent = store.save_agent("Any")
|
||||
other = store.save_agent("Other")
|
||||
store.set_affinity(agent.id, "muted", -1)
|
||||
|
||||
run(config, store, score.run_score)
|
||||
|
||||
assert set(store.scores(agent.id)) == {kept}
|
||||
assert muted not in {r.uid for r in store.roles(agent=agent.id, gated=True)}
|
||||
# The other agent did not hide it, so it is scored for that one.
|
||||
assert set(store.scores(other.id)) == {muted, kept}
|
||||
|
||||
|
||||
def test_an_older_role_scores_lower(
|
||||
@@ -235,6 +240,84 @@ def test_two_agents_rank_the_same_roles_the_other_way_round(
|
||||
assert store.scores(frontend.id)[back][0] == 0.0
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ taste
|
||||
|
||||
def _unit(*words: str) -> np.ndarray:
|
||||
return FakeEmbedder().encode([" ".join(words)])[0]
|
||||
|
||||
|
||||
def test_taste_direction_is_liked_minus_passed_and_none_without_votes() -> None:
|
||||
vectors = {"a": _unit("backend"), "b": _unit("frontend"), "c": _unit("data")}
|
||||
|
||||
assert score.taste_direction(vectors, {}) is None
|
||||
assert score.taste_direction(vectors, {"a": 0}) is None # neutral says nothing
|
||||
assert score.taste_direction(vectors, {"gone": 1}) is None # no vector to point at
|
||||
|
||||
liked_only = score.taste_direction(vectors, {"a": 1, "c": 1})
|
||||
assert liked_only is not None
|
||||
assert liked_only == pytest.approx((vectors["a"] + vectors["c"]) / 2)
|
||||
|
||||
passed_only = score.taste_direction(vectors, {"b": -1})
|
||||
assert passed_only is not None
|
||||
assert passed_only == pytest.approx(-vectors["b"])
|
||||
|
||||
both = score.taste_direction(vectors, {"a": 1, "b": -1, "c": 0})
|
||||
assert both is not None
|
||||
assert both == pytest.approx(vectors["a"] - vectors["b"])
|
||||
|
||||
|
||||
def test_taste_ranks_a_role_near_the_liked_one_above_one_near_the_passed(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
liked = role(store, "1", "Backend Engineer", body="Python backend")
|
||||
passed = role(store, "2", "Frontend Engineer", body="React frontend")
|
||||
near_liked = role(store, "3", "Platform Engineer", body="Python backend services")
|
||||
near_passed = role(store, "4", "Web Engineer", body="React frontend apps")
|
||||
# No intent: with taste alone weighted, the votes are all that orders them.
|
||||
agent = store.save_agent("Taste", "", weights=Weights(fit=0, recency=0, affinity=0,
|
||||
taste=1))
|
||||
store.set_vote(agent.id, liked, 1)
|
||||
store.set_vote(agent.id, passed, -1)
|
||||
|
||||
run(config, store, embed.run_embed)
|
||||
run(config, store, score.run_score)
|
||||
|
||||
scores = store.scores(agent.id)
|
||||
assert scores[near_liked][0] > scores[near_passed][0]
|
||||
assert scores[liked][0] == 1.0 and scores[passed][0] == 0.0
|
||||
assert all(reason == "" for _, reason in scores.values())
|
||||
|
||||
|
||||
def test_without_votes_taste_leaves_the_denominator(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
uid = role(store, "1")
|
||||
agent = store.save_agent("Any", weights=Weights(fit=0, recency=0, affinity=0, taste=1))
|
||||
|
||||
run(config, store, embed.run_embed)
|
||||
run(config, store, score.run_score)
|
||||
|
||||
# Taste is the only weighted term and there is no taste, so no weights.
|
||||
assert store.scores(agent.id)[uid] == (0.0, "no weights")
|
||||
|
||||
|
||||
def test_a_closed_liked_role_still_shapes_the_taste(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
liked = role(store, "1", "Backend Engineer", body="Python backend")
|
||||
near = role(store, "2", "Platform Engineer", body="Python backend")
|
||||
far = role(store, "3", "Web Engineer", body="React frontend")
|
||||
agent = store.save_agent("Taste", "", weights=Weights(fit=0, recency=0, affinity=0,
|
||||
taste=1))
|
||||
run(config, store, embed.run_embed)
|
||||
store.set_vote(agent.id, liked, 1)
|
||||
with store.transaction() as conn:
|
||||
conn.execute("UPDATE roles SET closed_at = ? WHERE uid = ?", (NOW.isoformat(), liked))
|
||||
|
||||
run(config, store, score.run_score)
|
||||
|
||||
scores = store.scores(agent.id)
|
||||
assert liked not in scores
|
||||
assert scores[near][0] == 1.0 and scores[far][0] == 0.0
|
||||
|
||||
|
||||
# ------------------------------------------------------------ fit scaling
|
||||
|
||||
def test_scale_maps_the_closest_to_one_and_the_farthest_to_zero() -> None:
|
||||
|
||||
+244
-39
@@ -85,20 +85,103 @@ def test_a_v1_file_migrates_to_the_shape_a_new_file_has(tmp_path: Path) -> None:
|
||||
Store(fresh)
|
||||
Store(old)
|
||||
with sqlite3.connect(old) as conn:
|
||||
for column in ("permit", "languages", "extract_tries", "vote", "voted_at",
|
||||
"summary", "summarised_at", "article_text", "article_at"):
|
||||
# v1 had no v2-v4 columns; the v4 vote columns that v5 drops again are
|
||||
# not in a fresh file, so there is nothing to drop for them.
|
||||
for column in ("permit", "languages", "extract_tries", "summary", "summarised_at",
|
||||
"article_text", "article_at"):
|
||||
conn.execute(f"ALTER TABLE roles DROP COLUMN {column}")
|
||||
for column in ("intent_key", "intent_vec"):
|
||||
conn.execute(f"ALTER TABLE agents DROP COLUMN {column}")
|
||||
conn.execute("DROP TABLE vectors")
|
||||
conn.execute("ALTER TABLE companies ADD COLUMN affinity INTEGER NOT NULL DEFAULT 0")
|
||||
for table in ("vectors", "agent_companies", "role_votes"):
|
||||
conn.execute(f"DROP TABLE {table}")
|
||||
conn.execute("PRAGMA user_version = 1")
|
||||
|
||||
assert Store(old).migrations_applied == list(range(2, LATEST + 1))
|
||||
# ALTER appends, so the order differs; every read is by column name.
|
||||
for table in ("roles", "agents", "vectors"):
|
||||
for table in ("roles", "agents", "vectors", "companies", "agent_companies", "role_votes"):
|
||||
assert sorted(_columns(old, table)) == sorted(_columns(fresh, table))
|
||||
|
||||
|
||||
def _downgrade_to_v4(path: Path) -> None:
|
||||
"""A fresh file put back to the v4 shape: votes on the role, affinity on
|
||||
the company, no per-agent tables."""
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("ALTER TABLE roles ADD COLUMN vote INTEGER CHECK (vote IN (-1, 0, 1))")
|
||||
conn.execute("ALTER TABLE roles ADD COLUMN voted_at TEXT")
|
||||
conn.execute("ALTER TABLE companies ADD COLUMN affinity INTEGER NOT NULL DEFAULT 0")
|
||||
conn.execute("DROP TABLE agent_companies")
|
||||
conn.execute("DROP TABLE role_votes")
|
||||
conn.execute("PRAGMA user_version = 4")
|
||||
|
||||
|
||||
def test_v5_moves_the_votes_and_affinities_to_the_default_agent(tmp_path: Path) -> None:
|
||||
path = tmp_path / "v4.db"
|
||||
store = Store(path)
|
||||
store.upsert_role(posting("liked"))
|
||||
store.upsert_role(posting("passed"))
|
||||
store.upsert_role(posting("none"))
|
||||
store.add_company("Acme", key="acme")
|
||||
store.add_company("Other", key="other")
|
||||
# The disabled agent has the lower id; the enabled one is the default.
|
||||
second = store.save_agent("Second", enabled=False)
|
||||
first = store.save_agent("First")
|
||||
assert first.id > second.id and store.default_agent().id == first.id
|
||||
_downgrade_to_v4(path)
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("UPDATE roles SET vote = 1, voted_at = 'then' WHERE uid = ?",
|
||||
(posting("liked").uid,))
|
||||
conn.execute("UPDATE roles SET vote = -1 WHERE uid = ?", (posting("passed").uid,))
|
||||
conn.execute("UPDATE companies SET affinity = -1 WHERE key = 'acme'")
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [5]
|
||||
assert [a.name for a in migrated.agents()] == ["First", "Second"] # none added
|
||||
assert migrated.votes(first.id) == {posting("liked").uid: 1, posting("passed").uid: -1}
|
||||
assert migrated.votes(second.id) == {}
|
||||
liked = migrated.role(posting("liked").uid, first.id)
|
||||
assert liked is not None and liked.voted_at == "then"
|
||||
passed = migrated.role(posting("passed").uid, first.id)
|
||||
assert passed is not None and passed.voted_at # stamped when v4 had none
|
||||
assert [c.affinity for c in migrated.companies(first.id)] == [-1, 0]
|
||||
assert [c.affinity for c in migrated.companies(second.id)] == [0, 0]
|
||||
with sqlite3.connect(path) as conn:
|
||||
columns = {r[1] for r in conn.execute("PRAGMA table_info(roles)")}
|
||||
assert not {"vote", "voted_at"} & columns
|
||||
assert "affinity" not in {r[1] for r in conn.execute("PRAGMA table_info(companies)")}
|
||||
|
||||
|
||||
def test_v5_makes_an_agent_when_there_is_something_to_move_and_none_to_take_it(
|
||||
tmp_path: Path) -> None:
|
||||
path = tmp_path / "v4.db"
|
||||
store = Store(path)
|
||||
store.upsert_role(posting("liked"))
|
||||
store.add_company("Acme", key="acme")
|
||||
_downgrade_to_v4(path)
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("UPDATE companies SET affinity = 2 WHERE key = 'acme'")
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
[agent] = migrated.agents()
|
||||
assert (agent.name, agent.enabled, agent.gates) == ("My ranking", True, [])
|
||||
assert agent.created_at.endswith("+00:00")
|
||||
assert migrated.default_agent() == agent
|
||||
assert migrated.company("acme", agent.id).affinity == 2 # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_v5_makes_no_agent_when_there_is_nothing_to_move(tmp_path: Path) -> None:
|
||||
path = tmp_path / "v4.db"
|
||||
store = Store(path)
|
||||
store.upsert_role(posting("plain"))
|
||||
store.add_company("Acme", key="acme")
|
||||
_downgrade_to_v4(path)
|
||||
|
||||
assert Store(path).migrations_applied == [5]
|
||||
assert Store(path).agents() == []
|
||||
|
||||
|
||||
def test_state_is_a_mapping(store: Store) -> None:
|
||||
store.state["ats:last"] = "2026-09-23"
|
||||
assert store.state["ats:last"] == "2026-09-23"
|
||||
@@ -190,7 +273,9 @@ def test_roles_filters_q_function_remote_and_days(store: Store, clock: Clock) ->
|
||||
|
||||
|
||||
def test_roles_hide_muted_excludes_before_the_limit(store: Store, clock: Clock) -> None:
|
||||
store.add_company("Acme", key="acme", affinity=-1)
|
||||
agent = store.save_agent("A")
|
||||
store.add_company("Acme", key="acme")
|
||||
store.set_affinity(agent.id, "acme", -1)
|
||||
store.upsert_role(posting("other", company="Other"))
|
||||
clock.tick()
|
||||
for i in range(3):
|
||||
@@ -199,10 +284,15 @@ def test_roles_hide_muted_excludes_before_the_limit(store: Store, clock: Clock)
|
||||
# Acme's roles are the three newest, so a plain limit=1 shows only Acme;
|
||||
# hide_muted has to reach past all three to find "other" rather than
|
||||
# just dropping Acme's rows out of an already-limited page.
|
||||
assert [r.source_id for r in store.roles(limit=1)] == ["a2"]
|
||||
assert [r.source_id for r in store.roles(limit=1, hide_muted=True)] == ["other"]
|
||||
assert {r.source_id for r in store.roles(hide_muted=True)} == {"other"}
|
||||
assert {r.source_id for r in store.roles()} == {"a0", "a1", "a2", "other"}
|
||||
listing = {"agent": agent.id, "by_score": False}
|
||||
assert [r.source_id for r in store.roles(limit=1, **listing)] == ["a2"]
|
||||
assert [r.source_id for r in store.roles(limit=1, hide_muted=True, **listing)] == ["other"]
|
||||
assert {r.source_id for r in store.roles(hide_muted=True, **listing)} == {"other"}
|
||||
assert {r.source_id for r in store.roles(**listing)} == {"a0", "a1", "a2", "other"}
|
||||
# Hidden is per agent: another agent, or no agent, hides nothing.
|
||||
other = store.save_agent("B")
|
||||
assert store.count_roles(hide_muted=True, agent=other.id, by_score=False) == 4
|
||||
assert store.count_roles(hide_muted=True) == 4
|
||||
|
||||
|
||||
def test_roles_page_by_offset_and_count_the_same_filter(
|
||||
@@ -214,34 +304,94 @@ def test_roles_page_by_offset_and_count_the_same_filter(
|
||||
assert [r.source_id for r in store.roles(limit=2, offset=3)] == ["1"]
|
||||
assert store.count_roles() == 4
|
||||
assert store.count_roles(company="acme") == 3
|
||||
store.add_company("Other", key="other", affinity=-1)
|
||||
assert store.count_roles(hide_muted=True) == 3
|
||||
agent = store.save_agent("A")
|
||||
store.add_company("Other", key="other")
|
||||
store.set_affinity(agent.id, "other", -1)
|
||||
assert store.count_roles(hide_muted=True, agent=agent.id, by_score=False) == 3
|
||||
|
||||
|
||||
def test_a_vote_is_stamped_cleared_and_filtered(store: Store, clock: Clock) -> None:
|
||||
for sid in ("up", "down", "fine", "none"):
|
||||
store.upsert_role(posting(sid))
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
role = store.set_vote(uid["up"], 1)
|
||||
agent = store.save_agent("A")
|
||||
role = store.set_vote(agent.id, uid["up"], 1)
|
||||
assert (role.vote, role.voted_at) == (1, clock().isoformat(timespec="seconds"))
|
||||
store.set_vote(uid["down"], -1)
|
||||
store.set_vote(uid["fine"], 0)
|
||||
store.set_vote(agent.id, uid["down"], -1)
|
||||
store.set_vote(agent.id, uid["fine"], 0)
|
||||
assert store.votes(agent.id) == {uid["up"]: 1, uid["down"]: -1, uid["fine"]: 0}
|
||||
|
||||
assert [r.source_id for r in store.roles(judged="liked")] == ["up"]
|
||||
assert [r.source_id for r in store.roles(judged="passed")] == ["down"]
|
||||
assert [r.source_id for r in store.roles(judged="unjudged")] == ["none"]
|
||||
assert store.count_roles(judged="unjudged") == 1
|
||||
def listed(judged: str) -> list[str]:
|
||||
return [r.source_id for r in store.roles(agent=agent.id, by_score=False,
|
||||
judged=judged)]
|
||||
|
||||
assert listed("liked") == ["up"]
|
||||
assert listed("passed") == ["down"]
|
||||
assert listed("unjudged") == ["none"]
|
||||
assert store.count_roles(agent=agent.id, by_score=False, judged="unjudged") == 1
|
||||
with pytest.raises(ValueError, match="judged"):
|
||||
store.roles(judged="maybe")
|
||||
|
||||
cleared = store.set_vote(uid["up"], None)
|
||||
clock.tick()
|
||||
changed = store.set_vote(agent.id, uid["up"], -1)
|
||||
assert (changed.vote, changed.voted_at) == (-1, clock().isoformat(timespec="seconds"))
|
||||
cleared = store.set_vote(agent.id, uid["up"], None)
|
||||
assert (cleared.vote, cleared.voted_at) == (None, None)
|
||||
assert store.set_vote(agent.id, uid["up"], None).vote is None # clearing twice is fine
|
||||
with pytest.raises(ValueError):
|
||||
store.set_vote(uid["up"], 2)
|
||||
store.set_vote(agent.id, uid["up"], 2)
|
||||
with pytest.raises(ValueError):
|
||||
store.set_vote(uid["up"], True)
|
||||
store.set_vote(agent.id, uid["up"], True)
|
||||
with pytest.raises(KeyError):
|
||||
store.set_vote("nope", 1)
|
||||
store.set_vote(agent.id, "nope", 1)
|
||||
with pytest.raises(KeyError):
|
||||
store.set_vote(999, uid["up"], 1)
|
||||
|
||||
|
||||
def test_votes_are_per_agent(store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
uid = posting("1").uid
|
||||
one = store.save_agent("One")
|
||||
two = store.save_agent("Two")
|
||||
store.set_vote(one.id, uid, 1)
|
||||
|
||||
assert store.role(uid, one.id).vote == 1 # type: ignore[union-attr]
|
||||
assert store.role(uid, two.id).vote is None # type: ignore[union-attr]
|
||||
assert store.role(uid).vote is None # type: ignore[union-attr]
|
||||
assert store.votes(two.id) == {}
|
||||
assert [r.vote for r in store.roles(agent=two.id, by_score=False)] == [None]
|
||||
assert [r.vote for r in store.roles()] == [None]
|
||||
assert [r.source_id for r in store.roles(agent=two.id, by_score=False, judged="liked")] == []
|
||||
assert [r.source_id for r in store.roles(judged="liked")] == []
|
||||
assert [r.source_id for r in store.roles(judged="unjudged")] == ["1"]
|
||||
|
||||
store.set_vote(two.id, uid, -1)
|
||||
assert store.role(uid, one.id).vote == 1 # type: ignore[union-attr]
|
||||
assert store.role(uid, two.id).vote == -1 # type: ignore[union-attr]
|
||||
|
||||
# Deleting the agent takes its votes with it and leaves the other's.
|
||||
store.delete_agent(two.id)
|
||||
assert store.votes(one.id) == {uid: 1}
|
||||
with store.transaction() as conn:
|
||||
assert conn.execute("SELECT COUNT(*) FROM role_votes").fetchone()[0] == 1
|
||||
|
||||
|
||||
def test_roles_with_an_agent_but_not_by_score_are_newest_first_with_votes(
|
||||
store: Store, clock: Clock) -> None:
|
||||
for sid in ("1", "2", "3"):
|
||||
store.upsert_role(posting(sid))
|
||||
clock.tick()
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
agent = store.save_agent("A")
|
||||
store.replace_scores(agent.id, [(uid["1"], 0.9, ""), (uid["2"], 0.1, "")]) # 3 unscored
|
||||
store.set_vote(agent.id, uid["1"], 1)
|
||||
|
||||
newest = store.roles(agent=agent.id, by_score=False)
|
||||
assert [r.source_id for r in newest] == ["3", "2", "1"]
|
||||
assert [r.score for r in newest] == [None, None, None]
|
||||
assert [r.vote for r in newest] == [None, None, 1]
|
||||
assert store.count_roles(agent=agent.id, by_score=False) == 3
|
||||
assert [r.source_id for r in store.roles(agent=agent.id)] == ["1", "2"]
|
||||
|
||||
|
||||
def test_a_vote_moves_the_served_score_and_the_order(store: Store) -> None:
|
||||
@@ -249,15 +399,21 @@ def test_a_vote_moves_the_served_score_and_the_order(store: Store) -> None:
|
||||
store.upsert_role(posting(sid))
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
agent = store.save_agent("A")
|
||||
other = store.save_agent("B")
|
||||
store.replace_scores(agent.id, [(uid["a"], 0.9, ""), (uid["b"], 0.5, ""),
|
||||
(uid["c"], 0.4, "")])
|
||||
store.set_vote(uid["a"], -1) # 0.45
|
||||
store.set_vote(uid["c"], 1) # 0.48
|
||||
store.replace_scores(other.id, [(uid["a"], 0.9, ""), (uid["b"], 0.5, ""),
|
||||
(uid["c"], 0.4, "")])
|
||||
store.set_vote(agent.id, uid["a"], -1) # 0.45
|
||||
store.set_vote(agent.id, uid["c"], 1) # 0.48
|
||||
ranked = [(r.source_id, round(r.score or 0, 3)) for r in store.roles(agent=agent.id)]
|
||||
assert ranked == [("b", 0.5), ("c", 0.48), ("a", 0.45)]
|
||||
assert store.scores(agent.id)[uid["a"]][0] == 0.9 # the stored score is kept
|
||||
store.set_vote(uid["a"], 1)
|
||||
store.set_vote(agent.id, uid["a"], 1)
|
||||
assert store.roles(agent=agent.id, limit=1)[0].score == 1.0
|
||||
# The other agent's ranking is untouched by these votes.
|
||||
assert [(r.source_id, r.score) for r in store.roles(agent=other.id)] == \
|
||||
[("a", 0.9), ("b", 0.5), ("c", 0.4)]
|
||||
|
||||
|
||||
def test_mark_closed_closes_what_the_board_no_longer_lists(store: Store) -> None:
|
||||
@@ -288,10 +444,10 @@ def test_companies_crud(store: Store) -> None:
|
||||
assert acme.key == "acme" and acme.affinity == 0 and acme.status == "researching"
|
||||
with pytest.raises(ValueError, match="already exists"):
|
||||
store.add_company("Acme")
|
||||
updated = store.update_company("acme", affinity=2, status="contacted")
|
||||
assert (updated.affinity, updated.status) == (2, "contacted")
|
||||
with pytest.raises(ValueError, match="affinity"):
|
||||
store.update_company("acme", affinity=5)
|
||||
updated = store.update_company("acme", status="contacted")
|
||||
assert updated.status == "contacted"
|
||||
with pytest.raises(ValueError, match="not a company field"):
|
||||
store.update_company("acme", affinity=2)
|
||||
with pytest.raises(ValueError, match="not a company field"):
|
||||
store.update_company("acme", created_at="x")
|
||||
assert [c.key for c in store.companies()] == ["acme"]
|
||||
@@ -299,6 +455,56 @@ def test_companies_crud(store: Store) -> None:
|
||||
assert store.company("acme") is None
|
||||
|
||||
|
||||
def test_affinity_is_per_agent(store: Store) -> None:
|
||||
store.add_company("Acme", key="acme")
|
||||
store.add_company("Other", key="other")
|
||||
one = store.save_agent("One")
|
||||
two = store.save_agent("Two")
|
||||
|
||||
assert store.set_affinity(one.id, "acme", 2).affinity == 2
|
||||
assert store.company("acme", one.id).affinity == 2 # type: ignore[union-attr]
|
||||
assert store.company("acme", two.id).affinity == 0 # type: ignore[union-attr]
|
||||
assert store.company("acme").affinity == 0 # type: ignore[union-attr]
|
||||
assert [(c.key, c.affinity) for c in store.companies(one.id)] == [("acme", 2), ("other", 0)]
|
||||
assert [c.affinity for c in store.companies(two.id)] == [0, 0]
|
||||
assert [c.affinity for c in store.companies()] == [0, 0]
|
||||
|
||||
store.set_affinity(two.id, "acme", -1)
|
||||
assert store.company("acme", one.id).affinity == 2 # type: ignore[union-attr]
|
||||
assert store.company("acme", two.id).affinity == -1 # type: ignore[union-attr]
|
||||
|
||||
# 0 deletes the row rather than keeping a neutral one.
|
||||
assert store.set_affinity(one.id, "acme", 0).affinity == 0
|
||||
with store.transaction() as conn:
|
||||
rows = conn.execute("SELECT agent_id, company_key FROM agent_companies").fetchall()
|
||||
assert [tuple(r) for r in rows] == [(two.id, "acme")]
|
||||
|
||||
with pytest.raises(ValueError, match="affinity"):
|
||||
store.set_affinity(one.id, "acme", 5)
|
||||
with pytest.raises(ValueError, match="affinity"):
|
||||
store.set_affinity(one.id, "acme", True) # type: ignore[arg-type]
|
||||
with pytest.raises(KeyError):
|
||||
store.set_affinity(one.id, "nope", 1)
|
||||
with pytest.raises(KeyError):
|
||||
store.set_affinity(999, "acme", 1)
|
||||
|
||||
store.delete_agent(two.id)
|
||||
with store.transaction() as conn:
|
||||
assert conn.execute("SELECT COUNT(*) FROM agent_companies").fetchone()[0] == 0
|
||||
|
||||
|
||||
def test_the_default_agent_is_the_lowest_enabled_id(store: Store) -> None:
|
||||
assert store.default_agent() is None
|
||||
off = store.save_agent("Off", enabled=False)
|
||||
assert store.default_agent() == off
|
||||
on = store.save_agent("On")
|
||||
assert store.default_agent() == on
|
||||
later = store.save_agent("Later")
|
||||
assert store.default_agent() == on
|
||||
store.delete_agent(on.id)
|
||||
assert store.default_agent() == later
|
||||
|
||||
|
||||
def test_open_role_counts_and_company_boards(store: Store) -> None:
|
||||
sub = store.add_subscription("ats", "greenhouse:acme", company="Acme", board="greenhouse")
|
||||
store.add_company("Acme", key="acme")
|
||||
@@ -390,23 +596,22 @@ def test_a_summary_is_written_once(store: Store) -> None:
|
||||
|
||||
|
||||
def test_summarise_waits_on_the_top_of_each_enabled_agent(store: Store) -> None:
|
||||
"""Two agents each contribute their own top one; a closed role, a hidden
|
||||
company's role and a gated score are not in anybody's top."""
|
||||
for sid, company in (("a", "Acme"), ("b", "Acme"), ("c", "Hidden"), ("d", "Acme")):
|
||||
store.upsert_role(posting(sid, company=company))
|
||||
"""Two agents each contribute their own top one; a closed role and a
|
||||
gated score are not in anybody's top. A hidden company needs no case:
|
||||
`score` writes no rows for it under the agent that hid it."""
|
||||
for sid in "abcd":
|
||||
store.upsert_role(posting(sid))
|
||||
a, b, c, d = (posting(s).uid for s in "abcd")
|
||||
store.add_company("Hidden", key="hidden", affinity=-1)
|
||||
with store.transaction() as conn:
|
||||
conn.execute("UPDATE roles SET closed_at = ? WHERE uid = ?", (store.now(), d))
|
||||
one = store.save_agent("One")
|
||||
two = store.save_agent("Two")
|
||||
store.replace_scores(one.id, [(d, 0.99, ""), (a, 0.9, ""), (b, 0.5, "")])
|
||||
store.replace_scores(two.id, [(a, 0.95, "remote"), (c, 0.9, ""), (b, 0.8, "")])
|
||||
store.replace_scores(two.id, [(a, 0.95, "remote"), (c, 0.7, ""), (b, 0.8, "")])
|
||||
|
||||
waiting = {r.uid for r in store.summarise_waiting(10, per_agent=1)}
|
||||
|
||||
# `c` is agent two's best open ungated role but its company is hidden.
|
||||
assert waiting == {a}
|
||||
assert {r.uid for r in store.summarise_waiting(10, per_agent=2)} == {a, b}
|
||||
assert store.summarise_pending(per_agent=2) == 2
|
||||
assert waiting == {a, b}
|
||||
assert {r.uid for r in store.summarise_waiting(10, per_agent=2)} == {a, b, c}
|
||||
assert store.summarise_pending(per_agent=2) == 3
|
||||
assert [r.uid for r in store.summarise_waiting(10, 1, uids=[d])] == [d]
|
||||
+185
-50
@@ -98,13 +98,25 @@ def test_muted_roles_are_hidden_unless_show_muted(client: TestClient, store: Sto
|
||||
store.add_company("Acme", key="acme")
|
||||
store.upsert_role(posting("1", company="Acme"))
|
||||
store.upsert_role(posting("2", company="Other"))
|
||||
agent = store.save_agent("A")
|
||||
other = store.save_agent("B")
|
||||
|
||||
assert {r["source_id"] for r in client.get("/api/roles").json()["items"]} == {"1", "2"}
|
||||
def shown(**params: Any) -> set[str]:
|
||||
return {r["source_id"] for r in client.get("/api/roles", params=params).json()["items"]}
|
||||
|
||||
assert shown() == {"1", "2"}
|
||||
|
||||
# No agent in the body: the default agent's, which is also who a list
|
||||
# without `agent` hides for.
|
||||
assert client.post("/api/companies/acme/affinity", json={"affinity": -1}).status_code == 200
|
||||
assert {r["source_id"] for r in client.get("/api/roles").json()["items"]} == {"2"}
|
||||
assert {r["source_id"] for r in
|
||||
client.get("/api/roles", params={"show_muted": "true"}).json()["items"]} == {"1", "2"}
|
||||
assert shown() == {"2"}
|
||||
assert shown(show_muted="true") == {"1", "2"}
|
||||
assert shown(agent=agent.id, order="newest") == {"2"}
|
||||
# Hidden is per agent: the other agent still sees Acme.
|
||||
assert shown(agent=other.id, order="newest") == {"1", "2"}
|
||||
assert [c["affinity"] for c in client.get("/api/companies").json()] == [-1]
|
||||
assert [c["affinity"] for c in
|
||||
client.get("/api/companies", params={"agent": other.id}).json()] == [0]
|
||||
|
||||
|
||||
def test_muted_is_excluded_before_the_limit_not_after(
|
||||
@@ -115,7 +127,8 @@ def test_muted_is_excluded_before_the_limit_not_after(
|
||||
of roles, all freshly (re-)pulled at once, produces."""
|
||||
clock = Clock()
|
||||
store.clock = clock
|
||||
store.add_company("Acme", key="acme", affinity=-1)
|
||||
store.add_company("Acme", key="acme")
|
||||
store.set_affinity(store.save_agent("A").id, "acme", -1)
|
||||
store.upsert_role(posting("other", company="Other"))
|
||||
clock.tick()
|
||||
for i in range(3):
|
||||
@@ -149,32 +162,104 @@ def test_a_vote_is_set_cleared_and_filtered_on(client: TestClient, store: Store)
|
||||
for sid in ("liked", "passed", "fine", "open"):
|
||||
store.upsert_role(posting(sid))
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
agent = store.save_agent("A")
|
||||
|
||||
# No `agent` in the body: the default agent's vote.
|
||||
res = client.post(f"/api/roles/{uid['liked']}/vote", json={"value": 1})
|
||||
assert res.status_code == 200
|
||||
assert res.json()["vote"] == 1 and res.json()["voted_at"] is not None
|
||||
client.post(f"/api/roles/{uid['passed']}/vote", json={"value": -1})
|
||||
assert store.votes(agent.id) == {uid["liked"]: 1}
|
||||
client.post(f"/api/roles/{uid['passed']}/vote", json={"value": -1, "agent": agent.id})
|
||||
client.post(f"/api/roles/{uid['fine']}/vote", json={"value": 0})
|
||||
|
||||
def judged(value: str) -> set[str]:
|
||||
page = client.get("/api/roles", params={"judged": value}).json()
|
||||
def judged(value: str, **params: Any) -> set[str]:
|
||||
page = client.get("/api/roles", params={"judged": value, **params}).json()
|
||||
return {r["source_id"] for r in page["items"]}
|
||||
|
||||
assert judged("liked") == {"liked"}
|
||||
assert judged("passed") == {"passed"}
|
||||
assert judged("unjudged") == {"open"}
|
||||
assert judged("") == {"liked", "passed", "fine", "open"} # a pass is not hidden
|
||||
assert judged("liked", agent=agent.id, order="newest") == {"liked"}
|
||||
assert client.get("/api/roles", params={"judged": "maybe"}).status_code == 422
|
||||
assert client.get(f"/api/roles/{uid['liked']}").json()["vote"] == 1
|
||||
assert client.get(f"/api/roles/{uid['liked']}", params={"agent": agent.id}).json()["vote"] == 1
|
||||
|
||||
cleared = client.delete(f"/api/roles/{uid['liked']}/vote")
|
||||
assert cleared.status_code == 200
|
||||
assert cleared.json()["vote"] is None and cleared.json()["voted_at"] is None
|
||||
assert judged("unjudged") == {"open", "liked"}
|
||||
cleared = client.delete(f"/api/roles/{uid['passed']}/vote", params={"agent": agent.id})
|
||||
assert cleared.status_code == 200 and cleared.json()["vote"] is None
|
||||
|
||||
assert client.post(f"/api/roles/{uid['open']}/vote",
|
||||
json={"value": 2}).status_code == 422
|
||||
assert client.post("/api/roles/nope/vote", json={"value": 1}).status_code == 404
|
||||
assert client.delete("/api/roles/nope/vote").status_code == 404
|
||||
assert client.post(f"/api/roles/{uid['open']}/vote",
|
||||
json={"value": 1, "agent": 999}).status_code == 404
|
||||
assert client.delete(f"/api/roles/{uid['open']}/vote", params={"agent": 999}).status_code == 404
|
||||
|
||||
|
||||
def test_votes_are_per_agent_over_the_api(client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
uid = posting("1").uid
|
||||
one = store.save_agent("One")
|
||||
two = store.save_agent("Two")
|
||||
|
||||
assert client.post(f"/api/roles/{uid}/vote", json={"value": 1, "agent": one.id}).json()["vote"] == 1
|
||||
assert client.post(f"/api/roles/{uid}/vote", json={"value": -1, "agent": two.id}).json()["vote"] == -1
|
||||
assert client.get(f"/api/roles/{uid}", params={"agent": one.id}).json()["vote"] == 1
|
||||
assert client.get(f"/api/roles/{uid}", params={"agent": two.id}).json()["vote"] == -1
|
||||
assert client.get(f"/api/roles/{uid}").json()["vote"] == 1 # the default's
|
||||
assert client.get(f"/api/roles/{uid}", params={"agent": 999}).status_code == 404
|
||||
|
||||
def listed(**params: Any) -> list[int | None]:
|
||||
return [r["vote"] for r in client.get("/api/roles", params=params).json()["items"]]
|
||||
|
||||
assert listed(agent=one.id, order="newest") == [1]
|
||||
assert listed(agent=two.id, order="newest") == [-1]
|
||||
assert listed() == [1]
|
||||
|
||||
|
||||
def test_a_vote_or_an_affinity_needs_an_agent_to_belong_to(
|
||||
client: TestClient, store: Store) -> None:
|
||||
"""Nothing to vote as: a 422 with a sentence, not a vote that lands
|
||||
nowhere. Reading is fine, everything is simply unjudged and neutral."""
|
||||
store.upsert_role(posting("1"))
|
||||
store.add_company("Acme", key="acme")
|
||||
uid = posting("1").uid
|
||||
|
||||
res = client.post(f"/api/roles/{uid}/vote", json={"value": 1})
|
||||
assert res.status_code == 422 and "Settings" in res.json()["detail"]
|
||||
assert client.delete(f"/api/roles/{uid}/vote").status_code == 422
|
||||
assert client.post("/api/companies/acme/affinity", json={"affinity": 1}).status_code == 422
|
||||
assert client.get(f"/api/roles/{uid}").json()["vote"] is None
|
||||
assert client.get("/api/roles").json()["items"][0]["vote"] is None
|
||||
assert client.get("/api/companies").json()[0]["affinity"] == 0
|
||||
|
||||
|
||||
def test_roles_with_an_agent_can_be_ordered_newest_and_keep_the_votes(
|
||||
client: TestClient, store: Store) -> None:
|
||||
clock = Clock()
|
||||
store.clock = clock
|
||||
for sid in ("1", "2", "3"):
|
||||
store.upsert_role(posting(sid))
|
||||
clock.tick()
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
agent = store.save_agent("A")
|
||||
store.replace_scores(agent.id, [(uid["1"], 0.9, ""), (uid["2"], 0.1, "")]) # 3 unscored
|
||||
store.set_vote(agent.id, uid["1"], 1)
|
||||
|
||||
page = client.get("/api/roles", params={"agent": agent.id, "order": "newest"}).json()
|
||||
assert [r["source_id"] for r in page["items"]] == ["3", "2", "1"]
|
||||
assert [r["score"] for r in page["items"]] == [None, None, None]
|
||||
assert [r["vote"] for r in page["items"]] == [None, None, 1]
|
||||
assert page["total"] == 3
|
||||
scored = client.get("/api/roles", params={"agent": agent.id, "order": "score"}).json()
|
||||
assert [r["source_id"] for r in scored["items"]] == ["1", "2"]
|
||||
assert client.get("/api/roles", params={"agent": agent.id,
|
||||
"order": "best"}).status_code == 422
|
||||
|
||||
|
||||
def test_a_vote_moves_a_role_in_the_ranking_at_once(
|
||||
@@ -249,15 +334,27 @@ def test_companies_lists_board_and_open_role_count(
|
||||
def test_set_affinity_validates_updates_and_enqueues_a_score(
|
||||
client: TestClient, store: Store, queue: Any) -> None:
|
||||
store.add_company("Acme", key="acme")
|
||||
agent = store.save_agent("A")
|
||||
other = store.save_agent("B")
|
||||
|
||||
# No `agent` in the body: the default agent's affinity.
|
||||
res = client.post("/api/companies/acme/affinity", json={"affinity": 2})
|
||||
assert res.status_code == 200
|
||||
assert res.json()["affinity"] == 2
|
||||
assert store.company("acme").affinity == 2 # type: ignore[union-attr]
|
||||
assert store.company("acme", agent.id).affinity == 2 # type: ignore[union-attr]
|
||||
assert store.company("acme", other.id).affinity == 0 # type: ignore[union-attr]
|
||||
assert queue.jobs.last("score", states=("queued", "running", "done")) is not None
|
||||
|
||||
res = client.post("/api/companies/acme/affinity", json={"affinity": -1, "agent": other.id})
|
||||
assert res.status_code == 200 and res.json()["affinity"] == -1
|
||||
assert store.company("acme", agent.id).affinity == 2 # type: ignore[union-attr]
|
||||
assert [c["affinity"] for c in client.get("/api/companies", params={"agent": other.id}).json()] == [-1]
|
||||
|
||||
assert client.post("/api/companies/acme/affinity", json={"affinity": 9}).status_code == 422
|
||||
assert client.post("/api/companies/nope/affinity", json={"affinity": 1}).status_code == 404
|
||||
assert client.post("/api/companies/acme/affinity",
|
||||
json={"affinity": 1, "agent": 999}).status_code == 404
|
||||
assert client.get("/api/companies", params={"agent": 999}).status_code == 404
|
||||
|
||||
|
||||
# ----------------------------------------------------------- applications
|
||||
@@ -338,8 +435,7 @@ def test_the_applications_page_has_no_next_column(client: TestClient) -> None:
|
||||
|
||||
def test_every_page_renders_with_the_whole_nav(client: TestClient) -> None:
|
||||
assert [t.label for t in TABS] == ["Roles", "Applications"]
|
||||
assert [t.label for t in SETTINGS] == ["Ranking", "Searches", "Companies", "Pulls",
|
||||
"Messages", "Account"]
|
||||
assert [t.label for t in SETTINGS] == ["Search agents", "Sources", "Account"]
|
||||
assert all(t.path.startswith("/settings/") for t in SETTINGS)
|
||||
for tab in (*TABS, *SETTINGS):
|
||||
res = client.get(tab.path)
|
||||
@@ -352,80 +448,99 @@ def test_every_page_renders_with_the_whole_nav(client: TestClient) -> None:
|
||||
|
||||
|
||||
def test_the_cog_and_one_sub_tab_are_current_on_a_settings_page(client: TestClient) -> None:
|
||||
page = client.get("/settings/pulls").text
|
||||
page = client.get("/settings/sources").text
|
||||
assert 'class="icon active"' in page
|
||||
for tab in SETTINGS:
|
||||
assert f">{tab.label}</a>" in page
|
||||
assert page.count('aria-current="page"') == 1
|
||||
current = page.index('aria-current="page"')
|
||||
assert page.rindex('href="', 0, current) == page.index('href="/settings/pulls"')
|
||||
assert page.rindex('href="', 0, current) == page.index('href="/settings/sources"')
|
||||
assert 'class="icon active"' not in client.get("/").text
|
||||
|
||||
|
||||
def test_settings_is_ranking(client: TestClient) -> None:
|
||||
def test_settings_is_search_agents(client: TestClient) -> None:
|
||||
res = client.get("/settings", follow_redirects=False)
|
||||
assert res.status_code == 302 and res.headers["location"] == "/settings/ranking"
|
||||
assert res.status_code == 302 and res.headers["location"] == "/settings/agents"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("old", "new"), sorted(MOVED.items()))
|
||||
def test_an_old_tab_moves_permanently_and_keeps_its_query(
|
||||
client: TestClient, old: str, new: str) -> None:
|
||||
"""A merged page's old path lands on its section: the query goes before
|
||||
the anchor, or the browser would take `#runs?q=` as one fragment."""
|
||||
assert {"/agents", "/settings/ranking", "/companies", "/sources", "/jobs",
|
||||
"/schedules", "/messages", "/settings/searches", "/settings/companies",
|
||||
"/settings/pulls", "/settings/messages", "/account"} <= set(MOVED)
|
||||
path, _, anchor = new.partition("#")
|
||||
res = client.get(old, follow_redirects=False)
|
||||
assert res.status_code == 301 and res.headers["location"] == new
|
||||
res = client.get(f"{old}?agent=3&q=a+b", follow_redirects=False)
|
||||
assert res.status_code == 301 and res.headers["location"] == f"{new}?agent=3&q=a+b"
|
||||
assert res.status_code == 301
|
||||
assert res.headers["location"] == f"{path}?agent=3&q=a+b" + (f"#{anchor}" if anchor else "")
|
||||
assert client.get(old).status_code == 200
|
||||
|
||||
|
||||
def test_each_page_loads_only_its_own_script(client: TestClient) -> None:
|
||||
scripts = {"roles.js", "applications.js", "ranking.js", "companies.js", "sources.js",
|
||||
"""Sources is four sections' scripts on one page, each guarding on its own
|
||||
root element; every other page is one."""
|
||||
scripts = {"roles.js", "applications.js", "agents.js", "companies.js", "sources.js",
|
||||
"jobs.js", "messages.js"}
|
||||
for path, container, script in [
|
||||
("/", 'id="roles-list"', "roles.js"),
|
||||
("/applications", 'id="applications-list"', "applications.js"),
|
||||
("/settings/ranking", 'id="ranking-form"', "ranking.js"),
|
||||
("/settings/searches", 'id="searches-list"', "sources.js"),
|
||||
("/settings/companies", 'id="companies-list"', "companies.js"),
|
||||
("/settings/pulls", 'id="kinds"', "jobs.js"),
|
||||
("/settings/messages", 'id="notices"', "messages.js")]:
|
||||
for path, container, own in [
|
||||
("/", 'id="roles-list"', ["roles.js"]),
|
||||
("/applications", 'id="applications-list"', ["applications.js"]),
|
||||
("/settings/agents", 'id="agent-form"', ["agents.js"]),
|
||||
("/settings/sources", 'id="searches-list"',
|
||||
["sources.js", "companies.js", "jobs.js", "messages.js"])]:
|
||||
page = client.get(path).text
|
||||
assert container in page, path
|
||||
assert [s for s in scripts if f"/static/{s}" in page] == [script], path
|
||||
# toasts.js before app.js before the page's own script: `api()` needs
|
||||
assert sorted(s for s in scripts if f"/static/{s}" in page) == sorted(own), path
|
||||
# toasts.js before app.js before the page's own scripts: `api()` needs
|
||||
# `window.toast`, and every page script needs `api()` and the helpers.
|
||||
assert page.index("toasts.js") < page.index("app.js") < page.index(f"/static/{script}")
|
||||
assert client.get(f"/static/{script}").status_code == 200
|
||||
for script in own:
|
||||
assert page.index("toasts.js") < page.index("app.js") < page.index(f"/static/{script}")
|
||||
assert client.get(f"/static/{script}").status_code == 200
|
||||
assert "ROLEDESK_STATUSES" in client.get("/applications").text
|
||||
assert client.get("/static/ranking.js").status_code == 404
|
||||
|
||||
|
||||
def test_the_ranking_page_edits_one_ranking(client: TestClient) -> None:
|
||||
page = client.get("/settings/ranking").text
|
||||
def test_the_agents_page_lists_and_edits_search_agents(client: TestClient) -> None:
|
||||
page = client.get("/settings/agents").text
|
||||
assert 'id="agents-list"' in page and 'id="agents-count"' in page
|
||||
assert 'id="a-name"' in page and 'placeholder="My search"' in page
|
||||
assert 'id="a-intent"' in page and "<details" in page and 'id="a-gates"' in page
|
||||
assert 'id="a-delete"' not in page and 'id="a-new"' not in page
|
||||
assert 'id="agents-list"' not in page
|
||||
for weight in ("a-fit", "a-recency", "a-affinity", "a-taste"):
|
||||
assert f'id="{weight}"' in page
|
||||
assert 'id="a-taste" min="0" step="0.05" value="0.2"' in page
|
||||
assert 'id="a-new"' in page and 'id="a-delete"' in page
|
||||
assert "Save and score" in page
|
||||
|
||||
|
||||
def test_the_searches_page_offers_the_jobindex_areas(client: TestClient) -> None:
|
||||
page = client.get("/settings/searches").text
|
||||
assert 'id="searches-list"' in page
|
||||
assert 'value="1" selected>Region Hovedstaden' in page # from plugins.search
|
||||
# Boards and the prune tool moved to Companies; a search has no board.
|
||||
assert 'id="boards-list"' not in page and 'id="prune-form"' not in page
|
||||
assert 'id="pull-now"' not in page # moved to Pulls
|
||||
|
||||
|
||||
def test_the_companies_page_offers_the_follow_form_and_the_prune_tool(
|
||||
client: TestClient) -> None:
|
||||
page = client.get("/settings/companies").text
|
||||
assert 'id="companies-list"' in page
|
||||
def test_the_sources_page_has_a_section_per_plugin(client: TestClient) -> None:
|
||||
"""Job boards, company boards and the runs, in that order, with the
|
||||
message log at the end of the runs and a jump row to each section."""
|
||||
page = client.get("/settings/sources").text
|
||||
for anchor in ("job-boards", "company-boards", "runs"):
|
||||
assert f'href="#{anchor}"' in page and f'id="{anchor}"' in page
|
||||
assert page.index('id="job-boards"') < page.index('id="company-boards"') \
|
||||
< page.index('id="runs"') < page.index('id="messages"')
|
||||
# Job boards: the Jobindex areas and the Adzuna countries, from plugins.search.
|
||||
assert 'id="searches-list"' in page and 'id="search-form"' in page
|
||||
assert 'value="1" selected>Region Hovedstaden' in page
|
||||
assert "job board" in page.lower() and "saved search" not in page.lower()
|
||||
# Company boards: the follow form, the agent select, the list, the prune tool.
|
||||
assert 'id="companies-list"' in page and 'id="c-agent"' in page
|
||||
assert 'id="b-host"' in page and 'id="b-slug"' in page and 'id="b-name"' in page
|
||||
assert '<option value="greenhouse">' in page and '<option value="personio">' in page
|
||||
assert 'id="prune-form"' in page and "Switch off boards with no roles in a region" in page
|
||||
assert "hidden" in page.lower() and "mute" not in page.lower()
|
||||
boards = page[page.index('id="company-boards"'):page.index('id="runs"')].lower()
|
||||
assert "hidden" in boards and "mute" not in boards
|
||||
# Runs: Pull now, the queue's elements, one stage at a time, the log.
|
||||
assert 'id="pull-now"' in page and 'id="kinds"' in page
|
||||
assert 'id="notices"' in page and 'id="clear-all"' in page
|
||||
|
||||
|
||||
def test_the_modules_bring_their_own_elements(client: TestClient) -> None:
|
||||
pulls = client.get("/settings/pulls").text
|
||||
pulls = client.get("/settings/sources").text
|
||||
assert pulls.index("<desk-jobs>") < pulls.index("<desk-schedules>")
|
||||
assert "<auth-account>" in client.get("/settings/account").text
|
||||
|
||||
@@ -491,13 +606,14 @@ def test_agents_are_created_updated_listed_and_deleted(client: TestClient) -> No
|
||||
created = client.post("/api/agents", json=body)
|
||||
assert created.status_code == 200
|
||||
agent = created.json()
|
||||
assert agent["weights"] == {"fit": 0.6, "recency": 0.2, "affinity": 0.2}
|
||||
assert agent["weights"] == {"fit": 0.6, "recency": 0.2, "affinity": 0.2, "taste": 0.2}
|
||||
assert agent["gates"][0]["weight"] == 1.0
|
||||
|
||||
updated = client.post("/api/agents", json={**body, "id": agent["id"], "enabled": False,
|
||||
"weights": {"fit": 1, "recency": 0,
|
||||
"affinity": 0}})
|
||||
"affinity": 0, "taste": 0.5}})
|
||||
assert updated.json()["enabled"] is False and updated.json()["weights"]["fit"] == 1
|
||||
assert updated.json()["weights"]["taste"] == 0.5
|
||||
|
||||
assert [a["name"] for a in client.get("/api/agents").json()] == ["Berlin"]
|
||||
assert client.post("/api/agents", json=body).status_code == 409
|
||||
@@ -506,6 +622,25 @@ def test_agents_are_created_updated_listed_and_deleted(client: TestClient) -> No
|
||||
assert client.delete(f"/api/agents/{agent['id']}").status_code == 404
|
||||
|
||||
|
||||
def test_deleting_an_agent_takes_its_votes_and_affinities_with_it(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
store.add_company("Acme", key="acme")
|
||||
uid = posting("1").uid
|
||||
agent = client.post("/api/agents", json={"name": "A"}).json()
|
||||
kept = client.post("/api/agents", json={"name": "B"}).json()
|
||||
client.post(f"/api/roles/{uid}/vote", json={"value": 1, "agent": agent["id"]})
|
||||
client.post(f"/api/roles/{uid}/vote", json={"value": -1, "agent": kept["id"]})
|
||||
client.post("/api/companies/acme/affinity", json={"affinity": 2, "agent": agent["id"]})
|
||||
|
||||
assert client.delete(f"/api/agents/{agent['id']}").status_code == 204
|
||||
|
||||
with store.transaction() as conn:
|
||||
assert conn.execute("SELECT COUNT(*) FROM role_votes").fetchone()[0] == 1
|
||||
assert conn.execute("SELECT COUNT(*) FROM agent_companies").fetchone()[0] == 0
|
||||
assert client.get(f"/api/roles/{uid}", params={"agent": kept["id"]}).json()["vote"] == -1
|
||||
|
||||
|
||||
def test_a_gate_on_an_unknown_field_is_refused(client: TestClient) -> None:
|
||||
body = {"name": "Bad", "gates": [{"field": "salary", "values": [1]}]}
|
||||
assert client.post("/api/agents", json=body).status_code == 422
|
||||
|
||||
Reference in new issue
Block a user