Wire the app like the boilerplate: door, queue, schedules, eight tabs
app/main.py assembles it in the boilerplate's order, auth.connect first, then the queue with the scheduler and the pages. TABS is Roles, Applications, Agents, Companies, Jobs, Schedules, Messages and Account: the alpha page's three views become templates on the boilerplate's base.html, driven by static/roles.js (the old app.js) through api() and toasts.js, over the unchanged JSON routes. Companies lists every board with its open roles and the affinity control. A 422 is one sentence, so a toast never reads [object Object]. Config takes the boilerplate's shape: APP_CONFIG or config.yaml, a missing file is the defaults, an unknown key is an error. roles.yaml is gone; config.yaml is the committed default and carries the starter agents. pull is now a job that asks for the pull cascade, because a schedule enqueues a job kind; its default schedule, every 6h, is declared beside it in app/jobs/cascade.py. pull_batch's targets are keyword-only so the Jobs tab offers no batch button. `app worker` is the boilerplate's; `app job` still drains a queue of its own and fires no schedules. test_coupling holds pipeline, auth and desk apart (desk may import pipeline) and plugins to desk; test_architecture keeps app's layers, now with main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
24508dd6fc
commit
59a301c351
42 files changed
+2407
-998
No files matched your search
+85
-14
@@ -1,4 +1,4 @@
|
||||
"""The JSON API the page calls, against a temp database and FastAPI's
|
||||
"""The tabs and the JSON API they call, 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."""
|
||||
|
||||
@@ -12,9 +12,12 @@ import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from desk.models import Item
|
||||
from app.config import Config, ServerConfig
|
||||
from app.main import create_app
|
||||
from app.storage import Store
|
||||
from app.web.app import create_app
|
||||
from app.web import TABS
|
||||
from auth import AuthConfig
|
||||
from desk.models import Item
|
||||
|
||||
|
||||
class Clock:
|
||||
@@ -41,10 +44,10 @@ def posting(source_id: str = "1", **raw: object) -> 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))
|
||||
"""The database in `tmp_path` and the config passed in, so a test never
|
||||
touches `roledesk.db` and two tests never share a jobs table."""
|
||||
return create_app(Config(server=ServerConfig(host="127.0.0.1", port=0),
|
||||
database=tmp_path / "roledesk.db"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -195,14 +198,82 @@ def test_set_status_validates_and_writes_an_event(
|
||||
json={"status": "applied"}).status_code == 404
|
||||
|
||||
|
||||
# --------------------------------------------------------------------- page
|
||||
# -------------------------------------------------------------------- tabs
|
||||
|
||||
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
|
||||
def test_every_tab_renders_with_the_whole_nav(client: TestClient) -> None:
|
||||
assert [t.label for t in TABS] == ["Roles", "Applications", "Agents", "Companies",
|
||||
"Jobs", "Schedules", "Messages", "Account"]
|
||||
for tab in TABS:
|
||||
res = client.get(tab.path)
|
||||
assert res.status_code == 200, f"{tab.path} answered {res.status_code}"
|
||||
assert "roledesk</title>" in res.text
|
||||
for other in TABS:
|
||||
assert f">{other.label}</a>" in res.text
|
||||
|
||||
|
||||
def test_each_roledesk_tab_is_a_shell_for_roles_js(client: TestClient) -> None:
|
||||
for path, container in [("/", 'id="roles-list"'),
|
||||
("/applications", 'id="applications-list"'),
|
||||
("/agents", 'id="agents-list"'),
|
||||
("/companies", 'id="companies-list"')]:
|
||||
page = client.get(path).text
|
||||
assert container in page and "/static/roles.js" in page
|
||||
# toasts.js before app.js before the page's own script: `api()` needs
|
||||
# `window.toast`, and roles.js needs `api()`.
|
||||
assert page.index("toasts.js") < page.index("app.js") < page.index("roles.js")
|
||||
assert "ROLEDESK_STATUSES" in client.get("/applications").text
|
||||
assert client.get("/static/roles.js").status_code == 200
|
||||
|
||||
|
||||
def test_the_modules_bring_their_own_elements(client: TestClient) -> None:
|
||||
assert "<desk-jobs>" in client.get("/jobs").text
|
||||
assert "<desk-schedules>" in client.get("/schedules").text
|
||||
assert "<auth-account>" in client.get("/account").text
|
||||
|
||||
|
||||
def test_pull_is_declared_every_six_hours(client: TestClient) -> None:
|
||||
rows = {r["name"]: r for r in client.get("/api/schedules").json()}
|
||||
assert rows["pull"]["kind"] == "pull"
|
||||
assert rows["pull"]["cadence"] == "every 6h"
|
||||
assert rows["pull"]["enabled"] is True and rows["pull"]["unknown"] is False
|
||||
|
||||
|
||||
def test_the_jobs_tab_offers_pull_once_and_no_batch(client: TestClient) -> None:
|
||||
"""A subset rather than the list: `pipeline/tests` registers kinds of its
|
||||
own into the same global `JOBS` when the whole suite runs."""
|
||||
kinds = [k["kind"] for k in client.get("/api/jobs/kinds").json()]
|
||||
assert {"embed", "extract", "pull", "score"} <= set(kinds)
|
||||
assert kinds.count("pull") == 1
|
||||
assert not {"pull_batch", "extract_batch", "advance"} & set(kinds)
|
||||
|
||||
|
||||
def test_an_error_is_one_sentence(client: TestClient) -> None:
|
||||
"""`api()` toasts `detail` as it is, so a 422 is a sentence, not a list."""
|
||||
res = client.post("/api/agents", json={"name": "Bad",
|
||||
"gates": [{"field": "salary", "values": [1]}]})
|
||||
assert res.status_code == 422
|
||||
assert "gates.0.field" in res.json()["detail"]
|
||||
missing = client.get("/nothing-here")
|
||||
assert missing.status_code == 404 and "text/html" in missing.headers["content-type"]
|
||||
|
||||
|
||||
def test_health_is_open_and_reads_the_store(client: TestClient) -> None:
|
||||
assert client.get("/health").json() == {"ok": True, "open_roles": 0}
|
||||
|
||||
|
||||
def test_a_locked_app_shuts_every_tab_and_the_api(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("APP_PASSWORD", "open-sesame-please")
|
||||
config = Config(server=ServerConfig(host="127.0.0.1", port=0),
|
||||
database=tmp_path / "locked.db", auth=AuthConfig(enabled="always"))
|
||||
with TestClient(create_app(config), follow_redirects=False) as locked:
|
||||
for tab in TABS:
|
||||
assert locked.get(tab.path).status_code == 303
|
||||
assert locked.get("/api/roles").status_code == 401
|
||||
assert locked.get("/health").status_code == 200
|
||||
signed_in = locked.post("/login", json={"password": "open-sesame-please"})
|
||||
assert signed_in.status_code == 200
|
||||
assert locked.get("/api/roles").status_code == 200
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ agents
|
||||
|
||||
Reference in new issue
Block a user