Files
cozystack/hack/select-e2e_test.bats
T
Myasnikov Daniil 0788e94a7c feat(ci): test-impact analysis E2E (default-on) + release E2E workflow
Three changes that compose into a single E2E policy:

1. **Test-impact analysis selector** (`hack/select-e2e.sh`).
   Reads `packages/core/platform/sources/*.yaml` (the PackageSource
   dependency graph also rendered by `cozypkg dot`) and emits the bats
   files affected by a PR diff. Library/core/networking/CI changes,
   shared `hack/*.sh` helpers, the install bats, and the
   `pull-requests` / `release-e2e` workflows trigger the full suite.
   Doc/dashboard/`*.md` diffs select nothing. Per-app bats edits
   select only that app. Anything inside `packages/` with no graph
   entry, or a system source whose graph has no `*-application`
   descendants, falls back to the full suite (conservative).

2. **Default-on TIA in `pull-requests.yaml`** with `full-e2e`
   opt-out. Drops the previous `e2e-tia` opt-in shape — the
   selector's behaviour has been validated, so making it the default
   gives PR runtime savings out of the box. PRs that need the full
   suite (e.g. cross-cutting refactors that the selector can't
   reason about) carry the `full-e2e` label and get the unchanged
   pre-TIA flow. Docs-only PRs (selector emits nothing) skip the
   `Run E2E tests` step entirely.

3. **`release-e2e.yaml`** runs the full suite on every tag push
   (`v*`). Independent of `tags.yaml`'s release publish flow — a
   failure here is an alarm, not a release blocker. Closes the
   coverage gap left by making PR runs use TIA: the full suite is
   now exercised against shipped code at tag-cut time.

Bug fixes vs. the original `feat/select-e2e-script` draft:
- `dashboard/` -> `dashboards/` (path is plural in this repo).
- `hack/e2e-apps/<name>.sh` and `hack/<name>.bats` were silently
  ignored; they now trigger the full suite (test infrastructure
  affecting all apps).
- A path matching the graph but yielding zero `*-application`
  descendants now falls back to the full suite instead of silently
  emitting nothing (system-only changes are no longer silently
  skipped).
- Per-app bats edits are matched before the full-suite pattern, so
  editing one bats file no longer escalates to the full suite.
- Removed the dead `skip_pattern` variable (PCRE syntax that
  `grep -qE` doesn't support; it was never matched).

Tests: `hack/select-e2e_test.bats` covers all 11 cases (the original
6 plus 5 for the bug fixes above).

Workflow inputs are passed via env vars rather than direct `${{ }}`
expansion into shell commands, per workflow injection guidance.

Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
Assisted-By: Claude <noreply@anthropic.com>
2026-05-02 19:09:39 +05:00

91 lines
2.9 KiB
Bash

#!/usr/bin/env bats
setup() {
TMPDIR=$(mktemp -d)
cp -r packages/core/platform/sources $TMPDIR/sources
}
@test "single app diff selects only that bats" {
echo "packages/apps/postgres/values.yaml" > $TMPDIR/diff
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
[ "$status" -eq 0 ]
[ "$output" = "postgres" ]
}
@test "operator diff selects all dependent app bats" {
# postgres-operator is depended on by postgres-application, harbor-application
# (Harbor uses postgres as its backing DB), and monitoring-application (Grafana
# DB). monitoring isn't in hack/e2e-apps/ so it's filtered out by the selector.
echo "packages/system/postgres-operator/values.yaml" > $TMPDIR/diff
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
[ "$status" -eq 0 ]
echo "$output" | grep -wq postgres
echo "$output" | grep -wq harbor
# Must NOT trigger full suite — confirm an unrelated bats is absent
! echo "$output" | grep -wq kafka
}
@test "networking change triggers full suite" {
echo "packages/system/cilium/values.yaml" > $TMPDIR/diff
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
[ "$status" -eq 0 ]
# Full suite means more than 5 bats files
[ "$(echo $output | wc -w)" -gt 5 ]
}
@test "library change triggers full suite" {
echo "packages/library/cozy-lib/templates/_helpers.tpl" > $TMPDIR/diff
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
[ "$(echo $output | wc -w)" -gt 5 ]
}
@test "docs-only diff selects nothing" {
echo "docs/README.md" > $TMPDIR/diff
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
[ "$status" -eq 0 ]
[ -z "$output" ]
}
@test "kubernetes-application maps to two bats files" {
echo "packages/apps/kubernetes/values.yaml" > $TMPDIR/diff
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
echo $output | grep -q "kubernetes-latest"
echo $output | grep -q "kubernetes-previous"
}
@test "dashboards-only diff selects nothing (path is plural)" {
echo "dashboards/gpu/gpu-fleet.json" > $TMPDIR/diff
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
[ "$status" -eq 0 ]
[ -z "$output" ]
}
@test "shared E2E helper script triggers full suite" {
echo "hack/e2e-apps/run-kubernetes.sh" > $TMPDIR/diff
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
[ "$(echo $output | wc -w)" -gt 5 ]
}
@test "install bats triggers full suite" {
echo "hack/e2e-install-cozystack.bats" > $TMPDIR/diff
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
[ "$(echo $output | wc -w)" -gt 5 ]
}
@test "per-app bats edit selects only that app, never escalates" {
echo "hack/e2e-apps/redis.bats" > $TMPDIR/diff
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
[ "$status" -eq 0 ]
[ "$output" = "redis" ]
}
@test "release-e2e workflow change triggers full suite" {
echo ".github/workflows/release-e2e.yaml" > $TMPDIR/diff
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
[ "$(echo $output | wc -w)" -gt 5 ]
}
teardown() {
rm -rf $TMPDIR
}