fleetd #528: pin drain_gate_refusal's call site, not just the predicate #532
Reference in New Issue
Block a user
Delete Branch "worker/528-drain-gate-call-site-5de83d-7"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes item 1 of fleetd #528.
What was wrong
scripts/redeploy-fleetd.sh's main flow built its owndie "$(drain_gate_refusal "$DO_BUILD" "$JAR_STAGED")"call.drain_gate_refusalitself is well tested (four cases), but nothing proved the main flow's abort actually consulted it. Replacing that whole line with a flatdie "aborted — nothing changed"left the suite green — silently reinstating the exact defect #517 was filed to fix.The fix
Same shape as #521/#526's
should_swap/swap_if_built: the decision and thedie()now live together in one function,refuse_drain_gate(do_build, staged_path), which the main flow calls unconditionally instead of building thedie()call itself.drain_gate_refusalstays separate and separately tested for the message-selection logic —refuse_drain_gateis the only thing that ever dies. A comment aboverefuse_drain_gatestates the remaining hole plainly (deleting its call from the main flow) and names the test that covers it.Four new behavioural tests stub
die()to record whether it was called and with what message, for each of the four cases — these fail ifrefuse_drain_gatestops consultingdrain_gate_refusal, mangles what it passes it, or never callsdieat all. A fifth test,test_refuse_drain_gate_call_site_present, is a source-text pin on the main flow's call site itself (same shape astest_swap_ordered_after_wait_and_before_start) — this is the one that actually kills the item-1 mutation, since sourcing stops before the main flow runs and the four behavioural tests never touch that call site.One care point: my first draft of the "what this doesn't pin" comment literally quoted the call-site string (
refuse_drain_gate "$DO_BUILD" "$JAR_STAGED"), which would have collided with the source-text grep and made it match the comment instead of the real call site (head -1grabs whichever line comes first). Reworded the comment to describe the gap without quoting the exact literal, and confirmed by grep that the literal now occurs exactly once in the file, at the real call site.Acceptance — reported line by line
1.
bash scripts/test-redeploy-fleetd.shexits 0, counts match.Output content (the 3 "FAIL:" substrings are the suite's own internal self-tests of the log-classifier mutation detectors, not real failures):
Test functions defined vs invoked:
2.
bash -npasses under both bash versions.3. The item 1 mutation is killed.
Baseline hash:
0e5a99a22c9c65f72960d8f179ca5299307889e06bc42131f098a513e7b97bd6Mutated
scripts/redeploy-fleetd.sh:710fromto
Ran the suite:
Restored and confirmed byte-identical:
Green control run afterward:
exit=0, 0 realFAIL:lines (same output as acceptance item 1 above).4. Two different-string greps + a line re-read, proving the mutation was actually applied.
Two different search strings (the mutant text vs. the original call-site text), each nonzero/zero as expected — never the false 0-and-0 pair the ticket warned about.
5. Harness proof on my own invocation — a different mutation than item 1's.
Inverted
should_swap's own body (scripts/redeploy-fleetd.sh:208) from[ "$do_build" = 1 ]to[ "$do_build" != 1 ]:Restored, confirmed byte-identical again (same hash as above), and the suite went green again (
exit=0, 0 realFAIL:lines).6. No piped exit-code reporting. Every suite run above was redirected to a file with
echo $?on its own line, never through| tail/| head.Sweep (report-only, per the ticket — nothing outside my two files touched)
Searched every
set -e+pipefailscript in the repo forx="$(cmd | cmd)"followed by a now-dead emptiness check:(
deploy/herdr-inner.shhas noset -eat all;scripts/probe-member-credentials.shhasset -uo pipefailbut deliberately no-eper its own comments — neither qualifies for this pattern, since without-ea failing pipeline can't abort the script early.)Findings:
scripts/rename-checkout.sh— everyvar="$(cmd | cmd)"assignment already carries its own|| true/|| echofallback (e.g. line 141, with a comment at line 139 noting this exact fix was already applied there).scripts/redeploy-fleetd.sh— same; the only pipe-into-assignment call sites (RESTART_MARK,CODE) already carry|| echo 0/|| echo 000.scripts/test-redeploy-fleetd.sh— the pre-existing source-text greps (test_swap_ordered_after_wait_and_before_start, from #526) already carry|| true; my newtest_refuse_drain_gate_call_site_presentgrep also carries|| true.scripts/test-probe-member-credentials.shandscripts/fleetd-launchd-wrapper.sh— no pipe-into-assignment patterns at all.No live instances of the dead-check pattern found outside what #526 already fixed. Nothing fixed in this PR beyond the two files in scope.
Untouched, per the ticket
The seven main-flow decisions with no test of any kind (the three
case "$SUPERVISOR_KIND"dispatches,if [ "$CHECK_ONLY" = 1 ], the drain-gate's own entry condition and itsif [ "$reply" != "yes" ],if [ -z "$HEALTH_BODY" ], and the ok/warn summary) are explicitly out of scope and untouched. My change touches theif [ "$reply" != "yes" ]block only insofar as replacing its body'sdie "$(...)"call withrefuse_drain_gate ...— theifguard itself (one of the seven) is unchanged.Files changed
scripts/redeploy-fleetd.shscripts/test-redeploy-fleetd.shNever ran
scripts/redeploy-fleetd.shitself, with any flag, against the live daemon — all verification was by sourcing the script (astest-redeploy-fleetd.shalready does) and by directbash -n/grep/sedmanipulation of a scratch copy.