All checks were successful
Deploy Development / deploy (push) Successful in 38s
Test Suite / pytest-backend (push) Successful in 18s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 24s
Migration 005, Registry-Sync, Placeholder-Validation, capability-geschuetzte API, Tests und Abschlussbericht v0.1. Co-authored-by: Cursor <cursoragent@cursor.com>
110 lines
3.5 KiB
Python
110 lines
3.5 KiB
Python
"""Prompt registry and rendering tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import prompt_registrations # noqa: F401
|
|
from auth import AUTH_HEADER
|
|
from db import get_connection
|
|
from prompt_registry import get_registered_prompts, sync_prompts_to_db
|
|
from prompt_rendering import PromptRenderError, render_prompt_single
|
|
from prompt_validation import PlaceholderValidationError, validate_placeholder_input
|
|
from tests.factories import provision_user_in_tenant
|
|
|
|
|
|
def test_prompt_registry_contains_smoke_prompts():
|
|
keys = {p.prompt_key for p in get_registered_prompts()}
|
|
assert "kairo.system.health_summary" in keys
|
|
assert "kairo.context.debug_summary" in keys
|
|
assert "kairo.pipeline.placeholder" in keys
|
|
|
|
|
|
def test_prompt_sync_idempotent():
|
|
assert sync_prompts_to_db() == 0
|
|
assert sync_prompts_to_db() == 0
|
|
conn = get_connection()
|
|
try:
|
|
with conn.cursor() as cur:
|
|
cur.execute("SELECT COUNT(*) FROM prompt_definitions")
|
|
assert cur.fetchone()[0] >= 4
|
|
cur.execute("SELECT COUNT(*) FROM prompt_steps")
|
|
assert cur.fetchone()[0] >= 1
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def test_placeholder_required_missing():
|
|
try:
|
|
validate_placeholder_input(
|
|
template="Hello {{debug_message}}",
|
|
context_kind="kairo.debug_context",
|
|
values={},
|
|
)
|
|
assert False, "expected validation error"
|
|
except PlaceholderValidationError as exc:
|
|
assert "debug_message" in exc.missing
|
|
|
|
|
|
def test_placeholder_optional_ok():
|
|
meta = validate_placeholder_input(
|
|
template="Level {{debug_level}}",
|
|
context_kind="kairo.debug_context",
|
|
values={"debug_message": "ok"},
|
|
)
|
|
assert "debug_level" in meta["optional_missing"]
|
|
|
|
|
|
def test_render_debug_prompt():
|
|
result = render_prompt_single(
|
|
"kairo.system.health_summary",
|
|
values={"debug_message": "All systems nominal", "debug_level": "info"},
|
|
log_execution=False,
|
|
)
|
|
assert "All systems nominal" in result["rendered_text"]
|
|
assert result["template_source"].startswith("step:")
|
|
|
|
|
|
def test_render_pipeline_mode_rejected():
|
|
try:
|
|
render_prompt_single(
|
|
"kairo.pipeline.placeholder",
|
|
values={"debug_message": "x"},
|
|
log_execution=False,
|
|
)
|
|
assert False, "expected error"
|
|
except PromptRenderError as exc:
|
|
assert exc.code == "mode_not_implemented"
|
|
|
|
|
|
def test_render_api(client):
|
|
user = provision_user_in_tenant(tenant_role="owner", portal_role="admin")
|
|
login = client.post(
|
|
"/api/auth/login",
|
|
json={"email": user["email"], "password": user["password"]},
|
|
)
|
|
token = login.json()["token"]
|
|
client.post(
|
|
"/api/me/tenant",
|
|
json={"tenant_id": user["tenant_id"]},
|
|
headers={AUTH_HEADER: token},
|
|
)
|
|
res = client.post(
|
|
"/api/prompts/kairo.context.debug_summary/render",
|
|
json={"values": {}, "use_context": True},
|
|
headers={AUTH_HEADER: token},
|
|
)
|
|
assert res.status_code == 200
|
|
assert user["tenant_id"] in res.json()["rendered_text"]
|
|
|
|
|
|
def test_prompts_list_api(client):
|
|
user = provision_user_in_tenant(portal_role="admin", tenant_role="owner")
|
|
login = client.post(
|
|
"/api/auth/login",
|
|
json={"email": user["email"], "password": user["password"]},
|
|
)
|
|
token = login.json()["token"]
|
|
res = client.get("/api/prompts", headers={AUTH_HEADER: token})
|
|
assert res.status_code == 200
|
|
keys = {item["prompt_key"] for item in res.json()}
|
|
assert "kairo.system.health_summary" in keys
|