From f0dc260c9b5735b8c907a28c845d00b6bf58d5d1 Mon Sep 17 00:00:00 2001 From: timmy Date: Wed, 5 Aug 2026 22:17:33 +0000 Subject: [PATCH] fix: serve dashboard independently of process cwd (#46) --- src/views.py | 5 ++++- tests/test_views.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/test_views.py diff --git a/src/views.py b/src/views.py index a891d9f..b16a3ab 100644 --- a/src/views.py +++ b/src/views.py @@ -1,9 +1,12 @@ +from pathlib import Path + from fastapi import APIRouter from fastapi.responses import HTMLResponse router = APIRouter() +DASHBOARD_FILE = Path(__file__).resolve().parent.parent / "frontend" / "index.html" @router.get("/", response_class=HTMLResponse) async def dashboard() -> str: - return open("frontend/index.html").read() + return DASHBOARD_FILE.read_text() diff --git a/tests/test_views.py b/tests/test_views.py new file mode 100644 index 0000000..ea6340b --- /dev/null +++ b/tests/test_views.py @@ -0,0 +1,12 @@ +import pytest + +from src.views import dashboard + + +@pytest.mark.anyio +async def test_dashboard_renders_outside_repository_working_directory(monkeypatch, tmp_path): + monkeypatch.chdir(tmp_path) + + html = await dashboard() + + assert "Stackchain Dashboard" in html -- 2.43.0