Configure full Docker setup and confirm consequential actions
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
func (m Model) updateActionConfirm(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
switch msg.String() {
|
||||
case "esc", "n":
|
||||
m.actionConfirm = nil
|
||||
return m, nil
|
||||
case "y":
|
||||
request := *m.actionConfirm
|
||||
m.actionConfirm = nil
|
||||
return m.sendRunRequest(request)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) actionConfirmView(height int) string {
|
||||
r := m.actionConfirm
|
||||
lines := []string{"Start pipeline run?", fmt.Sprintf("Pipeline #%d · v%d", r.PipelineID, r.Version), "Directory: " + r.Workspace,
|
||||
"This may edit files, execute commands and publish notifications."}
|
||||
if r.Type == protocol.RetryRun {
|
||||
lines = []string{fmt.Sprintf("Retry failed run #%d?", r.RunID), "Starts a NEW run from the entry stage with fresh OpenCode sessions.",
|
||||
"Reuses the original input, directory, pinned version and edit scope.", "Previous side effects are not undone; commands/notifications may repeat."}
|
||||
}
|
||||
if r.Type == protocol.CancelRun {
|
||||
lines = []string{fmt.Sprintf("Cancel run #%d?", r.RunID), "Stops execution and interrupts its active agent.", "Sessions/history are retained; previous side effects are not undone."}
|
||||
}
|
||||
return popup(m.width, height, 96, append(lines, "", "y confirm · n / Esc cancel"))
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConsequentialRunActionsRequireExplicitYes(t *testing.T) {
|
||||
for _, action := range []string{protocol.RunPipeline, protocol.RetryRun, protocol.CancelRun} {
|
||||
for _, cancel := range []string{"n", "esc"} {
|
||||
m := New(context.Background(), "")
|
||||
updated, cmd := m.runRequest(protocol.Message{Type: action, RunID: 42, PipelineID: 3, Version: 2, Workspace: "/original"})
|
||||
m = updated.(Model)
|
||||
if cmd != nil || m.nextID != 0 || m.actionConfirm == nil {
|
||||
t.Fatal("action sent before approval", action)
|
||||
}
|
||||
if !strings.Contains(ansi.Strip(m.View()), "y confirm") {
|
||||
t.Fatal("missing confirmation", action)
|
||||
}
|
||||
updated, cmd = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if cmd != nil || m.actionConfirm == nil {
|
||||
t.Fatal("Enter must not approve by default")
|
||||
}
|
||||
m = press(m, cancel)
|
||||
if m.actionConfirm != nil || m.nextID != 0 || m.runStartRequest != "" {
|
||||
t.Fatal("canceled action was sent")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,12 +61,12 @@ func TestDashboardRunUsesInvocationDirectory(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCLISuppliedArgumentsStartWithoutConfirmation(t *testing.T) {
|
||||
func TestCLISuppliedArgumentsRequireConfirmation(t *testing.T) {
|
||||
m := NewRun(context.Background(), "", RunOptions{Pipeline: "test", Prompt: "task", Workspace: "/repos/a"})
|
||||
m.detail = &protocol.PipelineDetail{PipelineSummary: protocol.PipelineSummary{ID: 1, Name: "test", Version: 1}}
|
||||
updated, _ := m.configureCLIRun()
|
||||
m = updated.(Model)
|
||||
if m.runForm != 0 || !m.runOpen || m.runTask != "task" || m.runWorkspace != "/repos/a" {
|
||||
t.Fatal("supplied task did not start immediately or lost repository")
|
||||
if m.runForm != 0 || !m.runOpen || m.runTask != "task" || m.runWorkspace != "/repos/a" || m.actionConfirm == nil || m.actionConfirm.Workspace != "/repos/a" || m.runStartRequest != "" {
|
||||
t.Fatal("supplied task bypassed confirmation or lost repository")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ func TestHomeShortcutOpensAllRunsAndDisplaysHintInBothPanels(t *testing.T) {
|
||||
m.runIndex = 1
|
||||
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'r'}})
|
||||
m = updated.(Model)
|
||||
if cmd == nil || m.runStartRequest == "" {
|
||||
t.Fatal("r on failed list no longer retries")
|
||||
if cmd != nil || m.actionConfirm == nil || m.actionConfirm.Type != protocol.RetryRun {
|
||||
t.Fatal("r on failed list should request retry confirmation")
|
||||
}
|
||||
m.closeRuns()
|
||||
if m.runFailedOnly {
|
||||
|
||||
@@ -132,6 +132,7 @@ type Model struct {
|
||||
versionsOpen bool
|
||||
versionIndex int
|
||||
confirmOpen bool
|
||||
actionConfirm *protocol.Message
|
||||
pendingDraft *editedMsg
|
||||
submitID string
|
||||
submitNotice string
|
||||
@@ -192,7 +193,7 @@ func New(ctx context.Context, url string) Model {
|
||||
enter: key.NewBinding(key.WithKeys("enter"), key.WithHelp("enter", "continue")),
|
||||
cancel: key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "cancel")),
|
||||
ping: key.NewBinding(key.WithKeys("t"), key.WithHelp("t", "test ping")),
|
||||
quit: key.NewBinding(key.WithKeys("q", "ctrl+c"), key.WithHelp("q", "quit")),
|
||||
quit: key.NewBinding(key.WithKeys(":quit"), key.WithHelp(":quit", "quit")),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -486,6 +487,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if msg.String() == "ctrl+c" {
|
||||
return m, tea.Quit
|
||||
}
|
||||
if m.actionConfirm != nil {
|
||||
return m.updateActionConfirm(msg)
|
||||
}
|
||||
if m.editorChecking {
|
||||
return m, nil
|
||||
}
|
||||
@@ -547,8 +551,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.commandInput.SetValue(":")
|
||||
}
|
||||
return m, m.commandInput.Focus()
|
||||
case m.homePage() && key.Matches(msg, m.keys.quit):
|
||||
return m, tea.Quit
|
||||
case m.homePage() && key.Matches(msg, m.keys.create):
|
||||
if m.conn == nil {
|
||||
m.appendLine("not connected")
|
||||
@@ -712,6 +714,9 @@ func (m Model) View() string {
|
||||
if m.statusOpen {
|
||||
content = m.statusView(bodyHeight)
|
||||
}
|
||||
if m.actionConfirm != nil {
|
||||
content = m.actionConfirmView(bodyHeight)
|
||||
}
|
||||
if m.editorChecking {
|
||||
content = popup(m.width, bodyHeight, 76, []string{"Checking published edits", m.loading("Refreshing pipeline information…"), "Local draft remains retained."})
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ func TestTKeyPingRoundTrip(t *testing.T) {
|
||||
t.Fatalf("missing responses: %s", text)
|
||||
}
|
||||
_, quit := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}})
|
||||
if _, ok := quit().(tea.QuitMsg); !ok {
|
||||
t.Fatal("q did not quit")
|
||||
if quit != nil {
|
||||
t.Fatal("q should not quit")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,11 @@ func TestRetryShortcutAndPaletteSendServerRetryWithoutReplacingDirectory(t *test
|
||||
updated, send = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'r'}})
|
||||
}
|
||||
m = updated.(Model)
|
||||
if send != nil || m.actionConfirm == nil || m.actionConfirm.RunID != id || m.runStartRequest != "" {
|
||||
t.Fatal("retry must ask before sending")
|
||||
}
|
||||
updated, send = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'y'}})
|
||||
m = updated.(Model)
|
||||
if send == nil || m.runStartRequest == "" || m.runDetail != nil || m.requestedRunID != 0 {
|
||||
t.Fatal("retry did not start cleanly")
|
||||
}
|
||||
|
||||
+16
-1
@@ -16,6 +16,14 @@ type runTick struct{}
|
||||
func runPoll() tea.Cmd { return tea.Tick(time.Second, func(time.Time) tea.Msg { return runTick{} }) }
|
||||
|
||||
func (m Model) runRequest(request protocol.Message) (tea.Model, tea.Cmd) {
|
||||
if request.Type == protocol.RunPipeline || request.Type == protocol.RetryRun || request.Type == protocol.CancelRun {
|
||||
m.actionConfirm = &request
|
||||
return m, nil
|
||||
}
|
||||
return m.sendRunRequest(request)
|
||||
}
|
||||
|
||||
func (m Model) sendRunRequest(request protocol.Message) (tea.Model, tea.Cmd) {
|
||||
if m.conn == nil {
|
||||
m.appendLine("not connected")
|
||||
return m, nil
|
||||
@@ -112,7 +120,14 @@ func (m *Model) startSelectedRun() tea.Cmd {
|
||||
m.runCollapsed = nil
|
||||
m.runDetail = nil
|
||||
m.runTop = 0
|
||||
updated, cmd := m.runRequest(protocol.Message{Type: protocol.RunPipeline, PipelineID: m.detail.ID, Version: m.detail.Version, RequestKey: fmt.Sprintf("tui-%d", time.Now().UnixNano()), Input: initialRunInput(m.runTask), AllowTools: m.runHasMutationTools(), WritePaths: m.runPaths, Workspace: m.runWorkspace})
|
||||
request := protocol.Message{Type: protocol.RunPipeline, PipelineID: m.detail.ID, Version: m.detail.Version, RequestKey: fmt.Sprintf("tui-%d", time.Now().UnixNano()), Input: initialRunInput(m.runTask), AllowTools: m.runHasMutationTools(), WritePaths: m.runPaths, Workspace: m.runWorkspace}
|
||||
updated, cmd := m.runRequest(request)
|
||||
if m.cliRun && m.cliOptions.Yes {
|
||||
updated, cmd = m.sendRunRequest(request)
|
||||
after := updated.(Model)
|
||||
after.cliOptions.Yes = false
|
||||
updated = after
|
||||
}
|
||||
*m = updated.(Model)
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -81,3 +81,24 @@ func TestCtrlCRemainsGlobal(t *testing.T) {
|
||||
t.Fatal("Ctrl+C did not quit")
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuitUsesCommandInsteadOfQ(t *testing.T) {
|
||||
for _, m := range []Model{New(context.Background(), ""), panelModel(t), runInspectionModel()} {
|
||||
_, cmd := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}})
|
||||
if cmd != nil {
|
||||
t.Fatal("q must not quit")
|
||||
}
|
||||
if !slices.Contains(m.pageCommands(), ":quit") {
|
||||
t.Fatal("quit command missing")
|
||||
}
|
||||
m = press(m, ":")
|
||||
m = press(m, "quit")
|
||||
_, cmd = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
if cmd == nil {
|
||||
t.Fatal("quit command did not exit")
|
||||
}
|
||||
if _, ok := cmd().(tea.QuitMsg); !ok {
|
||||
t.Fatal("quit command did not return QuitMsg")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user