Skip to content

Commit 39f4c34

Browse files
test(hack): cover both false verdicts the RD preset check can reach
A read that failed and a membership test that failed are different defects, and neither of them is drift, so each needs a guard that fails if the check goes back to reporting it as a missing preset. The membership guard feeds the check a list doubled past 4 MiB. fs/pipe-max-size is 1 MiB, so no pipe can hold that and the old pipeline fails on every preset rather than losing a race the writer often won at the sizes CI actually saw. Scoping that case to a one-file fixture tree keeps it at 47 greps instead of 1504. Two further guards exist because a fixture that merely omits a value cannot see what they cover. Both flags on the membership grep are load-bearing: `t1.nanoX` satisfies a match once -x is gone, `c1Xsmall` satisfies one once -F is gone, and either way the check passes a schema carrying neither preset. And every case here reads its fixture out of EXPECTED, so none of them can notice a name dropped from EXPECTED itself, which is the one thing this check exists to prevent; that array is now compared against the 40 instance types and 7 aliases its own header claims, built independently. The jq comment is corrected on two counts. A discarded status left a failed read either skipped in silence or truncated, not always empty. And the unit-lane failures it was written to explain come from the membership pipeline instead: all 41 broken-pipe lines in the September runs name line 39, which is that pipeline and not the jq one, and each accused exactly one preset rather than the contiguous tail a truncated read leaves behind. Assisted-by: LLM Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent a715840 commit 39f4c34

2 files changed

Lines changed: 175 additions & 26 deletions

File tree

‎hack/check-rd-presets.sh‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@ for f in packages/system/*-rd/cozyrds/*.yaml; do
2727
# path ending in "resourcesPreset" rather than a description heuristic,
2828
# so an unrelated field with "preset" in its description does not match.
2929
#
30-
# Fed by here-string rather than `printf | jq`, and its status is read rather
31-
# than discarded, because the two together produced a FALSE FAILURE naming a
32-
# preset that is present in the file. On a 4-CPU/16 GiB runner under `make
33-
# -j4`, jq processing the largest schema here would exit early; `printf` then
34-
# died of EPIPE ("write error: Broken pipe"), `2>/dev/null || true` hid the
35-
# status, and $enums held the PARTIAL output -- non-empty, so the guard below
36-
# passed it through, and every expected value past the truncation point was
37-
# reported missing. Seen on two PRs the same day naming different files and
38-
# different presets, which is the tell: a real drift names the same pair every
39-
# time. A here-string cannot raise EPIPE, and a non-zero jq is now named as an
40-
# unreadable schema instead of being converted into a data defect.
30+
# jq's status is read rather than discarded. `2>/dev/null || true` left a
31+
# read that failed indistinguishable from one that found nothing, and it goes
32+
# two ways: with no output the emptiness guard below turned it into a clean
33+
# skip, so a schema nobody could parse silently passed the check whose whole
34+
# job is to parse it, and with output already written before jq died $enums
35+
# held a truncated list that every preset past the cut was then judged
36+
# against. An errored read is now named as one and carries jq's own reason.
37+
# Fed by here-string for the same reason as the membership test below.
4138
if ! enums=$(jq -r '
4239
[paths(type == "object" and has("enum")) as $p
4340
| select($p[-1] == "resourcesPreset")

‎hack/check-rd-presets_test.bats‎

Lines changed: 167 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,73 @@
11
#!/usr/bin/env bats
22
# -----------------------------------------------------------------------------
3-
# Regression guard for hack/check-rd-presets.sh: a schema it could not read must
4-
# be reported as unreadable, never as a chart whose presets drifted.
3+
# Regression guards for hack/check-rd-presets.sh, covering the two ways it used
4+
# to reach a verdict the files do not support, plus the matching contract the
5+
# fix rests on.
56
#
6-
# The distinction is not academic. The script used to feed jq through a pipe and
7-
# discard its status (`printf '%s' "$schema" | jq ... 2>/dev/null || true`). When
8-
# jq exited early -- seen on the 4-CPU/16 GiB unit runner under `make -j4` --
9-
# printf died of EPIPE and the variable held PARTIAL output. Non-empty, so the
10-
# emptiness guard passed it through, and every expected preset past the
11-
# truncation point was reported missing from a file that contained all of them.
12-
# Two PRs the same day were reddened that way, naming different files and
13-
# different presets, which is the tell: real drift names the same pair every run.
7+
# The first is a read it could not complete. `printf '%s' "$schema" | jq ...
8+
# 2>/dev/null || true` discarded jq's status, so a read that failed was skipped
9+
# in silence, or worse, passed on whatever jq had already written before it
10+
# died: the check that exists to parse a schema was free not to parse it.
1411
#
15-
# The stub reproduces exactly that shape -- some values on stdout, an error on
16-
# stderr, a non-zero exit -- because that is the case the old code turned into a
17-
# false verdict, and a stub that merely fails with no output would pass against
18-
# the old code too.
12+
# The second is the one that reddened pull requests. Membership was decided by
13+
# `printf '%s\n' "$enums" | grep -Fqx -- "$want"`, and `grep -q` exits at its
14+
# first match. Once the list is longer than the pipe buffer the writer is still
15+
# writing when the reader leaves, the write fails, and `set -o pipefail` reports
16+
# the pipeline as failed even though grep matched -- a verdict indistinguishable
17+
# from "not found", so a preset that is present is named as missing. Below the
18+
# buffer size the writer usually wins, which is why it stayed hidden while
19+
# `make unit-tests` ran serially and started firing on the 4-CPU runner under
20+
# `make -j4`: 32 of the 48 unit-lane failures over 2026-09-04..09-10, each
21+
# naming a different preset in a different file, each carrying one
22+
# "printf: write error: Broken pipe" per preset it accused.
23+
#
24+
# Cases that need control over which files are walked build a package tree with
25+
# a single ApplicationDefinition in it, because the checker globs
26+
# packages/system/*-rd/cozyrds/*.yaml relative to the working directory. That
27+
# is what keeps the large-payload case to 47 greps rather than 1504.
1928
#
2029
# Compatible with the in-repo cozytest.sh runner, which runs each @test in a
2130
# fresh subshell under `set -u` and provides no bats `run`/`$status`.
2231
# -----------------------------------------------------------------------------
2332

33+
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
34+
CHECK="$REPO_ROOT/hack/check-rd-presets.sh"
35+
36+
# The presets the checker expects, one per line. Read from its own source of
37+
# truth so a fixture cannot disagree with it by accident; the last case below is
38+
# what stops that array from being whatever the schemas happen to carry.
39+
expected_presets() {
40+
sed -n '/^EXPECTED=(/,/^)/p' "$CHECK" | sed '1d;$d' | tr -s '[:space:]' '\n' | sed '/^$/d'
41+
}
42+
43+
# A package tree holding one ApplicationDefinition, left as the current
44+
# directory. The schema body is a placeholder: every case that uses this drives
45+
# the enum through the jq stub instead.
46+
make_tree() {
47+
dir=$(mktemp -d)
48+
cd "$dir"
49+
mkdir -p packages/system/foo-rd/cozyrds packages/apps packages/extra
50+
printf 'spec:\n application:\n openAPISchema: |-\n {"type":"object"}\n' \
51+
> packages/system/foo-rd/cozyrds/foo.yaml
52+
}
53+
54+
# A jq stub in $1/jq that prints the file $2 and exits 0.
55+
install_jq_stub() {
56+
cat > "$1/jq" <<STUB
57+
#!/bin/sh
58+
cat "$2"
59+
STUB
60+
chmod +x "$1/jq"
61+
}
62+
63+
# Last line of a test body rather than a trap, which the runners forbid: both
64+
# set -e, so a failing test never reaches this and its tree survives for
65+
# inspection, which is what a failed test wants.
66+
cleanup() {
67+
cd /
68+
rm -rf "$dir"
69+
}
70+
2471
@test "a schema that cannot be read is named as unreadable, not as a missing preset" {
2572
work=$(mktemp -d)
2673
cat > "$work/jq" <<'STUB'
@@ -32,7 +79,7 @@ STUB
3279
chmod +x "$work/jq"
3380

3481
rc=0
35-
out=$(PATH="$work:$PATH" hack/check-rd-presets.sh 2>&1) || rc=$?
82+
out=$(PATH="$work:$PATH" "$CHECK" 2>&1) || rc=$?
3683
rm -rf "$work"
3784

3885
if [ "$rc" -eq 0 ]; then
@@ -63,3 +110,108 @@ STUB
63110
exit 1 ;;
64111
esac
65112
}
113+
114+
@test "a preset list far past any pipe capacity is read whole, not reported missing" {
115+
# A schema that repeats the set per component is ordinary: seaweedfs-rd
116+
# carries 329 entries today. Doubled to 4 MiB it is past what a process can
117+
# even ask for -- fs/pipe-max-size is 1 MiB on the runners -- so the old
118+
# pipeline cannot finish its write before grep leaves, on any host, rather
119+
# than losing a race the writer often wins at the sizes seen in CI.
120+
make_tree
121+
expected_presets > enums
122+
while [ "$(wc -c < enums)" -lt 4194304 ]; do
123+
cat enums enums > enums.next
124+
mv enums.next enums
125+
done
126+
install_jq_stub "$dir" "$dir/enums"
127+
128+
rc=0
129+
out=$(PATH="$dir:$PATH" "$CHECK" 2>&1) || rc=$?
130+
if [ "$rc" -ne 0 ]; then
131+
echo "a complete preset list was rejected because of its length" >&2
132+
printf '%s\n' "$out" >&2
133+
exit 1
134+
fi
135+
cleanup
136+
}
137+
138+
@test "a preset genuinely absent from the schema is reported and named" {
139+
make_tree
140+
expected_presets | sed '/^c1\.medium$/d' > enums
141+
install_jq_stub "$dir" "$dir/enums"
142+
143+
rc=0
144+
out=$(PATH="$dir:$PATH" "$CHECK" 2>&1) || rc=$?
145+
if [ "$rc" -eq 0 ]; then
146+
echo "a schema missing c1.medium passed" >&2
147+
printf '%s\n' "$out" >&2
148+
exit 1
149+
fi
150+
case "$out" in
151+
*"resourcesPreset enum missing: c1.medium"*) ;;
152+
*)
153+
echo "the verdict did not name c1.medium as the missing preset" >&2
154+
printf '%s\n' "$out" >&2
155+
exit 1 ;;
156+
esac
157+
cleanup
158+
}
159+
160+
@test "a preset the schema only resembles does not count as carrying it" {
161+
# Both flags on the membership grep are load-bearing and neither is visible
162+
# from a fixture that simply omits a value. `t1.nanoX` satisfies a match
163+
# without -x, and `c1Xsmall` satisfies one without -F because the `.` in the
164+
# pattern then matches any character. Either way the checker would pass a
165+
# schema that carries neither preset, so the verdict has to name both.
166+
make_tree
167+
expected_presets | sed 's/^t1\.nano$/t1.nanoX/; s/^c1\.small$/c1Xsmall/' > enums
168+
install_jq_stub "$dir" "$dir/enums"
169+
170+
rc=0
171+
out=$(PATH="$dir:$PATH" "$CHECK" 2>&1) || rc=$?
172+
if [ "$rc" -eq 0 ]; then
173+
echo "a schema carrying t1.nanoX and c1Xsmall passed as carrying t1.nano and c1.small" >&2
174+
printf '%s\n' "$out" >&2
175+
exit 1
176+
fi
177+
for want in t1.nano c1.small; do
178+
case "$out" in
179+
*"$want"*) ;;
180+
*)
181+
echo "$want was not reported missing, so the match is not literal and whole-line" >&2
182+
printf '%s\n' "$out" >&2
183+
exit 1 ;;
184+
esac
185+
done
186+
cleanup
187+
}
188+
189+
@test "EXPECTED is the canonical set, not whatever the schemas happen to carry" {
190+
# Built from the contract the script's own header states -- five instance
191+
# type families across eight sizes, plus the seven legacy aliases, which
192+
# have no 4xlarge -- rather than read out of the array. Every case above
193+
# takes its fixture from EXPECTED and therefore cannot see a name being
194+
# dropped from it, which is the one thing this check exists to prevent.
195+
work=$(mktemp -d)
196+
for family in t1 c1 s1 u1 m1; do
197+
for size in nano micro small medium large xlarge 2xlarge 4xlarge; do
198+
echo "$family.$size"
199+
done
200+
done > "$work/canonical"
201+
printf '%s\n' nano micro small medium large xlarge 2xlarge >> "$work/canonical"
202+
sort "$work/canonical" > "$work/canonical.sorted"
203+
expected_presets | sort > "$work/actual.sorted"
204+
205+
n=$(wc -l < "$work/canonical.sorted")
206+
if [ "$n" -ne 47 ]; then
207+
echo "the canonical set built here is $n names, not the documented 47" >&2
208+
rm -rf "$work"
209+
exit 1
210+
fi
211+
if ! diff -u "$work/canonical.sorted" "$work/actual.sorted"; then
212+
echo "EXPECTED no longer matches the canonical 40 instance types plus 7 aliases" >&2
213+
rm -rf "$work"
214+
exit 1
215+
fi
216+
rm -rf "$work"
217+
}

0 commit comments

Comments
 (0)