Skip to content

Commit dffa880

Browse files
committed
test(ci): drop EXIT traps from the overlay tests and pin the classifier's narrowness
hack/bats-no-exit-trap.bats audits every .bats file under hack against the debt its own header declares, and the two commits before this one added three EXIT traps to a file declaring eleven, which is why Unit & controller tests is red. An EXIT trap inside an @test body replaces the one the bats binary installs for its own bookkeeping, so a test that then fails prints no TAP line at all and the suite reads as green. That is the reason the count is exact rather than a ceiling, and the reason the answer here is to stop installing the handler rather than to raise the number. Clean up at the end of the body instead: both runners set -e, so on failure the cleanup is unreachable and the scratch directory survives for inspection. Mutating the classifier separately showed its trailing colon was held by nothing. Remove it and imagePullPolicy matches the key branch, so a file differing only on a pull policy is overlaid and the ref the PR committed is silently replaced. The comment asserting that narrowness now has a test behind it. Assisted-by: LLM Signed-off-by: IvanHunters <[email protected]>
1 parent 895b30f commit dffa880

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

‎hack/overlay-main-images_test.bats‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,37 @@
230230
# digest-pinned siblings the classifier did recognise.
231231
@test "a suffixed image key is a ref, not a config change" {
232232
root=$(pwd)
233-
w=$(mktemp -d); trap 'rm -rf "$w"' EXIT
233+
w=$(mktemp -d)
234234
mkdir -p "$w/packages/system/gamma" "$w/main/system/gamma"
235235
printf 'gamma:\n image: "ghcr.io/cozystack/cozystack/gamma:v1.6.0@sha256:aaaa"\n clientImage: "ghcr.io/cozystack/cozystack/client:v1.6.0"\n' > "$w/packages/system/gamma/values.yaml"
236236
printf 'gamma:\n image: "iad.ocir.io/x/cozystack/gamma:main@sha256:cccc"\n clientImage: "iad.ocir.io/x/cozystack/client:main"\n' > "$w/main/system/gamma/values.yaml"
237237
( cd "$w" && "$root/hack/overlay-main-images.sh" main '[]' ) > "$w/out.txt"
238238
grep -q 'overlay: packages/system/gamma/values.yaml' "$w/out.txt"
239239
grep -q 'iad.ocir.io/x/cozystack/client:main' "$w/packages/system/gamma/values.yaml"
240+
rm -rf "$w"
241+
}
242+
243+
# imagePullPolicy and imagePullSecrets END in something else, and the classifier
244+
# accepts a prefix before `image` only up to a colon for exactly that reason. A
245+
# file differing on one of them differs on CONFIG, so it must keep its committed
246+
# ref rather than be overlaid: drop the colon from the key branch and this file
247+
# is overlaid on a policy change, silently replacing the ref the PR asked for.
248+
@test "a key merely STARTING with image is config, not a ref" {
249+
root=$(pwd)
250+
w=$(mktemp -d)
251+
mkdir -p "$w/packages/system/delta" "$w/main/system/delta"
252+
printf 'delta:\n image: "ghcr.io/cozystack/cozystack/delta:v1.6.0@sha256:aaaa"\n imagePullPolicy: IfNotPresent\n' > "$w/packages/system/delta/values.yaml"
253+
printf 'delta:\n image: "ghcr.io/cozystack/cozystack/delta:v1.6.0@sha256:aaaa"\n imagePullPolicy: Always\n' > "$w/main/system/delta/values.yaml"
254+
( cd "$w" && "$root/hack/overlay-main-images.sh" main '[]' ) > "$w/out.txt"
255+
grep -q 'drift (non-ref change) in packages/system/delta/values.yaml' "$w/out.txt"
256+
! grep -q 'overlay: packages/system/delta/values.yaml' "$w/out.txt"
257+
grep -q 'imagePullPolicy: IfNotPresent' "$w/packages/system/delta/values.yaml"
258+
rm -rf "$w"
240259
}
241260

242261
@test "drift is summarised as a GitHub annotation naming the packages" {
243262
root=$(pwd)
244-
w=$(mktemp -d); trap 'rm -rf "$w"' EXIT
263+
w=$(mktemp -d)
245264
mkdir -p "$w/packages/system/alpha" "$w/main/system/alpha"
246265
mkdir -p "$w/packages/system/beta" "$w/main/system/beta"
247266
printf 'tuning: old\nimage: ghcr.io/cozystack/cozystack/alpha:v1.5.0@sha256:aaaa\n' > "$w/packages/system/alpha/values.yaml"
@@ -257,15 +276,19 @@
257276
grep -q 'system/alpha' ann.txt
258277
grep -q 'system/beta' ann.txt
259278
grep -q '2 package(s)' ann.txt
279+
cd "$root"
280+
rm -rf "$w"
260281
}
261282

262283
@test "no annotation when nothing drifted" {
263284
root=$(pwd)
264-
w=$(mktemp -d); trap 'rm -rf "$w"' EXIT
285+
w=$(mktemp -d)
265286
mkdir -p "$w/packages/system/clean" "$w/main/system/clean"
266287
printf 'image: ghcr.io/cozystack/cozystack/clean:v1.5.0@sha256:aaaa\n' > "$w/packages/system/clean/values.yaml"
267288
printf 'image: iad.ocir.io/x/cozystack/clean:main@sha256:bbbb\n' > "$w/main/system/clean/values.yaml"
268289
cd "$w"
269290
"$root/hack/overlay-main-images.sh" main '[]' > out.txt
270291
! grep -q '::warning title=Image overlay drift' out.txt
292+
cd "$root"
293+
rm -rf "$w"
271294
}

0 commit comments

Comments
 (0)