This commit is contained in:
team3
2026-07-13 05:18:55 +02:00
parent 7ee425f7fa
commit 8926f87185
19 changed files with 703 additions and 41 deletions

View File

@@ -0,0 +1,80 @@
"""Spalten-Aktualisierung: Ebene erneut fahren ohne Reset, ohne Status-Rückschritt."""
import db
import pipeline
import pytest
from conftest import topic_anlegen
async def _voll_lauf(topic):
pipeline.lauf_starten(topic)
await pipeline._laeufe[topic]
assert db.one("SELECT status FROM topics WHERE name=?", (topic,))["status"] == "fertig"
async def test_aktualisieren_fuellt_nach_ohne_statusaenderung():
topic = topic_anlegen("akt1")
await _voll_lauf(topic)
# eine verifizierte Flashcard „verlieren" + Kaskade nach artefakte abschalten
opfer = db.one("SELECT ar.id FROM artefakte ar JOIN atome a ON a.id=ar.atom_id"
" WHERE a.topic=? AND ar.typ='flashcard' AND ar.status='verifiziert'",
(topic,))
db.execute("DELETE FROM artefakte WHERE id=?", (opfer["id"],))
db.update("topics", "name", topic, auto=db.j({"artefakte": False}))
run_id = pipeline.aktualisierung_starten(topic, "artefakte")
await pipeline._laeufe[topic]
run = db.one("SELECT * FROM runs WHERE id=?", (run_id,))
assert run["status"] == "done" and "Auto-Stopp nach artefakte" in run["grund"]
# nachgefüllt + Status NICHT zurückgedreht
atom = db.one("SELECT atom_id FROM artefakte WHERE id=?", (opfer["id"],)) or {}
fehlt = db.query("SELECT a.id FROM atome a WHERE a.topic=? AND a.status NOT IN"
" ('gemerged','verworfen') AND NOT EXISTS (SELECT 1 FROM artefakte ar"
" WHERE ar.atom_id=a.id AND ar.typ='flashcard' AND ar.status='verifiziert')",
(topic,))
assert fehlt == []
assert db.one("SELECT status FROM topics WHERE name=?", (topic,))["status"] == "fertig"
async def test_aktualisieren_kaskadiert_mit_auto():
topic = topic_anlegen("akt2")
await _voll_lauf(topic)
run_id = pipeline.aktualisierung_starten(topic, "struktur")
await pipeline._laeufe[topic]
run = db.one("SELECT * FROM runs WHERE id=?", (run_id,))
assert run["status"] == "done" and not (run["grund"] or "").startswith("Auto-Stopp")
assert db.one("SELECT status FROM topics WHERE name=?", (topic,))["status"] == "fertig"
letzte = db.one("SELECT ebene FROM runs WHERE id=?", (run_id,))["ebene"]
assert letzte == "guide" # bis zur letzten Ebene durchgelaufen
async def test_tief_reverifiziert_artefakte_und_guide():
topic = topic_anlegen("akt4")
await _voll_lauf(topic)
vorher = db.one("SELECT COUNT(*) n FROM artefakte ar JOIN atome a ON a.id=ar.atom_id"
" WHERE a.topic=? AND ar.status='verifiziert'", (topic,))["n"]
assert vorher > 0
pipeline._tief_zuruecksetzen(topic, "artefakte")
offen = db.one("SELECT COUNT(*) n FROM artefakte ar JOIN atome a ON a.id=ar.atom_id"
" WHERE a.topic=? AND ar.status='kandidat'", (topic,))["n"]
assert offen == vorher # alles zurück in die Prüfung
pipeline._tief_zuruecksetzen(topic, "guide")
assert db.one("SELECT COUNT(*) n FROM sections s JOIN bausteine b ON b.id=s.baustein_id"
" WHERE b.topic=? AND s.stage='done'", (topic,))["n"] == 0
# tief-Lauf beurteilt alles neu (Fake-Panel: ok) → wieder verifiziert, Status bleibt
db.update("topics", "name", topic, auto=db.j({"artefakte": False}))
pipeline.aktualisierung_starten(topic, "artefakte", tief=True)
await pipeline._laeufe[topic]
nachher = db.one("SELECT COUNT(*) n FROM artefakte ar JOIN atome a ON a.id=ar.atom_id"
" WHERE a.topic=? AND ar.status='verifiziert'", (topic,))["n"]
assert nachher >= vorher
assert db.one("SELECT status FROM topics WHERE name=?", (topic,))["status"] == "fertig"
async def test_aktualisieren_guards():
topic = topic_anlegen("akt3")
with pytest.raises(ValueError):
pipeline.aktualisierung_starten(topic, "gibtsnicht")
pipeline.lauf_starten(topic)
with pytest.raises(RuntimeError):
pipeline.aktualisierung_starten(topic, "artefakte")
await pipeline._laeufe[topic]