Add a Watchlist tab for the companies the app cannot read a board of
Rate each one Yes or No apart from affinity, open its careers page with the time noted, and set a missing or wrong link in the row. Migration 15 adds companies.watch and careers_opened_at. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6f273cfdd6
commit
7dcb2c1705
11 files changed
+445
-12
No files matched your search
@@ -34,12 +34,13 @@ A Jobindex query is its own syntax: words are OR, `"a b"` is a phrase, `+word` i
|
||||
|
||||
## The tabs
|
||||
|
||||
Two tabs, and a cog for settings.
|
||||
Three tabs, and a cog for settings.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Roles** | newsdesk's feed: a filter rail (Show read, Best first or Newest first, first seen, tags, more filters), the open roles with company, place, age, tags and a summary, votes (▲ like ● neither way ▼ pass) and a Save button. A title opens the reader beside the list; on a phone it takes the screen. `j`/`k` move, `Enter` opens, `/` searches |
|
||||
| **Applications** | the saved roles and their status, each change recorded as an event |
|
||||
| **Watchlist** | the companies whose board the app cannot read, for going through their careers pages by hand: Yes or No marks whether one is worth checking (a filter shows the unrated, the yes, the no or all), the careers page opens in a new tab and notes when, and a missing or wrong link is set in the row. A company whose board is failing is listed too. Separate from the affinity a search agent has |
|
||||
|
||||
The cog opens `/settings`: a rail of pages on the left, the page beside it, sticky so Runs is one click away however long the company list gets. On a phone the rail is a strip under the header.
|
||||
|
||||
|
||||
@@ -924,6 +924,11 @@ class Company(Model):
|
||||
#: The name `ats` knows the company by, the `acme` of acme.teamtailor.com;
|
||||
#: "" where discovery found none. Kept for a host no parser reads yet.
|
||||
ats_slug: str = ""
|
||||
#: The Watchlist's rating, global and not an agent's: None not yet rated,
|
||||
#: 1 worth checking by hand, 0 not.
|
||||
watch: int | None = None
|
||||
#: When the careers page was last opened from the Watchlist; "" never.
|
||||
careers_opened_at: str = ""
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
/* The Watchlist tab: the companies the app cannot read a board of, for
|
||||
* going through their careers pages by hand.
|
||||
*
|
||||
* The list is app.js's shared company list (`/api/companies`), narrowed to
|
||||
* the rule the "Not readable yet" filter of Company boards uses (no board
|
||||
* subscription, not from a search), plus every company whose board is
|
||||
* failing. The rating (`watch`: null unrated, 1 yes, 0 no) is global, not a
|
||||
* search agent's affinity, and is set with `POST .../watch`. Opening the
|
||||
* careers page stamps `careers_opened_at` (`POST .../opened`), so the row can
|
||||
* say when, and the On the list filter sorts what was opened longest ago
|
||||
* first. The filter is remembered per browser, and opens on Unrated.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const { api, count, debounce, safeUrl, companies, loadCompanies } = window;
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
|
||||
const FILTER = "roledesk.watchlist";
|
||||
const FILTERS = [
|
||||
["unrated", "Unrated"], ["yes", "On the list"], ["no", "Not on the list"], ["all", "All"],
|
||||
];
|
||||
const DAY = 24 * 60 * 60 * 1000;
|
||||
|
||||
/** The key of the row whose careers link editor is open, or null. */
|
||||
let editing = null;
|
||||
|
||||
function savedFilter() {
|
||||
try {
|
||||
const value = localStorage.getItem(FILTER);
|
||||
return FILTERS.some(([f]) => f === value) ? value : "unrated";
|
||||
} catch (err) {
|
||||
return "unrated";
|
||||
}
|
||||
}
|
||||
|
||||
function saveFilter(value) {
|
||||
try { localStorage.setItem(FILTER, value); } catch (err) { /* not remembered */ }
|
||||
}
|
||||
|
||||
/** The companies the tab is about, before any filter. */
|
||||
function watched() {
|
||||
return [...companies.values()].filter(
|
||||
(c) => (c.subscription_id == null && !c.from_search) || c.failing_since);
|
||||
}
|
||||
|
||||
function matchesFilter(company, filter) {
|
||||
switch (filter) {
|
||||
case "unrated": return company.watch == null;
|
||||
case "yes": return company.watch === 1;
|
||||
case "no": return company.watch === 0;
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
|
||||
function ago(iso) {
|
||||
if (!iso) return "not opened yet";
|
||||
const days = Math.floor((Date.now() - new Date(iso).getTime()) / DAY);
|
||||
if (Number.isNaN(days)) return "not opened yet";
|
||||
if (days < 1) return "opened today";
|
||||
return `opened ${count(days, "day")} ago`;
|
||||
}
|
||||
|
||||
/** Where the link goes: the careers page, else the company's own site. */
|
||||
function target(company) {
|
||||
const careers = safeUrl(company.careers_url);
|
||||
if (careers) return { url: careers, label: "Careers page" };
|
||||
const site = company.domain ? safeUrl(`https://${company.domain}`) : "";
|
||||
return site ? { url: site, label: "Website" } : null;
|
||||
}
|
||||
|
||||
async function rate(company, watch, rerender) {
|
||||
try {
|
||||
const updated = await api(`/api/companies/${encodeURIComponent(company.key)}/watch`, {
|
||||
method: "POST", body: { watch },
|
||||
});
|
||||
company.watch = updated.watch;
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
rerender();
|
||||
}
|
||||
|
||||
/** Yes and No, in `.affinity`'s look; pressing the pressed one clears it. */
|
||||
function ratingControl(company, rerender) {
|
||||
const span = document.createElement("span");
|
||||
span.className = "affinity";
|
||||
span.setAttribute("role", "group");
|
||||
span.setAttribute("aria-label", `Watch ${company.name}`);
|
||||
for (const [value, label, watch] of [[1, "Yes", true], [-1, "No", false]]) {
|
||||
const pressed = company.watch === (watch ? 1 : 0);
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.dataset.value = String(value);
|
||||
button.textContent = label;
|
||||
button.setAttribute("aria-pressed", String(pressed));
|
||||
button.addEventListener("click", () => rate(company, pressed ? null : watch, rerender));
|
||||
span.appendChild(button);
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
function subLine(company, rerender) {
|
||||
const sub = document.createElement("span");
|
||||
sub.className = "sub";
|
||||
const badge = document.createElement("span");
|
||||
badge.className = "badge";
|
||||
badge.textContent = company.board || company.ats || "board not found";
|
||||
sub.appendChild(badge);
|
||||
const place = [company.city, (company.country || "").toUpperCase()].filter(Boolean).join(", ");
|
||||
if (place) sub.append(` ${place}`);
|
||||
if (company.failing_since) {
|
||||
const failing = document.createElement("span");
|
||||
failing.className = "failing";
|
||||
failing.textContent = `board failing since ${company.failing_since.slice(0, 10)}`;
|
||||
sub.append(" · ");
|
||||
sub.appendChild(failing);
|
||||
}
|
||||
sub.append(" · ");
|
||||
const where = target(company);
|
||||
if (where) {
|
||||
const link = document.createElement("a");
|
||||
link.href = where.url;
|
||||
link.target = "_blank";
|
||||
link.rel = "noopener noreferrer";
|
||||
link.textContent = where.label;
|
||||
link.addEventListener("click", () => opened(company, rerender));
|
||||
sub.appendChild(link);
|
||||
sub.append(` · ${ago(company.careers_opened_at)} `);
|
||||
}
|
||||
const edit = document.createElement("button");
|
||||
edit.type = "button";
|
||||
edit.className = "linky";
|
||||
edit.textContent = company.careers_url ? "Edit link" : "Add careers page";
|
||||
edit.setAttribute("aria-expanded", String(editing === company.key));
|
||||
edit.addEventListener("click", () => {
|
||||
editing = editing === company.key ? null : company.key;
|
||||
rerender();
|
||||
});
|
||||
sub.appendChild(edit);
|
||||
return sub;
|
||||
}
|
||||
|
||||
/** The link was followed: stamp it. The new tab is already open, so this
|
||||
only updates the row, and only the stamp, so the row does not jump. */
|
||||
async function opened(company, rerender) {
|
||||
try {
|
||||
const updated = await api(`/api/companies/${encodeURIComponent(company.key)}/opened`,
|
||||
{ method: "POST" });
|
||||
company.careers_opened_at = updated.careers_opened_at;
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
rerender();
|
||||
}
|
||||
|
||||
function linkEditor(company, rerender) {
|
||||
const form = document.createElement("form");
|
||||
form.className = "board-edit";
|
||||
form.autocomplete = "off";
|
||||
const input = document.createElement("input");
|
||||
input.type = "url";
|
||||
input.spellcheck = false;
|
||||
input.placeholder = "https://";
|
||||
input.value = company.careers_url || "";
|
||||
input.setAttribute("aria-label", `${company.name}'s careers page`);
|
||||
const save = document.createElement("button");
|
||||
save.type = "submit";
|
||||
save.textContent = "Save";
|
||||
const cancel = document.createElement("button");
|
||||
cancel.type = "button";
|
||||
cancel.className = "linky";
|
||||
cancel.textContent = "Cancel";
|
||||
cancel.addEventListener("click", () => { editing = null; rerender(); });
|
||||
form.append(input, save, cancel);
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
save.disabled = true;
|
||||
try {
|
||||
const updated = await api(`/api/companies/${encodeURIComponent(company.key)}/careers`,
|
||||
{ method: "POST", body: { careers_url: input.value.trim() } });
|
||||
company.careers_url = updated.careers_url;
|
||||
editing = null;
|
||||
rerender();
|
||||
} catch (err) {
|
||||
save.disabled = false;
|
||||
}
|
||||
});
|
||||
return form;
|
||||
}
|
||||
|
||||
/** The filter's options with their counts, kept on the chosen one. */
|
||||
function drawFilter(all) {
|
||||
const select = $("#w-filter");
|
||||
const chosen = select.value || savedFilter();
|
||||
select.replaceChildren();
|
||||
for (const [value, label] of FILTERS) {
|
||||
const option = document.createElement("option");
|
||||
option.value = value;
|
||||
option.textContent = `${label} (${all.filter((c) => matchesFilter(c, value)).length})`;
|
||||
select.appendChild(option);
|
||||
}
|
||||
select.value = chosen;
|
||||
}
|
||||
|
||||
function render() {
|
||||
const all = watched();
|
||||
drawFilter(all);
|
||||
const q = $("#w-q").value.trim().toLowerCase();
|
||||
const filter = $("#w-filter").value;
|
||||
const rows = all
|
||||
.filter((c) => !q || c.name.toLowerCase().includes(q)
|
||||
|| (c.board || c.ats || "").includes(q) || (c.country || "").toLowerCase() === q)
|
||||
.filter((c) => matchesFilter(c, filter));
|
||||
// Overdue first on the list, never opened on top (the empty stamp sorts
|
||||
// before any date); every other filter is by name.
|
||||
rows.sort((a, b) => (filter === "yes"
|
||||
? a.careers_opened_at.localeCompare(b.careers_opened_at) : 0)
|
||||
|| a.name.localeCompare(b.name));
|
||||
const body = $("#watchlist-list");
|
||||
body.replaceChildren();
|
||||
for (const company of rows) {
|
||||
const row = document.createElement("div");
|
||||
row.className = "crow";
|
||||
const name = document.createElement("span");
|
||||
name.className = "name";
|
||||
name.textContent = company.name;
|
||||
row.appendChild(name);
|
||||
row.appendChild(ratingControl(company, render));
|
||||
row.appendChild(subLine(company, render));
|
||||
if (editing === company.key) row.appendChild(linkEditor(company, render));
|
||||
body.appendChild(row);
|
||||
}
|
||||
$("#watchlist-count").textContent = count(rows.length, "company", "companies");
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
if (!$("#watchlist-list")) return;
|
||||
try {
|
||||
await loadCompanies();
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
$("#w-filter").value = savedFilter();
|
||||
render();
|
||||
$("#w-q").addEventListener("input", debounce(render, 150));
|
||||
$("#w-filter").addEventListener("change", () => {
|
||||
saveFilter($("#w-filter").value);
|
||||
render();
|
||||
});
|
||||
});
|
||||
})();
|
||||
+14
-1
@@ -107,6 +107,9 @@ CREATE TABLE IF NOT EXISTS role_tags (
|
||||
-- yet. country is an ISO code and city the head office's. ats_slug is the
|
||||
-- name that host knows the company by (the acme of acme.teamtailor.com),
|
||||
-- '' where its URL carries none, kept for the parser written later.
|
||||
-- watch is the Watchlist's rating, global and not an agent's: NULL unrated, 1
|
||||
-- worth checking by hand, 0 not; careers_opened_at when its careers page was
|
||||
-- last opened from there.
|
||||
CREATE TABLE IF NOT EXISTS companies (
|
||||
key TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
@@ -119,7 +122,9 @@ CREATE TABLE IF NOT EXISTS companies (
|
||||
ats TEXT NOT NULL DEFAULT '',
|
||||
country TEXT NOT NULL DEFAULT '',
|
||||
city TEXT NOT NULL DEFAULT '',
|
||||
ats_slug TEXT NOT NULL DEFAULT ''
|
||||
ats_slug TEXT NOT NULL DEFAULT '',
|
||||
watch INTEGER CHECK (watch IN (0, 1)),
|
||||
careers_opened_at TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
-- The targets desk's runner hands to plugins. newsdesk's shape, with its two
|
||||
@@ -423,6 +428,14 @@ ALTER TABLE agents DROP COLUMN intent;
|
||||
ALTER TABLE agents DROP COLUMN intent_key;
|
||||
ALTER TABLE agents DROP COLUMN intent_vec;
|
||||
ALTER TABLE scores ADD COLUMN prompt TEXT NOT NULL DEFAULT '';
|
||||
"""),
|
||||
# The Watchlist's own rating, global and apart from an agent's affinity:
|
||||
# NULL not yet rated, 1 worth checking by hand, 0 not. Every company
|
||||
# starts unrated.
|
||||
(15, "companies.watch and careers_opened_at: the Watchlist's rating and "
|
||||
"when its careers page was last opened", """
|
||||
ALTER TABLE companies ADD COLUMN watch INTEGER CHECK (watch IN (0, 1));
|
||||
ALTER TABLE companies ADD COLUMN careers_opened_at TEXT NOT NULL DEFAULT '';
|
||||
"""),
|
||||
)
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ _EXCERPT_SOURCE = "COALESCE(NULLIF(roles.summary, ''), roles.description)"
|
||||
_EXCERPT_RAW = 240
|
||||
|
||||
_COMPANY_FIELDS = ("name", "domain", "status", "careers_url", "notes", "ats", "country", "city",
|
||||
"ats_slug")
|
||||
"ats_slug", "watch", "careers_opened_at")
|
||||
|
||||
#: 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
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Watchlist — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Watchlist</h1>
|
||||
<p class="lede">The companies roledesk knows but cannot read a board of, so their roles are not in Roles. Mark the ones worth checking by hand and open their careers page from here.</p>
|
||||
|
||||
<form class="filters" autocomplete="off" onsubmit="return false">
|
||||
<input type="search" id="w-q" placeholder="Filter by name, host or country code" aria-label="Filter companies">
|
||||
{# The options and their counts are drawn by watchlist.js, which also
|
||||
remembers the choice. #}
|
||||
<select id="w-filter" aria-label="Show"></select>
|
||||
</form>
|
||||
|
||||
<p id="watchlist-count" class="count" role="status"></p>
|
||||
<div id="watchlist-list" class="crows"></div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ asset('watchlist.js') }}"></script>
|
||||
{% endblock %}
|
||||
+52
-2
@@ -304,7 +304,8 @@ class CompanyOut(BaseModel):
|
||||
while it answers. `from_search` marks a row that exists only because a
|
||||
search listed its roles and somebody judged it (`Store.set_affinity`):
|
||||
no board, not even a detached one, and no `ats`, `careers_url` or
|
||||
`domain`, which every way of following a company writes one of."""
|
||||
`domain`, which every way of following a company writes one of.
|
||||
`watch` and `careers_opened_at` are the Watchlist's (`Company`'s)."""
|
||||
|
||||
key: str
|
||||
name: str
|
||||
@@ -317,6 +318,10 @@ class CompanyOut(BaseModel):
|
||||
ats_slug: str = ""
|
||||
careers_url: str = ""
|
||||
country: str = ""
|
||||
city: str = ""
|
||||
domain: str = ""
|
||||
watch: int | None = None
|
||||
careers_opened_at: str = ""
|
||||
failing_since: str = ""
|
||||
failing_reason: str = ""
|
||||
from_search: bool = False
|
||||
@@ -353,7 +358,8 @@ def list_companies(store: StoreDep, agent: int | None = None) -> list[CompanyOut
|
||||
subscription_id=sub_id, on=on, affinity=c.affinity,
|
||||
open_roles=counts.get(c.key, 0), ats=c.ats,
|
||||
ats_slug=c.ats_slug, careers_url=c.careers_url,
|
||||
country=c.country,
|
||||
country=c.country, city=c.city, domain=c.domain,
|
||||
watch=c.watch, careers_opened_at=c.careers_opened_at,
|
||||
failing_since=since, failing_reason=reason,
|
||||
from_search=not (c.key in ever_boarded or c.ats
|
||||
or c.careers_url or c.domain)))
|
||||
@@ -459,6 +465,50 @@ def set_affinity(key: str, body: AffinityBody, store: StoreDep,
|
||||
return AffinityOut(**company.model_dump(), score_job=job.id if job else None)
|
||||
|
||||
|
||||
class WatchBody(BaseModel):
|
||||
#: True on the Watchlist's list, False not on it, None clears the rating.
|
||||
watch: bool | None
|
||||
|
||||
|
||||
@router.post("/companies/{key}/watch")
|
||||
def set_watch(key: str, body: WatchBody, store: StoreDep) -> Company:
|
||||
"""Rate a company for the Watchlist: 1 worth checking by hand, 0 not,
|
||||
null back to unrated. Global, and apart from affinity. 404 for an
|
||||
unknown key."""
|
||||
watch = None if body.watch is None else int(body.watch)
|
||||
try:
|
||||
return store.update_company(key, watch=watch)
|
||||
except KeyError:
|
||||
raise HTTPException(404, f"no such company: {key}") from None
|
||||
|
||||
|
||||
class CareersBody(BaseModel):
|
||||
careers_url: str
|
||||
|
||||
|
||||
@router.post("/companies/{key}/careers")
|
||||
def set_careers_url(key: str, body: CareersBody, store: StoreDep) -> Company:
|
||||
"""Set or correct where a company's careers page is; "" clears it. 422
|
||||
for anything but an http(s) URL, 404 for an unknown key."""
|
||||
url = body.careers_url.strip()
|
||||
if url and not url.lower().startswith(("http://", "https://")):
|
||||
raise HTTPException(422, "careers_url must start with http:// or https://")
|
||||
try:
|
||||
return store.update_company(key, careers_url=url)
|
||||
except KeyError:
|
||||
raise HTTPException(404, f"no such company: {key}") from None
|
||||
|
||||
|
||||
@router.post("/companies/{key}/opened")
|
||||
def mark_careers_opened(key: str, store: StoreDep) -> Company:
|
||||
"""Stamp that the company's careers page was just opened from the
|
||||
Watchlist. 404 for an unknown key."""
|
||||
try:
|
||||
return store.update_company(key, careers_opened_at=store.now())
|
||||
except KeyError:
|
||||
raise HTTPException(404, f"no such company: {key}") from None
|
||||
|
||||
|
||||
# ----------------------------------------------------------------- sources
|
||||
|
||||
class SourceOut(BaseModel):
|
||||
|
||||
+8
-2
@@ -1,6 +1,6 @@
|
||||
"""The pages: two tabs, a cog, and three settings pages behind it.
|
||||
"""The pages: three tabs, a cog, and three settings pages behind it.
|
||||
|
||||
`TABS` is the top bar, Roles and Applications, and `SETTINGS` is the rail
|
||||
`TABS` is the top bar, Roles, Applications and Watchlist, and `SETTINGS` is the rail
|
||||
beside every page under the cog at `/settings/<name>`: Search agents,
|
||||
Sources, Account. `base.html` renders the first, `settings/_rail.html` the
|
||||
second, every page marks itself active by its own `path`, and adding one is
|
||||
@@ -68,6 +68,7 @@ class Tab:
|
||||
TABS: tuple[Tab, ...] = (
|
||||
Tab("/", "Roles", "roles.html"),
|
||||
Tab("/applications", "Applications", "applications.html"),
|
||||
Tab("/watchlist", "Watchlist", "watchlist.html"),
|
||||
)
|
||||
|
||||
#: The pages under the cog, in order; `settings/_rail.html` renders them.
|
||||
@@ -155,6 +156,11 @@ def applications(request: Request) -> HTMLResponse:
|
||||
return page(request, "applications.html", status_options=STATUS_OPTIONS)
|
||||
|
||||
|
||||
@router.get("/watchlist", response_class=HTMLResponse)
|
||||
def watchlist(request: Request) -> HTMLResponse:
|
||||
return page(request, "watchlist.html")
|
||||
|
||||
|
||||
@router.get("/settings", response_class=RedirectResponse)
|
||||
def settings() -> RedirectResponse:
|
||||
return RedirectResponse(SETTINGS[0].path, status_code=302)
|
||||
|
||||
@@ -85,6 +85,17 @@ def test_a_role_address_is_the_same_page_with_its_reader_open(
|
||||
assert missing.status_code == 404 and "text/html" in missing.headers["content-type"]
|
||||
|
||||
|
||||
def test_the_watchlist_is_the_third_tab_and_a_shell(client: TestClient) -> None:
|
||||
page = client.get("/watchlist")
|
||||
assert page.status_code == 200
|
||||
assert 'href="/watchlist"\n class="active" aria-current="page">Watchlist' in page.text
|
||||
assert 'id="watchlist-list"' in page.text and "/static/watchlist.js" in page.text
|
||||
nav = page.text[page.text.index("<nav>"):page.text.index("</nav>")]
|
||||
tabs = [t for t in ("Roles", "Applications", "Watchlist") if f">{t}</a>" in nav]
|
||||
assert tabs == ["Roles", "Applications", "Watchlist"]
|
||||
assert nav.count('aria-current="page"') == 1
|
||||
|
||||
|
||||
def test_the_read_page_of_its_own_is_gone(client: TestClient) -> None:
|
||||
assert client.get("/static/role.js").status_code == 404
|
||||
other = client.get("/applications").text
|
||||
|
||||
+29
-3
@@ -69,7 +69,7 @@ def test_schema_creates_on_an_empty_file(tmp_path: Path) -> None:
|
||||
"application_events", "agents", "scores", "state"} <= tables
|
||||
assert "idx_roles_cluster" in indexes
|
||||
assert store.migrations_applied == []
|
||||
assert LATEST == 14
|
||||
assert LATEST == 15
|
||||
# A second open finds it current and applies nothing.
|
||||
assert Store(path).migrations_applied == []
|
||||
|
||||
@@ -88,10 +88,19 @@ def _columns(path: Path, table: str) -> list[tuple[str, str, int, str]]:
|
||||
return [(r[1], r[2], r[3], r[4]) for r in conn.execute(f"PRAGMA table_info({table})")]
|
||||
|
||||
|
||||
def _undo_v15(conn: sqlite3.Connection) -> None:
|
||||
"""A fresh file put back to the v14 shape: no Watchlist columns on a
|
||||
company."""
|
||||
conn.execute("ALTER TABLE companies DROP COLUMN watch")
|
||||
conn.execute("ALTER TABLE companies DROP COLUMN careers_opened_at")
|
||||
|
||||
|
||||
def _undo_v14(conn: sqlite3.Connection) -> None:
|
||||
"""A fresh file put back to the v13 shape: an agent's intent and its
|
||||
cached vector on the agent row, no prompts, no prompt on a score. Every
|
||||
downgrade below starts here, since v14 is the last migration."""
|
||||
downgrade below starts here, after `_undo_v15`, since v15 is the last
|
||||
migration."""
|
||||
_undo_v15(conn)
|
||||
conn.execute("DROP TABLE agent_prompts")
|
||||
conn.execute("ALTER TABLE scores DROP COLUMN prompt")
|
||||
conn.execute("ALTER TABLE agents ADD COLUMN intent TEXT NOT NULL DEFAULT ''")
|
||||
@@ -127,6 +136,23 @@ def test_a_v1_file_migrates_to_the_shape_a_new_file_has(tmp_path: Path) -> None:
|
||||
assert sorted(_columns(old, table)) == sorted(_columns(fresh, table))
|
||||
|
||||
|
||||
def test_a_v14_file_gains_the_watchlist_columns_and_leaves_companies_unrated(
|
||||
tmp_path: Path) -> None:
|
||||
path = tmp_path / "v14.db"
|
||||
Store(path).add_company("Acme", ats="teamtailor", country="DK", careers_url="https://a.example")
|
||||
with sqlite3.connect(path) as conn:
|
||||
_undo_v15(conn)
|
||||
conn.execute("PRAGMA user_version = 14")
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [15]
|
||||
acme = migrated.company("acme")
|
||||
assert acme is not None
|
||||
assert (acme.ats, acme.careers_url) == ("teamtailor", "https://a.example")
|
||||
assert (acme.watch, acme.careers_opened_at) == (None, "")
|
||||
|
||||
|
||||
def test_a_v8_file_gains_ats_slug_and_keeps_its_companies(tmp_path: Path) -> None:
|
||||
path = tmp_path / "v8.db"
|
||||
Store(path).add_company("Acme", ats="teamtailor", country="DK")
|
||||
@@ -325,7 +351,7 @@ def test_v14_makes_each_intent_the_agents_one_prompt_with_its_vector(tmp_path: P
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [14]
|
||||
assert migrated.migrations_applied == [14, 15]
|
||||
assert migrated.agent(backend.id).prompts == [ # type: ignore[union-attr]
|
||||
Prompt(name="Backend", text="python backend")]
|
||||
assert migrated.agent(blank.id).prompts == [] # type: ignore[union-attr]
|
||||
|
||||
+50
-2
@@ -430,7 +430,8 @@ def test_companies_lists_board_and_open_role_count(
|
||||
assert row == {"key": "acme", "name": "Acme", "board": "greenhouse",
|
||||
"subscription_id": sub.id, "on": True, "affinity": 0, "open_roles": 1,
|
||||
"ats": "greenhouse", "ats_slug": "", "careers_url": "",
|
||||
"country": "DK", "failing_since": "", "failing_reason": "",
|
||||
"country": "DK", "city": "", "domain": "", "watch": None,
|
||||
"careers_opened_at": "", "failing_since": "", "failing_reason": "",
|
||||
"from_search": False}
|
||||
[other] = [c for c in res.json() if c["key"] == "other"]
|
||||
assert (other["board"], other["subscription_id"], other["on"], other["ats"]) == (
|
||||
@@ -552,6 +553,53 @@ def test_post_score_answers_with_the_job_to_wait_for(client: TestClient, queue:
|
||||
assert queue.jobs.get(res.json()["id"]).kind == "score"
|
||||
|
||||
|
||||
# ------------------------------------------------------------- watchlist
|
||||
|
||||
def test_the_watchlist_rating_is_global_and_leaves_affinity_alone(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.add_company("Acme", ats="workday")
|
||||
agent = store.save_agent("A")
|
||||
store.set_affinity(agent.id, "acme", 1)
|
||||
|
||||
for watch, stored in ((True, 1), (False, 0), (None, None)):
|
||||
res = client.post("/api/companies/acme/watch", json={"watch": watch})
|
||||
assert res.status_code == 200 and res.json()["watch"] == stored
|
||||
listed = client.get("/api/companies").json()[0]
|
||||
assert (listed["watch"], listed["affinity"]) == (stored, 1)
|
||||
|
||||
|
||||
def test_the_careers_page_is_set_cleared_and_must_be_a_web_address(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.add_company("Acme")
|
||||
|
||||
res = client.post("/api/companies/acme/careers", json={"careers_url": "https://a.example/jobs"})
|
||||
assert res.status_code == 200 and res.json()["careers_url"] == "https://a.example/jobs"
|
||||
for bad in ("javascript:alert(1)", "a.example/jobs", "ftp://a.example"):
|
||||
assert client.post("/api/companies/acme/careers",
|
||||
json={"careers_url": bad}).status_code == 422
|
||||
assert store.company("acme").careers_url == "https://a.example/jobs"
|
||||
cleared = client.post("/api/companies/acme/careers", json={"careers_url": ""})
|
||||
assert cleared.status_code == 200 and store.company("acme").careers_url == ""
|
||||
|
||||
|
||||
def test_opening_the_careers_page_stamps_the_time(client: TestClient, store: Store) -> None:
|
||||
store.add_company("Acme")
|
||||
assert client.get("/api/companies").json()[0]["careers_opened_at"] == ""
|
||||
|
||||
res = client.post("/api/companies/acme/opened")
|
||||
|
||||
assert res.status_code == 200
|
||||
assert res.json()["careers_opened_at"] == store.company("acme").careers_opened_at != ""
|
||||
assert client.get("/api/companies").json()[0]["careers_opened_at"] != ""
|
||||
|
||||
|
||||
def test_the_watchlist_endpoints_404_for_an_unknown_company(client: TestClient) -> None:
|
||||
assert client.post("/api/companies/nope/watch", json={"watch": True}).status_code == 404
|
||||
assert client.post("/api/companies/nope/careers",
|
||||
json={"careers_url": "https://a.example"}).status_code == 404
|
||||
assert client.post("/api/companies/nope/opened").status_code == 404
|
||||
|
||||
|
||||
# ----------------------------------------------------------- applications
|
||||
|
||||
def test_save_creates_an_application_with_a_saved_event(
|
||||
@@ -629,7 +677,7 @@ def test_the_applications_page_has_no_next_column(client: TestClient) -> None:
|
||||
# -------------------------------------------------------------------- tabs
|
||||
|
||||
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 TABS] == ["Roles", "Applications", "Watchlist"]
|
||||
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):
|
||||
|
||||
Reference in new issue
Block a user