From 2d270f0e54628eca63eca0a3ec586ac58fcb21d3 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 2 Nov 2026 19:54:09 +0100 Subject: [PATCH] Add a test showing that lazygit doesn't start if state.yml is broken Co-Authored-By: Claude Opus 5.5 --- pkg/config/app_state_test.go | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 pkg/config/app_state_test.go diff --git a/pkg/config/app_state_test.go b/pkg/config/app_state_test.go new file mode 100644 index 000000000..5558d6b08 --- /dev/null +++ b/pkg/config/app_state_test.go @@ -0,0 +1,38 @@ +package config + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +// useTempConfigDir points the config and state folder at a new temp dir and +// returns it. +func useTempConfigDir(t *testing.T) string { + t.Helper() + + configDir := t.TempDir() + t.Setenv("CONFIG_DIR", configDir) + t.Setenv("LG_CONFIG_FILE", "") + return configDir +} + +func newAppConfig(t *testing.T) (*AppConfig, error) { + t.Helper() + + return NewAppConfig("lazygit", "unversioned", "", "", "", false, t.TempDir()) +} + +func TestStartupWithBrokenAppStateFile(t *testing.T) { + configDir := useTempConfigDir(t) + err := os.WriteFile(filepath.Join(configDir, stateFileName), make([]byte, 4096), 0o644) + assert.NoError(t, err) + + _, err = newAppConfig(t) + /* EXPECTED: + assert.NoError(t, err) + ACTUAL: */ + assert.ErrorContains(t, err, "control characters are not allowed") +}