Self-hosted knowledge management for SMEs: a split-screen Markdown editor whose sections an LLM refines while you write, and RAG question answering over the documents that result. FastAPI + Postgres/pgvector on the back, SvelteKit on the front, everything OpenAI-compatible and self-hostable. Squashed into a single commit; the development history stays local. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CA43ZJda8Rbp2hKXNy8f6b
53 lines
1.9 KiB
Python
53 lines
1.9 KiB
Python
"""Admin-editable system prompts: override without a restart, reset to default."""
|
|
|
|
from httpx import AsyncClient
|
|
|
|
from app.prompts.defaults import DEFAULTS
|
|
from app.prompts.overrides import get_prompt
|
|
|
|
|
|
async def _login(client: AsyncClient, email: str) -> None:
|
|
response = await client.post(
|
|
"/api/auth/login", json={"email": email, "password": "secret123"}
|
|
)
|
|
assert response.status_code == 200
|
|
|
|
|
|
async def test_prompts_require_admin(client: AsyncClient, seeded_user) -> None:
|
|
await _login(client, "pablo@test.dev")
|
|
assert (await client.get("/api/admin/prompts")).status_code == 403
|
|
|
|
|
|
async def test_prompt_override_applies_and_resets(
|
|
client: AsyncClient, seeded_admin
|
|
) -> None:
|
|
await _login(client, "florian@test.dev")
|
|
|
|
listed = (await client.get("/api/admin/prompts")).json()
|
|
keys = {prompt["key"] for prompt in listed}
|
|
assert {"query_system", "refine_rules", "title"} <= keys
|
|
assert all(prompt["is_default"] for prompt in listed)
|
|
|
|
# Overriding applies immediately (get_prompt reads the refreshed cache).
|
|
put = await client.put(
|
|
"/api/admin/prompts/query_system",
|
|
json={"content": "You are a test assistant."},
|
|
)
|
|
assert put.status_code == 200
|
|
assert put.json()["is_default"] is False
|
|
assert get_prompt("query_system") == "You are a test assistant."
|
|
|
|
# An empty prompt is rejected; an unknown key is a 404.
|
|
assert (
|
|
await client.put("/api/admin/prompts/query_system", json={"content": " "})
|
|
).status_code == 422
|
|
assert (
|
|
await client.put("/api/admin/prompts/nope", json={"content": "x"})
|
|
).status_code == 404
|
|
|
|
# Resetting restores the shipped default.
|
|
reset = await client.put("/api/admin/prompts/query_system", json={"reset": True})
|
|
assert reset.status_code == 200
|
|
assert reset.json()["is_default"] is True
|
|
assert get_prompt("query_system") == DEFAULTS["query_system"]
|