Spec: Gedaechtnis-Haken mit MOTOR_ZEILE ohne AB_SPOT schreibt strom.jsonl in den Ordner aus MOTOR_ZEILE, _hand an die Hauptmotor-Bahnen, Spieler gesalzen; ohne Ordner haengt nichts ein

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-04 18:08:15 +01:00
co-authored by Claude Opus 5.5
parent de287ebb86
commit eb68f6033c
+68
View File
@@ -0,0 +1,68 @@
"""Spezifikation Gedaechtnis-Haken des Laeufers mit MOTOR_ZEILE (04.12., Hauptmotor allein, ohne AB_SPOT): Bei
GEDAECHTNIS2_LAEUFER=1 und MOTOR_ZEILE mit MOTOR_GEDAECHTNIS2=<Ordner> schreibt der Haken strom.jsonl in genau diesen Ordner und gibt
_hand an die Bahnen des Hauptmotors; Spieler nur gesalzen (lesen/vorwissen/kennung.py, Salz VORWISSEN_SALZ bzw. ~/pokerfreak-vorwissen).
Ohne Gedaechtnis-Ordner (weder MOTOR_ZEILE noch AB_SPOT_B) haengt nichts ein: kein Schreiben ins Leere, kein Abbruch."""
import json, os, queue, sys, tempfile
H = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(H, "..", "entscheiden"))
import schatten as S
d = tempfile.mkdtemp(prefix="g2-motorzeile-")
salz = os.path.join(d, "salz.bin")
open(salz, "wb").write(bytes(range(32)))
os.environ["VORWISSEN_SALZ"] = salz
sys.path.insert(0, os.path.join(H, "..", "lesen", "vorwissen"))
import kennung
hs = S.handsatz_mod()
echt_handsatz = hs.handsatz
# Verlauf -> Handsatz ist in handsatz_spec geprueft; hier zaehlt die Verdrahtung: Ordner, Bahnen, Schluessel
hs.handsatz = lambda raum, hand, verlauf, namen, aufgedeckt=None, board=None, jetzt=0, schluessel=lambda n: None: \
{"h": f"{raum}|{hand}", "spieler": schluessel("Alice")}
def stub(env):
m = S.Schatten.__new__(S.Schatten)
m.env, m.spielt, m.ab, m.verworfen = env, True, None, 0
m.schlange, m.tief = queue.Queue(S.SCHLANGE_MAX), queue.Queue(S.SCHLANGE_MAX)
m.vor_bahn = m.flop_bahn = None
m.b_bahnen = ()
return m
ohne = {k: v for k, v in os.environ.items() if k not in ("MOTOR_ZEILE", S.G2_ORDNER, "AB_SPOT", "AB_SPOT_B")}
try:
# 1. MOTOR_ZEILE mit Ordner: Haken an, strom.jsonl genau dort, _hand an beide Hauptmotor-Bahnen, Spieler gesalzen
g2 = os.path.join(d, "g2")
os.makedirs(g2)
S._schatten = stub({**ohne, "MOTOR_ZEILE": f"R0=1;{S.G2_ORDNER}={g2}"})
assert S.einrichten("1") == g2
S.hand("R7", "1001", [{"action": "POST_SB"}], {})
zeilen = [json.loads(z) for z in open(os.path.join(g2, "strom.jsonl"), encoding="ascii")]
assert len(zeilen) == 1 and zeilen[0]["h"] == "R7|1001", zeilen
vw = zeilen[0]["spieler"]
assert vw == kennung.schluessel("Alice") and len(vw) == 16 and "Alice" not in json.dumps(zeilen), vw
for b in (S._schatten.schlange, S._schatten.tief):
z = b.get_nowait()
assert z[1] == {"_hand": zeilen[0], "_schreibe": 0}, z
S.hand("R7", "1001", [{"action": "POST_SB"}], {}) # dieselbe Hand: nicht noch einmal
assert len(open(os.path.join(g2, "strom.jsonl")).read().splitlines()) == 1
assert S._schatten.schlange.qsize() == 0
# 2. ohne Gedaechtnis-Ordner (kein MOTOR_ZEILE, kein AB_SPOT): nichts haengt ein, nichts wird geschrieben, kein Fehler
leer = os.path.join(d, "leer")
os.makedirs(leer)
S._schatten = stub(dict(ohne))
assert S.einrichten("1") is None
S.hand("R7", "1002", [{"action": "POST_SB"}], {})
assert S._schatten.schlange.qsize() == 0 and S._schatten.tief.qsize() == 0
assert os.listdir(leer) == [] and len(open(os.path.join(g2, "strom.jsonl")).read().splitlines()) == 1
# 3. Schalter aus: auch mit Ordner in MOTOR_ZEILE haengt nichts ein
S._schatten = stub({**ohne, "MOTOR_ZEILE": f"{S.G2_ORDNER}={g2}"})
assert S.einrichten("0") is None and S.einrichten(None) is None
finally:
hs.handsatz = echt_handsatz
S._schatten = None
S.gedaechtnis2(None)
print("gedaechtnis2_motorzeile_spec: gruen")