runbook-tutorials/tests/test_feedback.py
tegwick c17b43264d
Some checks failed
CI Smoke / host-smoke (push) Successful in 1s
CI Smoke / container-smoke (push) Successful in 4s
Work Records / validate (push) Has been cancelled
Add smiley feedback collector with comment after a completed run (RBT-WP-0004-T12)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Assistant: claude-code
Assistant-Model: sonnet
Assistant-Process: 295952@bnt-lap001
Assistant-Session: e93f64ad-516c-46eb-9666-aad8d300c477
2026-09-29 11:10:25 +02:00

41 lines
1.3 KiB
Python

import shutil
from pathlib import Path
import pytest
from rtut import pack as P, run as R
ROOT = Path(__file__).resolve().parent.parent
@pytest.fixture
def pk(tmp_path):
d = tmp_path / "runbooks" / "hello"; d.mkdir(parents=True)
shutil.copy(ROOT / "runbooks/example-hello/pack.yaml", d / "pack.yaml")
return P.load(d / "pack.yaml")
def test_feedback_latest_wins_and_history_kept(pk):
r = R.create(pk, "bernd")
R.add_feedback(r, "poor", "confusing start")
R.add_feedback(r, "good", "fine after a second look")
r2 = R.load(pk, r.data["run_id"])
assert len(r2.data["feedback"]) == 2
assert R.latest_feedback(r2)["rating"] == "good"
def test_feedback_rejects_bad_rating_and_secrets(pk):
r = R.create(pk, "bernd")
with pytest.raises(R.RunError):
R.add_feedback(r, "great")
with pytest.raises(R.RunError):
R.add_feedback(r, "good", "-----BEGIN RSA PRIVATE KEY-----")
assert "feedback" not in R.load(pk, r.data["run_id"]).data
def test_all_feedback_lists_newest_first(pk):
a = R.create(pk, "ann"); b = R.create(pk, "bob"); R.create(pk, "cy") # cy gives none
R.add_feedback(a, "good", "one")
R.add_feedback(b, "poor", "two")
got = R.all_feedback(pk)
assert [g["operator"] for g in got] == ["bob", "ann"]