AP0.4: Feature-, Prompt- und Config-Registry mit Single-Render und Entitlements-Features.
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>
This commit is contained in:
LarsandCursor committed 2026-07-04 23:29:02 +02:00
1 parent f8af47d1d5
commit 53047b6c16
39 files changed
+2404 -34

No files matched your search

+11
View File
@@ -10,6 +10,7 @@ os.environ.setdefault("SKIP_DB_MIGRATE", "1")
os.environ.setdefault("SKIP_SEEDS", "1")
os.environ.setdefault("SKIP_BOOTSTRAP", "1")
os.environ.setdefault("SKIP_RIGHTS_SYNC", "1")
os.environ.setdefault("SKIP_REGISTRY_SYNC", "1")
def _db_available() -> bool:
@@ -57,6 +58,16 @@ def _sync_rights_registry():
assert sync_rights_registry_to_db() == 0
@pytest.fixture(scope="session", autouse=True)
def _sync_prompt_feature_config():
import feature_registrations # noqa: F401
import placeholder_registrations # noqa: F401
import prompt_registrations # noqa: F401
from sync_prompt_feature_config import main as sync_registries
assert sync_registries() == 0
@pytest.fixture()
def client():
import importlib
+66
View File
@@ -0,0 +1,66 @@
"""Configuration registry tests."""
from __future__ import annotations
import pytest
from auth import AUTH_HEADER
from config_service import SECRET_VALUE_FORBIDDEN, get_config, list_configs, upsert_config
from tests.factories import provision_user_in_tenant
def test_global_config_upsert_and_read():
upsert_config(
config_key="test.ap0.config",
scope="global",
value="enabled",
value_type="string",
description="pytest config",
)
item = get_config("test.ap0.config", scope="global")
assert item is not None
assert item["value"] == "enabled"
def test_secret_config_rejects_plaintext():
with pytest.raises(ValueError, match=SECRET_VALUE_FORBIDDEN):
upsert_config(
config_key="test.secret",
scope="global",
value="super-secret-token",
is_secret=True,
)
def test_config_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/config", headers={AUTH_HEADER: token})
assert res.status_code == 200
keys = {item["config_key"] for item in res.json()}
assert "prompt.default_execution_mode" in keys
def test_config_post_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.post(
"/api/config",
json={
"config_key": "test.api.config",
"scope": "global",
"value": True,
"value_type": "boolean",
"description": "via api",
},
headers={AUTH_HEADER: token},
)
assert res.status_code == 200
assert res.json()["config_key"] == "test.api.config"
+2 -1
View File
@@ -28,4 +28,5 @@ def test_entitlements_snapshot_shape(client):
assert "kairo.admin.access" in body["capabilities"]
assert body["enforcement"]["capabilities"] in ("probe", "enforce")
assert body["enforcement"]["features"] == "probe"
assert body["features"] == {}
assert "kairo.prompt.registry" in body["features"]
assert body["features"]["kairo.prompt.registry"]["enabled"] is True
+48
View File
@@ -0,0 +1,48 @@
"""Feature registry tests."""
from __future__ import annotations
import feature_registrations # noqa: F401
from auth import AUTH_HEADER
from db import get_connection
from feature_registry import get_registered_features, sync_features_to_db
from tests.factories import provision_user_in_tenant
def test_feature_registration_required_fields():
keys = {f.key for f in get_registered_features()}
assert keys == {
"kairo.feature.registry",
"kairo.config.registry",
"kairo.prompt.registry",
}
def test_feature_sync_idempotent():
assert sync_features_to_db() == 0
assert sync_features_to_db() == 0
conn = get_connection()
try:
with conn.cursor() as cur:
cur.execute("SELECT COUNT(*) FROM features WHERE is_active = TRUE")
assert cur.fetchone()[0] == 3
finally:
conn.close()
def test_features_in_entitlements(client):
user = provision_user_in_tenant(tenant_role="member", portal_role="user")
login = client.post(
"/api/auth/login",
json={"email": user["email"], "password": user["password"]},
)
token = login.json()["token"]
res = client.get("/api/me/entitlements", headers={AUTH_HEADER: token})
features = res.json()["features"]
assert "kairo.prompt.registry" in features
assert features["kairo.prompt.registry"]["enabled"] is True
assert features["kairo.prompt.registry"]["module"] == "prompt"
def test_features_api_requires_auth(client):
assert client.get("/api/features").status_code == 401
+2
View File
@@ -35,6 +35,7 @@ def test_migration_runner_finds_migrations():
assert "002_auth_identity_tenant_actor" in names
assert "003_data_seeds_tracking" in names
assert "004_capabilities_registry" in names
assert "005_prompt_feature_config_registry" in names
def test_migration_runner_is_idempotent():
@@ -48,6 +49,7 @@ def test_migration_runner_is_idempotent():
assert "002_auth_identity_tenant_actor" in executed
assert "003_data_seeds_tracking" in executed
assert "004_capabilities_registry" in executed
assert "005_prompt_feature_config_registry" in executed
def test_core_table_exists():
+109
View File
@@ -0,0 +1,109 @@
"""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
+8 -1
View File
@@ -15,6 +15,13 @@ def test_registry_contains_initial_capabilities():
"kairo.actor.manage",
"kairo.context.read",
"kairo.entitlements.read",
"kairo.feature.registry.read",
"kairo.feature.registry.manage",
"kairo.prompt.registry.read",
"kairo.prompt.registry.manage",
"kairo.config.registry.read",
"kairo.config.registry.manage",
"kairo.prompt.render",
}
@@ -26,7 +33,7 @@ def test_sync_is_idempotent():
try:
with conn.cursor() as cur:
cur.execute("SELECT COUNT(*) FROM capabilities")
assert cur.fetchone()[0] == 5
assert cur.fetchone()[0] == 12
cur.execute("SELECT COUNT(*) FROM role_capability_grants")
assert cur.fetchone()[0] >= 5
finally: