Serve one alpha page: filters, roles, the tracker, and Jobs
/, GET /api/roles|companies|applications, POST /api/companies/{key}/affinity
and /api/applications[/{id}/status]. The Jinja2 template renders an empty
shell; static/app.js fills it and drives Save, affinity and status changes.
<desk-jobs> from pipeline.web mounts at the bottom so Pull can be started
from the page.
Store.roles gains q, function, remote, days and hide_muted, and company/
place move from a key match to a substring on the text a board wrote.
hide_muted filters in SQL before LIMIT: filtering after it shipped first and
broke immediately on real data, since Databricks' freshly pulled 884 roles
were the newest 200-plus rows in the table and muting it left nothing to
show.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
867ebe6405
commit
b44f78ca7e
13 files changed
+1143
-22
No files matched your search
@@ -57,6 +57,14 @@ at least the listing.
|
||||
|
||||
**Summary and tagging are off; `extract` replaces them.** Every profile declares `SummaryPolicy(enabled=False)` and `TaggingPolicy(enabled=False)`. `extract` is a roledesk `ModelTask` on Haiku that turns title and description into the gate columns, and skips rows a plugin already filled from structured fields.
|
||||
|
||||
## The alpha page
|
||||
|
||||
**The template renders an empty shell; `static/app.js` fills it and drives every action.** `index.html` carries only the filter bar's `<select>` options (from `roledesk.models` and `plugins.ats.FUNCTIONS`, so they can't drift from what the store accepts) and the section containers. Every row, count and button state is a fetch from the JS, including the initial load — one code path for "show this" rather than a server-rendered first page plus a client re-render for every filter change after.
|
||||
|
||||
**`roles(company=, place=)` moved from a key match to a case-insensitive substring on the column a board wrote.** The API's company and place fields are free text a person types, not a slug; a search for "Trade Republic" should not have to know it folds to `trade-republic-bank`. Nothing outside `tests/test_storage.py` called either parameter, so the change is free.
|
||||
|
||||
**A muted company is excluded in SQL, before `LIMIT`, not filtered out of the page after.** Filtering after `LIMIT` shipped first and broke on real data within the same session: Databricks' 884 roles, all freshly pulled at once by the cap fix above, were the newest 200-plus rows in the table, so muting it — with the default query taking the newest 200 — left nothing to show. `Store.roles(hide_muted=True)` adds `company_key NOT IN (SELECT key FROM companies WHERE affinity = -1)` to the `WHERE` clause instead, so the limit is applied to what is actually shown.
|
||||
|
||||
## Outside the app
|
||||
|
||||
**Unposted roles and the network stay outside.** Their state is inside: an application row with no `role_uid`, a `contact`, `next_action` and `next_date`, and a company `status` such as researching or contacted.
|
||||
|
||||
@@ -8,6 +8,7 @@ dependencies = [
|
||||
# newsdesk distribution. Imported from there and never edited here.
|
||||
"newsdesk",
|
||||
"fastapi>=0.110",
|
||||
"jinja2>=3.1",
|
||||
"pydantic>=2.6",
|
||||
"pyyaml>=6.0",
|
||||
"uvicorn[standard]>=0.29",
|
||||
|
||||
@@ -12,7 +12,7 @@ import json
|
||||
import sqlite3
|
||||
from collections.abc import Callable, Iterator, MutableMapping, Sequence
|
||||
from contextlib import closing, contextmanager
|
||||
from datetime import UTC, datetime
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from uuid import uuid4
|
||||
@@ -51,6 +51,13 @@ def _remote(value: Any) -> str:
|
||||
return text if text in REMOTE else ""
|
||||
|
||||
|
||||
def _like(text: str) -> str:
|
||||
"""A `LIKE` pattern for a case-insensitive substring match, with SQLite's
|
||||
own wildcards escaped so a search for "50%" or "a_b" stays literal."""
|
||||
escaped = text.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_")
|
||||
return f"%{escaped}%"
|
||||
|
||||
|
||||
def _int_or_none(value: Any) -> int | None:
|
||||
if value is None or value == "" or isinstance(value, bool):
|
||||
return None
|
||||
@@ -204,18 +211,48 @@ class Store:
|
||||
return Role.from_row(row) if row else None
|
||||
|
||||
def roles(self, limit: int = 100, company: str | None = None,
|
||||
place: str | None = None, open_only: bool = True) -> list[Role]:
|
||||
"""Newest first by `first_seen`. `company` and `place` are matched by
|
||||
key, so any spelling that keys the same finds the same rows."""
|
||||
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) -> list[Role]:
|
||||
"""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.
|
||||
|
||||
`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."""
|
||||
where, params = [], []
|
||||
if company:
|
||||
where.append("company_key = ?")
|
||||
params.append(company_key(company))
|
||||
where.append("company LIKE ? ESCAPE '\\'")
|
||||
params.append(_like(company))
|
||||
if place:
|
||||
where.append("place_key = ?")
|
||||
params.append(place_key(place))
|
||||
where.append("place LIKE ? ESCAPE '\\'")
|
||||
params.append(_like(place))
|
||||
if function:
|
||||
where.append("function = ?")
|
||||
params.append(function)
|
||||
if remote:
|
||||
where.append("remote = ?")
|
||||
params.append(remote)
|
||||
if days is not None:
|
||||
where.append("first_seen >= ?")
|
||||
params.append(_iso(self.clock() - timedelta(days=days)))
|
||||
for word in (q or "").split():
|
||||
where.append("title LIKE ? ESCAPE '\\'")
|
||||
params.append(_like(word))
|
||||
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)")
|
||||
sql = "SELECT * FROM roles"
|
||||
if where:
|
||||
sql += " WHERE " + " AND ".join(where)
|
||||
@@ -287,6 +324,24 @@ class Store:
|
||||
raise KeyError(key)
|
||||
return found
|
||||
|
||||
def open_role_counts(self) -> dict[str, int]:
|
||||
"""`company_key -> open role count`, for the company list's row
|
||||
count. A key with no open roles is simply absent."""
|
||||
return {str(r["company_key"]): int(r["n"]) for r in self._rows(
|
||||
"SELECT company_key, COUNT(*) AS n FROM roles "
|
||||
"WHERE closed_at IS NULL GROUP BY company_key")}
|
||||
|
||||
def company_boards(self) -> dict[str, str]:
|
||||
"""`company_key -> ats host`, read off each company's own
|
||||
subscription. `Subscription.company` is the display name it and the
|
||||
company row were both added with, so `company_key` of one finds the
|
||||
other; a company added by hand with no subscription is simply
|
||||
absent."""
|
||||
boards: dict[str, str] = {}
|
||||
for sub in self.subscriptions(source="ats"):
|
||||
boards.setdefault(company_key(sub.company), sub.board)
|
||||
return boards
|
||||
|
||||
# -------------------------------------------------------- subscriptions
|
||||
|
||||
def subscriptions(self, source: str | None = None,
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
"""The JSON routes the page uses: roles, companies, applications.
|
||||
|
||||
`/api/jobs*`, `/_jobs/jobs.js` and `/ws/jobs` are `pipeline.web`'s, mounted by
|
||||
`connect` in `app.py`. This is roledesk's own API, over the same store.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from pydantic import BaseModel
|
||||
|
||||
from roledesk.models import AFFINITY, Application, Company, Role, Status
|
||||
from roledesk.web.deps import StoreDep
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["roledesk"])
|
||||
|
||||
|
||||
# ------------------------------------------------------------------- roles
|
||||
|
||||
@router.get("/roles")
|
||||
def list_roles(
|
||||
store: StoreDep,
|
||||
q: str = "",
|
||||
company: str = "",
|
||||
place: str = "",
|
||||
function: str = "",
|
||||
remote: str = "",
|
||||
days: int | None = None,
|
||||
show_muted: bool = False,
|
||||
limit: Annotated[int, Query(ge=1, le=1000)] = 200,
|
||||
) -> list[Role]:
|
||||
"""Open roles, newest first. See `Store.roles` for what each filter does.
|
||||
|
||||
A muted company's roles are left out unless `show_muted` is set."""
|
||||
return store.roles(limit=limit, 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)
|
||||
|
||||
|
||||
# --------------------------------------------------------------- companies
|
||||
|
||||
class CompanyOut(BaseModel):
|
||||
"""A company row plus the two things only the store can join in: the ats
|
||||
host it is read from, and how many of its roles are still open."""
|
||||
|
||||
key: str
|
||||
name: str
|
||||
board: str
|
||||
affinity: int
|
||||
open_roles: int
|
||||
|
||||
|
||||
@router.get("/companies")
|
||||
def list_companies(store: StoreDep) -> list[CompanyOut]:
|
||||
boards = store.company_boards()
|
||||
counts = store.open_role_counts()
|
||||
return [CompanyOut(key=c.key, name=c.name, board=boards.get(c.key, ""),
|
||||
affinity=c.affinity, open_roles=counts.get(c.key, 0))
|
||||
for c in store.companies()]
|
||||
|
||||
|
||||
class AffinityBody(BaseModel):
|
||||
affinity: int
|
||||
|
||||
|
||||
@router.post("/companies/{key}/affinity")
|
||||
def set_affinity(key: str, body: AffinityBody, store: StoreDep) -> Company:
|
||||
if body.affinity not in AFFINITY:
|
||||
raise HTTPException(422, "affinity is -1, 0, 1 or 2")
|
||||
try:
|
||||
return store.update_company(key, affinity=body.affinity)
|
||||
except KeyError:
|
||||
raise HTTPException(404, f"no such company: {key}") from None
|
||||
|
||||
|
||||
# ----------------------------------------------------------- applications
|
||||
|
||||
class SaveBody(BaseModel):
|
||||
role_uid: str
|
||||
status: Status = "saved"
|
||||
|
||||
|
||||
@router.post("/applications", status_code=201)
|
||||
def save_role(body: SaveBody, store: StoreDep) -> Application:
|
||||
"""Track one role. Pressing Save twice does not double-track it: the
|
||||
existing row comes back rather than a second one starting at `saved`
|
||||
over whatever status it has since moved to."""
|
||||
existing = next((a for a in store.applications() if a.role_uid == body.role_uid), None)
|
||||
if existing is not None:
|
||||
return existing
|
||||
role = store.role(body.role_uid)
|
||||
if role is None:
|
||||
raise HTTPException(404, f"no such role: {body.role_uid}")
|
||||
next_date = (store.clock() + timedelta(days=2)).date().isoformat()
|
||||
application = Application(
|
||||
role_uid=role.uid, company_key=role.company_key, role_title=role.title,
|
||||
url=role.original_url, status=body.status, source=role.source,
|
||||
next_action="Read the posting and decide", next_date=next_date)
|
||||
return store.save_application(application)
|
||||
|
||||
|
||||
@router.get("/applications")
|
||||
def list_applications(store: StoreDep) -> list[Application]:
|
||||
"""Every tracked application, with the role title and company key it was
|
||||
saved with — enough for the page to list them without a join; the
|
||||
company's full name comes from `/api/companies`, already on the page."""
|
||||
return store.applications()
|
||||
|
||||
|
||||
class StatusBody(BaseModel):
|
||||
status: Status
|
||||
|
||||
|
||||
@router.post("/applications/{app_id}/status")
|
||||
def set_status(app_id: str, body: StatusBody, store: StoreDep) -> Application:
|
||||
try:
|
||||
return store.set_application_status(app_id, body.status)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(422, str(exc)) from exc
|
||||
except KeyError:
|
||||
raise HTTPException(404, f"no such application: {app_id}") from None
|
||||
+11
-14
@@ -1,23 +1,22 @@
|
||||
"""The application factory. A stub page until the reader lands: the queue's
|
||||
routes and socket from `pipeline.web.connect`, and a one-line index."""
|
||||
"""The application factory: the queue's routes and socket from
|
||||
`pipeline.web.connect`, roledesk's own JSON API, and the one page."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from pipeline import Jobs
|
||||
from pipeline.web import connect
|
||||
from roledesk import config as config_mod
|
||||
from roledesk import jobs
|
||||
from roledesk.storage import Store
|
||||
from roledesk.web.api import router as api_router
|
||||
from roledesk.web.pages import router as pages_router
|
||||
|
||||
INDEX = """<!doctype html>
|
||||
<meta charset="utf-8"><title>roledesk</title>
|
||||
<p>roledesk: no reader yet.</p>
|
||||
<script type="module" src="/_jobs/jobs.js"></script>
|
||||
<desk-jobs></desk-jobs>
|
||||
"""
|
||||
WEB = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def create_app(config_path: str | None = None) -> FastAPI:
|
||||
@@ -31,11 +30,9 @@ def create_app(config_path: str | None = None) -> FastAPI:
|
||||
bootstrap=jobs.BOOTSTRAP, bootstrap_arg=config.path or "")
|
||||
app.state.config = config
|
||||
app.state.store = store
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
def index() -> str:
|
||||
return INDEX
|
||||
|
||||
app.include_router(api_router)
|
||||
app.include_router(pages_router)
|
||||
app.mount("/static", StaticFiles(directory=WEB / "static"), name="static")
|
||||
return app
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
"""How a route reaches the store.
|
||||
|
||||
Built once by the app's factory and parked on `app.state`; a route asks for
|
||||
it as a dependency rather than closing over it, the same split newsdesk's
|
||||
`web/deps.py` makes and for the same reason — a router module stays
|
||||
importable, and testable, on its own.
|
||||
|
||||
Not a `yield` dependency: `Store` holds no connection between calls (see
|
||||
`roledesk/storage/store.py`), so there is nothing to close, and building one
|
||||
per request would take SQLite's write lock for a plain read.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import Depends
|
||||
from starlette.requests import HTTPConnection
|
||||
|
||||
from roledesk.storage import Store
|
||||
|
||||
|
||||
def get_store(request: HTTPConnection) -> Store:
|
||||
return request.app.state.store
|
||||
|
||||
|
||||
StoreDep = Annotated[Store, Depends(get_store)]
|
||||
@@ -0,0 +1,47 @@
|
||||
"""The one page. Everything under `/api` and `/_jobs` is JSON; this route
|
||||
hands the browser an empty shell — the filter bar, the section headers, the
|
||||
`<select>` options a plugin's vocabulary decides — and `static/app.js` fills
|
||||
it and drives every action from there.
|
||||
|
||||
`FUNCTIONS` is `plugins.ats`'s, not `roledesk`'s: the nine job functions are
|
||||
the classifier's vocabulary, and this reaches `plugins/` the same way
|
||||
`roledesk.cli` already does, since a plugin is app-agnostic and never reaches
|
||||
back into `roledesk`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from roledesk.models import REMOTE, STATUSES
|
||||
|
||||
_ROOT = Path(__file__).resolve().parents[2]
|
||||
if str(_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(_ROOT))
|
||||
|
||||
from plugins.ats import FUNCTIONS # noqa: E402
|
||||
|
||||
WEB = Path(__file__).resolve().parent
|
||||
templates = Jinja2Templates(directory=WEB / "templates")
|
||||
|
||||
router = APIRouter(tags=["pages"])
|
||||
|
||||
#: `value, label` for each function select option. `FUNCTIONS` is already the
|
||||
#: value a role's `function` column holds; only the label is dressed up.
|
||||
FUNCTION_OPTIONS = [(f, f.replace("/", " / ").capitalize()) for f in FUNCTIONS]
|
||||
REMOTE_OPTIONS = [(r, r.capitalize()) for r in REMOTE if r]
|
||||
STATUS_OPTIONS = [(s, s.capitalize()) for s in STATUSES]
|
||||
|
||||
|
||||
@router.get("/", response_class=HTMLResponse)
|
||||
def index(request: Request) -> HTMLResponse:
|
||||
return templates.TemplateResponse(request, "index.html", {
|
||||
"functions": FUNCTION_OPTIONS,
|
||||
"remote_options": REMOTE_OPTIONS,
|
||||
"status_options": STATUS_OPTIONS,
|
||||
})
|
||||
@@ -0,0 +1,193 @@
|
||||
/* roledesk — an alpha to look at real ads, not the final reader. The palette
|
||||
and type stack borrow newsdesk's visual language (news/newsdesk/web/static
|
||||
/app.css): a quiet UI face and a teal signal colour, nothing ported beyond
|
||||
that — no reader, no auth, no passkeys. */
|
||||
|
||||
:root {
|
||||
--bg: #eceff1;
|
||||
--panel: #ffffff;
|
||||
--ink: #1a2027;
|
||||
--muted: #505c67;
|
||||
--faint: #6d7883;
|
||||
--rule: #d6dbdf;
|
||||
--signal: #14655b;
|
||||
--signal-weak: #a9c4bf;
|
||||
--mute: #96382c;
|
||||
--focus: #1b4f8f;
|
||||
|
||||
--ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto,
|
||||
"Helvetica Neue", Arial, sans-serif;
|
||||
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg: #14181c;
|
||||
--panel: #1b2126;
|
||||
--ink: #e3e7ea;
|
||||
--muted: #a8b2ba;
|
||||
--faint: #8b959d;
|
||||
--rule: #2a3238;
|
||||
--signal: #4fb3a3;
|
||||
--signal-weak: #35544f;
|
||||
--mute: #cd6a5b;
|
||||
--focus: #6ea8e8;
|
||||
}
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
html, body { max-width: 100%; overflow-x: hidden; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--ink);
|
||||
font-family: var(--ui);
|
||||
line-height: 1.45;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
button, input, select { font: inherit; color: inherit; }
|
||||
|
||||
a { color: var(--signal); }
|
||||
|
||||
/* ---------------------------------------------------------------- chrome */
|
||||
|
||||
header {
|
||||
position: sticky; top: 0; z-index: 10;
|
||||
display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
|
||||
padding: .7rem 1rem;
|
||||
background: var(--panel);
|
||||
border-bottom: 1px solid var(--rule);
|
||||
}
|
||||
|
||||
.wordmark { font-weight: 640; letter-spacing: -.01em; font-size: 1.1rem; }
|
||||
.wordmark span { color: var(--signal); }
|
||||
|
||||
.tabs { display: flex; gap: .25rem; }
|
||||
|
||||
.tab {
|
||||
background: none; border: 1px solid transparent; border-radius: .3rem;
|
||||
padding: .35rem .75rem; cursor: pointer; color: var(--muted);
|
||||
}
|
||||
.tab[aria-pressed="true"] { color: var(--ink); background: var(--bg); border-color: var(--rule); }
|
||||
|
||||
/* --------------------------------------------------------------- filters */
|
||||
|
||||
.filters {
|
||||
display: flex; flex-wrap: wrap; gap: .5rem;
|
||||
padding: .75rem 1rem;
|
||||
background: var(--panel);
|
||||
border-bottom: 1px solid var(--rule);
|
||||
}
|
||||
|
||||
.filters input[type="search"], .filters input[type="text"], .filters select {
|
||||
padding: .4rem .55rem;
|
||||
border: 1px solid var(--rule); border-radius: .3rem;
|
||||
background: var(--bg); color: var(--ink);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.filters input[type="search"] { flex: 1 1 12rem; }
|
||||
.filters input[type="text"] { flex: 1 1 8rem; }
|
||||
|
||||
.show-muted {
|
||||
display: flex; align-items: center; gap: .35rem;
|
||||
color: var(--muted); font-size: .9rem; white-space: nowrap;
|
||||
}
|
||||
|
||||
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
|
||||
outline: 2px solid var(--focus); outline-offset: 1px;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ views */
|
||||
|
||||
.view { padding: 0 1rem 1.5rem; }
|
||||
|
||||
.count { color: var(--faint); font-size: .85rem; margin: .75rem 0 .5rem; }
|
||||
|
||||
/* ------------------------------------------------------------------- roles */
|
||||
|
||||
.roles { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
|
||||
|
||||
.role {
|
||||
background: var(--panel); border: 1px solid var(--rule); border-radius: .5rem;
|
||||
padding: .6rem .8rem;
|
||||
display: flex; flex-direction: column; gap: .35rem;
|
||||
}
|
||||
|
||||
.role-main {
|
||||
display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem;
|
||||
}
|
||||
|
||||
.role-title { font-weight: 600; text-decoration: none; }
|
||||
.role-title:hover { text-decoration: underline; }
|
||||
|
||||
.role-company { color: var(--muted); }
|
||||
|
||||
.role-meta {
|
||||
display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
|
||||
color: var(--faint); font-size: .85rem;
|
||||
}
|
||||
|
||||
.badge {
|
||||
border: 1px solid var(--rule); border-radius: 1rem;
|
||||
padding: .05rem .55rem; font-size: .78rem;
|
||||
}
|
||||
.role-remote.badge:empty, .role-function.badge:empty { display: none; }
|
||||
|
||||
.role-age { margin-left: auto; }
|
||||
|
||||
.affinity { display: inline-flex; gap: .15rem; margin-left: auto; }
|
||||
.affinity button {
|
||||
background: none; border: 1px solid var(--rule); border-radius: .3rem;
|
||||
padding: .1rem .4rem; cursor: pointer; color: var(--muted); font-size: .85rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.affinity button[aria-pressed="true"] { color: #fff; background: var(--signal); border-color: var(--signal); }
|
||||
.affinity button[data-value="-1"][aria-pressed="true"] { background: var(--mute); border-color: var(--mute); }
|
||||
|
||||
.save {
|
||||
align-self: flex-start;
|
||||
background: var(--signal); color: #fff; border: 1px solid var(--signal);
|
||||
border-radius: .3rem; padding: .3rem .8rem; cursor: pointer; font-weight: 600;
|
||||
}
|
||||
.save[disabled] {
|
||||
background: var(--bg); color: var(--muted); border-color: var(--rule); cursor: default;
|
||||
}
|
||||
|
||||
.role.muted { opacity: .55; }
|
||||
|
||||
/* ------------------------------------------------------------ applications */
|
||||
|
||||
.applications { width: 100%; border-collapse: collapse; background: var(--panel); }
|
||||
.applications th, .applications td {
|
||||
text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--rule);
|
||||
font-size: .9rem;
|
||||
}
|
||||
.applications select { padding: .25rem .4rem; }
|
||||
|
||||
/* Below tablet width, a table stops being a table: each row becomes a card,
|
||||
its cells stacked, so nothing scrolls sideways to be read. */
|
||||
@media (max-width: 640px) {
|
||||
.applications thead { display: none; }
|
||||
.applications, .applications tbody, .applications tr, .applications td { display: block; width: 100%; }
|
||||
.applications tr { margin-bottom: .6rem; border: 1px solid var(--rule); border-radius: .4rem; }
|
||||
.applications td { border-bottom: none; }
|
||||
.applications td::before {
|
||||
content: attr(data-label);
|
||||
display: block; font-size: .72rem; color: var(--faint); margin-bottom: .1rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------- jobs */
|
||||
|
||||
#jobs { padding: 1rem; border-top: 1px solid var(--rule); }
|
||||
#jobs h2 { font-size: .95rem; color: var(--muted); margin: 0 0 .6rem; }
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.role-age { margin-left: 0; }
|
||||
.affinity { margin-left: 0; }
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
// roledesk's page: the filter bar, the role list, the tracker, and the tab
|
||||
// switch between them. The template renders an empty shell (see index.html);
|
||||
// everything on screen comes from the API, and every action — Save, an
|
||||
// affinity click, a status change — is a fetch from here, not a form post.
|
||||
"use strict";
|
||||
|
||||
const ROLES_URL = "/api/roles";
|
||||
|
||||
/** @type {Map<string, object>} company_key -> company row from /api/companies */
|
||||
let companies = new Map();
|
||||
/** @type {Map<string, object>} role_uid -> application row, for roles that are already tracked */
|
||||
let trackedByRole = new Map();
|
||||
/** @type {object[]} the last /api/roles response, already muted-filtered by the server */
|
||||
let roles = [];
|
||||
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
const $$ = (sel, root = document) => Array.from(root.querySelectorAll(sel));
|
||||
|
||||
function debounce(fn, ms) {
|
||||
let timer;
|
||||
return (...args) => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => fn(...args), ms);
|
||||
};
|
||||
}
|
||||
|
||||
async function api(path, options) {
|
||||
const res = await fetch(path, options);
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
throw new Error(body.detail || `${path}: ${res.status}`);
|
||||
}
|
||||
return res.status === 204 ? null : res.json();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ tabs
|
||||
|
||||
function initTabs() {
|
||||
$$(".tab").forEach((tab) => {
|
||||
tab.addEventListener("click", () => {
|
||||
$$(".tab").forEach((t) => t.setAttribute("aria-pressed", String(t === tab)));
|
||||
const name = tab.dataset.tab;
|
||||
$("#roles-view").hidden = name !== "roles";
|
||||
$("#applications-view").hidden = name !== "applications";
|
||||
if (name === "applications") loadApplications();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------- roles
|
||||
|
||||
function filterParams() {
|
||||
const params = new URLSearchParams();
|
||||
const q = $("#f-q").value.trim();
|
||||
const company = $("#f-company").value.trim();
|
||||
const place = $("#f-place").value.trim();
|
||||
const fn = $("#f-function").value;
|
||||
const remote = $("#f-remote").value;
|
||||
const days = $("#f-days").value;
|
||||
if (q) params.set("q", q);
|
||||
if (company) params.set("company", company);
|
||||
if (place) params.set("place", place);
|
||||
if (fn) params.set("function", fn);
|
||||
if (remote) params.set("remote", remote);
|
||||
if (days) params.set("days", days);
|
||||
if ($("#f-show-muted").checked) params.set("show_muted", "true");
|
||||
return params;
|
||||
}
|
||||
|
||||
async function loadRoles() {
|
||||
const params = filterParams();
|
||||
roles = await api(`${ROLES_URL}?${params.toString()}`);
|
||||
renderRoles();
|
||||
}
|
||||
|
||||
function relativeAge(iso) {
|
||||
const then = new Date(iso);
|
||||
const minutes = Math.max(0, Math.floor((Date.now() - then.getTime()) / 60000));
|
||||
if (minutes < 60) return `${minutes} min ago`;
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours < 24) return `${hours} h ago`;
|
||||
const days = Math.floor(hours / 24);
|
||||
return `${days} d ago`;
|
||||
}
|
||||
|
||||
function renderRoles() {
|
||||
const list = $("#roles-list");
|
||||
const template = $("#role-row");
|
||||
list.replaceChildren();
|
||||
|
||||
for (const role of roles) {
|
||||
const node = template.content.cloneNode(true);
|
||||
const li = node.querySelector(".role");
|
||||
const company = companies.get(role.company_key);
|
||||
|
||||
if (company && company.affinity === -1) li.classList.add("muted");
|
||||
|
||||
const titleLink = node.querySelector(".role-title");
|
||||
titleLink.textContent = role.title || "(untitled)";
|
||||
titleLink.href = role.original_url || "#";
|
||||
|
||||
node.querySelector(".role-company").textContent = role.company || "";
|
||||
node.querySelector(".role-place").textContent = role.place || "";
|
||||
node.querySelector(".role-remote").textContent = role.remote || "";
|
||||
node.querySelector(".role-function").textContent = role.function || "";
|
||||
node.querySelector(".role-age").textContent = relativeAge(role.first_seen);
|
||||
|
||||
node.querySelector(".affinity").replaceWith(
|
||||
affinityControl(role.company_key, company ? company.affinity : 0));
|
||||
|
||||
const saveButton = node.querySelector(".save");
|
||||
setSaveButton(saveButton, role.uid);
|
||||
saveButton.addEventListener("click", () => saveRole(role.uid, saveButton));
|
||||
|
||||
list.appendChild(node);
|
||||
}
|
||||
|
||||
$("#roles-count").textContent = `${roles.length} role${roles.length === 1 ? "" : "s"}`;
|
||||
}
|
||||
|
||||
function setSaveButton(button, uid) {
|
||||
const saved = trackedByRole.has(uid);
|
||||
button.textContent = saved ? "Saved" : "Save";
|
||||
button.disabled = saved;
|
||||
}
|
||||
|
||||
async function saveRole(uid, button) {
|
||||
button.disabled = true;
|
||||
button.textContent = "Saving…";
|
||||
try {
|
||||
const application = await api("/api/applications", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ role_uid: uid, status: "saved" }),
|
||||
});
|
||||
trackedByRole.set(uid, application);
|
||||
setSaveButton(button, uid);
|
||||
} catch (err) {
|
||||
button.disabled = false;
|
||||
button.textContent = "Save";
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------- affinity
|
||||
|
||||
const AFFINITY_LEVELS = [
|
||||
{ value: -1, label: "Mute" },
|
||||
{ value: 0, label: "Neutral" },
|
||||
{ value: 1, label: "Like" },
|
||||
{ value: 2, label: "Favourite" },
|
||||
];
|
||||
|
||||
function affinityControl(companyKey, current) {
|
||||
const span = document.createElement("span");
|
||||
span.className = "affinity";
|
||||
span.setAttribute("role", "group");
|
||||
span.setAttribute("aria-label", "Company affinity");
|
||||
for (const level of AFFINITY_LEVELS) {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.dataset.value = String(level.value);
|
||||
button.textContent = level.label[0];
|
||||
button.title = level.label;
|
||||
button.setAttribute("aria-label", level.label);
|
||||
button.setAttribute("aria-pressed", String(level.value === current));
|
||||
button.addEventListener("click", () => setAffinity(companyKey, level.value));
|
||||
span.appendChild(button);
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
async function setAffinity(companyKey, affinity) {
|
||||
if (!companyKey) return;
|
||||
try {
|
||||
const updated = await api(`/api/companies/${encodeURIComponent(companyKey)}/affinity`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ affinity }),
|
||||
});
|
||||
const company = companies.get(companyKey);
|
||||
if (company) company.affinity = updated.affinity;
|
||||
// Muting or unmuting changes which roles the server hands back, so the
|
||||
// list is refetched rather than just re-rendered from what is on hand.
|
||||
await loadRoles();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ applications
|
||||
|
||||
// `ROLEDESK_STATUSES` is set by index.html from the same `STATUSES` tuple
|
||||
// the store validates against, so this list can never drift from what a
|
||||
// `POST .../status` will actually accept.
|
||||
function statusSelect(current) {
|
||||
const select = document.createElement("select");
|
||||
for (const status of window.ROLEDESK_STATUSES) {
|
||||
const option = document.createElement("option");
|
||||
option.value = status;
|
||||
option.textContent = status[0].toUpperCase() + status.slice(1);
|
||||
option.selected = status === current;
|
||||
select.appendChild(option);
|
||||
}
|
||||
return select;
|
||||
}
|
||||
|
||||
async function loadApplications() {
|
||||
const applications = await api("/api/applications");
|
||||
trackedByRole = new Map(applications.filter((a) => a.role_uid).map((a) => [a.role_uid, a]));
|
||||
renderApplications(applications);
|
||||
}
|
||||
|
||||
function renderApplications(applications) {
|
||||
const body = $("#applications-list");
|
||||
body.replaceChildren();
|
||||
for (const application of applications) {
|
||||
const tr = document.createElement("tr");
|
||||
|
||||
const roleTd = document.createElement("td");
|
||||
roleTd.dataset.label = "Role";
|
||||
roleTd.textContent = application.role_title || "(untitled)";
|
||||
tr.appendChild(roleTd);
|
||||
|
||||
const companyTd = document.createElement("td");
|
||||
companyTd.dataset.label = "Company";
|
||||
const company = companies.get(application.company_key);
|
||||
companyTd.textContent = company ? company.name : application.company_key;
|
||||
tr.appendChild(companyTd);
|
||||
|
||||
const statusTd = document.createElement("td");
|
||||
statusTd.dataset.label = "Status";
|
||||
const select = statusSelect(application.status);
|
||||
select.addEventListener("change", () => setStatus(application.id, select.value));
|
||||
statusTd.appendChild(select);
|
||||
tr.appendChild(statusTd);
|
||||
|
||||
const nextTd = document.createElement("td");
|
||||
nextTd.dataset.label = "Next";
|
||||
nextTd.textContent = [application.next_action, application.next_date]
|
||||
.filter(Boolean).join(" · ");
|
||||
tr.appendChild(nextTd);
|
||||
|
||||
body.appendChild(tr);
|
||||
}
|
||||
$("#applications-count").textContent =
|
||||
`${applications.length} tracked application${applications.length === 1 ? "" : "s"}`;
|
||||
}
|
||||
|
||||
async function setStatus(id, status) {
|
||||
try {
|
||||
await api(`/api/applications/${encodeURIComponent(id)}/status`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ status }),
|
||||
});
|
||||
await loadApplications();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- init
|
||||
|
||||
async function loadCompanies() {
|
||||
const rows = await api("/api/companies");
|
||||
companies = new Map(rows.map((c) => [c.key, c]));
|
||||
}
|
||||
|
||||
async function init() {
|
||||
initTabs();
|
||||
await Promise.all([loadCompanies(), loadApplications()]);
|
||||
await loadRoles();
|
||||
|
||||
const refetch = debounce(loadRoles, 300);
|
||||
$("#f-q").addEventListener("input", refetch);
|
||||
$("#f-company").addEventListener("input", refetch);
|
||||
$("#f-place").addEventListener("input", refetch);
|
||||
$("#f-function").addEventListener("change", loadRoles);
|
||||
$("#f-remote").addEventListener("change", loadRoles);
|
||||
$("#f-days").addEventListener("change", loadRoles);
|
||||
$("#f-show-muted").addEventListener("change", loadRoles);
|
||||
$("#filters").addEventListener("submit", (e) => e.preventDefault());
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
@@ -0,0 +1,92 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>roledesk</title>
|
||||
<link rel="stylesheet" href="/static/app.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<span class="wordmark">role<span>desk</span></span>
|
||||
<nav class="tabs" id="tabs">
|
||||
<button type="button" class="tab" data-tab="roles" aria-pressed="true">Roles</button>
|
||||
<button type="button" class="tab" data-tab="applications" aria-pressed="false">Applications</button>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<section id="roles-view" class="view">
|
||||
<form id="filters" class="filters" autocomplete="off">
|
||||
<input type="search" id="f-q" placeholder="Search titles" aria-label="Search titles">
|
||||
<input type="text" id="f-company" placeholder="Company" aria-label="Company">
|
||||
<input type="text" id="f-place" placeholder="Place" aria-label="Place">
|
||||
<select id="f-function" aria-label="Function">
|
||||
<option value="">Any function</option>
|
||||
{% for value, label in functions %}
|
||||
<option value="{{ value }}">{{ label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select id="f-remote" aria-label="Remote">
|
||||
<option value="">Any remote</option>
|
||||
{% for value, label in remote_options %}
|
||||
<option value="{{ value }}">{{ label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select id="f-days" aria-label="New in">
|
||||
<option value="">Any time</option>
|
||||
<option value="1">New in 1 day</option>
|
||||
<option value="3">New in 3 days</option>
|
||||
<option value="7">New in 7 days</option>
|
||||
<option value="30">New in 30 days</option>
|
||||
</select>
|
||||
<label class="show-muted">
|
||||
<input type="checkbox" id="f-show-muted"> Show muted
|
||||
</label>
|
||||
</form>
|
||||
|
||||
<p id="roles-count" class="count" role="status"></p>
|
||||
<ul id="roles-list" class="roles"></ul>
|
||||
</section>
|
||||
|
||||
<section id="applications-view" class="view" hidden>
|
||||
<p id="applications-count" class="count" role="status"></p>
|
||||
<table class="applications">
|
||||
<thead>
|
||||
<tr><th>Role</th><th>Company</th><th>Status</th><th>Next</th></tr>
|
||||
</thead>
|
||||
<tbody id="applications-list"></tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<section id="jobs">
|
||||
<h2>Jobs</h2>
|
||||
<script type="module" src="/_jobs/jobs.js"></script>
|
||||
<desk-jobs></desk-jobs>
|
||||
</section>
|
||||
|
||||
<template id="role-row">
|
||||
<li class="role">
|
||||
<div class="role-main">
|
||||
<a class="role-title" target="_blank" rel="noopener"></a>
|
||||
<span class="role-company"></span>
|
||||
<span class="affinity" role="group"></span>
|
||||
</div>
|
||||
<div class="role-meta">
|
||||
<span class="role-place"></span>
|
||||
<span class="role-remote badge"></span>
|
||||
<span class="role-function badge"></span>
|
||||
<span class="role-age"></span>
|
||||
</div>
|
||||
<button type="button" class="save"></button>
|
||||
</li>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// The tracker's status vocabulary, from the same `STATUSES` tuple the
|
||||
// store validates a status change against — see roledesk/web/pages.py.
|
||||
window.ROLEDESK_STATUSES = {{ status_options | map(attribute=0) | list | tojson }};
|
||||
</script>
|
||||
<script src="/static/app.js" defer></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -149,6 +149,38 @@ def test_roles_newest_first_and_filtered(store: Store, clock: Clock) -> None:
|
||||
assert [r.source_id for r in store.roles(limit=1)] == ["3"]
|
||||
|
||||
|
||||
def test_roles_filters_q_function_remote_and_days(store: Store, clock: Clock) -> None:
|
||||
store.upsert_role(posting("1", company="Acme", place="Berlin",
|
||||
function="engineering", remote=True))
|
||||
clock.tick(hours=48)
|
||||
store.upsert_role(posting("2", company="Acme", place="Munich",
|
||||
function="sales"))
|
||||
assert [r.source_id for r in store.roles(q="senior engineer")] == ["2", "1"]
|
||||
assert [r.source_id for r in store.roles(q="backend nonsense")] == []
|
||||
assert [r.source_id for r in store.roles(function="engineering")] == ["1"]
|
||||
assert [r.source_id for r in store.roles(remote="remote")] == ["1"]
|
||||
assert [r.source_id for r in store.roles(company="ac")] == ["2", "1"]
|
||||
assert [r.source_id for r in store.roles(place="berlin")] == ["1"]
|
||||
assert [r.source_id for r in store.roles(days=1)] == ["2"]
|
||||
assert [r.source_id for r in store.roles(days=30)] == ["2", "1"]
|
||||
|
||||
|
||||
def test_roles_hide_muted_excludes_before_the_limit(store: Store, clock: Clock) -> None:
|
||||
store.add_company("Acme", key="acme", affinity=-1)
|
||||
store.upsert_role(posting("other", company="Other"))
|
||||
clock.tick()
|
||||
for i in range(3):
|
||||
store.upsert_role(posting(f"a{i}", company="Acme"))
|
||||
clock.tick()
|
||||
# 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"}
|
||||
|
||||
|
||||
def test_mark_closed_closes_what_the_board_no_longer_lists(store: Store) -> None:
|
||||
sub = store.add_subscription("ats", "greenhouse:acme")
|
||||
other = store.add_subscription("ats", "greenhouse:other")
|
||||
@@ -188,6 +220,16 @@ def test_companies_crud(store: Store) -> None:
|
||||
assert store.company("acme") is None
|
||||
|
||||
|
||||
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")
|
||||
store.upsert_role(posting("1", company="Acme", place="Berlin"), sub)
|
||||
store.upsert_role(posting("2", company="Acme", place="Munich"), sub)
|
||||
store.mark_closed("ats", ["1"], sub.id)
|
||||
assert store.open_role_counts() == {"acme": 1}
|
||||
assert store.company_boards() == {"acme": "greenhouse"}
|
||||
|
||||
|
||||
# ----------------------------------------------------------- subscriptions
|
||||
|
||||
def test_subscriptions_crud(store: Store) -> None:
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
"""The JSON API the page calls, against a temp database and FastAPI's
|
||||
TestClient. No network — nothing here touches an ATS host or the queue's own
|
||||
worker beyond starting and stopping it with the app."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from desk.models import Item
|
||||
from roledesk.storage import Store
|
||||
from roledesk.web.app import create_app
|
||||
|
||||
|
||||
class Clock:
|
||||
"""A controllable `Store.clock`, for tests that need upserts to land at
|
||||
distinct, known moments — see `test_storage.py`'s twin of this."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.at = datetime(2026, 9, 23, 9, 0, tzinfo=UTC)
|
||||
|
||||
def __call__(self) -> datetime:
|
||||
return self.at
|
||||
|
||||
def tick(self, hours: float = 1) -> None:
|
||||
self.at += timedelta(hours=hours)
|
||||
|
||||
|
||||
def posting(source_id: str = "1", **raw: object) -> Item:
|
||||
item = Item(source_id=source_id, location=f"https://boards.example/acme/{source_id}",
|
||||
title="Senior Backend Engineer", body="Build things.",
|
||||
published_at=datetime(2026, 9, 20, tzinfo=UTC), raw=dict(raw))
|
||||
item.source = "ats"
|
||||
return item
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app(tmp_path: Path) -> FastAPI:
|
||||
db = tmp_path / "roledesk.db"
|
||||
config_path = tmp_path / "roles.yaml"
|
||||
config_path.write_text(f"database: {db.as_posix()}\n", encoding="utf-8")
|
||||
return create_app(str(config_path))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store(app: FastAPI) -> Store:
|
||||
return app.state.store
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(app: FastAPI) -> Iterator[TestClient]:
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
|
||||
|
||||
# ------------------------------------------------------------------- roles
|
||||
|
||||
def test_list_roles_filters_by_query_place_and_function(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1", company="Acme", place="Berlin", function="engineering"))
|
||||
store.upsert_role(posting("2", company="Acme", place="Munich", function="sales"))
|
||||
store.upsert_role(posting("3", company="Other", place="Berlin", function="engineering"))
|
||||
|
||||
res = client.get("/api/roles", params={"q": "engineer", "place": "Berlin"})
|
||||
assert res.status_code == 200
|
||||
assert {r["source_id"] for r in res.json()} == {"1", "3"}
|
||||
|
||||
res = client.get("/api/roles", params={"function": "sales"})
|
||||
assert [r["source_id"] for r in res.json()] == ["2"]
|
||||
|
||||
res = client.get("/api/roles", params={"company": "other"})
|
||||
assert [r["source_id"] for r in res.json()] == ["3"]
|
||||
|
||||
|
||||
def test_list_roles_limit_is_bounded(client: TestClient, store: Store) -> None:
|
||||
for i in range(3):
|
||||
store.upsert_role(posting(str(i)))
|
||||
assert len(client.get("/api/roles", params={"limit": 1}).json()) == 1
|
||||
assert client.get("/api/roles", params={"limit": 0}).status_code == 422
|
||||
assert client.get("/api/roles", params={"limit": 1001}).status_code == 422
|
||||
|
||||
|
||||
def test_muted_roles_are_hidden_unless_show_muted(client: TestClient, store: Store) -> None:
|
||||
store.add_company("Acme", key="acme")
|
||||
store.upsert_role(posting("1", company="Acme"))
|
||||
store.upsert_role(posting("2", company="Other"))
|
||||
|
||||
assert {r["source_id"] for r in client.get("/api/roles").json()} == {"1", "2"}
|
||||
|
||||
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()} == {"2"}
|
||||
assert {r["source_id"] for r in
|
||||
client.get("/api/roles", params={"show_muted": "true"}).json()} == {"1", "2"}
|
||||
|
||||
|
||||
def test_muted_is_excluded_before_the_limit_not_after(
|
||||
client: TestClient, store: Store) -> None:
|
||||
"""A regression case: filtering a muted company out of an already
|
||||
`LIMIT`-ed page can leave nothing to show, if that company happens to be
|
||||
the newest thing in the database — exactly what a company with hundreds
|
||||
of roles, all freshly (re-)pulled at once, produces."""
|
||||
clock = Clock()
|
||||
store.clock = clock
|
||||
store.add_company("Acme", key="acme", affinity=-1)
|
||||
store.upsert_role(posting("other", company="Other"))
|
||||
clock.tick()
|
||||
for i in range(3):
|
||||
store.upsert_role(posting(f"a{i}", company="Acme"))
|
||||
clock.tick()
|
||||
|
||||
res = client.get("/api/roles", params={"limit": 1})
|
||||
assert [r["source_id"] for r in res.json()] == ["other"]
|
||||
|
||||
|
||||
# --------------------------------------------------------------- companies
|
||||
|
||||
def test_companies_lists_board_and_open_role_count(
|
||||
client: TestClient, store: Store) -> None:
|
||||
sub = store.add_subscription("ats", "greenhouse:acme", company="Acme", board="greenhouse")
|
||||
store.add_company("Acme", key="acme")
|
||||
store.upsert_role(posting("1", company="Acme"), sub)
|
||||
|
||||
res = client.get("/api/companies")
|
||||
assert res.status_code == 200
|
||||
[row] = [c for c in res.json() if c["key"] == "acme"]
|
||||
assert row == {"key": "acme", "name": "Acme", "board": "greenhouse",
|
||||
"affinity": 0, "open_roles": 1}
|
||||
|
||||
|
||||
def test_set_affinity_validates_and_updates(client: TestClient, store: Store) -> None:
|
||||
store.add_company("Acme", key="acme")
|
||||
|
||||
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 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
|
||||
|
||||
|
||||
# ----------------------------------------------------------- applications
|
||||
|
||||
def test_save_creates_an_application_with_a_saved_event(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1", company="Acme", place="Berlin"))
|
||||
uid = posting("1").uid
|
||||
|
||||
res = client.post("/api/applications", json={"role_uid": uid, "status": "saved"})
|
||||
assert res.status_code == 201
|
||||
body = res.json()
|
||||
assert body["role_uid"] == uid
|
||||
assert body["status"] == "saved"
|
||||
assert body["company_key"] == "acme"
|
||||
assert body["next_action"] == "Read the posting and decide"
|
||||
assert body["next_date"] is not None
|
||||
|
||||
events = store.application_events(body["id"])
|
||||
assert [e.status for e in events] == ["saved"]
|
||||
|
||||
# Saving the same role again returns the existing row rather than a
|
||||
# second one.
|
||||
again = client.post("/api/applications", json={"role_uid": uid, "status": "saved"})
|
||||
assert again.json()["id"] == body["id"]
|
||||
|
||||
listed = client.get("/api/applications").json()
|
||||
assert [a["id"] for a in listed] == [body["id"]]
|
||||
assert listed[0]["role_title"] == "Senior Backend Engineer"
|
||||
|
||||
|
||||
def test_save_an_unknown_role_is_refused(client: TestClient) -> None:
|
||||
res = client.post("/api/applications", json={"role_uid": "nope", "status": "saved"})
|
||||
assert res.status_code == 404
|
||||
|
||||
|
||||
def test_set_status_validates_and_writes_an_event(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1", company="Acme"))
|
||||
uid = posting("1").uid
|
||||
saved = client.post("/api/applications", json={"role_uid": uid}).json()
|
||||
|
||||
res = client.post(f"/api/applications/{saved['id']}/status", json={"status": "applied"})
|
||||
assert res.status_code == 200
|
||||
assert res.json()["status"] == "applied"
|
||||
assert [e.status for e in store.application_events(saved["id"])] == ["saved", "applied"]
|
||||
|
||||
assert client.post(f"/api/applications/{saved['id']}/status",
|
||||
json={"status": "ghosted"}).status_code == 422
|
||||
assert client.post("/api/applications/nope/status",
|
||||
json={"status": "applied"}).status_code == 404
|
||||
|
||||
|
||||
# --------------------------------------------------------------------- page
|
||||
|
||||
def test_index_renders_the_shell(client: TestClient) -> None:
|
||||
res = client.get("/")
|
||||
assert res.status_code == 200
|
||||
assert "roledesk" in res.text
|
||||
assert 'id="roles-list"' in res.text
|
||||
assert "<desk-jobs>" in res.text
|
||||
@@ -408,6 +408,18 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/cb/b1/3846dd7f199d53cb17f49cba7e651e9ce294d8497c8c150530ed11865bb8/iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12", size = 7484, upload-time = "2025-10-18T21:55:41.639Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jinja2"
|
||||
version = "3.1.6"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "markupsafe" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/df/bf/f7da0350254c0ed7c72f3e33cef02e048281fec7ecec5f032d4aac52226b/jinja2-3.1.6.tar.gz", hash = "sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d", size = 245115, upload-time = "2025-03-05T20:05:02.478Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67", size = 134899, upload-time = "2025-03-05T20:05:00.369Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "joblib"
|
||||
version = "1.6.0"
|
||||
@@ -593,6 +605,36 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/6a/bd/6e2b76a6c5dee10397db9c929f0c5066766ec1036046f0335b7ca7ca08b8/lxml_html_clean-0.4.5-py3-none-any.whl", hash = "sha256:c76fcadd1e5bfb9b8bafc2200d51e4e78eb0dad67f56881c21dfb6484c7e7746", size = 14573, upload-time = "2026-05-20T12:17:52.215Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "markupsafe"
|
||||
version = "3.0.3"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/7e/99/7690b6d4034fffd95959cbe0c02de8deb3098cc577c67bb6a24fe5d7caa7/markupsafe-3.0.3.tar.gz", hash = "sha256:722695808f4b6457b320fdc131280796bdceb04ab50fe1795cd540799ebe1698", size = 80313, upload-time = "2025-09-27T18:37:40.426Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/33/8a/8e42d4838cd89b7dde187011e97fe6c3af66d8c044997d2183fbd6d31352/markupsafe-3.0.3-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:eaa9599de571d72e2daf60164784109f19978b327a3910d3e9de8c97b5b70cfe", size = 11619, upload-time = "2025-09-27T18:37:06.342Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b5/64/7660f8a4a8e53c924d0fa05dc3a55c9cee10bbd82b11c5afb27d44b096ce/markupsafe-3.0.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:c47a551199eb8eb2121d4f0f15ae0f923d31350ab9280078d1e5f12b249e0026", size = 12029, upload-time = "2025-09-27T18:37:07.213Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/da/ef/e648bfd021127bef5fa12e1720ffed0c6cbb8310c8d9bea7266337ff06de/markupsafe-3.0.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f34c41761022dd093b4b6896d4810782ffbabe30f2d443ff5f083e0cbbb8c737", size = 24408, upload-time = "2025-09-27T18:37:09.572Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/41/3c/a36c2450754618e62008bf7435ccb0f88053e07592e6028a34776213d877/markupsafe-3.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:457a69a9577064c05a97c41f4e65148652db078a3a509039e64d3467b9e7ef97", size = 23005, upload-time = "2025-09-27T18:37:10.58Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/bc/20/b7fdf89a8456b099837cd1dc21974632a02a999ec9bf7ca3e490aacd98e7/markupsafe-3.0.3-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:e8afc3f2ccfa24215f8cb28dcf43f0113ac3c37c2f0f0806d8c70e4228c5cf4d", size = 22048, upload-time = "2025-09-27T18:37:11.547Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/9a/a7/591f592afdc734f47db08a75793a55d7fbcc6902a723ae4cfbab61010cc5/markupsafe-3.0.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:ec15a59cf5af7be74194f7ab02d0f59a62bdcf1a537677ce67a2537c9b87fcda", size = 23821, upload-time = "2025-09-27T18:37:12.48Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/7d/33/45b24e4f44195b26521bc6f1a82197118f74df348556594bd2262bda1038/markupsafe-3.0.3-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:0eb9ff8191e8498cca014656ae6b8d61f39da5f95b488805da4bb029cccbfbaf", size = 21606, upload-time = "2025-09-27T18:37:13.485Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ff/0e/53dfaca23a69fbfbbf17a4b64072090e70717344c52eaaaa9c5ddff1e5f0/markupsafe-3.0.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:2713baf880df847f2bece4230d4d094280f4e67b1e813eec43b4c0e144a34ffe", size = 23043, upload-time = "2025-09-27T18:37:14.408Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/46/11/f333a06fc16236d5238bfe74daccbca41459dcd8d1fa952e8fbd5dccfb70/markupsafe-3.0.3-cp314-cp314-win32.whl", hash = "sha256:729586769a26dbceff69f7a7dbbf59ab6572b99d94576a5592625d5b411576b9", size = 14747, upload-time = "2025-09-27T18:37:15.36Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/28/52/182836104b33b444e400b14f797212f720cbc9ed6ba34c800639d154e821/markupsafe-3.0.3-cp314-cp314-win_amd64.whl", hash = "sha256:bdc919ead48f234740ad807933cdf545180bfbe9342c2bb451556db2ed958581", size = 15341, upload-time = "2025-09-27T18:37:16.496Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/6f/18/acf23e91bd94fd7b3031558b1f013adfa21a8e407a3fdb32745538730382/markupsafe-3.0.3-cp314-cp314-win_arm64.whl", hash = "sha256:5a7d5dc5140555cf21a6fefbdbf8723f06fcd2f63ef108f2854de715e4422cb4", size = 14073, upload-time = "2025-09-27T18:37:17.476Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/3c/f0/57689aa4076e1b43b15fdfa646b04653969d50cf30c32a102762be2485da/markupsafe-3.0.3-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:1353ef0c1b138e1907ae78e2f6c63ff67501122006b0f9abad68fda5f4ffc6ab", size = 11661, upload-time = "2025-09-27T18:37:18.453Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/89/c3/2e67a7ca217c6912985ec766c6393b636fb0c2344443ff9d91404dc4c79f/markupsafe-3.0.3-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:1085e7fbddd3be5f89cc898938f42c0b3c711fdcb37d75221de2666af647c175", size = 12069, upload-time = "2025-09-27T18:37:19.332Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f0/00/be561dce4e6ca66b15276e184ce4b8aec61fe83662cce2f7d72bd3249d28/markupsafe-3.0.3-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1b52b4fb9df4eb9ae465f8d0c228a00624de2334f216f178a995ccdcf82c4634", size = 25670, upload-time = "2025-09-27T18:37:20.245Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/50/09/c419f6f5a92e5fadde27efd190eca90f05e1261b10dbd8cbcb39cd8ea1dc/markupsafe-3.0.3-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:fed51ac40f757d41b7c48425901843666a6677e3e8eb0abcff09e4ba6e664f50", size = 23598, upload-time = "2025-09-27T18:37:21.177Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/22/44/a0681611106e0b2921b3033fc19bc53323e0b50bc70cffdd19f7d679bb66/markupsafe-3.0.3-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:f190daf01f13c72eac4efd5c430a8de82489d9cff23c364c3ea822545032993e", size = 23261, upload-time = "2025-09-27T18:37:22.167Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/5f/57/1b0b3f100259dc9fffe780cfb60d4be71375510e435efec3d116b6436d43/markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:e56b7d45a839a697b5eb268c82a71bd8c7f6c94d6fd50c3d577fa39a9f1409f5", size = 24835, upload-time = "2025-09-27T18:37:23.296Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/26/6a/4bf6d0c97c4920f1597cc14dd720705eca0bf7c787aebc6bb4d1bead5388/markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:f3e98bb3798ead92273dc0e5fd0f31ade220f59a266ffd8a4f6065e0a3ce0523", size = 22733, upload-time = "2025-09-27T18:37:24.237Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/14/c7/ca723101509b518797fedc2fdf79ba57f886b4aca8a7d31857ba3ee8281f/markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:5678211cb9333a6468fb8d8be0305520aa073f50d17f089b5b4b477ea6e67fdc", size = 23672, upload-time = "2025-09-27T18:37:25.271Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/fb/df/5bd7a48c256faecd1d36edc13133e51397e41b73bb77e1a69deab746ebac/markupsafe-3.0.3-cp314-cp314t-win32.whl", hash = "sha256:915c04ba3851909ce68ccc2b8e2cd691618c4dc4c4232fb7982bca3f41fd8c3d", size = 14819, upload-time = "2025-09-27T18:37:26.285Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/1a/8a/0402ba61a2f16038b48b39bccca271134be00c5c9f0f623208399333c448/markupsafe-3.0.3-cp314-cp314t-win_amd64.whl", hash = "sha256:4faffd047e07c38848ce017e8725090413cd80cbc23d86e55c587bf979e579c9", size = 15426, upload-time = "2025-09-27T18:37:27.316Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/70/bc/6f1c2f612465f5fa89b95bead1f44dcb607670fd42891d8fdcd5d039f4f4/markupsafe-3.0.3-cp314-cp314t-win_arm64.whl", hash = "sha256:32001d6a8fc98c8cb5c947787c5d08b0a50663d139f1305bac5885d98d9b40fa", size = 14146, upload-time = "2025-09-27T18:37:28.327Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mypy"
|
||||
version = "2.3.1"
|
||||
@@ -1003,6 +1045,7 @@ version = "0.1.0"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "fastapi" },
|
||||
{ name = "jinja2" },
|
||||
{ name = "newsdesk" },
|
||||
{ name = "pydantic" },
|
||||
{ name = "pyyaml" },
|
||||
@@ -1020,6 +1063,7 @@ dev = [
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "fastapi", specifier = ">=0.110" },
|
||||
{ name = "jinja2", specifier = ">=3.1" },
|
||||
{ name = "newsdesk", editable = "../news" },
|
||||
{ name = "pydantic", specifier = ">=2.6" },
|
||||
{ name = "pyyaml", specifier = ">=6.0" },
|
||||
|
||||
Reference in new issue
Block a user