fix(e2e): validate the leak allowlist against every suite layout (#4972)

`lg_allowlist_validate` in `hack/e2e-chainsaw/_lib/leak-guard.sh`
accepted only `<suite>/chainsaw-test.y*ml`, while the selectors already
see step-file suites and a Test nested below the suite directory
(#4630). A suite in one of those layouts could not be put on the leak
allowlist at all: validation failed and the run stopped before the first
suite.

- `lg_suite_has_test` validates an allowlist entry with the rule
`hack/select-e2e.sh` enumerates suites with: `chainsaw-test.yaml`,
`chainsaw-test.yml`, or a numbered step file, anywhere in or below the
suite directory, with the selector's type test (a step-file name counts
unless it is a directory, a `chainsaw-test.y*ml` counts whatever its
type, so Chainsaw reports a directory by that name); a parked
`chainsaw-test.yaml.disabled` matches none. Both sides carry a comment
pointing at the other so they move together.
- `hack/e2e-chainsaw/README.md` describes the three layouts once, under
Layout, and lists `kubernetes-proxmox` as the parked suite.
`docs/agents/e2e-testing.md` points at it.
- Unit tests: every layout is accepted, including a `chainsaw-test.yaml`
that is a directory; a parked, empty, or not-a-step-file directory is
refused, including `1a-install.yaml` (passes the `find` glob, not the
step-file regex) and a directory named `01-install.yaml`.

Left as they are, with the reasons:
- `docs/agents/e2e-testing.md` calling `kubernetes-proxmox` the one
parked suite is correct on main now: `hack/e2e-chainsaw/backup/` was
removed in 9cc3a9e45.
- The top-level globs in `hack/e2e-chainsaw-run.sh` are wider than
Chainsaw's step-file pattern, but they only refuse a test at the top
level and fail closed.
- A file under `examples/backups/<other>/` that matches no suite is
documented in `select-e2e.sh` as a docs-only demo that stays ignored.

Verified with Bats and `hack/cozytest.sh` on
`hack/chainsaw-leak-guard_test.bats` (34 tests) and
`hack/select-e2e_test.bats` (65 tests; one case, "a path owned by
several sources counts as covered if any one is", fails on my machine on
main as well, from the local yq build, and does not touch this change).

Closes #4659


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Documentation**
* Clarified that Chainsaw suites may use `chainsaw-test.yaml` or `.yml`,
numbered step files, or either layout in a subdirectory.
* Updated guidance on suite selection and noted that disabled test files
are not selected or allowlisted.
* Identified the parked Kubernetes Proxmox suite and its workflow
availability.
* **Bug Fixes**
  * Suite validation now recognizes tests in the documented layouts.
* Validation rejects empty directories, parked test files, invalid
step-file names, and directories named like step files.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Backported-from: ba0b1ac6ef
This commit is contained in:
Myasnikov Daniil committed 2026-11-10 12:23:21 +00:00
commit 3d68d416b7
5 files changed
+81 -6

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
Guidance for writing, changing, and reviewing Cozystack's end-to-end (E2E) tests and the CI that runs them. Read this **before** touching anything under `hack/e2e-chainsaw/`, the bootstrap/OpenAPI BATS (`hack/e2e-*.bats`), `hack/*.sh` test helpers, either E2E CI workflow (`.github/workflows/pull-requests.yaml` for same-repo pull requests, `.github/workflows/e2e-fork.yaml` for forks), or `packages/core/testing/`. §10 covers how the two split the work and which invariants hold them together.
The app suite is **Kyverno Chainsaw** (`hack/e2e-chainsaw/`, one directory per app, each with a `chainsaw-test.yaml`; §7 lists the other layouts Chainsaw accepts). Cluster bootstrap (`hack/e2e-install-cozystack.bats`, `hack/e2e-prepare-cluster.bats`) and the OpenAPI checks (`hack/e2e-test-openapi.bats`) remain BATS.
The app suite is **Kyverno Chainsaw** (`hack/e2e-chainsaw/`, one directory per app, usually with a `chainsaw-test.yaml`; the README there describes the layouts a suite can take, and §7 how they are selected). Cluster bootstrap (`hack/e2e-install-cozystack.bats`, `hack/e2e-prepare-cluster.bats`) and the OpenAPI checks (`hack/e2e-test-openapi.bats`) remain BATS.
## The core principle
+41
View File
@@ -434,6 +434,47 @@ baseline_of_platform() {
rm -rf "$FIX"
}
@test "an allowlist entry is accepted for every suite layout the selectors see" {
# hack/select-e2e.sh enumerates a suite as a directory in or below which
# Chainsaw finds a Test: chainsaw-test.yaml, chainsaw-test.yml, numbered step
# files, or a Test nested in a subdirectory. The allowlist has to accept the
# same set, or a suite that runs cannot be exempted and the run stops before
# the first suite. That includes a chainsaw-test.y*ml that is a directory:
# the selector keeps it so Chainsaw fails on it loudly, and refusing it here
# would stop the run before Chainsaw could report it.
new_fixture
mkdir -p "$FIX/root/plain" "$FIX/root/yml" "$FIX/root/steps" "$FIX/root/nested/sub" "$FIX/root/dirtest/chainsaw-test.yaml" "$FIX/root/dirtestyml/chainsaw-test.yml"
: >"$FIX/root/plain/chainsaw-test.yaml"
: >"$FIX/root/yml/chainsaw-test.yml"
: >"$FIX/root/steps/01-install.yaml"
: >"$FIX/root/nested/sub/chainsaw-test.yaml"
printf 'plain cozystack/cozystack#1\nyml cozystack/cozystack#1\nsteps cozystack/cozystack#1\nnested cozystack/cozystack#1\ndirtest cozystack/cozystack#1\ndirtestyml cozystack/cozystack#1\n' >"$FIX/allow"
lg lg_allowlist_validate "$FIX/allow" "$FIX/root"
rm -rf "$FIX"
}
@test "a parked, empty or step-file-less suite directory cannot be allowlisted" {
# A chainsaw-test.yaml.disabled is registered nowhere and runs nowhere, so an
# exemption for it would exempt nothing today and a real suite the day the
# suffix goes. A file that only looks like a step file is not one to Chainsaw
# either: install-01.yaml has no digits before the dash, and 1a-install.yaml
# passes the find glob but not the step-file regex behind it. A directory
# with a step-file name is not a step file.
new_fixture
mkdir -p "$FIX/root/parked" "$FIX/root/empty" "$FIX/root/notsteps" "$FIX/root/globonly" "$FIX/root/dirsteps/01-install.yaml"
: >"$FIX/root/parked/chainsaw-test.yaml.disabled"
: >"$FIX/root/notsteps/install-01.yaml"
: >"$FIX/root/globonly/1a-install.yaml"
for suite in parked empty notsteps globonly dirsteps; do
printf '%s cozystack/cozystack#1\n' "$suite" >"$FIX/allow"
if lg lg_allowlist_validate "$FIX/allow" "$FIX/root" 2>/dev/null; then
echo "an allowlist entry for '$suite' was accepted" >&2
return 1
fi
done
rm -rf "$FIX"
}
@test "an allowlist whose last line has no newline still has that line validated" {
new_fixture
mkdir -p "$FIX/root/kafka"
+10 -2
View File
@@ -18,7 +18,15 @@ hack/e2e-chainsaw/
└── ...
```
Suites: `postgres`, `bucket`, `mariadb`, `mongodb`, `redis`, `valkey`, `qdrant`, `clickhouse`, `kafka`, `kafka-metadata`, `rabbitmq`, `etcd`, `openbao`, `harbor`, `foundationdb`, `external-dns`, `kuberture`, `vminstance`, `gateway`, `opensearch`, `monitoring`, `kubernetes-latest`, `kubernetes-previous`, `securitygroup`, `seaweedfs`, `computeplane`.
A suite is a directory directly under `hack/e2e-chainsaw/` in or below which Chainsaw finds a Test. Three layouts do that, and the selector (`hack/select-e2e.sh`) and the leak-guard allowlist both recognise the same three:
- `chainsaw-test.yaml`, the usual one, or `chainsaw-test.yml` when the `.yaml` is absent;
- numbered step files such as `01-install.yaml`, which Chainsaw turns into a Test on its own when neither of the above exists;
- either of those in a subdirectory of the suite, since Chainsaw walks every subdirectory of the directory it is handed.
A parked `chainsaw-test.yaml.disabled` is none of these: the directory is then not a suite, is selected by nothing and cannot be allowlisted.
Suites: `postgres`, `bucket`, `mariadb`, `mongodb`, `redis`, `valkey`, `qdrant`, `clickhouse`, `kafka`, `kafka-metadata`, `rabbitmq`, `etcd`, `openbao`, `harbor`, `foundationdb`, `external-dns`, `kuberture`, `vminstance`, `gateway`, `opensearch`, `monitoring`, `kubernetes-latest`, `kubernetes-previous`, `securitygroup`, `seaweedfs`, `computeplane`. `kubernetes-proxmox` is parked as `chainsaw-test.yaml.disabled` and runs only in `.github/workflows/e2e-proxmox.yaml`, which needs a Proxmox hypervisor.
## What Chainsaw buys over the BATS suite
@@ -30,7 +38,7 @@ Suites: `postgres`, `bucket`, `mariadb`, `mongodb`, `redis`, `valkey`, `qdrant`,
## Test anatomy
Each suite is a directory with a `chainsaw-test.yaml` (one or more `Test` docs) plus the manifests it applies. A step has `try` (operations: `apply`, `assert`, `error`, `script`, `delete`, …), optional `catch` (diagnostics on failure), and optional `finally` (teardown regardless of outcome).
Each suite is a directory with one or more `Test` docs (in one of the layouts above, usually a `chainsaw-test.yaml`) plus the manifests it applies. A step has `try` (operations: `apply`, `assert`, `error`, `script`, `delete`, …), optional `catch` (diagnostics on failure), and optional `finally` (teardown regardless of outcome).
Declarative suites assert on `status.conditions` and concrete fields. Inherently imperative suites keep their logic in `script` steps:
+27 -3
View File
@@ -175,9 +175,33 @@ lg_allowlisted() {
awk -v s="$1" '$1 !~ /^#/ && $1 == s { print $2; exit }' "$2"
}
# lg_suite_has_test ROOT SUITE — true when ROOT/SUITE is a directory in or
# below which Chainsaw would find a Test: a chainsaw-test.yaml, a
# chainsaw-test.yml, or a numbered step file such as 01-install.yaml. This is
# the rule hack/select-e2e.sh enumerates the suites with (the find and sed that
# build all_apps there), spelled the same way on purpose: a layout one side
# accepts and the other refuses would run a suite the selector never selects,
# or make a suite that runs impossible to allowlist. Change both together. A
# parked chainsaw-test.yaml.disabled matches none of the names. The type test
# is the selector's too: a step-file name counts unless it is a directory, and
# a chainsaw-test.y*ml counts whatever its type, so Chainsaw reports a
# directory by that name instead of this validation stopping the run first.
lg_suite_has_test() {
local root=$1 suite=$2 path
[ -d "$root/$suite" ] || return 1
while IFS= read -r path; do
case ${path##*/} in
chainsaw-test.yaml|chainsaw-test.yml) return 0 ;;
esac
[[ ${path##*/} =~ ^[0-9]+-[^/]*\.ya?ml$ ]] && return 0
done < <(find "$root/$suite" -mindepth 1 \( ! -type d -o -name chainsaw-test.yaml -o -name chainsaw-test.yml \) \( -name chainsaw-test.yaml -o -name chainsaw-test.yml -o -name '[0-9]*-*.yaml' -o -name '[0-9]*-*.yml' \) 2>/dev/null)
return 1
}
# lg_allowlist_validate ALLOWLIST ROOT — every entry must name an existing suite
# directory under ROOT and carry an issue ref, so a renamed or removed suite
# cannot keep an exemption nobody reads.
# cannot keep an exemption nobody reads. A suite directory is one Chainsaw
# would find a Test in, whatever its layout (lg_suite_has_test).
lg_allowlist_validate() {
local list=$1 root=$2 bad=0 suite ref rest
# `|| [ -n "$suite" ]` keeps a last line with no newline, which `read`
@@ -189,8 +213,8 @@ lg_allowlist_validate() {
echo "leak-guard: allowlist line for '$suite' must be '<suite-dir> <issue-ref>'" >&2
bad=1
fi
if [ ! -f "$root/$suite/chainsaw-test.yaml" ] && [ ! -f "$root/$suite/chainsaw-test.yml" ]; then
echo "leak-guard: allowlist names '$suite', which is not a suite directory under $root" >&2
if ! lg_suite_has_test "$root" "$suite"; then
echo "leak-guard: allowlist names '$suite', which is not a suite directory under $root (no chainsaw-test.yaml, chainsaw-test.yml or numbered step file in or below it)" >&2
bad=1
fi
done <"$list"
+2
View File
@@ -178,6 +178,8 @@ inert_config_pattern='^(examples/|\.github/|\.claude/|\.gemini/|img/|hack/testda
# and `-type f` would be too narrow. A chainsaw-test.y*ml counts whatever its
# type: Chainsaw stats it and fails loudly on a directory, and leaving that
# suite out would hide the failure instead.
# The leak guard's allowlist accepts a suite by the same rule, in
# lg_suite_has_test (hack/e2e-chainsaw/_lib/leak-guard.sh). Change both together.
#
# Captured before the sed/sort rather than piped straight into them: a pipeline
# carries its LAST command's status, so `$(find ... | sed | sort)` would report