package tui import ( "context" "git.a-wan.net/alan/pipelines/internal/protocol" tea "github.com/charmbracelet/bubbletea" "testing" ) func TestDirectRunSenderCannotBypassConfirmation(t *testing.T) { for _, kind := range []string{protocol.RunPipeline, protocol.RetryRun, protocol.CancelRun} { m := New(context.Background(), "") updated, cmd := m.sendRunRequest(protocol.Message{Type: kind, RunID: 42}) m = updated.(Model) if cmd != nil || m.actionConfirm == nil { t.Fatal(kind, "bypassed modal") } m = press(m, "enter") if m.actionConfirm == nil { t.Fatal(kind, "Enter approved") } m = press(m, "esc") if m.actionConfirm != nil { t.Fatal(kind, "cancel failed") } } } func TestMutationFactoryOnlyRunsAfterExplicitApproval(t *testing.T) { for _, key := range []string{"enter", "n", "esc", "y"} { called := false m := New(context.Background(), "") updated, cmd := m.confirmMutation("Create draft?", func() tea.Cmd { called = true; return func() tea.Msg { return nil } }) m = updated.(Model) if cmd != nil || called { t.Fatal("factory ran before confirmation") } updated, cmd = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(key)}) if called != (key == "y") || (cmd != nil) != (key == "y") { t.Fatal(key, "incorrect approval", called) } } }