Repository navigation
Commit c0ff783
authored
fix(hack): make bats unit tests pass on a BSD/macOS checkout (#4284)
## What this PR does
Refs #4272 (Defects 1 and 2). On a clean checkout of `main`, `make
unit-tests` is red out of the box on macOS for reasons that have nothing
to do with the change under test: the BSD userland shipped with macOS
differs from the GNU tools on the Linux CI runners, and CI never sees
any of it. This PR closes the two worst of those, both scoped to
`hack/`.
**Defect 1 — the runner cannot parse a non-ASCII `@test` title.**
`hack/cozytest.sh` rebuilds each test's function name by walking its
title one character at a time with awk `substr()`. BSD awk aborts that
walk on the first multibyte byte (`towc: multibyte conversion failure`)
rather than returning it, so a file carrying a non-ASCII `@test` title
never parses and not one of its tests runs — silently, because the suite
only reports that the runner errored. Four `hack/*.bats` files carry
such a title today. The fix pins `LC_ALL=C` on all three awk passes
(title parse, run selection, and the exit-code scan of the captured log)
so each reads the input byte-wise; the parse and selection passes must
share the ctype or they would derive mismatched function names for one
title. A new regression test, `hack/cozytest-nonascii-title.bats`,
builds a multibyte-titled fixture at runtime and asserts the runner
actually runs it; it is red against the pre-fix runner
(mutation-verified) and green after.
**Defect 2 — GNU-only `sed -i`.** `hack/nightly-mirror.sh`,
`hack/promote-rewrite-tags.sh`, and the fixture builder in
`hack/promote-rewrite-tags_test.bats` edit files in place with `sed -i`.
BSD sed reads the argument after `-i` as a mandatory backup suffix, so
`sed -i -e` and `sed -i -E` swallow the following flag as that suffix
and the edit either errors or silently no-ops. Each is rerouted through
a temp file, portable to both seds. The `nightly-mirror.sh` rewrite
additionally relied on the GNU `\?` optional quantifier, which BSD BRE
reads as a literal `?` so a bare host was never matched; it is replaced
with the POSIX `\{0,1\}`, equivalent on both. All three suites are green
on macOS after the change, and behaviour on GNU sed is unchanged.
### Scope
This PR is deliberately scoped to Defects 1 and 2. Defect 3 from the
issue — a GNU-only `date -d` in `hack/seaweedfs-naming-audit.sh` — is
tracked separately as #4273 and is left untouched here.
For transparency: with Defect 1 fixed, several `hack/*.bats` suites that
previously never ran now run, and a handful still fail on macOS because
they depend on GNU coreutils `timeout`, which base macOS lacks
(`capture-dataplane`, `cozytest-capture-gate`,
`run-kubernetes-join-timing_test`, `run-kubernetes-runner-cpu_test`,
`runner-identity`). Those failures are pre-existing — identical before
and after this change when the runner is swapped in place — and are a
distinct defect from the two fixed here, so they are out of this PR's
scope. A fully green `make unit-tests` on macOS additionally depends on
#4273 and on that separate `timeout` gap.
### Verification
All fixes were verified on a genuine macOS host (Darwin, BSD awk
20200816 / BSD sed). `hack/cozytest-nonascii-title.bats`,
`hack/nightly-mirror_test.bats` (5 tests), and
`hack/promote-rewrite-tags_test.bats` (17 tests) are green; the two
files the issue reports as running zero tests
(`overlay-main-images_test.bats`, `promote-gate-contract.bats`) now
yield 13 and 15 `Test OK`, matching the issue's numbers. Each fix is
mutation-proven: reverting it turns the corresponding suite red again.
### Downstream repositories
The diff touches only internal `hack/` tooling — the bats test runner
and two release scripts. No downstream repository vendors or restates
these: `cozystack/ccp` and `cozystack/external-apps-example` gate on
`hack/package.mk`, `hack/common-envs.mk` and `hack/update-crd.sh`, none
of which this PR changes, and nothing renames or moves a file or alters
what a make target does.
- [x] No downstream repository is affected by this change
### Release note
```release-note
fix(hack): make the bats unit-test runner parse non-ASCII `@test` titles under BSD awk, and route the in-place edits in `nightly-mirror.sh` and `promote-rewrite-tags.sh` through a temp file so they work under BSD sed — closing two of the host-tool gaps that make `make unit-tests` red on a clean macOS checkout
```
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved test runner compatibility with non-ASCII test titles and
output.
* Improved text-processing and file-rewrite behavior across BSD and GNU
environments.
* Preserved file permissions and metadata during automated rewrites.
* Improved handling of host values and release tags across supported
platforms.
* **Tests**
* Added coverage for non-ASCII test titles.
* Updated rewrite tests for portable BSD and GNU tooling.
* **Documentation**
* Clarified supported BSD and GNU command-line tool compatibility.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->6 files changed
Lines changed: 122 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
97 | 100 | | |
98 | 101 | | |
99 | 102 | | |
| |||
281 | 284 | | |
282 | 285 | | |
283 | 286 | | |
284 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
285 | 295 | | |
286 | 296 | | |
287 | 297 | | |
| |||
310 | 320 | | |
311 | 321 | | |
312 | 322 | | |
313 | | - | |
| 323 | + | |
314 | 324 | | |
315 | 325 | | |
316 | 326 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
137 | 140 | | |
138 | 141 | | |
139 | 142 | | |
| |||
156 | 159 | | |
157 | 160 | | |
158 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
159 | 169 | | |
160 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
161 | 177 | | |
162 | | - | |
163 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
164 | 182 | | |
165 | 183 | | |
166 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | | - | |
191 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
192 | 196 | | |
193 | 197 | | |
194 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
75 | 85 | | |
76 | 86 | | |
77 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
66 | 70 | | |
67 | | - | |
68 | | - | |
| 71 | + | |
| 72 | + | |
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
| |||
0 commit comments