53 lines
2.3 KiB
Python
53 lines
2.3 KiB
Python
"""Lektorat: EIN Blick über den ganzen Guide, Befunde in die Fix-Maschine."""
|
|
from backend import db, guide
|
|
from .conftest import topic_anlegen
|
|
|
|
|
|
def _guide_anlegen(topic):
|
|
kid = db.insert("kapitel", topic=topic, titel="K1", ord=0)
|
|
bids = []
|
|
for i in range(2):
|
|
zid = db.insert("lernziele", topic=topic, text=f"z{i}")
|
|
bid = db.insert("bausteine", topic=topic, ziel_id=zid, titel=f"B{i}",
|
|
kapitel_id=kid, ord=i)
|
|
db.insert("sections", baustein_id=bid, text=f"Text der Section {i}.")
|
|
bids.append(bid)
|
|
return bids
|
|
|
|
|
|
async def test_lektorat_meldet_befund(monkeypatch):
|
|
from backend import llm as llm_mod
|
|
topic = topic_anlegen()
|
|
run_id = db.insert("runs", topic=topic, status="running")
|
|
bids = _guide_anlegen(topic)
|
|
tid = db.insert("tasks", run_id=run_id, topic=topic, knoten="lektorat",
|
|
item="r1:lektorat", status="laufend")
|
|
|
|
async def antwort(**kw):
|
|
assert f"[SECTION {bids[1]}]" in kw["werte"]["guide"]
|
|
return (f"===BEFUND===\nSECTION: {bids[1]}\nART: redundanz\n"
|
|
f"DETAIL: Fakt doppelt erklärt, kürzen.")
|
|
|
|
monkeypatch.setattr(llm_mod, "call", antwort)
|
|
erg = await guide.lektorat({"id": tid, "run_id": run_id, "topic": topic,
|
|
"knoten": "lektorat", "runde": 1,
|
|
"item": "r1:lektorat", "payload": "{}"})
|
|
assert erg.daten["befunde"] == 1
|
|
b = db.one("SELECT * FROM befunde WHERE run_id=? AND knoten='lektorat'",
|
|
run_id)
|
|
assert b["art"] == "redundanz" and b["item"] == f"baustein:{bids[1]}"
|
|
|
|
|
|
async def test_lektorat_laeuft_nur_einmal(monkeypatch):
|
|
topic = topic_anlegen()
|
|
run_id = db.insert("runs", topic=topic, status="running")
|
|
_guide_anlegen(topic)
|
|
db.insert("tasks", run_id=run_id, topic=topic, knoten="lektorat",
|
|
item="r1:lektorat", status="fertig")
|
|
t2 = db.insert("tasks", run_id=run_id, topic=topic, knoten="lektorat",
|
|
item="r2:lektorat", status="laufend")
|
|
erg = await guide.lektorat({"id": t2, "run_id": run_id, "topic": topic,
|
|
"knoten": "lektorat", "runde": 2,
|
|
"item": "r2:lektorat", "payload": "{}"})
|
|
assert erg.daten.get("skip")
|