Skip to content

Commit 13be5a0

Browse files
committed
feat: add public demo mode
1 parent f6399ed commit 13be5a0

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ python helix_code/live_demo_server.py
121121
- Audit dashboard endpoints: `GET /audit-dashboard` and `GET /api/audit-dashboard`
122122
- Optional operator auth: `HELIX_ADMIN_TOKEN` for runtime, security, dashboard, and receipt surfaces
123123
- Recommended production operator posture: set `HELIX_ADMIN_TOKEN` and `HELIX_ENFORCE_ADMIN_TOKEN=true`
124+
- Hackathon/demo posture: set `HELIX_PUBLIC_DEMO=true` to open only `/` and `/demo-live` while keeping operator surfaces under admin auth
124125
- Recommended production throttling posture: keep operator APIs on `HELIX_OPERATOR_RATE_LIMIT_MAX_REQUESTS=120` / `HELIX_OPERATOR_RATE_LIMIT_WINDOW_SECONDS=60` and audio ingress on `HELIX_AUDIO_INGRESS_MAX_CONNECTIONS=12` / `HELIX_AUDIO_INGRESS_RATE_LIMIT_WINDOW_SECONDS=60` unless measured load requires adjustment
125126
- Recommended production browser posture: set `HELIX_ALLOWED_ORIGINS` to the exact trusted UI origins; otherwise Guardian WebSockets default to same-origin-only in production
126127
- Optional durable receipt envs: `HELIX_RECEIPT_PERSISTENCE`, `HELIX_RECEIPT_STORE_PATH`, `GCS_RECEIPT_BUCKET`

helix_code/live_guardian.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,11 @@ def _admin_auth_enabled() -> bool:
529529
return bool(_configured_admin_token()) or _env_flag("HELIX_ENFORCE_ADMIN_TOKEN")
530530

531531

532+
def _public_demo_enabled() -> bool:
533+
"""[FACT] Optional public demo mode opens only the hackathon demo surface."""
534+
return _env_flag("HELIX_PUBLIC_DEMO")
535+
536+
532537
def _require_admin_token(request: Request) -> str:
533538
"""[FACT] Enforce admin auth on protected request handlers."""
534539
required_token = _configured_admin_token()
@@ -640,6 +645,7 @@ def _runtime_config_snapshot() -> dict[str, Any]:
640645
"audio_audit_allowed_origins": allowed_origins,
641646
"admin_token_required": bool(resolve_admin_token(refresh=True)),
642647
"admin_token_enforced": _env_flag("HELIX_ENFORCE_ADMIN_TOKEN"),
648+
"public_demo_enabled": _public_demo_enabled(),
643649
"guardian_allowed_origins": _guardian_allowed_origins(),
644650
"guardian_origin_enforced": _guardian_origin_enforced(),
645651
},
@@ -1207,15 +1213,18 @@ async def health_check() -> JSONResponse:
12071213
@app.get("/", response_class=HTMLResponse)
12081214
async def root(request: Request) -> HTMLResponse:
12091215
"""[FACT] Root endpoint serves the interactive demo dashboard."""
1210-
gate = _guard_html_page(request, "/")
1211-
if isinstance(gate, HTMLResponse):
1212-
return gate
1216+
gate: str | HTMLResponse = ""
1217+
if not _public_demo_enabled():
1218+
gate = _guard_html_page(request, "/")
1219+
if isinstance(gate, HTMLResponse):
1220+
return gate
12131221

12141222
# Import demo HTML from live_demo_server_html
12151223
from live_demo_server_html import DEMO_HTML
12161224

12171225
response = HTMLResponse(content=DEMO_HTML)
1218-
_set_admin_session_cookie(response, request, gate)
1226+
if gate:
1227+
_set_admin_session_cookie(response, request, gate)
12191228
return response
12201229

12211230

helix_code/tests/test_live_guardian_extended.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,32 @@ def test_audit_dashboard_page_returns_login_form_when_token_missing(self, monkey
526526
assert response.status_code == 401
527527
assert "Admin Access Required" in response.text
528528

529+
def test_root_demo_page_can_be_public_when_enabled(self, monkeypatch) -> None:
530+
"""[FACT] Public demo mode opens only the root demo surface."""
531+
monkeypatch.setenv("HELIX_ADMIN_TOKEN", "secret-token")
532+
monkeypatch.setenv("HELIX_PUBLIC_DEMO", "true")
533+
534+
with TestClient(app) as client:
535+
response = client.get("/")
536+
537+
assert response.status_code == 200
538+
assert "CONSTITUTIONAL GUARDIAN" in response.text
539+
assert "LIVE v1.4.8" in response.text
540+
541+
def test_runtime_config_reports_public_demo_flag(self, monkeypatch) -> None:
542+
"""[FACT] Runtime config reports whether public demo mode is enabled."""
543+
monkeypatch.setenv("HELIX_ADMIN_TOKEN", "secret-token")
544+
monkeypatch.setenv("HELIX_PUBLIC_DEMO", "true")
545+
546+
with TestClient(app) as client:
547+
response = client.get(
548+
"/api/runtime-config",
549+
headers={"X-Helix-Admin-Token": "secret-token"},
550+
)
551+
552+
assert response.status_code == 200
553+
assert response.json()["auth"]["public_demo_enabled"] is True
554+
529555
def test_receipts_api_accepts_custom_admin_header(self, monkeypatch) -> None:
530556
"""[FACT] Receipts API accepts custom admin header."""
531557
monkeypatch.setenv("HELIX_ADMIN_TOKEN", "secret-token")

0 commit comments

Comments
 (0)