from __future__ import annotations from pathlib import Path AUTH = {"Authorization": "Bearer test-admin-token"} ROOT = Path(__file__).resolve().parent.parent async def test_cron_reindex_urls_requires_admin(app_client): _app, client = app_client assert (await client.post("/admin/cron/reindex-urls")).status_code == 401 async def test_cron_reindex_urls_runs(app_client, monkeypatch): _app, client = app_client # avoid real network/embeddings during the reindex from app.rag import index async def fake_index_source(db, src): src.status = "indexed" return src monkeypatch.setattr(index, "index_source", fake_index_source) await client.post("/admin/tenants", headers=AUTH, json={"slug": "rx"}) await client.post( "/admin/tenants/rx/sources/url", headers=AUTH, json={"kind": "url", "location": "https://rx.com/faq"}, ) r = await client.post("/admin/cron/reindex-urls", headers=AUTH) assert r.status_code == 200 assert r.json()["reindexed"] >= 1 def test_widget_has_proactive_and_starters(): js = (ROOT / "app" / "static" / "widget.js").read_text() assert "ssb-bubble" in js # proactive nudge assert "renderStarters" in js # guided starter chips assert "cfg.starters" in js # chips are per-tenant (not hardcoded) assert "sendText" in js # chips reuse the send path