Derive runs purge context from the command instead of context.Background() - #5
Merged
Merged
Conversation
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.
Problem
newRunsPurgeCommand'sRunEusedcontext.Background()— the onlyRunEininternal/clithat did. Its two siblings in the same file (runs.go:39,runs.go:61)use
signalCommandContext(cmd), which derives fromcmd.Context()when set and wrapsit in
signal.NotifyContext.So
runs purgediscarded both signal handling and any embedder-supplied context. Thatcontext is not decorative — it flows into cancellable work, including
daemon.LoadRunLifecycleSettings(ctx)andglobaldb.Open(ctx, ...), so a purge blockedon the database could not be interrupted with Ctrl-C.
Fix
Two lines in
internal/cli/runs.go:context.Background()becomessignalCommandContext(cmd)withdefer stop(), and the now-unusedcontextimport isdropped. No other behaviour changed.
Test
Adds
TestRunsPurgeCommandHonorsCanceledCommandContext. It isolatesHOMEto a tempdir and builds the home layout so the purge would otherwise succeed, sets an
already-cancelled context via
cmd.SetContext(ctx), runsruns purge, and assertserrors.Is(err, context.Canceled)and that no "purged" line was printed.Red-green confirmed: with
context.Background()restored the test fails withruns purge error = <nil>, want context.Canceled.Verification
make verifypasses end to end —golangci-lint fmt,golangci-lint runwith zeroissues, 3666 tests, and the build. Also verified merged together with #(the replay fix)
on an integration branch: 3669 tests, gate green.
🤖 Generated with Claude Code