From ae36143b72f72cbcef1277e2e490c27822b90c5d Mon Sep 17 00:00:00 2001 From: Marian Koreniuk Date: Mon, 19 Oct 2026 23:20:19 +0200 Subject: [PATCH 1/3] fix(e2e): validate the leak allowlist against every suite layout lg_allowlist_validate accepted only /chainsaw-test.y*ml, while the selectors already see step-file suites and a Test nested below the suite directory. A suite in one of those layouts could not be allowlisted at all: the run stopped before the first suite. Validate the allowlist with the rule hack/select-e2e.sh enumerates suites with, spelled the same way on both sides and cross-referenced so they move together. Describe the three layouts once in the e2e-chainsaw README, point the agent doc at it, and list kubernetes-proxmox as the parked suite. Closes #4659 Signed-off-by: Marian Koreniuk Assisted-by: LLM (cherry picked from commit 782e0ab64d67c9d476c4ed7aae9a450446d44d52) Signed-off-by: cozystack-ci[bot] <274107086+cozystack-ci[bot]@users.noreply.github.com> --- docs/agents/e2e-testing.md | 2 +- hack/chainsaw-leak-guard_test.bats | 36 ++++++++++++++++++++++++++++ hack/e2e-chainsaw/README.md | 12 ++++++++-- hack/e2e-chainsaw/_lib/leak-guard.sh | 27 ++++++++++++++++++--- 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/docs/agents/e2e-testing.md b/docs/agents/e2e-testing.md index 55709771d..2d5b2e668 100644 --- a/docs/agents/e2e-testing.md +++ b/docs/agents/e2e-testing.md @@ -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 diff --git a/hack/chainsaw-leak-guard_test.bats b/hack/chainsaw-leak-guard_test.bats index 8bf3a2618..3fbe5f173 100644 --- a/hack/chainsaw-leak-guard_test.bats +++ b/hack/chainsaw-leak-guard_test.bats @@ -434,6 +434,42 @@ 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. + new_fixture + mkdir -p "$FIX/root/plain" "$FIX/root/yml" "$FIX/root/steps" "$FIX/root/nested/sub" + : >"$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\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 (no digits before the + # dash) is not one to Chainsaw either. + new_fixture + mkdir -p "$FIX/root/parked" "$FIX/root/empty" "$FIX/root/notsteps" + : >"$FIX/root/parked/chainsaw-test.yaml.disabled" + : >"$FIX/root/notsteps/install-01.yaml" + for suite in parked empty notsteps; 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" diff --git a/hack/e2e-chainsaw/README.md b/hack/e2e-chainsaw/README.md index d4dd0814c..10da4dc3d 100644 --- a/hack/e2e-chainsaw/README.md +++ b/hack/e2e-chainsaw/README.md @@ -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`), the runner (`hack/e2e-chainsaw-run.sh`) and the leak-guard allowlist all 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: diff --git a/hack/e2e-chainsaw/_lib/leak-guard.sh b/hack/e2e-chainsaw/_lib/leak-guard.sh index d63cd944e..8ae93bb01 100644 --- a/hack/e2e-chainsaw/_lib/leak-guard.sh +++ b/hack/e2e-chainsaw/_lib/leak-guard.sh @@ -175,9 +175,30 @@ 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. +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 \( -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 +210,8 @@ lg_allowlist_validate() { echo "leak-guard: allowlist line for '$suite' must be ' '" >&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" From 10d1e7d28643793512994975433a96506713d21c Mon Sep 17 00:00:00 2001 From: Marian Koreniuk Date: Wed, 28 Oct 2026 18:53:07 +0100 Subject: [PATCH 2/3] fix(e2e): take the selector's type test in the allowlist scan and pin its regex lg_suite_has_test dropped every directory with `! -type d`, but the selector keeps a chainsaw-test.y*ml whatever its type, so Chainsaw can fail loudly on a directory by that name. An allowlisted suite in that shape failed validation and stopped the run before Chainsaw reported the real error. Use the selector's own `\( ! -type d -o -name chainsaw-test.yaml -o -name chainsaw-test.yml \)`, which still drops a directory with a step-file name. The step-file regex behind the find glob was never reached by a test: install-01.yaml is already filtered by the glob. 1a-install.yaml passes the glob and not the regex, so it pins the regex; a directory named chainsaw-test.yaml and one named 01-install.yaml pin the type test. The README said the runner recognises the same three layouts. It recognises none: it hands every top-level directory to Chainsaw. Signed-off-by: Marian Koreniuk Assisted-by: LLM (cherry picked from commit cd983d416eaa8925467c6d1ff431faec3d11c317) Signed-off-by: cozystack-ci[bot] <274107086+cozystack-ci[bot]@users.noreply.github.com> --- hack/chainsaw-leak-guard_test.bats | 19 ++++++++++++------- hack/e2e-chainsaw/README.md | 2 +- hack/e2e-chainsaw/_lib/leak-guard.sh | 7 +++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/hack/chainsaw-leak-guard_test.bats b/hack/chainsaw-leak-guard_test.bats index 3fbe5f173..6dadd5e5d 100644 --- a/hack/chainsaw-leak-guard_test.bats +++ b/hack/chainsaw-leak-guard_test.bats @@ -439,14 +439,16 @@ baseline_of_platform() { # 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. + # the first suite. That includes a chainsaw-test.yaml 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" + mkdir -p "$FIX/root/plain" "$FIX/root/yml" "$FIX/root/steps" "$FIX/root/nested/sub" "$FIX/root/dirtest/chainsaw-test.yaml" : >"$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\n' >"$FIX/allow" + printf 'plain cozystack/cozystack#1\nyml cozystack/cozystack#1\nsteps cozystack/cozystack#1\nnested cozystack/cozystack#1\ndirtest cozystack/cozystack#1\n' >"$FIX/allow" lg lg_allowlist_validate "$FIX/allow" "$FIX/root" rm -rf "$FIX" } @@ -454,13 +456,16 @@ baseline_of_platform() { @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 (no digits before the - # dash) is not one to Chainsaw either. + # 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" + 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" - for suite in parked empty notsteps; do + : >"$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 diff --git a/hack/e2e-chainsaw/README.md b/hack/e2e-chainsaw/README.md index 10da4dc3d..f76e1ff04 100644 --- a/hack/e2e-chainsaw/README.md +++ b/hack/e2e-chainsaw/README.md @@ -18,7 +18,7 @@ hack/e2e-chainsaw/ └── ... ``` -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`), the runner (`hack/e2e-chainsaw-run.sh`) and the leak-guard allowlist all recognise the same three: +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; diff --git a/hack/e2e-chainsaw/_lib/leak-guard.sh b/hack/e2e-chainsaw/_lib/leak-guard.sh index 8ae93bb01..ec3705265 100644 --- a/hack/e2e-chainsaw/_lib/leak-guard.sh +++ b/hack/e2e-chainsaw/_lib/leak-guard.sh @@ -182,7 +182,10 @@ lg_allowlisted() { # 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. +# 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 @@ -191,7 +194,7 @@ lg_suite_has_test() { chainsaw-test.yaml|chainsaw-test.yml) return 0 ;; esac [[ ${path##*/} =~ ^[0-9]+-[^/]*\.ya?ml$ ]] && return 0 - done < <(find "$root/$suite" -mindepth 1 ! -type d \( -name chainsaw-test.yaml -o -name chainsaw-test.yml -o -name '[0-9]*-*.yaml' -o -name '[0-9]*-*.yml' \) 2>/dev/null) + 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 } From 7ec550b7b81fd49f87b2f17a19b21d96dac9937d Mon Sep 17 00:00:00 2001 From: Marian Koreniuk Date: Thu, 29 Oct 2026 13:59:43 +0100 Subject: [PATCH 3/3] fix(e2e): point the selector's suite rule back at the allowlist rule The first commit says the two rules are cross-referenced so they move together, but only lg_suite_has_test pointed at the selector. The selector's suite enumeration comment now names lg_suite_has_test as well, so a change to either side prompts the other. The layout case also pins a chainsaw-test.yml that is a directory, the other half of the type test: dropping that name from the find now turns the case red. Signed-off-by: Marian Koreniuk Assisted-by: LLM (cherry picked from commit b61ad29783f6377d538bff5110eb796c26d207cd) Signed-off-by: cozystack-ci[bot] <274107086+cozystack-ci[bot]@users.noreply.github.com> --- hack/chainsaw-leak-guard_test.bats | 6 +++--- hack/select-e2e.sh | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/hack/chainsaw-leak-guard_test.bats b/hack/chainsaw-leak-guard_test.bats index 6dadd5e5d..5506e8c40 100644 --- a/hack/chainsaw-leak-guard_test.bats +++ b/hack/chainsaw-leak-guard_test.bats @@ -439,16 +439,16 @@ baseline_of_platform() { # 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.yaml that is a directory: + # 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" + 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\n' >"$FIX/allow" + 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" } diff --git a/hack/select-e2e.sh b/hack/select-e2e.sh index 4c33cb594..fcb7651e3 100755 --- a/hack/select-e2e.sh +++ b/hack/select-e2e.sh @@ -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