Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions .github-staging/workflows/test-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
name: Integration Tests

on:
workflow_call:
outputs:
passed:
description: 'Whether all integration tests passed'
value: ${{ jobs.aggregate.outputs.passed }}
workflow_dispatch: # Allow manual testing

jobs:
integration:
name: Integration Tests
runs-on: ubuntu-latest
# The 30-min budget set on the caller (.github/workflows/test.yml)
# is repeated here as defense in depth so the budget is enforced
# whether this workflow is invoked via `uses:` or via
# `workflow_dispatch`.
timeout-minutes: 30
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.14"

- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Install dependencies
run: uv sync --extra dev

- name: Build containers
run: |
docker build -t egg-gateway -f gateway/Dockerfile .
docker build -t egg-sandbox -f sandbox/Dockerfile .

- name: Set up k3s
run: |
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--flannel-backend=none --disable-network-policy --write-kubeconfig-mode=644" sh -
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
echo "KUBECONFIG=/etc/rancher/k3s/k3s.yaml" >> "$GITHUB_ENV"
# Install Calico CNI
scripts/install-calico.sh
# Wait for node to be ready
kubectl wait --for=condition=Ready node --all --timeout=120s

- name: Import images into k3s
# Flake guard (HITL Q1 of #2474): retry the image-import step
# up to 3 attempts with a short backoff. Transient k3s
# containerd import failures (rare but observed in #2556's
# early runs) should not flake the entire integration tier.
# `set -o pipefail` ensures a `docker save` failure on the
# left side of the pipe propagates to the loop condition;
# otherwise an empty-pipe `k3s ctr images import` exit-0
# would falsely report success.
run: |
set -eo pipefail
attempt=0
max_attempts=3
until [ "$attempt" -ge "$max_attempts" ]; do
attempt=$((attempt + 1))
echo "::group::Image import attempt ${attempt}/${max_attempts}"
if docker save egg-gateway:latest | sudo k3s ctr images import - \
&& docker save egg-sandbox:latest | sudo k3s ctr images import -; then
echo "::endgroup::"
echo "Image import succeeded on attempt ${attempt}"
exit 0
fi
echo "::endgroup::"
echo "Image import failed on attempt ${attempt}"
if [ "$attempt" -lt "$max_attempts" ]; then
echo "Sleeping 5s before retry..."
sleep 5
fi
done
echo "Image import failed after ${max_attempts} attempts" >&2
exit 1

- name: Deploy egg to k3s
run: |
kubectl apply -k k8s/overlays/local/
kubectl -n egg-system wait --for=condition=Available deployment/egg-gateway --timeout=120s

- name: Run integration and security tests
env:
EGG_RUNTIME: kubernetes
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
run: |
PYTHONPATH=shared .venv/bin/pytest integration_tests -v \
-m "integration or security" \
--timeout=300

- name: Collect k3s debug artifacts on failure
# Flake guard (HITL Q1 of #2474): on any prior-step failure,
# capture cluster-wide events and per-pod logs so the
# debugger doesn't have to reproduce locally to triage a CI
# flake. Uploaded as a single `k3s-debug` workflow artifact.
# NB: `kubectl logs` requires an explicit pod name or a
# non-empty label selector - there is no "all pods in
# namespace" primitive, so we enumerate pods per namespace
# via `kubectl get pods -o name` and tail each individually.
if: failure()
run: |
set +e
echo "Collecting cluster events..."
kubectl get events --all-namespaces -o yaml > k3s-debug-events.yaml 2>&1 || true
echo "Collecting pod logs..."
{
for ns in egg-system egg-test-agents; do
echo "===== Namespace: ${ns} ====="
for pod in $(kubectl get pods -n "${ns}" -o name 2>/dev/null); do
echo "----- ${ns}/${pod} -----"
kubectl logs -n "${ns}" "${pod}" --all-containers=true --tail=-1 --prefix=true 2>&1 || true
done
echo
echo "===== Pods in ${ns} ====="
kubectl get pods -n "${ns}" -o wide 2>&1 || true
echo
done
} > k3s-debug-pods.log 2>&1 || true
ls -la k3s-debug-events.yaml k3s-debug-pods.log || true

- name: Upload k3s debug artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: k3s-debug
path: |
k3s-debug-events.yaml
k3s-debug-pods.log
if-no-files-found: warn
retention-days: 14

- name: Cleanup
if: always()
run: |
kubectl delete namespace egg-test-agents --ignore-not-found=true 2>/dev/null || true
kubectl delete namespace egg-system --ignore-not-found=true 2>/dev/null || true
/usr/local/bin/k3s-uninstall.sh 2>/dev/null || true

aggregate:
name: Aggregate Integration Test Results
runs-on: ubuntu-latest
if: always()
needs: [integration]
outputs:
passed: ${{ steps.check.outputs.passed }}
steps:
- name: Check all jobs passed
id: check
run: |
if [[ "${{ needs.integration.result }}" != "success" ]]; then
echo "passed=false" >> "$GITHUB_OUTPUT"
echo "Integration tests failed"
echo " integration: ${{ needs.integration.result }}"
else
echo "passed=true" >> "$GITHUB_OUTPUT"
echo "All integration tests passed"
fi
103 changes: 103 additions & 0 deletions .github-staging/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Test

on:
pull_request:
types: [opened, synchronize, reopened]
workflow_call:
outputs:
passed:
description: 'Whether all tests passed'
value: ${{ jobs.aggregate.outputs.passed }}
workflow_dispatch: # Allow manual testing

concurrency:
group: test-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
unit:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.14"

- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Install dependencies
run: uv sync --extra dev

- name: Run unit tests
run: |
make test-all PYTEST_ARGS="--cov=gateway --cov=shared --cov=sandbox --cov-report=term-missing --cov-fail-under=80"

security:
name: Security Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.14"

- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Install dependencies
run: uv sync --extra dev

- name: Run security scan
run: make security

integration:
name: Integration Tests
# Required-from-day-1 per decision-3 of #2474. The reusable
# workflow lives at .github/workflows/test-integration.yml after
# the human reviewer performs the pre-merge `git mv` from
# .github-staging/. Folded into `aggregate` below so the
# canonical required-check name stays `Test / aggregate`.
#
# `timeout-minutes` historically wasn't in the documented
# keyword set for `uses:` caller jobs in GitHub Actions, but is
# honored in practice. The test-integration.yml reusable
# workflow also carries per-job `timeout-minutes` as a defense
# in depth so the budget is enforced regardless.
uses: ./.github/workflows/test-integration.yml
timeout-minutes: 30

aggregate:
# Intentionally NO `name:` override here: the GitHub-rendered
# check name must be `Test / aggregate` (lowercase job-id) so it
# matches the canonical required-check name documented in
# decision-3 / `manual_steps` of #2474 ("repo admin flips
# `Test / aggregate` to required-for-merge"). Adding a `name:`
# override would render the check as `Test / <override>` and
# silently desync from the operator-flipped required-check.
runs-on: ubuntu-latest
if: always()
needs: [unit, security, integration]
outputs:
passed: ${{ steps.check.outputs.passed }}
steps:
- name: Check all jobs passed
id: check
run: |
if [[ "${{ needs.unit.result }}" != "success" || \
"${{ needs.security.result }}" != "success" || \
"${{ needs.integration.result }}" != "success" ]]; then
echo "passed=false" >> "$GITHUB_OUTPUT"
echo "Some tests failed"
echo " unit: ${{ needs.unit.result }}"
echo " security: ${{ needs.security.result }}"
echo " integration: ${{ needs.integration.result }}"
else
echo "passed=true" >> "$GITHUB_OUTPUT"
echo "All tests passed"
fi
Loading
Loading