diff --git a/internal/provider/install_test.go b/internal/provider/install_test.go index 4330c7796..b89e50579 100644 --- a/internal/provider/install_test.go +++ b/internal/provider/install_test.go @@ -32,14 +32,25 @@ func TestSignInInstallsMissingCLI(t *testing.T) { return "" } t.Cleanup(func() { DevinExecutable = oldExe }) - release := make(chan struct{}) + // an early failure ends the test with the install still held: the + // fake then gives up without touching the test that has gone + release, ended := make(chan struct{}), make(chan struct{}) + t.Cleanup(func() { close(ended) }) var ran string oldRun := runInstaller runInstaller = func(ctx context.Context, c agentCLI) ([]byte, error) { ran = c.sh - <-release + select { + case <-release: + case <-ended: + return nil, errors.New("the test ended") + } os.MkdirAll(filepath.Dir(exe), 0o755) - testenv.Program(t, exe, "#!/bin/sh\nprintf 'Logged in (via Devin).\\n Email: dev@example.com\\n Tier: Devin Pro\\n'\n") + // not testenv.Program: this runs on the sign-in's goroutine, which a + // failed test can leave behind + if err := testenv.WriteProgram(exe, "#!/bin/sh\nprintf 'Logged in (via Devin).\\n Email: dev@example.com\\n Tier: Devin Pro\\n'\n"); err != nil { + return nil, err + } // as Devin's does: `devin setup` gives up on its sign-in without a terminal return []byte("Installed devin\nError: Login canceled\n"), errors.New("exit status 1") } diff --git a/internal/provider/plugin_moved_test.go b/internal/provider/plugin_moved_test.go index 64a85bdb2..8cdbd521d 100644 --- a/internal/provider/plugin_moved_test.go +++ b/internal/provider/plugin_moved_test.go @@ -3,6 +3,7 @@ package provider import ( "context" "encoding/json" + "errors" "os" "path/filepath" "strings" @@ -222,10 +223,17 @@ func TestMovedSignInAsBuiltIn(t *testing.T) { return "" } t.Cleanup(func() { DevinExecutable = oldExe }) - release := make(chan struct{}) + // an early failure ends the test with the install still held: the + // fake then gives up without touching the test that has gone + release, ended := make(chan struct{}), make(chan struct{}) + t.Cleanup(func() { close(ended) }) oldRun := runInstaller runInstaller = func(ctx context.Context, c agentCLI) ([]byte, error) { - <-release + select { + case <-release: + case <-ended: + return nil, errors.New("the test ended") + } os.MkdirAll(filepath.Dir(exe), 0o755) return nil, testenv.WriteProgram(exe, "#!/bin/sh\n") }