"""Tests for sanguo_api.main container entrypoint (app loader + SPA mount). Covers Task S0.1: build_app(config_path, static_dir) loads backtest.yaml and mounts SPA static files when the directory exists. """ from sanguo_api.main import build_app def _cfg(tmp_path) -> str: cfg = tmp_path / "bt.yaml" cfg.write_text( "backtest:\n max_workers: 1\n db_path: %s\n file_dir: %s\n" "api:\n host: 0.0.0.0\n port: 8000\n" "auth:\n username: admin\n password_hash: x\n jwt_secret: s\n token_expire_minutes: 60\n" "pool:\n max_workers: 1\n" % (tmp_path / "r.db", tmp_path / "f") ) return str(cfg) def test_build_app_has_api_routes(tmp_path): app = build_app(_cfg(tmp_path)) paths = [getattr(r, "path", "") for r in app.routes] assert "/api/v1/auth/login" in paths def test_build_app_mounts_spa_when_static_exists(tmp_path): spa = tmp_path / "spa" spa.mkdir() (spa / "index.html").write_text("

SPA

") app = build_app(_cfg(tmp_path), static_dir=str(spa)) paths = [getattr(r, "path", "") for r in app.routes] assert "/" in paths def test_build_app_no_static_skips_mount(tmp_path): """When static dir absent, build must still succeed (no SPA mount).""" app = build_app(_cfg(tmp_path), static_dir=str(tmp_path / "nope")) paths = [getattr(r, "path", "") for r in app.routes] assert "/api/v1/auth/login" in paths