Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

UN-3636 [DEV] Build images and run e2e tier in one workflow (#2151)

Chandrasekharan Mc525d1a2e3c0
diff --git a/.github/workflows/ci-container-build.yaml b/.github/workflows/ci-container-build.yaml
deleted file mode 100644
index aacd0d60e..000000000
--- a/.github/workflows/ci-container-build.yaml
+++ /dev/null
@@ -1,52 +0,0 @@
-name: Container Image Build Test for PRs
-
-on:
- push:
- branches:
- - main
- pull_request:
- types: [opened, synchronize, reopened, ready_for_review]
- branches:
- - main
- workflow_dispatch:
-
-jobs:
- build:
- if: github.event.pull_request.draft == false
- runs-on: ubuntu-latest
- steps:
- - name: Checkout code
- uses: actions/checkout@v6
- - name: Login to Docker Hub
- if: github.event.pull_request == null || github.event.pull_request.head.repo.fork == false
- uses: docker/login-action@v4
- with:
- username: ${{ secrets.DOCKERHUB_USERNAME }}
- password: ${{ secrets.DOCKERHUB_TOKEN }}
- - name: Container Run
- run: |
- ./run-platform.sh -b
- sleep 30
- docker compose -f docker/docker-compose.yaml ps -a
- # Get the names of exited containers
- custom_format="{{.Name}}\t{{.Image}}\t{{.Service}}"
- EXITED_CONTAINERS=$(docker compose -f docker/docker-compose.yaml ps -a --filter status=exited --format "$custom_format")
-
- line_count=$(echo "$EXITED_CONTAINERS" | wc -l)
-
- if [ "$line_count" -gt 1 ]; then
- echo "Exited Containers: $EXITED_CONTAINERS"
-
- SERVICE=$(echo "$EXITED_CONTAINERS" | awk 'NR>0 {print $3}')
- echo "Exited Services:"
- echo "$SERVICE"
- echo "There are exited containers."
- # Print logs of exited containers
- IFS=$'\n'
- for SERVICE in $SERVICE; do
- docker compose -f docker/docker-compose.yaml logs "$SERVICE"
- done
- docker compose -f docker/docker-compose.yaml down -v
- exit 1
- fi
- docker compose -f docker/docker-compose.yaml down -v
diff --git a/.github/workflows/ci-test-e2e.yaml b/.github/workflows/ci-test-e2e.yaml
deleted file mode 100644
index fb93d3aea..000000000
--- a/.github/workflows/ci-test-e2e.yaml
+++ /dev/null
@@ -1,87 +0,0 @@
-name: Run e2e tests (rig + docker compose)
-
-# Image-build wiring is not yet in place: the base docker/docker-compose.yaml
-# references ${VERSION} for ~15 services without a default, and this workflow
-# does not build/pull images or export VERSION/UNSTRACT_TEST_VERSION. Running
-# the compose lane on push:main + nightly would fail deterministically (empty-
-# tag image refs) before any test executes. Restore the `push: main` and
-# `schedule:` triggers once a build step that exports the SHA tag lands.
-on:
- pull_request:
- types: [labeled, synchronize]
- branches: [main]
- workflow_dispatch:
-
-jobs:
- e2e:
- # Only run on PRs that opt in via the `run-e2e` label, plus manual dispatch.
- if: >
- github.event_name != 'pull_request' ||
- contains(github.event.pull_request.labels.*.name, 'run-e2e')
- runs-on: ubuntu-latest
- timeout-minutes: 60
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v6
- with:
- fetch-depth: 0
-
- - name: Install uv
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
- with:
- version: "0.6.14"
- python-version: 3.12.9
-
- - name: Install tox with UV
- run: uv tool install tox --with tox-uv
-
- - name: Validate test manifests
- run: tox -e rig -- validate
-
- - name: Restore main-branch test baseline
- # See ci-test.yaml for the rationale on namespacing per-workflow.
- uses: actions/cache@v5
- with:
- path: reports/previous-summary.json
- key: unstract-test-baseline-e2e-main-${{ github.run_id }}
- restore-keys: |
- unstract-test-baseline-e2e-main-
- unstract-test-baseline-e2e-
-
- - name: Run e2e tier via docker compose
- env:
- UNSTRACT_E2E_RUNTIME: compose
- run: |
- # Use --tier e2e (not `all`) so this workflow runs only e2e groups.
- # The main-branch baseline-update path is preserved for the eventual
- # `workflow_dispatch` from main and future restoration of push: main.
- if [ "${{ github.ref }}" = "refs/heads/main" ]; then
- tox -e e2e -- --fail-on-critical-gap --update-baseline
- else
- tox -e e2e
- fi
-
- - name: Capture docker compose logs on failure
- if: failure()
- run: |
- mkdir -p reports
- docker compose -p unstract-test \
- -f docker/docker-compose.yaml \
- -f tests/compose/docker-compose.test.yaml \
- logs --no-color > reports/docker-compose-logs.txt || true
-
- - name: Output e2e report to job summary
- if: always() && hashFiles('reports/summary.md') != ''
- shell: bash
- run: |
- cat reports/summary.md >> $GITHUB_STEP_SUMMARY
-
- - name: Upload e2e reports artifact
- if: always()
- uses: actions/upload-artifact@v4
- with:
- name: test-reports-e2e
- path: reports/
- if-no-files-found: ignore
- retention-days: 30
diff --git a/.github/workflows/ci-test.yaml b/.github/workflows/ci-test.yaml
index 87bf2f658..acb7a466f 100644
--- a/.github/workflows/ci-test.yaml
+++ b/.github/workflows/ci-test.yaml
@@ -1,4 +1,13 @@
-name: Run unit + integration tests (rig)
+name: Run tests (unit + integration + e2e)
+
+# Multi-job, one report. unit/integration run as parallel matrix legs on
+# testcontainers; e2e builds images and boots the full platform via compose on
+# its own runner (images don't travel across jobs). The report job needs all
+# three, merges every tier's junit into ONE critical-path evaluation, and posts
+# a single sticky PR comment — so e2e coverage (e.g. auth-login) shows up next
+# to unit/integration. Tiers never run in one rig invocation: the rig picks one
+# infra mode per call, so mixing compose e2e with testcontainers integration
+# would point the backend at the compose DB hostname, unreachable from pytest.
on:
push:
@@ -6,19 +15,24 @@ on:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
+ branches:
+ - main
+ workflow_dispatch:
jobs:
# Path filtering at job level, not trigger paths-ignore: an untriggered
# workflow reports no check run, so a required check waits forever; a job
- # skipped via `if:` reports conclusion `skipped`, which passes.
+ # skipped via `if:` reports conclusion `skipped`, which passes. Gates only
+ # unit/integration — e2e runs regardless (docker/** changes affect it).
changes:
runs-on: ubuntu-latest
outputs:
relevant: ${{ steps.filter.outputs.relevant }}
steps:
- name: Checkout repository
- # paths-filter needs the local git history for push events.
- uses: actions/checkout@v6
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
+ with:
+ persist-credentials: false
- name: Check for changes outside ignored paths
uses: dorny/paths-filter@7b450fff21473bca461d4b92ce414b9d0420d706 # v4.0.2
@@ -34,23 +48,22 @@ jobs:
- "!docs/**"
# Tiers share no state (separate runners, disjoint groups), so they run as
- # parallel matrix legs; whatever needs both tiers' results happens in `report`.
+ # parallel matrix legs; cross-tier reconciliation happens in `report`.
test:
needs: changes
if: needs.changes.outputs.relevant == 'true' && github.event.pull_request.draft == false
runs-on: ubuntu-latest
strategy:
- # One tier failing must not cancel the other; the report job needs
- # whatever results exist from both.
+ # One tier failing must not cancel the other; report needs both results.
fail-fast: false
matrix:
tier: [unit, integration]
-
steps:
- name: Checkout repository
- uses: actions/checkout@v6
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
- fetch-depth: 0 # rig --changed-only needs git history
+ fetch-depth: 0 # rig --changed-only needs git history
+ persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
@@ -62,45 +75,30 @@ jobs:
uses: actions/cache@v5
with:
path: .tox/
- # Tier in the key: legs build different tox envs, and parallel
- # saves to one key race (first save wins).
+ # Tier in the key: legs build different tox envs, and parallel saves
+ # to one key race (first save wins).
key: ${{ runner.os }}-tox-uv-${{ matrix.tier }}-${{ hashFiles('**/pyproject.toml', '**/tox.ini') }}
restore-keys: |
${{ runner.os }}-tox-uv-${{ matrix.tier }}-
${{ runner.os }}-tox-uv-
- - name: Restore main-branch test baseline (for regression detection)
- # Restore-only: the report job is the sole baseline writer (a save
- # here would claim this run's key with an unmerged file). Baseline is
- # separate from the e2e workflow's — their scope_groups don't overlap,
- # and a cross-lane restore would flag the other lane's paths as
- # regressions.
- uses: actions/cache/restore@v5
- with:
- path: reports/previous-summary.json
- key: unstract-test-baseline-ut-main-${{ github.run_id }}
- restore-keys: |
- unstract-test-baseline-ut-main-
- unstract-test-baseline-ut-
-
- name: Install tox with UV
run: uv tool install tox --with tox-uv
- name: Validate test manifests
- # Cheap pre-flight: catches groups.yaml / critical_paths.yaml schema
- # errors before we spend minutes on tier runs.
+ # Cheap pre-flight: catches manifest schema errors before tier runs.
run: tox -e rig -- validate
- name: Run ${{ matrix.tier }} tier
- # Gap check on PRs too: main is gap-free and PRs test the merge ref,
- # so a gap here can only be PR-introduced. No --update-baseline:
- # parallel writes would race; the report job merges once (main only).
+ # Gap check on PRs too: main is gap-free and PRs test the merge ref, so
+ # an in-scope gap here is PR-introduced. No baseline restore or
+ # --update-baseline — the report job is the sole regression authority
+ # (a per-tier eval would flag other tiers' paths as missing).
run: tox -e ${{ matrix.tier }} -- --fail-on-critical-gap
- name: Suffix coverage data for cross-tier merge
- # Both tiers emit a bare reports/.coverage that would clobber on
- # download; suffixed names match the `.coverage.*` glob `report
- # combine` unions.
+ # Every tier emits a bare reports/.coverage that would clobber on
+ # download; suffixed names match the `.coverage.*` glob combine unions.
if: always()
run: |
if [ -f reports/.coverage ]; then
@@ -109,31 +107,113 @@ jobs:
- name: Upload tier reports artifact
if: always()
- uses: actions/upload-artifact@v4
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: reports-${{ matrix.tier }}
- # Baseline excluded: it's cache-managed, and a stale copy inside the
- # artifact would overwrite the report job's freshly restored one.
- path: |
- reports/
- !reports/previous-summary.json
+ path: reports/
if-no-files-found: ignore
retention-days: 14
- report:
- needs: [changes, test]
- # `always()` so a red tier still gets a PR report. Skip only a legitimate
- # skip — irrelevant paths / draft, decided by a *successful* changes job.
- # A failed changes job skips the tiers, so this must run and go red
- # (final step) instead of green-skipping the required check.
- if: >-
- always() && (needs.changes.result != 'success'
- || (needs.changes.outputs.relevant == 'true' && github.event.pull_request.draft == false))
+ # Own runner: builds images then runs e2e against the full compose platform.
+ # Not gated by `changes` — docker/** edits don't count as "relevant" yet must
+ # be e2e-tested.
+ e2e:
+ if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
+ timeout-minutes: 45
+ env:
+ # One tag end to end: docker-compose.build.yaml tags images with VERSION,
+ # the base compose boots ${VERSION}, and the test overlay pins its
+ # services via UNSTRACT_TEST_VERSION. Keep them identical.
+ VERSION: ${{ github.sha }}
+ UNSTRACT_TEST_VERSION: ${{ github.sha }}
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
+ with:
+ fetch-depth: 0
+ persist-credentials: false
+ - name: Login to Docker Hub
+ # Authenticated pulls avoid the anonymous rate limit shared by all
+ # runners. Forks have no access to secrets.
+ if: github.event.pull_request == null || github.event.pull_request.head.repo.fork == false
+ uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0
+ with:
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
+
+ - name: Install uv
+ uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
+ with:
+ version: "0.6.14"
+ python-version: 3.12.9
+
+ - name: Cache tox environments
+ uses: actions/cache@v5
+ with:
+ path: .tox/
+ key: ${{ runner.os }}-tox-uv-e2e-${{ hashFiles('**/pyproject.toml', '**/tox.ini') }}
+ restore-keys: |
+ ${{ runner.os }}-tox-uv-e2e-
+ ${{ runner.os }}-tox-uv-
+
+ - name: Install tox with UV
+ run: uv tool install tox --with tox-uv
+
+ - name: Validate test manifests
+ # Cheap pre-flight before the multi-minute image build.
+ run: tox -e rig -- validate
+
+ - name: Set up env files
+ run: ./run-platform.sh -e
+
+ - name: Build service images
+ run: docker compose -f docker/docker-compose.build.yaml build
+
+ - name: Run e2e tier (rig boots the platform via compose)
+ env:
+ UNSTRACT_E2E_RUNTIME: compose
+ # Gap check only; report owns baseline/regression across all tiers.
+ run: tox -e e2e -- --fail-on-critical-gap
+
+ - name: Suffix coverage data for cross-tier merge
+ if: always()
+ run: |
+ if [ -f reports/.coverage ]; then
+ mv reports/.coverage "reports/.coverage.tier-e2e"
+ fi
+
+ - name: Capture docker compose logs on failure
+ if: failure()
+ run: |
+ mkdir -p reports
+ docker compose -p unstract-test \
+ -f docker/docker-compose.yaml \
+ -f tests/compose/docker-compose.test.yaml \
+ logs --no-color > reports/docker-compose-logs.txt || true
+
+ - name: Upload e2e reports artifact
+ if: always()
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
+ with:
+ name: reports-e2e
+ path: reports/
+ if-no-files-found: ignore
+ retention-days: 14
+
+ report:
+ needs: [changes, test, e2e]
+ # `always()` so a red tier still posts a report. e2e always runs on
+ # non-draft, so gate only on draft; the fail step below distinguishes a
+ # legitimate skip (irrelevant paths) from a real tier failure.
+ if: always() && github.event.pull_request.draft == false
+ runs-on: ubuntu-latest
steps:
- name: Checkout repository
- uses: actions/checkout@v6
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
+ with:
+ persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
@@ -150,17 +230,18 @@ jobs:
${{ runner.os }}-tox-uv-rig-
${{ runner.os }}-tox-uv-
- - name: Restore main-branch test baseline
+ - name: Install tox with UV
+ run: uv tool install tox --with tox-uv
+
+ - name: Restore main-branch test baseline (for regression detection)
+ # One unified baseline across all tiers; this job is its sole
+ # reader+writer. Restore-only here, save below on green main.
uses: actions/cache/restore@v5
with:
path: reports/previous-summary.json
- key: unstract-test-baseline-ut-main-${{ github.run_id }}
+ key: unstract-test-baseline-main-${{ github.run_id }}
restore-keys: |
- unstract-test-baseline-ut-main-
- unstract-test-baseline-ut-
-
- - name: Install tox with UV
- run: uv tool install tox --with tox-uv
+ unstract-test-baseline-main-
- name: Download tier reports
uses: actions/download-artifact@v4
@@ -169,24 +250,27 @@ jobs:
path: reports/
merge-multiple: true
- - name: Combine reports from both tiers
- # On green main builds also merge covered paths into the baseline
- # (single writer; the rig refuses the merge if any group is red).
+ - name: Combine tiers into one report
+ # Merges every tier's junit into a single critical-path evaluation + PR
+ # comment. --update-baseline is main-only and green-only — a PR must not
+ # write main's baseline, nor a red build a partial one.
run: |
flags=""
- if [ "${{ github.ref }}" = "refs/heads/main" ] && [ "${{ needs.test.result }}" = "success" ]; then
+ if [ "${{ github.ref }}" = "refs/heads/main" ] \
+ && [ "${{ needs.test.result }}" = "success" ] \
+ && [ "${{ needs.e2e.result }}" = "success" ]; then
flags="--update-baseline"
fi
tox -e rig -- report combine $flags
- name: Save updated baseline
- # actions/cache saves only on a miss; the run id keys each main build
- # a fresh entry, and restore-keys' prefix pulls the latest next run.
+ # actions/cache saves only on a miss; the run id keys each main build a
+ # fresh entry, and restore-keys' prefix pulls the latest next run.
if: github.ref == 'refs/heads/main'
uses: actions/cache/save@v5
with:
path: reports/previous-summary.json
- key: unstract-test-baseline-ut-main-${{ github.run_id }}
+ key: unstract-test-baseline-main-${{ github.run_id }}
- name: Render combined test report to PR
uses: marocchino/sticky-pull-request-comment@70d2764d1a7d5d9560b100cbea0077fc8f633987 # v3.0.2
@@ -199,21 +283,24 @@ jobs:
- name: Output combined report to job summary
if: always() && hashFiles('reports/summary.md') != ''
shell: bash
- run: |
- cat reports/summary.md >> $GITHUB_STEP_SUMMARY
+ run: cat reports/summary.md >> $GITHUB_STEP_SUMMARY
- - name: Upload reports artifact
+ - name: Upload combined reports artifact
if: always()
- uses: actions/upload-artifact@v4
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
- name: test-reports-unit-integration
+ name: test-reports
path: reports/
if-no-files-found: ignore
retention-days: 14
- name: Fail if any tier failed
- # Lets this job serve as the single branch-protection check: a matrix
- # `result` is success only when every leg passed.
+ # Single branch-protection check. A skipped `test` means irrelevant
+ # paths (path-filter skip == pass); e2e always runs, so it must be
+ # green. Runs after the comment so a red tier still reports.
if: always()
run: |
- [ "${{ needs.test.result }}" = "success" ] || exit 1
+ test_result="${{ needs.test.result }}"
+ e2e_result="${{ needs.e2e.result }}"
+ [ "$test_result" = "success" ] || [ "$test_result" = "skipped" ] || exit 1
+ [ "$e2e_result" = "success" ] || exit 1
diff --git a/pyproject.toml b/pyproject.toml
index b9d373892..d46632ef4 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -185,6 +185,7 @@ markers = [
"unit: marks tests as unit (no external services required)",
"e2e: marks tests as end-to-end (require full platform stack)",
"critical: marks tests covering a critical path (see tests/critical_paths.yaml)",
+ "critical_path(path_id): attests coverage of the named critical path(s) when this test passes",
]
[tool.coverage.run]
diff --git a/tests/compose/docker-compose.test.yaml b/tests/compose/docker-compose.test.yaml
index ee10d9416..a5cbbee0c 100644
--- a/tests/compose/docker-compose.test.yaml
+++ b/tests/compose/docker-compose.test.yaml
@@ -11,8 +11,8 @@
services:
backend:
# Defaults to `latest` so contributors can run without setting
- # UNSTRACT_TEST_VERSION. CI will pin it to the built image SHA once the
- # image-build wiring lands (see .github/workflows/ci-test-e2e.yaml header).
+ # UNSTRACT_TEST_VERSION. CI pins it to the commit SHA of the images built
+ # in the same run (see the e2e job in .github/workflows/ci-test.yaml).
image: unstract/backend:${UNSTRACT_TEST_VERSION:-latest}
environment:
- ENVIRONMENT=test
diff --git a/tests/critical_paths.yaml b/tests/critical_paths.yaml
index ed06895e3..2c7b045da 100644
--- a/tests/critical_paths.yaml
+++ b/tests/critical_paths.yaml
@@ -27,11 +27,9 @@ version: 1
paths:
- id: auth-login
description: "User can log in and obtain a session cookie."
- entry: "POST /api/v1/auth/login"
- # Honest declaration: e2e-smoke only exercises the session sentinel +
- # /health/, never POST /api/v1/auth/login. Track as a gap until a real
- # login test exists (likely under tests/e2e/smoke/ or tests/e2e/auth/).
- covered_by: []
+ entry: "POST /api/v1/login"
+ covered_by: [e2e-login]
+ proof: marker
- id: adapter-register-llm
description: "Register and validate an LLM adapter."
diff --git a/tests/e2e/auth/__init__.py b/tests/e2e/auth/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/e2e/auth/test_login.py b/tests/e2e/auth/test_login.py
new file mode 100644
index 000000000..d9f41a7eb
--- /dev/null
+++ b/tests/e2e/auth/test_login.py
@@ -0,0 +1,49 @@
+"""E2E: OSS mock-login over real HTTP (covers the ``auth-login`` critical path).
+
+Self-contained on purpose — it builds its own session because it is the thing
+under test. Other e2e tests should take the shared ``authed_session`` fixture.
+"""
+
+from __future__ import annotations
+
+import pytest
+import requests
+
+from tests.rig.runtime import PlatformEndpoints
+
+pytestmark = [pytest.mark.e2e, pytest.mark.critical]
+
+
[email protected]_path("auth-login")
+def test_login_sets_usable_session(platform: PlatformEndpoints) -> None:
+ base = platform.backend_url.rstrip("/")
+ session = requests.Session()
+
+ resp = session.post(
+ f"{base}/api/v1/login",
+ data={"username": platform.admin_user, "password": platform.admin_password},
+ allow_redirects=False,
+ timeout=10,
+ )
+ assert resp.status_code == 302, (
+ f"expected 302 redirect on login, got {resp.status_code} "
+ "(200 with HTML means bad credentials)"
+ )
+ assert session.cookies.get("sessionid"), "login did not set a sessionid cookie"
+
+ # The cookie is only meaningful if it authenticates a follow-up request.
+ who = session.get(f"{base}/api/v1/session", timeout=10)
+ assert who.status_code in (200, 201), f"/api/v1/session returned {who.status_code}"
+ assert who.json().get("email"), f"/api/v1/session returned no user: {who.text}"
+
+
+def test_login_rejects_bad_credentials(platform: PlatformEndpoints) -> None:
+ base = platform.backend_url.rstrip("/")
+ resp = requests.Session().post(
+ f"{base}/api/v1/login",
+ data={"username": "unstract", "password": "wrong-password"},
+ allow_redirects=False,
+ timeout=10,
+ )
+ # Bad creds re-render the login page (200 HTML), never a 302 redirect.
+ assert resp.status_code != 302, "bad credentials should not yield a login redirect"
diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py
index b184df964..d4ba14750 100644
--- a/tests/e2e/conftest.py
+++ b/tests/e2e/conftest.py
@@ -11,6 +11,7 @@ from __future__ import annotations
import os
import pytest
+import requests
from tests.rig.runtime import PlatformEndpoints
@@ -24,3 +25,47 @@ def platform() -> PlatformEndpoints:
"UNSTRACT_BACKEND_URL (etc.) yourself."
)
return PlatformEndpoints.from_env()
+
+
[email protected](scope="session")
+def authed_session(platform: PlatformEndpoints) -> requests.Session:
+ """A logged-in session with the active organization set.
+
+ Standardizes the OSS mock-login flow so tests don't re-implement it: form
+ POST to /api/v1/login (302 + sessionid), then the org handshake
+ (GET /organization seeds the csrftoken cookie, POST /organization/{id}/set
+ with X-CSRFToken) so org-scoped endpoints are reachable. Session-scoped:
+ logged in once, reused across tests. Tests that exercise login itself
+ should build their own session instead.
+ """
+ base = platform.backend_url.rstrip("/")
+ session = requests.Session()
+
+ resp = session.post(
+ f"{base}/api/v1/login",
+ data={"username": platform.admin_user, "password": platform.admin_password},
+ allow_redirects=False,
+ timeout=10,
+ )
+ assert resp.status_code == 302, (
+ f"login failed: expected 302, got {resp.status_code} "
+ "(200 with HTML means bad credentials)"
+ )
+
+ # GET /organization sets the csrftoken cookie and returns the org id, which
+ # the following POST needs both as a cookie and echoed in the CSRF header.
+ orgs = session.get(f"{base}/api/v1/organization", timeout=10)
+ orgs.raise_for_status()
+ org_list = orgs.json().get("organizations", [])
+ assert org_list, (
+ f"no organizations returned by /api/v1/organization — is seed data "
+ f"loaded? response: {orgs.text}"
+ )
+ org_id = org_list[0]["id"]
+ resp = session.post(
+ f"{base}/api/v1/organization/{org_id}/set",
+ headers={"X-CSRFToken": session.cookies.get("csrftoken", "")},
+ timeout=10,
+ )
+ resp.raise_for_status()
+ return session
diff --git a/tests/e2e/smoke/test_smoke.py b/tests/e2e/smoke/test_smoke.py
index 4e496196f..8f60e3d6a 100644
--- a/tests/e2e/smoke/test_smoke.py
+++ b/tests/e2e/smoke/test_smoke.py
@@ -1,9 +1,8 @@
-"""Single placeholder e2e smoke test.
+"""E2E smoke gate: rig plumbing is wired and every service is up.
-Exercises the rig's e2e plumbing end-to-end (platform up → URL injection →
-pytest discovery → result aggregation → platform down) without depending on
-auth state or seed data. Real workflow + API-deployment tests will land in
-adjacent files (tests/e2e/workflows/, tests/e2e/api_deployment/, ...).
+Depends on no auth state or seed data, so it isolates "is the platform
+healthy" from feature tests. The other e2e groups depend on this one, so a
+red smoke run stops them before they produce confusing failures.
"""
from __future__ import annotations
@@ -13,6 +12,8 @@ import os
import pytest
import requests
+from tests.rig.runtime import PlatformEndpoints, health_targets
+
pytestmark = [pytest.mark.e2e, pytest.mark.critical]
@@ -30,6 +31,18 @@ def test_rig_session_sentinel_present() -> None:
)
-def test_backend_health(platform) -> None:
- response = requests.get(f"{platform.backend_url.rstrip('/')}/health/", timeout=10)
- assert response.status_code < 500, f"backend /health returned {response.status_code}"
+def test_all_services_healthy(platform: PlatformEndpoints) -> None:
+ """Every HTTP service in the stack answers its health endpoint with 200.
+
+ This is the gate the rest of the e2e tier depends on — a half-booted stack
+ should fail here loudly rather than surface as confusing downstream errors.
+ """
+ failures = []
+ for name, url in health_targets(platform):
+ try:
+ resp = requests.get(url, timeout=10)
+ if resp.status_code != 200:
+ failures.append(f"{name} ({url}) -> HTTP {resp.status_code}")
+ except requests.RequestException as exc:
+ failures.append(f"{name} ({url}) -> {exc}")
+ assert not failures, "unhealthy services: " + "; ".join(failures)
diff --git a/tests/groups.yaml b/tests/groups.yaml
index 90435deac..47b77ce16 100644
--- a/tests/groups.yaml
+++ b/tests/groups.yaml
@@ -155,6 +155,15 @@ groups:
timeout_seconds: 1200
depends_on: [unit-sdk1, unit-workers]
+ # Not optional: login is the first e2e critical path we gate on. A red login
+ # test fails the build and (on main) surfaces as an in-scope critical gap.
+ e2e-login:
+ tier: e2e
+ paths: [tests/e2e/auth]
+ requires_platform: true
+ critical: true
+ depends_on: [e2e-smoke]
+
e2e-workflow:
tier: e2e
paths: [tests/e2e/workflows]
diff --git a/tests/rig/cli.py b/tests/rig/cli.py
index e37649852..8cc9e2c4c 100644
--- a/tests/rig/cli.py
+++ b/tests/rig/cli.py
@@ -779,6 +779,9 @@ def _execute_group(
return parse_junit(group.name, group.tier, reports_dir), exit_code
+# Injected into every group's ephemeral `uv run` env via --with, so they
+# survive the per-call venv re-sync (unlike `uv pip install`). Includes pytest
+# and requests themselves — needed regardless of the workdir project's deps.
RIG_PYTEST_PLUGINS = (
"pytest>=8.0.1",
"pytest-md-report>=0.6.2",
@@ -786,6 +789,7 @@ RIG_PYTEST_PLUGINS = (
"pytest-xdist>=3.5.0",
"pytest-cov>=4.1.0",
"pytest-mock>=3.12.0",
+ "requests>=2.31.0",
)
diff --git a/tests/rig/runtime.py b/tests/rig/runtime.py
index 70de5db40..06a6b82fd 100644
--- a/tests/rig/runtime.py
+++ b/tests/rig/runtime.py
@@ -262,14 +262,26 @@ def _run(cmd: list[str], *, check: bool = True) -> None:
) from exc
+def health_targets(endpoints: PlatformEndpoints) -> list[tuple[str, str]]:
+ """(service name, health URL) for every HTTP service in the platform.
+
+ Single source of truth for the readiness probe and the e2e smoke test.
+ Paths are service-specific: runner and x2text mount health under blueprint
+ prefixes, and there is no standalone prompt-service (folded into workers).
+ """
+ return [
+ ("backend", endpoints.backend_url.rstrip("/") + "/health"),
+ ("platform-service", endpoints.platform_service_url.rstrip("/") + "/health"),
+ ("runner", endpoints.runner_url.rstrip("/") + "/v1/api/health"),
+ ("x2text-service", endpoints.x2text_url.rstrip("/") + "/api/v1/x2text/health"),
+ ]
+
+
def _wait_ready(endpoints: PlatformEndpoints, *, timeout_seconds: int = 300) -> None:
- """Poll each service's /health endpoint until all respond or timeout.
+ """Poll each service's health endpoint until all respond or timeout.
- If ``requests`` isn't importable (e.g. running the rig on a bare interpreter
- just to list groups), readiness probing is skipped. That's safe because the
- only caller, ``ComposeRuntime.up``, is on the e2e path where requests is in
- the rig's deps; getting here without requests installed implies a broken
- install and the developer will surface it shortly.
+ Skips probing if ``requests`` isn't importable — the rig may run on a bare
+ interpreter just to list groups. The e2e path always has requests installed.
"""
try:
import requests
@@ -277,13 +289,7 @@ def _wait_ready(endpoints: PlatformEndpoints, *, timeout_seconds: int = 300) ->
log.warning("`requests` not installed; skipping platform readiness probe")
return
- targets = [
- endpoints.backend_url.rstrip("/") + "/health/",
- endpoints.prompt_service_url.rstrip("/") + "/health",
- endpoints.platform_service_url.rstrip("/") + "/health",
- endpoints.runner_url.rstrip("/") + "/health",
- endpoints.x2text_url.rstrip("/") + "/health",
- ]
+ targets = [url for _, url in health_targets(endpoints)]
deadline = time.monotonic() + timeout_seconds
while time.monotonic() < deadline:
if all(_responds(t, requests) for t in targets):
diff --git a/tox.ini b/tox.ini
index 10b455e32..798d4a96c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -42,6 +42,9 @@ passenv =
GITHUB_*
DOCKER_HOST
UNSTRACT_*
+ # ComposeRuntime's `docker compose up` resolves ${VERSION} image tags in
+ # docker/docker-compose.yaml from the caller's environment.
+ VERSION
changedir = {toxinidir}
[testenv:unit]