From 4392df8d0c05714ba5dddfebe23341ffdb4e2e55 Mon Sep 17 00:00:00 2001 From: codex Date: Thu, 21 May 2026 05:40:15 -0300 Subject: [PATCH] game-stream: add Wolf control dashboard --- ariadne/app_game_routes.py | 227 ++++++++++++++++++++++++- tests/unit/app/test_app_game_routes.py | 10 ++ 2 files changed, 236 insertions(+), 1 deletion(-) diff --git a/ariadne/app_game_routes.py b/ariadne/app_game_routes.py index f842323..7bc203e 100644 --- a/ariadne/app_game_routes.py +++ b/ariadne/app_game_routes.py @@ -1,11 +1,12 @@ from __future__ import annotations from datetime import datetime, timezone +from html import escape import secrets from typing import Any, Callable from fastapi import Depends, FastAPI, HTTPException, Request -from fastapi.responses import JSONResponse +from fastapi.responses import HTMLResponse, JSONResponse from .auth.keycloak import AuthContext from .db.storage import TaskRunRecord @@ -100,7 +101,231 @@ def _ensure_wolf_oauth2(module: Any, ctx: AuthContext) -> JSONResponse: _record_simple_task(module, "wolf_oidc_ensure", started, status, detail or None) +def _dashboard_html(ctx: AuthContext) -> str: + display_name = escape(ctx.username or ctx.email or "player") + return f""" + + + + + Wolf Game Stream + + + +
+
+
+

Wolf Game Stream

+
Signed in as {display_name}
+
+ checking +
+
+
+

Profile

+
+
+
+

Game Mode

+
+
+
+

Controls

+
+ + +
+
+ + + +
+
+
+

Result

+
Ready.
+
+
+
+ + +""" + + def _register_game_routes(app: FastAPI, require_auth: Callable, deps: Callable[[], Any]) -> None: + @app.get("/", response_class=HTMLResponse) + @app.get("/game-stream", response_class=HTMLResponse) + def get_game_stream_dashboard(ctx: AuthContext = Depends(require_auth)) -> HTMLResponse: + """Return the authenticated Wolf game-stream control surface.""" + + return HTMLResponse(_dashboard_html(ctx)) + @app.get("/api/game-stream/me") def get_game_stream_profile(ctx: AuthContext = Depends(require_auth)) -> JSONResponse: """Return the Wolf profile policy for the authenticated Keycloak user.""" diff --git a/tests/unit/app/test_app_game_routes.py b/tests/unit/app/test_app_game_routes.py index 6f8c40c..ba9c904 100644 --- a/tests/unit/app/test_app_game_routes.py +++ b/tests/unit/app/test_app_game_routes.py @@ -1,6 +1,16 @@ from tests.unit.app.app_route_helpers import * +def test_game_stream_dashboard(monkeypatch) -> None: + ctx = AuthContext(username="bstein", email="", groups=["admin"], claims={}) + client = _client(monkeypatch, ctx) + + resp = client.get("/", headers={"Authorization": "Bearer token"}) + assert resp.status_code == 200 + assert "Wolf Game Stream" in resp.text + assert "/api/admin/game-mode/${kind}" in resp.text + + def test_game_stream_profile_me(monkeypatch) -> None: ctx = AuthContext(username="brad", email="", groups=["game-stream-users"], claims={}) client = _client(monkeypatch, ctx)