Skip to content

Commit a5d12e7

Browse files
fix(ci): reconcile three unit-test contracts broken by adjacent merges (cozystack#4751)
## What this PR does Unit tests on main are red, and that blocks E2E on every open PR. Three contracts broke the same way. In each case a check from one PR and a line from another merged a few minutes apart on 2026-10-05, with no textual conflict. Any one of them alone keeps the job red, so they are fixed together. The first is the pin on how a suite reads HelmRelease history. cozystack#4689 added it. It accepts `$(kubectl ...` and, since cozystack#3594, the bounded `$(_cozy_guard_kubectl ...` wrapper. Nothing in front of kubectl is allowed. The monitoring suite from cozystack#4678 bounds that read with `$(timeout 30 kubectl ...`, and the bound is wanted. So the pin now accepts an optional `timeout [-k N] N` in front of kubectl. The prefix is spelled out on purpose. Any text would also let through `$(echo kubectl ...)`, which names the shared expansion without running it, and that form is now a refuse case. I checked it with mutations: the new accept cases fail against the old pattern, and a pin that takes any prefix fails a refuse case. The second is the flux install in workflows. cozystack#4645 forbids running fluxcd.io/install.sh and moved every workflow to the SHA-pinned fluxcd/flux2 action. The isp-hosted lane from cozystack#4712 still ran the script. It now uses the same action and version. The third is the negated-assertion audit. It reads the find operand in `\( ! -type d` in select-e2e_test.bats as a shell negation and fails. The line now says `-not -type d`. This is the same change as cozystack#4748, so this PR supersedes it. The audit bug itself is cozystack#4752. After the Go fix, the full log of the unit job had only these two bats failures left. Closes cozystack#4750 Closes cozystack#4755 ### Screenshots ### Downstream repositories - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: ### Release note ```release-note fix(ci): fix three unit-test contracts that went red on main after adjacent merges. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * History checks now recognize direct `kubectl` reads and reads through the supported wrapper, including timeout-bounded commands with an optional kill-grace setting. Commands that only include `kubectl` as an argument, use similarly named commands, or place a timeout before the wrapper are not treated as reads. * **Chores** * The hosted end-to-end workflow now uses a pinned Flux version, and suite selection handles directory exclusions consistently. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents f4a6eb8 + 0cae0e8 commit a5d12e7

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

‎.github/workflows/e2e-isp-hosted.yaml‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,12 @@ jobs:
5050
contents: read
5151
packages: read
5252
steps:
53-
- name: Set up toolchain (flux, oras)
54-
env:
55-
FLUX_VERSION: "2.8.6"
53+
- name: Set up flux
54+
uses: fluxcd/flux2/action@04acaec6161ac4fb1a82ffafa88901c03271d34f # v2.8.6
55+
with:
56+
version: "2.8.6"
57+
- name: Set up toolchain (oras)
5658
run: |
57-
if ! flux version --client 2>/dev/null | grep -Fqx "flux: v${FLUX_VERSION}"; then
58-
install_script="$(mktemp)"
59-
curl -fsSL https://fluxcd.io/install.sh -o "$install_script"
60-
sudo env "FLUX_VERSION=$FLUX_VERSION" bash "$install_script"
61-
rm -f "$install_script"
62-
fi
6359
command -v oras >/dev/null || { curl -fsSL https://github.com/oras-project/oras/releases/download/v1.2.0/oras_1.2.0_linux_amd64.tar.gz | sudo tar -xz -C /usr/local/bin oras; }
6460
6561
- name: Login to GHCR

‎hack/select-e2e_test.bats‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# expanded, but not which side is which, and reading a whole-tree diff off a trace
3232
# line is exactly the moment a test stops being worth having.
3333
full_suite_list() {
34-
find hack/e2e-chainsaw -mindepth 2 \( ! -type d -o -name chainsaw-test.yaml -o -name chainsaw-test.yml \) \
34+
find hack/e2e-chainsaw -mindepth 2 \( -not -type d -o -name chainsaw-test.yaml -o -name chainsaw-test.yml \) \
3535
| sed -nE 's,^hack/e2e-chainsaw/([^/]+)/(.*/)?(chainsaw-test|[0-9]+-[^/]*)\.ya?ml$,\1,p' \
3636
| sort -u | paste -sd ' ' -
3737
}

‎internal/fluxcontract/snapshot_shape_test.go‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,16 @@ var guardConsumers = regexp.MustCompile(
107107
// arriving with the pin green over it.
108108
//
109109
// The spelling of `-o` and the quoting of the substitution are left free, for
110-
// the reason above; each is a case in the accept table below, so that "free"
111-
// is enforced rather than announced. A spelling absent from that table is one
112-
// nobody checked, not one known to be rejected.
110+
// the reason above. So is a `timeout` bound in front of kubectl, which limits
111+
// how long the read may hang and not what it reads. Each is a case in the
112+
// accept table below, so that "free" is enforced rather than announced. The
113+
// bound is spelled out rather than admitted as any text before kubectl,
114+
// because `$(echo kubectl ...)` names the expansion without running it and
115+
// hands the guard the command line as text. Nor is it admitted in front of the
116+
// wrapper: timeout runs a program, the wrapper is a shell function, and that
117+
// read fails every time. The name ends at a blank, so a command that only
118+
// starts with either name is not taken for it. A spelling absent from that
119+
// table is one nobody checked, not one known to be rejected.
113120
//
114121
// A form this pattern does not cover reddens rather than passing: the caller
115122
// test fails with the pattern printed. So the list is a record of what was
@@ -140,7 +147,7 @@ var guardConsumers = regexp.MustCompile(
140147
// unterminated is how a later rewrite reopens the other one.
141148
func sharedReadBy(local string) *regexp.Regexp {
142149
return regexp.MustCompile(`(?m)^[ \t]*` + regexp.QuoteMeta(local) +
143-
`="?\$\((?:_cozy_guard_)?kubectl[^)]*jsonpath=[^)]*\$\{?` + sharedName + `\b`)
150+
`="?\$\((?:(?:timeout[ \t]+(?:-k[ \t]+[0-9]+[smhd]?[ \t]+)?[0-9]+[smhd]?[ \t]+)?kubectl|_cozy_guard_kubectl)[ \t][^)]*jsonpath=[^)]*\$\{?` + sharedName + `\b`)
144151
}
145152

146153
// localFollowedByEquals counts occurrences of one named local followed by an
@@ -418,6 +425,11 @@ func TestGuardCallerReferencesTheSharedExpansion(t *testing.T) {
418425
{"another local carries the shared read", "history_statuses", ` example=$(kubectl get hr -o"jsonpath=${HELMRELEASE_HISTORY_JSONPATH}")`},
419426
{"a longer name starting with the shared one", "history_statuses", ` history_statuses=$(kubectl get hr -o"jsonpath=$HELMRELEASE_HISTORY_JSONPATH_OLD")`},
420427
{"the same, braced", "history_statuses", ` history_statuses=$(kubectl get hr -o"jsonpath=${HELMRELEASE_HISTORY_JSONPATH_OLD}")`},
428+
{"kubectl only an argument", "history_statuses", ` history_statuses=$(echo kubectl get hr -o"jsonpath=${HELMRELEASE_HISTORY_JSONPATH}")`},
429+
{"the same, behind a timeout", "history_statuses", ` history_statuses=$(timeout 30 echo kubectl get hr -o"jsonpath=${HELMRELEASE_HISTORY_JSONPATH}")`},
430+
{"a timeout in front of the wrapper, which it cannot run", "_history", ` _history=$(timeout 30 _cozy_guard_kubectl get hr -o"jsonpath=${HELMRELEASE_HISTORY_JSONPATH}")`},
431+
{"a command whose name only starts with kubectl", "history_statuses", ` history_statuses=$(kubectlx get hr -o"jsonpath=${HELMRELEASE_HISTORY_JSONPATH}")`},
432+
{"a function whose name only starts with the wrapper's", "_history", ` _history=$(_cozy_guard_kubectl_v2 get hr -o"jsonpath=${HELMRELEASE_HISTORY_JSONPATH}")`},
421433
} {
422434
t.Run(tc.flaw, func(t *testing.T) {
423435
if sharedReadBy(tc.local).MatchString(tc.line) {
@@ -438,6 +450,8 @@ func TestGuardCallerReferencesTheSharedExpansion(t *testing.T) {
438450
{"spaced -o", "history_statuses", ` history_statuses=$(kubectl get hr -o jsonpath="${HELMRELEASE_HISTORY_JSONPATH}")`},
439451
{"braceless expansion", "history_statuses", ` history_statuses=$(kubectl get hr -o"jsonpath=$HELMRELEASE_HISTORY_JSONPATH")`},
440452
{"shipped form: through the bounded wrapper, continued", "_history", " _history=$(_cozy_guard_kubectl get hr -n \"$_ns\" \"${_hr}\" \\\n -o\"jsonpath=${HELMRELEASE_HISTORY_JSONPATH}\") || _read_rc=$?"},
453+
{"bounded by timeout", "statuses", ` statuses=$(timeout 30 kubectl get hr -o jsonpath="$HELMRELEASE_HISTORY_JSONPATH")`},
454+
{"bounded with a kill grace", "statuses", ` statuses=$(timeout -k 5 30s kubectl get hr -o jsonpath="$HELMRELEASE_HISTORY_JSONPATH")`},
441455
} {
442456
t.Run(tc.spelling, func(t *testing.T) {
443457
if !sharedReadBy(tc.local).MatchString(tc.line) {

0 commit comments

Comments
 (0)