From d2f5254cebc4ef92a514b3249c7c7f670c3133a3 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Sat, 21 Nov 2026 03:08:28 -0500 Subject: [PATCH] fix(terminal): never confirm a restart prompt that was cancelled ConfirmRestart returned (true, Canceled) when y was typed before ^C. Its one caller reads the error first, so no restart happened, but the answer contradicted the cancellation and the next caller could act on it. A cancelled prompt now answers false. --- cli/internal/terminal/restart.go | 6 +++++- cli/internal/terminal/restart_test.go | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cli/internal/terminal/restart.go b/cli/internal/terminal/restart.go index 6d65a9341..26bbf088d 100644 --- a/cli/internal/terminal/restart.go +++ b/cli/internal/terminal/restart.go @@ -42,7 +42,11 @@ func (t *Service) ConfirmRestart(ctx context.Context, running daemon.ConnectionS return false, err } answer := final.(restartConfirmation) - return Confirmed(answer.input), answer.err + // A cancelled prompt never confirms, whatever was typed before it. + if answer.err != nil { + return false, answer.err + } + return Confirmed(answer.input), nil } type restartConfirmation struct { diff --git a/cli/internal/terminal/restart_test.go b/cli/internal/terminal/restart_test.go index 5c2ab0111..d2e26af54 100644 --- a/cli/internal/terminal/restart_test.go +++ b/cli/internal/terminal/restart_test.go @@ -102,11 +102,10 @@ func TestRestartConfirmationDecidesFromTheAnswer(t *testing.T) { ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second) defer cancel() restart, err := service.ConfirmRestart(ctx, daemon.ConnectionSnapshot{Pid: 42}, daemon.BuildIdentity{Digest: "a"}) - // A cancellation is an error, which its caller reads before the - // answer typed so far. + // A cancellation is an error and never a yes, even after a typed y. if tc.canceled { - if !errors.Is(err, context.Canceled) { - t.Fatalf("answer %q was not a cancellation: %v", tc.input, err) + if !errors.Is(err, context.Canceled) || restart { + t.Fatalf("answer %q: restart=%v err=%v, want a cancellation", tc.input, restart, err) } return } -- knotmirror 0.0.1