Skip to content

Commit 1b42179

Browse files
author
Dylan Huang
committed
TODO: test HTML injection
- also test TestAsyncWebSocketOperations
1 parent 88f0f3a commit 1b42179

2 files changed

Lines changed: 24 additions & 23 deletions

File tree

eval_protocol/utils/vite_server.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,17 @@ def _setup_routes(self):
9797
# Mount static files
9898
self.app.mount("/assets", StaticFiles(directory=self.build_dir / "assets"), name="assets")
9999

100-
# Serve other static files from build directory
100+
@self.app.get("/")
101+
async def root():
102+
"""Serve the main index.html file with injected configuration."""
103+
return self._serve_index_with_config()
104+
105+
@self.app.get("/health")
106+
async def health():
107+
"""Health check endpoint."""
108+
return {"status": "ok", "build_dir": str(self.build_dir)}
109+
110+
# Serve other static files from build directory - this must be last
101111
@self.app.get("/{path:path}")
102112
async def serve_spa(path: str):
103113
"""
@@ -114,22 +124,12 @@ async def serve_spa(path: str):
114124

115125
# For SPA routing, serve index.html for non-existent routes
116126
# but exclude API routes and asset requests
117-
if not path.startswith(("api/", "assets/")):
127+
if not path.startswith(("api/", "assets/", "health")):
118128
return self._serve_index_with_config()
119129

120130
# If we get here, the file doesn't exist and it's not a SPA route
121131
raise HTTPException(status_code=404, detail="File not found")
122132

123-
@self.app.get("/")
124-
async def root():
125-
"""Serve the main index.html file with injected configuration."""
126-
return self._serve_index_with_config()
127-
128-
@self.app.get("/health")
129-
async def health():
130-
"""Health check endpoint."""
131-
return {"status": "ok", "build_dir": str(self.build_dir)}
132-
133133
def run(self):
134134
"""
135135
Run the Vite server.

tests/test_logs_server.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,22 @@ class TestLogsServerIntegration:
378378

379379
@pytest.fixture
380380
def temp_build_dir_with_files(self):
381-
"""Create a temporary build directory with various test files."""
381+
"""Create a temporary build directory with index.html and assets/ directory."""
382382
with tempfile.TemporaryDirectory() as temp_dir:
383383
temp_path = Path(temp_dir)
384384

385385
# Create index.html
386386
(temp_path / "index.html").write_text("<html><body>Test</body></html>")
387387

388-
# Create some static assets
389-
(temp_path / "static").mkdir()
390-
(temp_path / "static" / "app.js").write_text("console.log('test');")
391-
(temp_path / "static" / "style.css").write_text("body { color: black; }")
388+
# Create assets directory and some files inside it
389+
assets_dir = temp_path / "assets"
390+
assets_dir.mkdir()
391+
(assets_dir / "app.js").write_text("console.log('test');")
392+
(assets_dir / "style.css").write_text("body { color: black; }")
392393

393-
# Create a nested directory structure
394-
(temp_path / "nested").mkdir()
395-
(temp_path / "nested" / "file.txt").write_text("nested content")
394+
# Optionally, create a nested directory inside assets
395+
(assets_dir / "nested").mkdir()
396+
(assets_dir / "nested" / "file.txt").write_text("nested content")
396397

397398
yield temp_path
398399

@@ -407,11 +408,11 @@ def test_static_file_serving(self, temp_build_dir_with_files):
407408
assert "Test" in response.text
408409

409410
# Test serving static files
410-
response = client.get("/static/app.js")
411+
response = client.get("/assets/app.js")
411412
assert response.status_code == 200
412413
assert "console.log('test')" in response.text
413414

414-
response = client.get("/static/style.css")
415+
response = client.get("/assets/style.css")
415416
assert response.status_code == 200
416417
assert "color: black" in response.text
417418

@@ -442,7 +443,7 @@ def test_health_endpoint(self, temp_build_dir_with_files):
442443
response = client.get("/health")
443444
assert response.status_code == 200
444445
data = response.json()
445-
assert data["status"] == "healthy"
446+
assert data["status"] == "ok"
446447

447448

448449
@pytest.mark.asyncio

0 commit comments

Comments
 (0)