jesseduffield.lazygit/pkg/gui/context/context_test.go
Stefan Haller e0927d4faf Validate the context names in the "context" field of custom commands
If a custom command's "context" field contains a context name that
doesn't exist, lazygit panics when building the keybindings. This could
happen either because of a typo, or because a context is removed or
renamed in a later version. Prevent the panic by validating those names
at config load time, and rejecting the config as invalid there, like we
do for other config errors.

The gui package owns the list, but can't be imported from here, so it is
mirrored and a test over there ensures the copies stay in sync.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-03 21:07:32 +02:00

23 lines
748 B
Go

package context
import (
"testing"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
)
// The config package validates a custom command's context against its own copy of
// these names, being unable to import this package. A name in one list but not the
// other would be either a context that validation rejects although you can bind to
// it, or one it accepts although binding to it exits lazygit.
func TestValidCustomCommandContextsMatchesAllContextKeys(t *testing.T) {
keys := lo.Map(AllContextKeys, func(key types.ContextKey, _ int) string {
return string(key)
})
assert.Equal(t, keys, config.ValidCustomCommandContexts)
}