From 978688ca62a7313f1212e9e38e6c7111aaed2528 Mon Sep 17 00:00:00 2001 From: Nicole Rappe Date: Wed, 22 Oct 2025 18:25:21 -0600 Subject: [PATCH] Fix Engine static asset resolution --- Data/Engine/README.md | 2 +- Data/Engine/config/environment.py | 3 ++ Data/Engine/tests/test_config_environment.py | 44 ++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 Data/Engine/tests/test_config_environment.py diff --git a/Data/Engine/README.md b/Data/Engine/README.md index cb67187..b83cb85 100644 --- a/Data/Engine/README.md +++ b/Data/Engine/README.md @@ -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. | `/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` | diff --git a/Data/Engine/config/environment.py b/Data/Engine/config/environment.py index c294d8f..58ccf66 100644 --- a/Data/Engine/config/environment.py +++ b/Data/Engine/config/environment.py @@ -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", diff --git a/Data/Engine/tests/test_config_environment.py b/Data/Engine/tests/test_config_environment.py new file mode 100644 index 0000000..b5b46a1 --- /dev/null +++ b/Data/Engine/tests/test_config_environment.py @@ -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("", 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)