Test migration 32, the cut, saved filters and the override rescore, and bring the READMEs and config comments to fetch text and the cut
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
617356e60c
commit
8b6c6d5ac3
9 files changed
+260
-37
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
from collections.abc import Iterator
|
||||
from datetime import UTC, datetime, timedelta
|
||||
@@ -1778,3 +1779,116 @@ def test_summarise_waits_on_the_top_of_each_enabled_agent_by_its_own_limits(
|
||||
conn.execute("UPDATE agents SET limits = '{}'")
|
||||
assert {r.uid for r in store.summarise_waiting(10)} == {a, b, c}
|
||||
assert store.agents()[0].limits == Limits()
|
||||
|
||||
|
||||
# ------------------------------------------------------------- migration 32
|
||||
|
||||
def _v31(path: Path) -> None:
|
||||
"""Take a file `Store` made back to v31: no cut columns, no saved
|
||||
filters."""
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("DROP INDEX idx_scores_cut")
|
||||
conn.execute("ALTER TABLE scores DROP COLUMN cut")
|
||||
conn.execute("ALTER TABLE scores DROP COLUMN fit")
|
||||
conn.execute("DROP TABLE saved_filters")
|
||||
conn.execute("PRAGMA user_version = 31")
|
||||
|
||||
|
||||
def test_v32_resets_the_limits_drops_prefer_gates_and_renames_enrich(tmp_path: Path) -> None:
|
||||
"""An agent stored before the cut, with the old limits keys, a prefer
|
||||
gate and a `weight` on every gate, loads after migrating; the switch and
|
||||
the queued jobs of `enrich` follow the rename."""
|
||||
from pipeline import Jobs
|
||||
|
||||
path = tmp_path / "v31.db"
|
||||
store = Store(path)
|
||||
upsert(store, posting("a"))
|
||||
Jobs(path)
|
||||
old_gates = [{"field": "country", "values": ["DK"], "mode": "require", "weight": 1.0},
|
||||
{"field": "remote", "values": ["hybrid", "remote"], "mode": "prefer",
|
||||
"weight": 0.05},
|
||||
{"field": "title", "values": ["account executive"], "mode": "exclude",
|
||||
"weight": 1.0}]
|
||||
old_limits = {"extract_top": 500, "extract_min": 0.55, "summarise_top": 30,
|
||||
"summarise_min": 0.65, "judge_top": 150, "judge_min": 0.55,
|
||||
"judge_cv_top": 50}
|
||||
_v31(path)
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("INSERT INTO agents (name, gates, limits, created_at) VALUES (?,?,?,?)",
|
||||
("Wolf", json.dumps(old_gates), json.dumps(old_limits), "2026-10-01"))
|
||||
conn.execute("INSERT INTO agents (name, created_at) VALUES ('Bare', '2026-10-01')")
|
||||
conn.execute("INSERT INTO state (key, value) VALUES ('stage:enrich', 'off')")
|
||||
for kind, state in (("enrich", "queued"), ("enrich_batch", "queued"),
|
||||
("enrich", "done"), ("score", "queued")):
|
||||
conn.execute("INSERT INTO jobs (kind, state, created_at) VALUES (?,?,?)",
|
||||
(kind, state, "2026-10-01"))
|
||||
conn.execute("INSERT INTO schedules (name, kind, cadence, created_at) "
|
||||
"VALUES ('texts', 'enrich', 'every 1d', '2026-10-01')")
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [32]
|
||||
by_name = {a.name: a for a in migrated.agents()}
|
||||
assert by_name["Wolf"].limits == Limits() == by_name["Bare"].limits
|
||||
assert [(g.field, g.mode) for g in by_name["Wolf"].gates] == [
|
||||
("country", "require"), ("title", "exclude")]
|
||||
assert migrated.state["stage:fetch_text"] == "off" and "stage:enrich" not in migrated.state
|
||||
with sqlite3.connect(path) as conn:
|
||||
assert conn.execute("SELECT kind, state FROM jobs ORDER BY id").fetchall() == [
|
||||
("enrich", "done"), ("score", "queued")]
|
||||
assert conn.execute("SELECT kind FROM schedules WHERE name = 'texts'").fetchone() == (
|
||||
"fetch_text",)
|
||||
stored = json.loads(conn.execute(
|
||||
"SELECT gates FROM agents WHERE name = 'Wolf'").fetchone()[0])
|
||||
assert all("weight" not in g for g in stored)
|
||||
agent = by_name["Wolf"]
|
||||
migrated.replace_scores(agent.id, [(posting("a").uid, 0.5, "", "", 0.7, 0.6, "fit")])
|
||||
assert migrated.cut(agent.id) == {posting("a").uid: "fit"}
|
||||
assert migrated.save_filter(agent.id, "Remote", "remote=remote").name == "Remote"
|
||||
|
||||
|
||||
def test_v32_runs_twice_and_keeps_limits_set_since(tmp_path: Path) -> None:
|
||||
path = tmp_path / "v31.db"
|
||||
store = Store(path)
|
||||
agent = store.save_agent("Wolf", limits=Limits(cut_fit_top=900))
|
||||
_v31(path)
|
||||
assert Store(path).migrations_applied == [32]
|
||||
assert Store(path).agent(agent.id).limits == Limits() # type: ignore[union-attr]
|
||||
narrow = Limits(cut_fit_top=900, summarise_top=10)
|
||||
store.save_agent("Wolf", agent_id=agent.id, limits=narrow)
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("PRAGMA user_version = 31") # the columns are there already
|
||||
again = Store(path)
|
||||
assert again.migrations_applied == [32]
|
||||
assert again.agent(agent.id).limits == narrow # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_a_fresh_file_has_the_cut_columns_and_saved_filters(store: Store) -> None:
|
||||
with store.transaction() as conn:
|
||||
columns = {r[1] for r in conn.execute("PRAGMA table_info(scores)")}
|
||||
tables = {r[0] for r in conn.execute("SELECT name FROM sqlite_master")}
|
||||
assert {"fit", "cut", "cv_fit"} <= columns and "saved_filters" in tables
|
||||
|
||||
|
||||
# ------------------------------------------------------------ saved filters
|
||||
|
||||
def test_saved_filters_are_per_agent_named_once_regardless_of_case(store: Store) -> None:
|
||||
one, two = store.save_agent("One"), store.save_agent("Two")
|
||||
remote = store.save_filter(one.id, " Remote only ", "remote=remote&order=newest")
|
||||
store.save_filter(one.id, "berlin", "places=place:berlin")
|
||||
store.save_filter(two.id, "Remote only", "remote=remote")
|
||||
|
||||
assert (remote.name, remote.query) == ("Remote only", "remote=remote&order=newest")
|
||||
assert [f.name for f in store.saved_filters(one.id)] == ["berlin", "Remote only"]
|
||||
with pytest.raises(ValueError, match="already saved"):
|
||||
store.save_filter(one.id, "REMOTE ONLY", "x=1")
|
||||
with pytest.raises(ValueError, match="needs a name"):
|
||||
store.save_filter(one.id, " ", "x=1")
|
||||
with pytest.raises(KeyError):
|
||||
store.save_filter(999, "Nobody", "x=1")
|
||||
|
||||
assert store.delete_filter(remote.id) and not store.delete_filter(remote.id)
|
||||
assert [f.name for f in store.saved_filters(one.id)] == ["berlin"]
|
||||
store.delete_agent(one.id)
|
||||
assert store.saved_filters(one.id) == []
|
||||
assert [f.name for f in store.saved_filters(two.id)] == ["Remote only"]
|
||||
Reference in new issue
Block a user