Repository navigation
fix(cmd): exit non-zero on a declined prompt, and fix connect's command string (#737, #738) - #745
Merged
Merged
Conversation
…onnect's command string #737: declining a prompt exited 0. `spawn terminate <name>` with non-interactive stdin printed "Aborted." and exited 0 while the instance kept running and kept billing — and the only thing separating success from a no-op was a line on stderr, which the reporter's output filter hid. An agent or CI step checking the exit code concluded the spore was gone. A declined prompt now exits 75 (EX_TEMPFAIL, "the user is invited to retry"). Not 1: "you said no" and "it failed" need different handling, and collapsing them forces a caller to parse text. Messages name the consequence — "aborted: web-1 (i-abc) is still running" — instead of a bare "Aborted.". The issue counted ELEVEN such sites, from a hand-picked file list. An exhaustive grep found NINETEEN: terminate (single + job array), cleanup, cancel, state, arraygroup ×2, team ×2, stage, schedule, plugin, dns, alerts, autoscale, pipeline, reaper, bot. All converted. #648's opposite case is preserved: a NAME that resolves to nothing stays success for terminate, because the instance is already gone, which is what the caller wanted. An abort is the reverse. An unanswered prompt (EOF, nothing read) now says "No answer on stdin — pass --yes" rather than the same "Aborted." as a typed no. My first version gated this on stdinIsInteractive() and so refused to read a PIPED answer — breaking `echo y | spawn terminate`, which is legitimate. The pre-existing confirmYes tests caught it: they feed stdin through an os.Pipe, which is not a character device. Narrowed to the EOF case. #738: `connect -- 'cmd; cmd'` quoted a single argument into one word, so the remote shell looked for a command literally named "free -m; tail /var/log/x" and exited 127. That was #369's fix over-correcting — #369 was the opposite bug (argv re-split by space-joining, leaving bash's -c without an argument). The rule is now explicit on argument count: ONE argument is a shell command line, SEVERAL are an argv. Both directions are pinned, since each has now been broken by fixing the other. This deliberately does not match ssh exactly: real ssh does no quoting at all, which is why `ssh h bash -lc "a && b"` is broken for ssh too. The static abort gate took FOUR attempts to make real, each failing for a different reason, all recorded in its comment: 1. grepped `confirmYes(` only — missed terminate.go, which goes via confirmTerminate, and so PASSED against a revert of the very site the issue was filed for; 2. used strings.HasSuffix — `return nil // pre-#737` slipped past it, which is exactly what a revert looks like; 3. used -A 2 — the two lines after terminate's prompt are comments, so the return sat outside the window; 4. now -A 8, any confirm* helper, regex allowing a trailing comment, stopping at the branch's closing brace. Verified against two revert shapes, and a companion test asserts the gate's own reach (33 sites, 4 helpers) so it cannot silently shrink.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #737. Closes #738.
#737 — a declined prompt exited 0
spawn terminate <name>with non-interactive stdin printedAborted.andexited 0 while the instance kept running and kept billing. The only thing
separating success from a no-op was a line on stderr, which the reporter's output
filter hid — so it read as "terminate silently did nothing". An agent or CI step
checking the exit code concludes the spore is gone and stops watching.
Now exits 75 (
EX_TEMPFAIL, "the user is invited to retry"). Deliberatelynot 1: "you said no" and "it failed" need different handling, and collapsing them
forces a caller to parse text to tell a deliberate decline from a broken command.
Messages name the consequence —
aborted: web-1 (i-abc) is still running (terminate it with --yes)— instead of a bareAborted.The issue said eleven sites. There are nineteen. My original count came from
grepping a hand-picked list of files; an exhaustive grep found
terminate(single + job array),
cleanup,cancel,state,arraygroup×2,team×2,stage,schedule,plugin,dns,alerts,autoscale,pipeline,reaperand
bot. All converted.#648's opposite case is preserved and worth restating: a name that resolves to
nothing stays success for
terminate, because the instance is already gone,which is what the caller wanted. An abort is the reverse — the instance is
definitely still there.
A regression I introduced, caught by existing tests
An unanswered prompt (EOF, nothing read) now says
No answer on stdin — pass --yes to confirm non-interactivelyrather than the sameAborted.as a typed"no".
My first version gated that on
stdinIsInteractive()and therefore refused toread a piped answer — breaking
echo y | spawn terminate …, which is alegitimate scripted confirmation. The pre-existing
confirmYestests failedimmediately, because they feed stdin through an
os.Pipe, which is not acharacter device. Narrowed to the EOF case, which is the one the issue was
actually about.
The static gate took four attempts to make real
Each failed differently, and each is recorded in the test's comment because the
pattern is the point:
confirmYes(only — missedterminate.go, which goes throughconfirmTerminate, and so passed against a deliberate revert of the verysite the issue was filed for. Same blind spot that made my count eleven.
strings.HasSuffix—return nil // pre-#737slipped past, which isexactly the shape a revert (or a well-meant annotation) takes.
-A 2— the two lines afterterminate's prompt are comments, so thereturnsat outside the window. Passed again.-A 8, anyconfirm*helper, a regex allowing a trailing comment, and astop at the branch's closing brace so a
return nilafter the block is notblamed on it.
Verified against two revert shapes (via
confirmTerminatewith a comment,and a plain
return nilat aconfirmYessite). A companion test asserts thegate's own reach — 33 sites across 4 helpers — so it cannot silently shrink when
a helper is renamed.
#738 —
connect -- 'cmd; cmd'ran the string as a command nameA single post-
--argument was quoted into one word, so the remote shell lookedfor a command literally named
free -m; tail /var/log/xand exited 127 withNo such file or directorynaming the user's whole command.That was #369's fix over-correcting: #369 was the opposite bug (argv
re-split by space-joining, so
-- bash -lc "a && b"left-cwith no argument),and per-argument quoting fixed it at the cost of the command-string form.
The rule is now explicit on argument count — one argument is a shell command
line, several are an argv — so both work. Both directions are pinned by tests,
since each has now been broken by fixing the other.
This deliberately does not match
sshexactly, and shouldn't: realsshdoes no quoting at all, which is why
ssh h bash -lc "a && b"is broken forsshtoo and why everyone single-quotes for it. Matching it literally wouldreintroduce #369. (Thanks for conceding the point in the issue — the argument
count is what reconciles the two.)
One more thing worth knowing: the single-argument passthrough is unquoted by
design, and there is an explicit test asserting it stays that way, so nobody
"hardens" it back into #738.
Verification
terminate's abort returnsnil(with a comment)1 declined-prompt site(s) still return nil: ./terminate.go:114team delete's abort returnsnil(plain)./team.go:309connectarg quoted again#738: quoting it made the remote shell look for a command with that literal name (exit 127)gofmt,go vet ./...,go test -short ./...(all green),make check-docs,changelog gate,
semgrep scan --config=auto --error(0 findings).Also fixed a malformed expectation in my own new test: I wrote
'echo' 'it'\'''where the real output is
'echo' 'it'\''s'— I'd dropped the trailings'. Thecode was right; the test wasn't.
Remaining from the demo notes
#733 (
spawn statusperforms a DNS write), #734 (CPU sentinels), #735 (boot timereported as stopped time), #736 (terminated instances invisible to lookup).