46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
from app.api.server import chat, critic_feedback, health, resolve_permission, resolve_secret
|
|
from app.core.permission_resolution import PermissionResolutionRequest, SecretResolutionRequest
|
|
from app.api.server import CriticFeedbackRequest
|
|
from app.core.contracts import UserTask
|
|
|
|
|
|
def test_health_handler() -> None:
|
|
assert health() == {"status": "ok"}
|
|
|
|
|
|
def test_chat_handler_returns_runtime_events() -> None:
|
|
body = chat(UserTask(input="hello from handler test"))
|
|
assert body["status"] == "completed"
|
|
assert body["events"][0]["type"] == "task_received"
|
|
|
|
|
|
def test_resolve_permission_handler_allows_completion() -> None:
|
|
initial = chat(UserTask(input="запусти pwd"))
|
|
if initial["status"] == "awaiting_permission":
|
|
body = resolve_permission(
|
|
PermissionResolutionRequest(task_id=initial["task_id"], decision="allow_once")
|
|
)
|
|
assert body["status"] in {"completed", "failed"}
|
|
|
|
|
|
def test_resolve_secret_handler_requires_pending_request() -> None:
|
|
body = resolve_secret(SecretResolutionRequest(task_id="missing", secret="x"))
|
|
assert body["status"] == "failed"
|
|
|
|
|
|
def test_structured_feedback_can_be_accepted_without_memory_write() -> None:
|
|
initial = chat(UserTask(input="feedback target"))
|
|
body = critic_feedback(
|
|
CriticFeedbackRequest(
|
|
task_id=initial["task_id"],
|
|
feedback="wrong answer",
|
|
feedback_type="hallucination",
|
|
severity="major",
|
|
correction="check first",
|
|
remember=False,
|
|
)
|
|
)
|
|
assert body["status"] == "ok"
|
|
assert body["stored"] is False
|
|
assert "hallucination" in body["lesson"]
|