Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 9 additions & 3 deletions internal/cli/prescript_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"path/filepath"
"runtime"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/fullsend-ai/fullsend/internal/harness"
"github.com/fullsend-ai/fullsend/internal/sandbox"
"github.com/fullsend-ai/fullsend/internal/ui"
)

Expand Down Expand Up @@ -97,8 +99,7 @@ func TestRunAgent_PreScriptSkip_ReturnsBeforeSandboxCreation(t *testing.T) {
// Without a skip, the run must still reach sandbox creation — a guard
// against the skip path swallowing every run — and skipped=false must be
// relayed so an absent key means only "this CLI predates the protocol".
// The two assertions share one run: reaching sandbox creation costs the
// full create-retry backoff.
// The two assertions share one run.
func TestRunAgent_PreScriptNoSkip_ProceedsToSandboxAndRelaysFalse(t *testing.T) {
usePreScriptStub(t)
out := filepath.Join(t.TempDir(), "github-output")
Expand Down Expand Up @@ -201,12 +202,17 @@ func TestRunPreScript_CleansUpOutputFile(t *testing.T) {

// usePreScriptStub puts an openshell stub on PATH that passes the gateway
// check but refuses sandbox creation, so a run that gets that far fails
// recognizably.
// recognizably. It also replaces sandbox.RetrySleep with a no-op so retry
// backoff does not add real delays (see #6060).
func usePreScriptStub(t *testing.T) {
t.Helper()
stubDir, err := filepath.Abs(filepath.Join("testdata", "prescript-stub"))
require.NoError(t, err)
t.Setenv("PATH", stubDir+string(filepath.ListSeparator)+os.Getenv("PATH"))

orig := sandbox.RetrySleep
sandbox.RetrySleep = func(time.Duration) {}
t.Cleanup(func() { sandbox.RetrySleep = orig })
}

// newSkipHarnessDir builds a minimal fullsend dir whose code harness runs
Expand Down
7 changes: 6 additions & 1 deletion internal/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ const (
retryMaxBackoff = 15 * time.Second
)

// RetrySleep is the function called between retry attempts in CreateWithRetry.
Comment thread
ralphbean marked this conversation as resolved.
Resolved
Comment thread
ralphbean marked this conversation as resolved.
Resolved
Comment thread
ralphbean marked this conversation as resolved.
Resolved
// It defaults to time.Sleep. Tests can replace it with a no-op to avoid real
// delays (restore the original in a cleanup function).
var RetrySleep = time.Sleep

// errSymlink wraps symlink-related os.Remove failures during
// sanitizeDownload with the symlink path and target, so error messages
// in cleanup reporting carry enough context to diagnose which symlink
Expand Down Expand Up @@ -544,7 +549,7 @@ func CreateWithRetry(name string, providers []string, image, policy string, maxA
backoff = retryMaxBackoff
}
fmt.Fprintf(os.Stderr, " Sandbox creation attempt %d/%d failed (%v), retrying in %s...\n", attempt, maxAttempts, lastErr, backoff)
time.Sleep(backoff)
RetrySleep(backoff)
}
}
return fmt.Errorf("sandbox creation failed after %d attempts: %w", maxAttempts, lastErr)
Expand Down
14 changes: 14 additions & 0 deletions internal/sandbox/sandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,20 @@ func TestCreateWithRetry_NegativeAttempts(t *testing.T) {
assert.Contains(t, err.Error(), "maxAttempts must be >= 1")
}

func TestCreateWithRetry_SleepsBetweenAttempts(t *testing.T) {
t.Setenv("PATH", "")

var sleeps []time.Duration
orig := RetrySleep
RetrySleep = func(d time.Duration) { sleeps = append(sleeps, d) }
t.Cleanup(func() { RetrySleep = orig })

err := CreateWithRetry("test-sandbox", nil, "", "", 3, 0)
assert.Error(t, err)
assert.Contains(t, err.Error(), "sandbox creation failed after 3 attempts")
assert.Equal(t, []time.Duration{retryInitialBackoff, retryInitialBackoff * 2}, sleeps)
}

func TestEffectiveReadyTimeout_CappedAtMax(t *testing.T) {
got := effectiveReadyTimeout(999 * time.Second)
assert.Equal(t, maxReadyTimeout, got)
Expand Down
Loading