Skip to content

Commit e935c79

Browse files
fix(ui): resolve static SPA routing for /, /index.html, and /studio endpoints
1 parent 56a0354 commit e935c79

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

‎codeslim/ui/server.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
Provides REST API endpoints for single-file analysis, optimization, codebase scanning,
55
AI provider health checks, git hook installation, and interactive HTML report export.
66
"""
7+
78
from pathlib import Path
89
from typing import Any
10+
911
import httpx
1012
from fastapi import FastAPI, HTTPException
1113
from fastapi.responses import HTMLResponse
@@ -24,6 +26,7 @@
2426
log = get_logger("codeslim.ui.server")
2527
settings = get_settings()
2628

29+
2730
# Pydantic Schemas
2831
class CodeAnalysisRequest(BaseModel):
2932
code: str = Field(..., description="Python source code snippet")
@@ -234,12 +237,17 @@ def export_html(directory: str = ".") -> HTMLResponse:
234237
html_content = generate_html_observatory_report(report)
235238
return HTMLResponse(content=html_content, status_code=200)
236239

237-
# 7. Serve Web Studio SPA Front-End
240+
# 7. Serve Web Studio SPA Front-End at /, /index.html, and /studio
238241
@app.get("/", response_class=HTMLResponse)
242+
@app.get("/index.html", response_class=HTMLResponse)
243+
@app.get("/studio", response_class=HTMLResponse)
239244
def studio_home() -> HTMLResponse:
240245
index_file = static_dir / "index.html"
241246
if not index_file.exists():
242-
return HTMLResponse("<h1>CodeSlim Web Studio Initializing...</h1>", status_code=200)
247+
return HTMLResponse(
248+
"<h1>CodeSlim Web Studio Initializing...</h1><p>Please refresh in a moment.</p>",
249+
status_code=200,
250+
)
243251
return HTMLResponse(content=index_file.read_text(encoding="utf-8"), status_code=200)
244252

245253
app.mount("/static", StaticFiles(directory=static_dir), name="static")

‎pyproject.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ codeslim = "codeslim.cli:main"
4545
where = ["."]
4646
include = ["codeslim*"]
4747

48+
[tool.setuptools.package-data]
49+
codeslim = ["ui/static/*.html", "ui/static/*"]
50+
4851
[tool.pytest.ini_options]
4952
testpaths = ["tests"]
5053
markers = ["llm: tests that make real LLM calls (slow)"]

‎tests/ui/test_server.py‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
client = TestClient(app)
1111

1212

13+
def test_ui_root_endpoint():
14+
response = client.get("/")
15+
assert response.status_code == 200
16+
assert "CodeSlim Web Studio" in response.text
17+
18+
19+
def test_ui_studio_endpoint():
20+
response = client.get("/studio")
21+
assert response.status_code == 200
22+
assert "CodeSlim Web Studio" in response.text
23+
24+
1325
def test_ui_healthcheck():
1426
response = client.get("/api/v1/healthcheck")
1527
assert response.status_code == 200
@@ -32,7 +44,7 @@ def test_ui_analyze_endpoint():
3244
assert response.status_code == 200
3345
data = response.json()
3446
assert data["grade"] in ["A", "B", "C", "D", "F"]
35-
assert "sys" in data["dead_code_items"] or len(data["dead_code_items"]) >= 0
47+
assert len(data["dead_code_items"]) >= 0
3648

3749

3850
def test_ui_optimize_endpoint_no_llm():
@@ -46,7 +58,6 @@ def test_ui_optimize_endpoint_no_llm():
4658

4759

4860
def test_ui_scan_endpoint(tmp_path):
49-
# Create test python file in temp path
5061
test_file = tmp_path / "sample.py"
5162
test_file.write_text("import sys\ndef hello(): pass\n", encoding="utf-8")
5263

@@ -55,3 +66,12 @@ def test_ui_scan_endpoint(tmp_path):
5566
data = response.json()
5667
assert data["total_files"] == 1
5768
assert data["overall_grade"] in ["A", "B", "C", "D", "F"]
69+
70+
71+
def test_ui_export_html_endpoint(tmp_path):
72+
test_file = tmp_path / "sample.py"
73+
test_file.write_text("import sys\ndef hello(): pass\n", encoding="utf-8")
74+
75+
response = client.get(f"/api/v1/export-html?directory={tmp_path}")
76+
assert response.status_code == 200
77+
assert "<!DOCTYPE html>" in response.text

0 commit comments

Comments
 (0)