2026-07-04 22:54:58 +02:00
|
|
|
"""Rights registry and DB sync tests."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import rights_registrations # noqa: F401
|
|
|
|
|
from db import get_connection
|
|
|
|
|
from rights_registry import get_registered_capabilities, sync_rights_registry_to_db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_registry_contains_initial_capabilities():
|
|
|
|
|
keys = {reg.key for reg in get_registered_capabilities()}
|
|
|
|
|
assert keys == {
|
|
|
|
|
"kairo.admin.access",
|
|
|
|
|
"kairo.tenant.manage",
|
|
|
|
|
"kairo.actor.manage",
|
2026-07-05 07:25:01 +02:00
|
|
|
"kairo.actor.read",
|
2026-07-04 22:54:58 +02:00
|
|
|
"kairo.context.read",
|
|
|
|
|
"kairo.entitlements.read",
|
2026-07-04 23:29:02 +02:00
|
|
|
"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",
|
2026-07-05 06:15:40 +02:00
|
|
|
"kairo.initiative.read",
|
|
|
|
|
"kairo.initiative.manage",
|
|
|
|
|
"kairo.action.read",
|
|
|
|
|
"kairo.action.manage",
|
2026-07-05 07:25:01 +02:00
|
|
|
"kairo.workspace.read",
|
2026-07-05 15:11:15 +02:00
|
|
|
"kairo.attention.read",
|
|
|
|
|
"kairo.blocker.read",
|
|
|
|
|
"kairo.blocker.manage",
|
|
|
|
|
"kairo.backlog.read",
|
|
|
|
|
"kairo.backlog.manage",
|
|
|
|
|
"kairo.milestone.read",
|
|
|
|
|
"kairo.milestone.manage",
|
2026-07-05 15:27:03 +02:00
|
|
|
"kairo.evidence.read",
|
|
|
|
|
"kairo.evidence.manage",
|
|
|
|
|
"kairo.decision.read",
|
|
|
|
|
"kairo.decision.manage",
|
|
|
|
|
"kairo.review.read",
|
|
|
|
|
"kairo.review.manage",
|
|
|
|
|
"kairo.recurring.read",
|
|
|
|
|
"kairo.recurring.manage",
|
2026-07-06 06:53:49 +02:00
|
|
|
"kairo.roadmap.reopen",
|
|
|
|
|
"kairo.roadmap.reopen.emergency",
|
2026-07-06 08:19:05 +02:00
|
|
|
"kairo.project.read",
|
|
|
|
|
"kairo.project.manage",
|
2026-07-04 22:54:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_sync_is_idempotent():
|
|
|
|
|
assert sync_rights_registry_to_db() == 0
|
|
|
|
|
assert sync_rights_registry_to_db() == 0
|
|
|
|
|
|
|
|
|
|
conn = get_connection()
|
|
|
|
|
try:
|
|
|
|
|
with conn.cursor() as cur:
|
|
|
|
|
cur.execute("SELECT COUNT(*) FROM capabilities")
|
2026-07-06 08:19:05 +02:00
|
|
|
assert cur.fetchone()[0] == 37
|
2026-07-04 22:54:58 +02:00
|
|
|
cur.execute("SELECT COUNT(*) FROM role_capability_grants")
|
|
|
|
|
assert cur.fetchone()[0] >= 5
|
|
|
|
|
finally:
|
|
|
|
|
conn.close()
|