From 14df139e42fcfb64216c50864210848e8afb5d43 Mon Sep 17 00:00:00 2001 From: Mahfuzur Rahman Emon Date: Sun, 14 Jun 2026 11:36:07 +0100 Subject: [PATCH 1/2] fix: skip DB migrations when DATABASE_URL is unset and add full pytest step to CI --- .github/workflows/ci.yml | 10 ++++++++++ api/app.py | 17 ++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46f174f..2ac7f30 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -337,6 +337,15 @@ jobs: echo "=== Running rule regression tests ===" pytest tests/test_rules_*.py -v --tb=short + # ── CHECK 8: Full Python test suite ────────────────────────────── + - name: Run Python test suite + id: pytest_check + run: | + echo "=== Running full Python test suite ===" + python -m pytest tests/ --ignore=tests/smoke_test.py -v --tb=short -q + env: + OPENSHIELD_ENV: "development" + # ── Final summary — always runs, shows per-check pass/fail ──────── - name: CI Summary if: always() @@ -361,6 +370,7 @@ jobs: ("Compliance JSON validation", os.environ["JSON"]), ("API syntax check", os.environ["API"]), ("Compliance vs rule cross-reference", os.environ["XREF"]), + ("Python test suite", os.environ["PYTEST"]), ("Rule regression tests", os.environ["RULE_TESTS"]), ] diff --git a/api/app.py b/api/app.py index 053e32d..1c695ec 100644 --- a/api/app.py +++ b/api/app.py @@ -117,9 +117,20 @@ def create_app() -> Flask: # ------------------------------------------------------------------ # # Database Management # # ------------------------------------------------------------------ # - with app.app_context(): - db = DatabaseManager() - db.run_migrations() + # Skip migrations when DATABASE_URL is not set (e.g. during unit tests). + # Deployment startup always sets DATABASE_URL so migrations still run in + # production and staging. Tests that need a real database should set + # DATABASE_URL explicitly in their environment. + if os.environ.get("DATABASE_URL"): + with app.app_context(): + db = DatabaseManager() + db.run_migrations() + else: + logger.info( + "DATABASE_URL not set — skipping migrations. " + "This is expected during unit tests and local development " + "without a database." + ) @app.teardown_appcontext def close_db(error=None): From 262378d0cccee896a01aefd4c5ba4b1b61e4aeae Mon Sep 17 00:00:00 2001 From: Mahfuzur Rahman Emon Date: Sun, 14 Jun 2026 11:44:47 +0100 Subject: [PATCH 2/2] fix: add PYTEST to CI Summary env section --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ac7f30..7ec34c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -357,6 +357,7 @@ jobs: JSON: ${{ steps.json_check.outcome }} API: ${{ steps.api_check.outcome }} XREF: ${{ steps.xref_check.outcome }} + PYTEST: ${{ steps.pytest_check.outcome }} RULE_TESTS: ${{ steps.rule_tests.outcome }} run: | python - <<'PYEOF'