Repository navigation
Commit b7d0adc
committed
test(hack): run the unit bats suite under bats(1)
hack/cozytest.sh serves two populations that want opposite things from a
runner: 66 hermetic unit files covering hack/*.sh, the workflows and the
packages tree, and 3 live-cluster imperative suites. This moves the unit half
to real bats and leaves the live half where it is; the hack/e2e-%.bats filter
already in BATS_UNIT_FILES is what keeps them apart.
The unit files need no edits beyond the `load test_helper` the layer below
added. They pass under vanilla bats unchanged because their authors wrote to
the intersection of both runners -- no run, no $status, no skip,
repo-root-relative paths.
What this buys, none of which cozytest offers: --filter-status failed to rerun
only the previous failures, JUnit so CI annotates the failing test instead of
requiring a log read, -j, and deletion of a bespoke awk parser whose rewrite
rules void helper exit codes, corrupt heredoc fixtures on a column-0 brace,
and collide test names after sanitization.
WHY THIS COULD NOT LAND FIRST. Under bats an EXIT handler inside a test body
replaces the one the binary installs for its own bookkeeping, and a test that
then fails prints no TAP line at all -- not `not ok`, nothing. The suite would
have gone green and stayed green while real failures vanished. The 67
test-level handlers are gone as of the commits below this one, and that this
closed the hole is measured rather than assumed: under Bats 1.14.0 all 66
files report a plan equal to their declared @test count and execute all of it
-- 1161 declared, 1161 planned, 1161 executed, 0 failures, and no
`bats warning: Executed N instead of expected M` from any file. An exit code
would have answered whether anything failed and never whether anything ran.
The same 66 files under hack/cozytest.sh execute 1116 of the 1161. The gap is
one pre-existing failure, hack/ghcr-mirror_test.bats, byte-identical to
origin/main here apart from its load line: it fails at its 20th test under
cozytest, which ends that file, and passes 65 of 65 under bats. Not caused by
this change and not addressed by it.
Timing, measured on this tree on 8 cores: 367s of work, 151s wall under
`bats -j`, against 312s serial under cozytest. The wall time is one file
rather than the runner -- hack/run-kubernetes-node-join_test.bats spends 138s
of it in real sleeps -- which is worth knowing before reading the parallel
speedup as the ceiling.
Two consequences worth naming, neither covered by the issue:
bats is a new dependency. cozytest is pure bash+awk, so no runner image or
contributor machine has ever needed anything else. The checks job installs it
from a pinned tag rather than the distro package, whose version varies by base
image, and the pin is the version the suite was verified against. The make
target says so plainly when bats is absent. GNU parallel stays optional --
BATS_JOBS resolves to 1 without it, since `bats -j` exits non-zero rather than
degrading.
The pre-commit lane is the second consumer and does NOT get bats. That job
lints changed YAML and Markdown on a runner with no bats, and the new hook's
path filter covers .github/workflows/, so a workflow edit would drag the whole
shell suite into a lint lane and duplicate the checks job that already runs
`make unit-tests`. It is skipped there by id, keeping the hook a
local-developer gate -- one that costs 151s, which the hook's own comment says
rather than implies.
The tested shell changes. cozytest is #!/bin/sh, which is dash on the CI
runner, and bats runs bash. The POSIX scripts that tests source rather than
execute therefore lose a runtime dash check they had by accident, while the
shell=bash files under e2e-chainsaw/_lib gain correct fidelity for the same
reason. The static replacement is the shellcheck gate in item 5 of #3453,
which does not exist yet.
Refs: #3453
Assisted-By: LLM
Signed-off-by: Myasnikov Daniil <[email protected]>1 parent d63f216 commit b7d0adc
4 files changed
Lines changed: 78 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
60 | 68 | | |
61 | 69 | | |
62 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
| 314 | + | |
| 315 | + | |
314 | 316 | | |
| 317 | + | |
315 | 318 | | |
316 | 319 | | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
317 | 333 | | |
318 | 334 | | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
319 | 342 | | |
320 | 343 | | |
321 | 344 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
29 | 52 | | |
30 | 53 | | |
31 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
153 | | - | |
154 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
155 | 162 | | |
156 | 163 | | |
157 | 164 | | |
| |||
167 | 174 | | |
168 | 175 | | |
169 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
170 | 185 | | |
171 | 186 | | |
172 | 187 | | |
173 | 188 | | |
174 | 189 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
179 | 196 | | |
180 | 197 | | |
181 | 198 | | |
| |||
0 commit comments