Files
de-praxis/scripts/smoke.py
T
juli 64b0379056 Run live rooms on the campaign engine with protocol v2
- Rooms hold seats plus engine GameState and pin their campaign by hash
  under DATA_DIR/campaigns/pinned; CampaignLibrary offers the built-ins
- Protocol v2: campaign-defined roles and actions, personal snapshots with
  filtered logs, hidden goals, action menus with relay-computed check
  previews, exits, items and stats; structured rolls in the log
- GET /campaigns and GET /rooms/{code}/lobby; /health reports api 2; room
  requests without X-DePraxis-Api: 2 get a 426 "update the app" message
- Narrator takes the campaign brief and only the public log
- Actions can be limited to roles; Hollow Point's Burn uses it
- App: campaign picker, per-campaign roles, lobby lookup before joining,
  server-driven action menu with move/exit chooser, items, stats, statuses,
  campaign clock and endings with debriefs; rolls from structured data
- Original Dead Channel rules kept in tests as the parity reference
- Smoke scripts, Caddyfile and architecture docs updated
2026-10-25 02:46:50 +02:00

49 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""Exercise a running relay without third-party Python dependencies."""
import json
import sys
import urllib.error
import urllib.request
base = (sys.argv[1] if len(sys.argv) > 1 else "http://127.0.0.1:1337").rstrip("/")
def call(path, body=None, token=None, expected=200):
headers = {"Content-Type": "application/json", "X-DePraxis-Api": "2"}
if token:
headers["Authorization"] = "Bearer " + token
request = urllib.request.Request(base + path, data=None if body is None else json.dumps(body).encode(), headers=headers)
try:
with urllib.request.urlopen(request, timeout=15) as response:
status, result = response.status, json.load(response)
except urllib.error.HTTPError as error:
status, result = error.code, json.load(error)
assert status == expected, (path, status, result)
return result
health = call("/health")
assert health["status"] == "ok" and health["api"] == 2, health
assert "dead-channel" in [c["id"] for c in call("/campaigns")]
host = call("/rooms", {"name": "Smoke engineer", "role": "engineer", "campaign": "dead-channel"}, expected=201)
code = host["snapshot"]["code"]
path = "/rooms/" + code
assert call(path + "/lobby")["joinable"]
guest = call(path + "/join", {"name": "Smoke analyst", "role": "analyst"})
call(path, token="invalid", expected=401)
call(path + "/start", {}, guest["token"], expected=403)
call(path + "/start", {}, host["token"])
action = {"requestId": "smoke-host-1", "round": 1, "action": "observe", "text": "Read the maintenance annotation."}
pending = call(path + "/actions", action, host["token"])
assert pending["round"] == 1 and pending["clock"] == 12
assert pending["players"][0]["submitted"]
resolved = call(path + "/actions", {**action, "requestId": "smoke-guest-1"}, guest["token"])
assert resolved["round"] == 2 and resolved["clock"] == 11
# Snapshots are personal (check previews depend on role), so a replay must match the host's own view.
replayed = call(path + "/actions", action, host["token"])
assert replayed == call(path, token=host["token"]) and replayed["round"] == 2
assert host["token"] not in json.dumps(resolved)
assert guest["token"] not in json.dumps(resolved)
call(path + "/actions", {**action, "requestId": "stale"}, host["token"], expected=409)
print("PASS: health, campaigns, lobby, crew join, authorization, simultaneous resolution, replay protection, token privacy, stale-round rejection")