Fix Engine static asset resolution

This commit is contained in:
2025-10-22 18:25:21 -06:00
parent 7aa6474a6d
commit 978688ca62
3 changed files with 48 additions and 1 deletions

View File

@@ -42,7 +42,7 @@ The Engine mirrors the legacy defaults so it can boot without additional configu
| `BOREALIS_ROOT` | Overrides automatic project root detection. Useful when running from a packaged location. | Directory two levels above `Data/Engine/` |
| `BOREALIS_DATABASE_PATH` | Path to the SQLite database. | `<project_root>/database.db` |
| `BOREALIS_ENGINE_AUTO_MIGRATE` | Run Engine-managed schema migrations during bootstrap (`true`/`false`). | `true` |
| `BOREALIS_STATIC_ROOT` | Directory that serves static assets for the SPA. | First existing path among `Data/Server/web-interface/build`, `Data/Server/WebUI/build`, `Data/WebUI/build` |
| `BOREALIS_STATIC_ROOT` | Directory that serves static assets for the SPA. | First existing path among `Engine/web-interface/build`, `Engine/web-interface/dist`, `Data/Engine/WebUI/build`, `Data/Server/web-interface/build`, `Data/Server/WebUI/build`, `Data/WebUI/build` |
| `BOREALIS_CORS_ALLOWED_ORIGINS` | Comma-delimited list of origins granted CORS access. Use `*` for all origins. | `*` |
| `BOREALIS_FLASK_SECRET_KEY` | Secret key for Flask session signing. | `change-me` |
| `BOREALIS_DEBUG` | Enables debug logging, disables secure-cookie requirements, and allows Werkzeug debug mode. | `false` |

View File

@@ -112,6 +112,9 @@ def _resolve_static_root(project_root: Path) -> Path:
return Path(candidate).expanduser().resolve()
candidates = (
project_root / "Engine" / "web-interface" / "build",
project_root / "Engine" / "web-interface" / "dist",
project_root / "Data" / "Engine" / "WebUI" / "build",
project_root / "Data" / "Server" / "web-interface" / "build",
project_root / "Data" / "Server" / "WebUI" / "build",
project_root / "Data" / "WebUI" / "build",

View File

@@ -0,0 +1,44 @@
"""Tests for environment configuration helpers."""
from __future__ import annotations
from Data.Engine.config.environment import load_environment
def test_static_root_prefers_engine_runtime(tmp_path, monkeypatch):
"""Engine static root should prefer the staged web-interface build."""
engine_build = tmp_path / "Engine" / "web-interface" / "build"
engine_build.mkdir(parents=True)
(engine_build / "index.html").write_text("<html></html>", encoding="utf-8")
# Ensure other fallbacks exist but should not be selected while the Engine
# runtime assets are present.
legacy_build = tmp_path / "Data" / "Server" / "WebUI" / "build"
legacy_build.mkdir(parents=True)
(legacy_build / "index.html").write_text("legacy", encoding="utf-8")
monkeypatch.setenv("BOREALIS_ROOT", str(tmp_path))
monkeypatch.delenv("BOREALIS_STATIC_ROOT", raising=False)
settings = load_environment()
assert settings.flask.static_root == engine_build.resolve()
def test_static_root_env_override(tmp_path, monkeypatch):
"""Explicit overrides should win over filesystem detection."""
override = tmp_path / "custom" / "build"
override.mkdir(parents=True)
(override / "index.html").write_text("override", encoding="utf-8")
monkeypatch.setenv("BOREALIS_ROOT", str(tmp_path))
monkeypatch.setenv("BOREALIS_STATIC_ROOT", str(override))
settings = load_environment()
assert settings.flask.static_root == override.resolve()
monkeypatch.delenv("BOREALIS_STATIC_ROOT", raising=False)
monkeypatch.delenv("BOREALIS_ROOT", raising=False)