Skip to content

Commit 14297c4

Browse files
test(hack): drop EXIT-trap cleanup from select-e2e_test
An EXIT handler installed inside an @test body replaces the one the bats binary keeps its bookkeeping in, so a test that FAILS under it prints no TAP line at all and the run merely warns that it executed fewer tests than it planned -- which reads as green to anyone grepping for `not ok`. The file already cleaned up on the last line of the body in every test added since #3392; this brings the older fourteen to the same shape. All fourteen removed one mktemp -d directory, and each test's final statement is an aborting assertion (`[ ... ]`, a grep pipeline, or a helper that exits non-zero), so `set -e` still stops before the appended `rm -rf` and leaves the scratch directory for inspection on a red test. The mid-file note that described the convention for the newer tests now speaks for the whole file, and the `# EXIT-TRAP DEBT:` declaration is gone: hack/bats-no-exit-trap.bats wants the line deleted at zero rather than kept saying zero. Assisted-By: Claude <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent c098d03 commit 14297c4

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

‎hack/select-e2e_test.bats‎

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env bats
2-
# EXIT-TRAP DEBT: 14 -- see hack/bats-no-exit-trap.bats; lower it as the traps go, delete it at zero.
32
# -----------------------------------------------------------------------------
43
# Unit tests for hack/select-e2e.sh
54
#
@@ -9,6 +8,14 @@
98
# non-zero on failure. setup()/teardown() are not honored — each test creates
109
# and cleans its own scratch dir.
1110
#
11+
# That cleanup is the last statement of the body and never a `trap ... EXIT`. A
12+
# handler installed inside an @test body replaces the one the bats binary keeps
13+
# its bookkeeping in, and a test that then FAILS prints no TAP line at all — the
14+
# run only reports having executed fewer tests than it planned, which reads as a
15+
# green suite. Both runners set -e, so on failure the cleanup is unreachable and
16+
# the scratch directory survives for inspection, which is what a failed test
17+
# wants anyway. See hack/bats-no-exit-trap.bats and docs/agents/e2e-testing.md.
18+
#
1219
# Run with: hack/cozytest.sh hack/select-e2e_test.bats
1320
# -----------------------------------------------------------------------------
1421

@@ -48,19 +55,18 @@ assert_full_suite() {
4855

4956
@test "single app diff selects only that suite" {
5057
tmp=$(mktemp -d)
51-
trap 'rm -rf "$tmp"' EXIT
5258
cp -r packages/core/platform/sources "$tmp/sources"
5359
echo "packages/apps/postgres/values.yaml" > "$tmp/diff"
5460
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
5561
[ "$output" = "postgres" ]
62+
rm -rf "$tmp"
5663
}
5764

5865
@test "operator diff selects all dependent app suites" {
5966
# postgres-operator is depended on by postgres-application, harbor-application
6067
# (Harbor uses postgres as its backing DB), and monitoring-application (Grafana
6168
# DB). monitoring has no chainsaw suite so it's filtered out by the selector.
6269
tmp=$(mktemp -d)
63-
trap 'rm -rf "$tmp"' EXIT
6470
cp -r packages/core/platform/sources "$tmp/sources"
6571
echo "packages/system/postgres-operator/values.yaml" > "$tmp/diff"
6672
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
@@ -70,6 +76,7 @@ assert_full_suite() {
7076
echo "operator diff must not trigger full suite; got: $output" >&2
7177
exit 1
7278
fi
79+
rm -rf "$tmp"
7380
}
7481

7582
@test "engine-dependency change does not fan out via the ordering edge" {
@@ -80,7 +87,6 @@ assert_full_suite() {
8087
# genuine direct dependents (postgres, harbor, ...), never unrelated apps
8188
# like kafka that reach cert-manager solely through the engine.
8289
tmp=$(mktemp -d)
83-
trap 'rm -rf "$tmp"' EXIT
8490
cp -r packages/core/platform/sources "$tmp/sources"
8591
echo "packages/system/cert-manager/values.yaml" > "$tmp/diff"
8692
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
@@ -90,6 +96,7 @@ assert_full_suite() {
9096
echo "cert-manager change must not fan out via engine; got: $output" >&2
9197
exit 1
9298
fi
99+
rm -rf "$tmp"
93100
}
94101

95102
@test "cozystack-basics does not narrow to a suite that lands downstream of it" {
@@ -168,7 +175,6 @@ assert_full_suite() {
168175

169176
@test "library change triggers full suite" {
170177
tmp=$(mktemp -d)
171-
trap 'rm -rf "$tmp"' EXIT
172178
cp -r packages/core/platform/sources "$tmp/sources"
173179
echo "packages/library/cozy-lib/templates/_helpers.tpl" > "$tmp/diff"
174180
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources" 2>"$tmp/err")
@@ -183,20 +189,20 @@ assert_full_suite() {
183189
cat "$tmp/err" >&2
184190
exit 1
185191
fi
192+
rm -rf "$tmp"
186193
}
187194

188195
@test "docs-only diff selects nothing" {
189196
tmp=$(mktemp -d)
190-
trap 'rm -rf "$tmp"' EXIT
191197
cp -r packages/core/platform/sources "$tmp/sources"
192198
echo "docs/README.md" > "$tmp/diff"
193199
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
194200
[ -z "$output" ]
201+
rm -rf "$tmp"
195202
}
196203

197204
@test "kubernetes-application maps to the four kubernetes suites" {
198205
tmp=$(mktemp -d)
199-
trap 'rm -rf "$tmp"' EXIT
200206
cp -r packages/core/platform/sources "$tmp/sources"
201207
echo "packages/apps/kubernetes/values.yaml" > "$tmp/diff"
202208
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
@@ -206,20 +212,20 @@ assert_full_suite() {
206212
# chart-only change must select them too.
207213
echo "$output" | grep -q "kubernetes-oidc-system"
208214
echo "$output" | grep -q "kubernetes-oidc-customconfig"
215+
rm -rf "$tmp"
209216
}
210217

211218
@test "dashboards-only diff selects nothing (path is plural)" {
212219
tmp=$(mktemp -d)
213-
trap 'rm -rf "$tmp"' EXIT
214220
cp -r packages/core/platform/sources "$tmp/sources"
215221
echo "dashboards/gpu/gpu-fleet.json" > "$tmp/diff"
216222
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
217223
[ -z "$output" ]
224+
rm -rf "$tmp"
218225
}
219226

220227
@test "shared E2E helper script triggers full suite" {
221228
tmp=$(mktemp -d)
222-
trap 'rm -rf "$tmp"' EXIT
223229
cp -r packages/core/platform/sources "$tmp/sources"
224230
echo "hack/e2e-chainsaw/_lib/run-kubernetes.sh" > "$tmp/diff"
225231
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources" 2>"$tmp/err")
@@ -229,60 +235,61 @@ assert_full_suite() {
229235
cat "$tmp/err" >&2
230236
exit 1
231237
fi
238+
rm -rf "$tmp"
232239
}
233240

234241
@test "chainsaw config change triggers full suite" {
235242
tmp=$(mktemp -d)
236-
trap 'rm -rf "$tmp"' EXIT
237243
cp -r packages/core/platform/sources "$tmp/sources"
238244
echo "hack/e2e-chainsaw/.chainsaw.yaml" > "$tmp/diff"
239245
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
240246
assert_full_suite "$output"
247+
rm -rf "$tmp"
241248
}
242249

243250
@test "install bats triggers full suite" {
244251
tmp=$(mktemp -d)
245-
trap 'rm -rf "$tmp"' EXIT
246252
cp -r packages/core/platform/sources "$tmp/sources"
247253
echo "hack/e2e-install-cozystack.bats" > "$tmp/diff"
248254
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
249255
assert_full_suite "$output"
256+
rm -rf "$tmp"
250257
}
251258

252259
@test "per-suite edit selects only that suite, never escalates" {
253260
tmp=$(mktemp -d)
254-
trap 'rm -rf "$tmp"' EXIT
255261
cp -r packages/core/platform/sources "$tmp/sources"
256262
echo "hack/e2e-chainsaw/redis/chainsaw-test.yaml" > "$tmp/diff"
257263
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
258264
[ "$output" = "redis" ]
265+
rm -rf "$tmp"
259266
}
260267

261268
@test "pull-requests workflow change triggers full suite" {
262269
tmp=$(mktemp -d)
263-
trap 'rm -rf "$tmp"' EXIT
264270
cp -r packages/core/platform/sources "$tmp/sources"
265271
echo ".github/workflows/pull-requests.yaml" > "$tmp/diff"
266272
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
267273
assert_full_suite "$output"
274+
rm -rf "$tmp"
268275
}
269276

270277
@test "backup example harness edit selects its app suite" {
271278
tmp=$(mktemp -d)
272-
trap 'rm -rf "$tmp"' EXIT
273279
cp -r packages/core/platform/sources "$tmp/sources"
274280
echo "examples/backups/postgres/run-all.sh" > "$tmp/diff"
275281
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
276282
[ "$output" = "postgres" ]
283+
rm -rf "$tmp"
277284
}
278285

279286
@test "backup example without a matching suite selects nothing" {
280287
tmp=$(mktemp -d)
281-
trap 'rm -rf "$tmp"' EXIT
282288
cp -r packages/core/platform/sources "$tmp/sources"
283289
echo "examples/backups/no-such-app/run.sh" > "$tmp/diff"
284290
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources") || true
285291
[ -z "$output" ]
292+
rm -rf "$tmp"
286293
}
287294

288295
# --- #3392: every path is classified; unclassified escalates -----------------
@@ -409,12 +416,12 @@ assert_full_suite() {
409416
# invisible to a caller that pipes it; a caller assembling the list itself sees
410417
# it immediately. Both cases below are red without `|| [ -n "$file" ]`.
411418
#
412-
# Cleanup here, as in every test added with this change, is the last statement
413-
# of the body rather than a `trap ... EXIT`: that trap replaces the one the bats
414-
# binary installs for its own bookkeeping, and a test failing under it can print
415-
# no TAP line at all, which is the opposite of what a regression pin is for.
416-
# Last, not before the assertion, so that `set -e` leaves the scratch directory
417-
# behind on failure for inspection (docs/agents/e2e-testing.md §3).
419+
# Cleanup here, as everywhere in this file, is the last statement of the body
420+
# rather than a `trap ... EXIT`: that trap replaces the one the bats binary
421+
# installs for its own bookkeeping, and a test failing under it can print no TAP
422+
# line at all, which is the opposite of what a regression pin is for. Last, not
423+
# before the assertion, so that `set -e` leaves the scratch directory behind on
424+
# failure for inspection (docs/agents/e2e-testing.md §3).
418425

419426
@test "editing a disabled chainsaw suite selects nothing" {
420427
# A .disabled suite runs nowhere, so its edits are the one file class that

0 commit comments

Comments
 (0)