Files
lazygit/pkg/gui/test_mode.go
Stefan HallerandClaude Opus 5.5 73fac4a554 Restore the terminal if a goroutine panics
Most goroutines run their function through utils.Safe, which closes
the screen if the function panics. Without it, the panic is printed to
a terminal that is still in raw mode and on the alternate screen, and
the terminal needs a reset afterwards. Go has no process-wide hook for
panics, so every goroutine has to do this itself.

Use utils.Safe for the goroutines that don't use it yet.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-14 20:28:53 +02:00

65 lines
1.6 KiB
Go

package gui
import (
"log"
"os"
"runtime/pprof"
"time"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/popup"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/integration/components"
"github.com/jesseduffield/lazygit/pkg/utils"
)
type IntegrationTest interface {
Run(*GuiDriver)
}
func (gui *Gui) handleTestMode() {
test := gui.integrationTest
if os.Getenv(components.SANDBOX_ENV_VAR) == "true" {
return
}
if test != nil {
waitUntilIdle := func() {
gui.c.GocuiGui().WaitUntilIdle()
}
go utils.Safe(func() {
waitUntilIdle()
toastChan := make(chan string, 100)
gui.PopupHandler.(*popup.PopupHandler).SetToastFunc(
func(message string, kind types.ToastKind) { toastChan <- message })
test.Run(&GuiDriver{gui: gui, toastChan: toastChan, headless: Headless()})
gui.g.Update(func(*gocui.Gui) error {
return gocui.ErrQuit
})
// Wait for the event loop to actually exit.
<-gui.g.LoopExited()
})
if os.Getenv(components.WAIT_FOR_DEBUGGER_ENV_VAR) == "" {
timeout := 40 * time.Second * testTimeoutMultiplier
go utils.Safe(func() {
time.Sleep(timeout)
// Dump all goroutine stacks before dying, so a hung test shows
// where it got stuck rather than just that it timed out. The
// test harness surfaces this process's stderr on failure.
_ = pprof.Lookup("goroutine").WriteTo(os.Stderr, 2)
log.Fatalf("%v is up, lazygit integration test took too long to complete", timeout)
})
}
}
}
func Headless() bool {
return os.Getenv("LAZYGIT_HEADLESS") != ""
}