The web page (sicht/seite.html) and the floating web bar (sicht/leiste.py, leiste_mac.js) duplicated what the Swift app already does: panel, ESC Not-Aus (EscRegel, tested in RegelnSpec), click protection via cockpit.json. The server keeps /ws, /api/steuern and /foto; "/" is now 404. start.py always runs server-only, so the app no longer passes --nur-server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
144 lines
6.4 KiB
Python
144 lines
6.4 KiB
Python
"""Cockpit-Panel der Mac-App, Anordnen und Klickschutz: Raster neben dem Panel, Ausweichen nur darunter.
|
|
|
|
Die ESC-Regel (Not-Aus) prueft die App selbst: mac/Tests/Pruefung/RegelnSpec.swift."""
|
|
import json
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
import unittest
|
|
|
|
W = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
os.environ.setdefault("COINPOKER_MOCK", "1") # act laedt dann klonmaus statt click.py
|
|
for _u in ("sicht", "hand", "lesen", "betrieb"):
|
|
sys.path.insert(0, os.path.join(W, _u))
|
|
|
|
import act
|
|
import tische
|
|
|
|
|
|
def _ueberlappen(a, b):
|
|
return a[0] < b[0] + b[2] and b[0] < a[0] + a[2] and a[1] < b[1] + b[3] and b[1] < a[1] + a[3]
|
|
|
|
|
|
class Flaeche(unittest.TestCase):
|
|
def test_ohne_leiste_bleibt_rechts_platz(self):
|
|
self.assertEqual(tische.flaeche((0, 0, 1920, 1040), None), (0, 0, 1920 - tische.LEISTE, 1040))
|
|
|
|
def test_leiste_rechts(self):
|
|
self.assertEqual(tische.flaeche((0, 0, 1920, 1040), (1460, 0, 460, 1040)), (0, 0, 1460, 1040))
|
|
|
|
def test_leiste_links(self):
|
|
self.assertEqual(tische.flaeche((0, 0, 1920, 1040), (0, 0, 460, 1040)), (460, 0, 1460, 1040))
|
|
|
|
|
|
class Raster(unittest.TestCase):
|
|
def test_keiner(self):
|
|
self.assertEqual(tische.raster(0, (0, 0, 1000, 800)), [])
|
|
|
|
def test_einer_fuellt_im_seitenverhaeltnis(self):
|
|
(r,) = tische.raster(1, (0, 0, 1460, 1040))
|
|
self.assertLessEqual(r[2], 1460)
|
|
self.assertLessEqual(r[3], 1040)
|
|
self.assertAlmostEqual(r[2] / r[3], tische.SEITE, delta=0.01)
|
|
|
|
def test_vier_nebeneinander_ohne_ueberlappen(self):
|
|
f = (0, 0, 1460, 1040)
|
|
rs = tische.raster(4, f)
|
|
for i, a in enumerate(rs):
|
|
self.assertTrue(f[0] <= a[0] and a[0] + a[2] <= f[0] + f[2] + 1, a)
|
|
self.assertTrue(f[1] <= a[1] and a[1] + a[3] <= f[1] + f[3] + 1, a)
|
|
for b in rs[i + 1:]:
|
|
self.assertFalse(_ueberlappen(a, b), (a, b))
|
|
|
|
def test_zwoelf_bleiben_in_der_flaeche_und_lesbar(self):
|
|
f = (0, 25, 1452, 875)
|
|
rs = tische.raster(12, f)
|
|
self.assertEqual(len(rs), 12)
|
|
for a in rs:
|
|
self.assertGreaterEqual(a[2], min(tische.MIN_BREITE, f[2]) - 1)
|
|
self.assertTrue(f[0] <= a[0] and a[0] + a[2] <= f[0] + f[2] + 1, a)
|
|
self.assertTrue(f[1] <= a[1] and a[1] + a[3] <= f[1] + f[3] + 1, a)
|
|
self.assertEqual(len({(a[0], a[1]) for a in rs}), 12) # keiner genau unter einem anderen
|
|
|
|
|
|
class Ausweichen(unittest.TestCase):
|
|
def setUp(self):
|
|
self.ordner = tempfile.mkdtemp()
|
|
self.alt = act.COCKPIT, act.AUSWEICHEN, act.time.sleep
|
|
act.COCKPIT = os.path.join(self.ordner, "cockpit.json")
|
|
act.AUSWEICHEN = os.path.join(self.ordner, "ausweichen")
|
|
act.time.sleep = lambda s: None
|
|
|
|
def tearDown(self):
|
|
act.COCKPIT, act.AUSWEICHEN, act.time.sleep = self.alt
|
|
|
|
def _leiste(self, rect, zeit):
|
|
with open(act.COCKPIT, "w", encoding="utf-8") as f:
|
|
json.dump({"rect": rect, "zeit": zeit}, f)
|
|
|
|
def test_ohne_leiste_nichts(self):
|
|
self.assertFalse(act.cockpit_ausweichen(100, 100))
|
|
self.assertFalse(os.path.exists(act.AUSWEICHEN))
|
|
|
|
def test_klick_unter_der_leiste(self):
|
|
jetzt = time.time()
|
|
self._leiste([1460, 0, 460, 1040], jetzt)
|
|
self.assertTrue(act.cockpit_ausweichen(1500, 900, jetzt))
|
|
self.assertTrue(os.path.exists(act.AUSWEICHEN))
|
|
|
|
def test_klick_daneben(self):
|
|
jetzt = time.time()
|
|
self._leiste([1460, 0, 460, 1040], jetzt)
|
|
self.assertFalse(act.cockpit_ausweichen(1000, 900, jetzt))
|
|
self.assertFalse(os.path.exists(act.AUSWEICHEN))
|
|
|
|
def test_veraltete_leiste_zaehlt_nicht(self):
|
|
jetzt = time.time()
|
|
self._leiste([1460, 0, 460, 1040], jetzt - 60)
|
|
self.assertFalse(act.cockpit_ausweichen(1500, 900, jetzt))
|
|
|
|
def test_kaputte_datei(self):
|
|
with open(act.COCKPIT, "w", encoding="utf-8") as f:
|
|
f.write("{halb")
|
|
self.assertFalse(act.cockpit_ausweichen(1500, 900))
|
|
|
|
|
|
class EinTischNachVorn(unittest.TestCase):
|
|
"""Ein Tisch nach vorn (Klick auf seine Karte im Cockpit): echte Tische laufen je als eigener
|
|
Prozess mit roomName=... in der Befehlszeile."""
|
|
PS = ["37562 /Applications/CoinPoker.app/Contents/MacOS/CoinPoker --remote-debugging-port=9333",
|
|
"60467 /Applications/CoinPoker.app/Contents/Resources/unity-resources-arm64/CoinPoker Game.app/"
|
|
"Contents/MacOS/CoinPoker serverIp=x:7000 roomName=Big Ben 1673541 isSuspectedFraud=false tableSize=6",
|
|
"60999 /Applications/CoinPoker.app/Contents/Resources/unity-resources-arm64/CoinPoker Game.app/"
|
|
"Contents/MacOS/CoinPoker serverIp=x:7000 roomName=Big Ben 16735 tableSize=6",
|
|
"70001 python3 -c print('roomName=Big Ben 1673541 x=1')", # Koeder: kein Tischprozess
|
|
"70002 /bin/zsh -c ed CoinPoker Game.app/Contents/MacOS/CoinPoker roomName=Big Ben 777 x=1"]
|
|
|
|
def test_findet_den_prozess_des_raums(self):
|
|
self.assertEqual(tische.pid_fuer_raum(self.PS, "Big Ben 1673541"), 60467)
|
|
self.assertEqual(tische.pid_fuer_raum(self.PS, "Big Ben 16735"), 60999) # kein Praefix-Treffer
|
|
self.assertNotEqual(tische.pid_fuer_raum(list(reversed(self.PS)), "Big Ben 1673541"), 70001)
|
|
|
|
def test_offene_raeume_aus_ps(self):
|
|
self.assertEqual(tische.raeume_aus_ps(self.PS), ["Big Ben 1673541", "Big Ben 16735"]) # ohne Koeder 777
|
|
self.assertEqual(tische.raeume_aus_ps(["kaputt", "", self.PS[0]]), [])
|
|
|
|
def test_debug_port_des_clients(self):
|
|
"""Ohne --remote-debugging-port scheitert jede Lobby-Steuerung ("fetch failed", live 22:51)."""
|
|
mit = "1 /Applications/CoinPoker.app/Contents/MacOS/CoinPoker --remote-debugging-port=9333"
|
|
ohne = "2 /Applications/CoinPoker.app/Contents/MacOS/CoinPoker"
|
|
helfer = "3 /Applications/CoinPoker.app/Contents/Frameworks/CoinPoker Helper.app/Contents/MacOS/CoinPoker Helper --remote-debugging-port=9333"
|
|
self.assertIs(tische.debug_port_aus_ps([mit, helfer]), True)
|
|
self.assertIs(tische.debug_port_aus_ps([ohne, helfer]), False)
|
|
self.assertIsNone(tische.debug_port_aus_ps([helfer, self.PS[1]])) # kein Hauptprozess: unbekannt
|
|
|
|
def test_unbekannter_raum_oder_muell(self):
|
|
self.assertIsNone(tische.pid_fuer_raum(self.PS, "Big Ben 999"))
|
|
self.assertIsNone(tische.pid_fuer_raum(["kaputt", ""], "Big Ben 1"))
|
|
self.assertIsNone(tische.pid_fuer_raum(self.PS, ""))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=1)
|