Merge summaries for saved and liked roles and the order buttons Agent match, CV match, Newest (wp-summaries)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
b481cb5692
20 files changed
+208
-60
No files matched your search
@@ -1,4 +1,4 @@
|
||||
"""The CV match in the feed and the API: Best CV match, Closing soon, the
|
||||
"""The CV match in the feed and the API: CV match, Closing soon, the
|
||||
new row and role fields, the agent's CV fields over `/api/agents`, and the
|
||||
languages suggested from a CV. Nothing here reaches a model."""
|
||||
|
||||
|
||||
@@ -214,3 +214,47 @@ def test_summarise_follows_score_and_finds_nothing_without_a_model(
|
||||
[batch] = stage.finder(config, store)
|
||||
assert len(batch.payload["uids"]) == 2
|
||||
assert stage.kind == "summarise_batch" and stage.callback == cascade.STEP
|
||||
|
||||
|
||||
def test_saved_and_liked_roles_are_waiting_whatever_their_rank(
|
||||
store: Store, config: Config) -> None:
|
||||
"""The owner's picks join the top lists: an application (the star) or an
|
||||
up vote from an enabled agent. A vote from a disabled agent, a pass, a
|
||||
closed role and a role given up on do not."""
|
||||
from app.models import Application
|
||||
|
||||
first, second, saved, liked, passed, disabled_like, closed, given_up = ranked(
|
||||
store, "1", "2", "3", "4", "5", "6", "7", "8")
|
||||
backend = store.agents()[0]
|
||||
quiet = store.save_agent("Quiet", "python", enabled=False)
|
||||
store.save_application(Application(role_uid=saved, company_key="acme", role_title="B"))
|
||||
store.save_application(Application(role_uid=closed, company_key="acme", role_title="B"))
|
||||
store.save_application(Application(role_uid=given_up, company_key="acme", role_title="B"))
|
||||
store.set_vote(backend.id, liked, 1)
|
||||
store.set_vote(backend.id, passed, -1)
|
||||
store.set_vote(quiet.id, disabled_like, 1)
|
||||
with store.transaction() as conn:
|
||||
conn.execute("UPDATE roles SET closed_at = ? WHERE uid = ?", (store.now(), closed))
|
||||
store.summarise_missed([given_up])
|
||||
store.summarise_missed([given_up])
|
||||
store.summarise_missed([given_up])
|
||||
|
||||
waiting = {r.uid for r in store.summarise_waiting(20)}
|
||||
|
||||
assert waiting == {first, second, saved, liked}
|
||||
assert store.summarise_pending() == 4
|
||||
|
||||
|
||||
def test_a_saved_role_is_summarised_once_by_the_stage(
|
||||
store: Store, config: Config, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
from app.models import Application
|
||||
|
||||
*_, deep = ranked(store, "1", "2", "3")
|
||||
store.save_application(Application(role_uid=deep, company_key="acme", role_title="B"))
|
||||
model = stub(monkeypatch)
|
||||
|
||||
modeltask.run(summarise.TASK, config, store)
|
||||
modeltask.run(summarise.TASK, config, store)
|
||||
|
||||
asked = [i["uid"] for batch in model.asked for i in batch]
|
||||
assert sorted(asked) == sorted({deep, posting("1").uid, posting("2").uid})
|
||||
@@ -1807,3 +1807,60 @@ def test_suggest_companies_matches_through_an_alias(client: TestClient, store: S
|
||||
for q in ("orsted", "ørsted", "dong"):
|
||||
res = client.get("/api/suggest/companies", params={"q": q})
|
||||
assert [(c["key"], c["name"]) for c in res.json()] == [("ørsted", "Ørsted")]
|
||||
|
||||
|
||||
def _summary_jobs(queue: Any) -> list[Any]:
|
||||
return [j for j in queue.jobs.snapshot().queued if j.kind == "summarise_batch"]
|
||||
|
||||
|
||||
def test_saving_or_liking_a_role_queues_its_summary_once(
|
||||
app: FastAPI, store: Store, queue: Any, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""With the stage on, a model reachable and the role without a summary, the
|
||||
star and an up vote from an enabled agent queue a batch of that uid under
|
||||
the button's key, so double taps and both together are one job."""
|
||||
from desk.tools import agent
|
||||
|
||||
monkeypatch.setattr(agent, "backend", lambda settings: "api")
|
||||
app.state.config.summarise.enabled = True
|
||||
client = TestClient(app)
|
||||
upsert(store, posting("1"))
|
||||
upsert(store, posting("2"))
|
||||
saved, liked = posting("1").uid, posting("2").uid
|
||||
owner = store.save_agent("A", "python")
|
||||
|
||||
assert client.post("/api/applications", json={"role_uid": saved}).status_code == 201
|
||||
client.post("/api/applications", json={"role_uid": saved})
|
||||
assert [j.payload for j in _summary_jobs(queue)] == [{"uids": [saved]}]
|
||||
|
||||
assert client.post(f"/api/roles/{liked}/vote", json={"value": -1, "agent": owner.id}).status_code == 200
|
||||
assert len(_summary_jobs(queue)) == 1
|
||||
client.post(f"/api/roles/{liked}/vote", json={"value": 1, "agent": owner.id})
|
||||
client.post(f"/api/roles/{liked}/vote", json={"value": 1, "agent": owner.id})
|
||||
assert sorted(j.payload["uids"][0] for j in _summary_jobs(queue)) == sorted([saved, liked])
|
||||
# The button shares the key.
|
||||
assert client.post(f"/api/roles/{liked}/summarise").status_code == 202
|
||||
assert len(_summary_jobs(queue)) == 2
|
||||
|
||||
|
||||
def test_saving_queues_no_summary_when_the_stage_is_off_or_it_has_one(
|
||||
app: FastAPI, store: Store, queue: Any, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
from desk.tools import agent
|
||||
|
||||
monkeypatch.setattr(agent, "backend", lambda settings: "api")
|
||||
client = TestClient(app)
|
||||
upsert(store, posting("1"))
|
||||
upsert(store, posting("2"))
|
||||
off, done = posting("1").uid, posting("2").uid
|
||||
|
||||
client.post("/api/applications", json={"role_uid": off})
|
||||
assert _summary_jobs(queue) == []
|
||||
|
||||
app.state.config.summarise.enabled = True
|
||||
store.set_summary(done, "Already written, long enough.")
|
||||
client.post("/api/applications", json={"role_uid": done})
|
||||
assert _summary_jobs(queue) == []
|
||||
|
||||
monkeypatch.setattr(agent, "backend", lambda settings: "")
|
||||
store.upsert_role(posting("3"))
|
||||
client.post("/api/applications", json={"role_uid": posting("3").uid})
|
||||
assert _summary_jobs(queue) == []
|
||||
Reference in new issue
Block a user