Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions internal/cli/root_command_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,33 @@ func TestRunsPurgeCommandRemovesTerminalRunArtifactsOldestFirst(t *testing.T) {
}
}

func TestRunsPurgeCommandHonorsCanceledCommandContext(t *testing.T) {
homeDir := t.TempDir()
t.Setenv("HOME", homeDir)

paths, err := productizeconfig.ResolveHomePaths()
if err != nil {
t.Fatalf("ResolveHomePaths() error = %v", err)
}
if err := productizeconfig.EnsureHomeLayout(paths); err != nil {
t.Fatalf("EnsureHomeLayout() error = %v", err)
}
withWorkingDir(t, t.TempDir())

ctx, cancel := context.WithCancel(context.Background())
cancel()

cmd := NewRootCommand()
cmd.SetContext(ctx)
output, err := executeCommandCombinedOutput(cmd, nil, "runs", "purge")
if !errors.Is(err, context.Canceled) {
t.Fatalf("runs purge error = %v, want context.Canceled\noutput:\n%s", err, output)
}
if strings.Contains(output, "purged") {
t.Fatalf("expected canceled runs purge to skip the sweep, got output:\n%s", output)
}
}

func TestExecCommandWithInstalledWorkspaceExtensionStaysEphemeralWithoutFlag(t *testing.T) {
workspaceRoot, recordPath := prepareWorkspaceExtensionFixtureForCLI(t, "normal")
withWorkingDir(t, workspaceRoot)
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/runs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cli

import (
"context"
"fmt"
"strings"

Expand Down Expand Up @@ -79,7 +78,8 @@ func newRunsPurgeCommand() *cobra.Command {
Short: "Delete terminal run artifacts according to configured retention",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, _ []string) error {
ctx := context.Background()
ctx, stop := signalCommandContext(cmd)
defer stop()

settings, _, err := daemon.LoadRunLifecycleSettings(ctx)
if err != nil {
Expand Down