Validate providers and retain complete run debugging context
This commit is contained in:
@@ -14,11 +14,18 @@ func (m Model) updateActionConfirm(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
case "y":
|
||||
request := *m.actionConfirm
|
||||
m.actionConfirm = nil
|
||||
m.actionApproved = true
|
||||
return m.sendRunRequest(request)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) confirmMutation(title string, cmd func() tea.Cmd) (tea.Model, tea.Cmd) {
|
||||
m.mutationTitle = title
|
||||
m.mutationCommand = cmd
|
||||
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,
|
||||
|
||||
@@ -46,8 +46,13 @@ func TestCreateAndSubmit(t *testing.T) {
|
||||
m.editorInput.SetValue("ocd")
|
||||
updated, editor = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if editor == nil || m.editorOpen {
|
||||
t.Fatal("new editor choice did not launch")
|
||||
if editor != nil || m.editorOpen || m.mutationCommand == nil {
|
||||
t.Fatal("new editor choice did not require approval")
|
||||
}
|
||||
updated, editor = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'y'}})
|
||||
m = updated.(Model)
|
||||
if editor == nil {
|
||||
t.Fatal("approved editor did not launch")
|
||||
}
|
||||
// Editor lifecycle is smoke-tested separately; feed its completion here.
|
||||
source := pipeline.Template([]string{"a", "b"}, true)
|
||||
|
||||
@@ -38,6 +38,6 @@ func (m Model) debugRun() (tea.Model, tea.Cmd) {
|
||||
m.appendLine("debug: pipelines CLI is unavailable: " + err.Error())
|
||||
return m, nil
|
||||
}
|
||||
cmd := exec.Command(cli, "--url", m.url, "debug", fmt.Sprint(id))
|
||||
return m, tea.ExecProcess(cmd, func(err error) tea.Msg { return debugClosedMsg{err} })
|
||||
cmd := exec.Command(cli, "--url", m.url, "debug", fmt.Sprint(id), "--yes")
|
||||
return m.confirmMutation(fmt.Sprintf("Open a new debugging session for run #%d?", id), func() tea.Cmd { return tea.ExecProcess(cmd, func(err error) tea.Msg { return debugClosedMsg{err} }) })
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestRunDebugActionAvailableForRunningAndFinishedRuns(t *testing.T) {
|
||||
}
|
||||
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'D'}})
|
||||
m = updated.(Model)
|
||||
if cmd == nil || m.runDetail.ID != 7 || m.runStartRequest != "" || m.runDetail.Status != status {
|
||||
if cmd != nil || m.mutationCommand == nil || m.runDetail.ID != 7 || m.runStartRequest != "" || m.runDetail.Status != status {
|
||||
t.Fatal("debug changed or retried run", status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func (m Model) updateDrafts(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
switch msg.String() {
|
||||
case "enter", "e":
|
||||
return m, editDraftMode(d.Name, source, true, d.CreateOnly, d)
|
||||
return m.confirmMutation("Edit retained draft?", func() tea.Cmd { return editDraftMode(d.Name, source, true, d.CreateOnly, d) })
|
||||
case "s":
|
||||
m.pendingDraft = &editedMsg{name: d.Name, path: d.Path, source: source, createOnly: d.CreateOnly, baseVersion: d.BaseVersion}
|
||||
m.confirmOpen = true
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/sahilm/fuzzy"
|
||||
@@ -19,7 +20,7 @@ func (m Model) openAuthorPicker(edit editedMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
func (m Model) newPipeline(source string) (tea.Model, tea.Cmd) {
|
||||
return m.openAuthorPicker(editedMsg{source: source, createOnly: true})
|
||||
return m.openAuthorPicker(editedMsg{source: pipeline.WithDefaultModel(source, m.defaultModel), createOnly: true})
|
||||
}
|
||||
|
||||
func (m Model) editorChoices() []string {
|
||||
@@ -59,7 +60,9 @@ func (m Model) updateEditorPicker(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
d := m.editorDraft
|
||||
m.editorOpen = false
|
||||
m.editorDraft = nil
|
||||
return m, editDraftUsing(choice, d.name, d.source, true, d.createOnly, draft.Draft{Path: d.path, Name: d.name, Server: m.url, CreateOnly: d.createOnly, BaseVersion: d.baseVersion})
|
||||
return m.confirmMutation("Open "+choice+" to create/edit a draft?", func() tea.Cmd {
|
||||
return editDraftUsing(choice, d.name, d.source, true, d.createOnly, draft.Draft{Path: d.path, Name: d.name, Server: m.url, CreateOnly: d.createOnly, BaseVersion: d.baseVersion})
|
||||
})
|
||||
}
|
||||
var cmd tea.Cmd
|
||||
m.editorInput, cmd = m.editorInput.Update(msg)
|
||||
|
||||
@@ -48,8 +48,16 @@ func TestPipelineEditPickerHasTabNavigationFuzzySearchAndRetainedDraft(t *testin
|
||||
m.editorInput.SetValue("nv")
|
||||
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if cmd == nil || m.editorOpen {
|
||||
t.Fatal("editor selection did not launch")
|
||||
if cmd != nil || m.editorOpen || m.mutationCommand == nil {
|
||||
t.Fatal("editor selection did not require confirmation")
|
||||
}
|
||||
if items, _ := draft.List(); len(items) != 0 {
|
||||
t.Fatal("draft created before approval")
|
||||
}
|
||||
updated, cmd = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'y'}})
|
||||
m = updated.(Model)
|
||||
if cmd == nil {
|
||||
t.Fatal("approved editor did not launch")
|
||||
}
|
||||
items, err := draft.List()
|
||||
if err != nil || len(items) != 1 || items[0].BaseVersion != 4 || items[0].Server != m.url {
|
||||
@@ -77,8 +85,13 @@ func TestNewPickerSupportsBothEditorsWithoutCreatingDraftOnCancel(t *testing.T)
|
||||
m.editorInput.SetValue(choice)
|
||||
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if cmd == nil || m.editorOpen || m.confirmOpen || m.submitID != "" {
|
||||
t.Fatal("new choice did not launch editor or bypassed publication")
|
||||
if cmd != nil || m.editorOpen || m.mutationCommand == nil || m.confirmOpen || m.submitID != "" {
|
||||
t.Fatal("new choice did not require approval or bypassed publication")
|
||||
}
|
||||
updated, cmd = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'y'}})
|
||||
m = updated.(Model)
|
||||
if cmd == nil {
|
||||
t.Fatal("approved editor did not launch")
|
||||
}
|
||||
}
|
||||
items, err := draft.List()
|
||||
|
||||
+27
-1
@@ -133,6 +133,10 @@ type Model struct {
|
||||
versionIndex int
|
||||
confirmOpen bool
|
||||
actionConfirm *protocol.Message
|
||||
actionApproved bool
|
||||
defaultModel string
|
||||
mutationTitle string
|
||||
mutationCommand func() tea.Cmd
|
||||
pendingDraft *editedMsg
|
||||
submitID string
|
||||
submitNotice string
|
||||
@@ -315,6 +319,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
if msg.Type == protocol.PipelineList || msg.Type == protocol.Submitted {
|
||||
m.notificationEndpoints = msg.NotificationEndpoints
|
||||
if msg.DefaultModel != "" {
|
||||
m.defaultModel = msg.DefaultModel
|
||||
}
|
||||
}
|
||||
if msg.Type == protocol.Templates && msg.ID == m.templateRequest {
|
||||
m.templates = msg.Templates
|
||||
@@ -490,6 +497,19 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if m.actionConfirm != nil {
|
||||
return m.updateActionConfirm(msg)
|
||||
}
|
||||
if m.mutationCommand != nil {
|
||||
if msg.String() == "y" {
|
||||
command := m.mutationCommand
|
||||
m.mutationCommand = nil
|
||||
m.mutationTitle = ""
|
||||
return m, command()
|
||||
}
|
||||
if msg.String() == "n" || msg.String() == "esc" {
|
||||
m.mutationCommand = nil
|
||||
m.mutationTitle = ""
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
if m.editorChecking {
|
||||
return m, nil
|
||||
}
|
||||
@@ -620,6 +640,9 @@ func (m *Model) appendLine(line string) {
|
||||
|
||||
func (m Model) View() string {
|
||||
connection := m.status
|
||||
if m.conn != nil {
|
||||
connection = "Connected · :status"
|
||||
}
|
||||
if m.conn == nil {
|
||||
connection = m.loading(connection)
|
||||
}
|
||||
@@ -631,7 +654,7 @@ func (m Model) View() string {
|
||||
}
|
||||
connection += " · ntfy " + address + " · topic " + endpoint.Topic
|
||||
if m.width < 100 {
|
||||
connection = m.status + " · ntfy " + address + "/" + endpoint.Topic
|
||||
connection = "Connected · ntfy " + address + "/" + endpoint.Topic
|
||||
}
|
||||
}
|
||||
status := ansi.Truncate(connection, max(0, m.width-min(24, m.width/4)), "…")
|
||||
@@ -717,6 +740,9 @@ func (m Model) View() string {
|
||||
if m.actionConfirm != nil {
|
||||
content = m.actionConfirmView(bodyHeight)
|
||||
}
|
||||
if m.mutationCommand != nil {
|
||||
content = popup(m.width, bodyHeight, 76, []string{m.mutationTitle, "This opens a new session/editor and may modify a retained draft.", "Published definitions and previous run history are unchanged.", "y confirm · n / Esc cancel"})
|
||||
}
|
||||
if m.editorChecking {
|
||||
content = popup(m.width, bodyHeight, 76, []string{"Checking published edits", m.loading("Refreshing pipeline information…"), "Local draft remains retained."})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -301,7 +301,9 @@ func (m Model) updateConfirm(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
case "e":
|
||||
m.confirmOpen = false
|
||||
m.keys.confirm = false
|
||||
return m, editDraftMode(m.pendingDraft.name, m.pendingDraft.source, true, m.pendingDraft.createOnly, draft.Draft{Path: m.pendingDraft.path, Name: m.pendingDraft.name, Server: m.url, CreateOnly: m.pendingDraft.createOnly, BaseVersion: m.pendingDraft.baseVersion})
|
||||
return m.confirmMutation("Edit retained draft?", func() tea.Cmd {
|
||||
return editDraftMode(m.pendingDraft.name, m.pendingDraft.source, true, m.pendingDraft.createOnly, draft.Draft{Path: m.pendingDraft.path, Name: m.pendingDraft.name, Server: m.url, CreateOnly: m.pendingDraft.createOnly, BaseVersion: m.pendingDraft.baseVersion})
|
||||
})
|
||||
case "s", "enter":
|
||||
if strings.TrimSpace(m.pendingDraft.name) == "" {
|
||||
m.submitNotice = "Draft needs a name. Press e and ask OpenCode to name it, or submit with CLI --name."
|
||||
|
||||
+7
-10
@@ -16,14 +16,17 @@ 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 request.Type == protocol.RunPipeline || request.Type == protocol.RetryRun || request.Type == protocol.CancelRun {
|
||||
if !m.actionApproved {
|
||||
m.actionConfirm = &request
|
||||
return m, nil
|
||||
}
|
||||
m.actionApproved = false
|
||||
}
|
||||
if m.conn == nil {
|
||||
m.appendLine("not connected")
|
||||
return m, nil
|
||||
@@ -122,12 +125,6 @@ func (m *Model) startSelectedRun() tea.Cmd {
|
||||
m.runTop = 0
|
||||
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
|
||||
}
|
||||
|
||||
+25
-15
@@ -5,7 +5,8 @@ import (
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/statusview"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"net/url"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (m Model) openStatus() (tea.Model, tea.Cmd) {
|
||||
@@ -45,14 +46,7 @@ func (m Model) updateStatus(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
func (m Model) statusLines() []string {
|
||||
connection := "invalid URL"
|
||||
if u, err := url.Parse(m.url); err == nil {
|
||||
u.User = nil
|
||||
u.RawQuery = ""
|
||||
u.Fragment = ""
|
||||
connection = u.String()
|
||||
}
|
||||
lines := []string{"Client connection: " + connection}
|
||||
lines := []string{}
|
||||
if m.statusRequest != "" {
|
||||
lines = append(lines, m.loading("Checking server and ntfy…"))
|
||||
}
|
||||
@@ -69,10 +63,26 @@ func (m Model) statusLines() []string {
|
||||
return lines
|
||||
}
|
||||
func (m Model) statusView(height int) string {
|
||||
lines := m.statusLines()
|
||||
page := max(1, height-5)
|
||||
top := min(m.statusTop, max(0, len(lines)-page))
|
||||
rows := []string{"Status · Pipelines & ntfy", "↑/↓ scroll · PgUp/PgDn · r refresh · Esc close", ""}
|
||||
rows = append(rows, lines[top:min(len(lines), top+page)]...)
|
||||
return popup(m.width, height, 108, rows)
|
||||
server, ntfy := statusview.ServerLines(m.systemStatus), statusview.NtfyLines(m.systemStatus)
|
||||
if m.systemStatus == nil && m.statusError != "" {
|
||||
s := statusview.Offline(m.url)
|
||||
server, ntfy = statusview.ServerLines(s), statusview.NtfyLines(s)
|
||||
}
|
||||
if m.statusError != "" {
|
||||
server = append([]string{m.statusError}, server...)
|
||||
}
|
||||
if m.statusRequest != "" {
|
||||
server = append([]string{m.loading("Checking…")}, server...)
|
||||
}
|
||||
width := m.width
|
||||
if width >= 100 {
|
||||
w := (width - 2) / 2
|
||||
left := panel(w, max(4, height-2), []string{"Pipelines server"}, server, "", false)
|
||||
right := panel(width-w-2, max(4, height-2), []string{"ntfy · phone connection"}, ntfy, "", false)
|
||||
return fitBlock(append(strings.Split(lipgloss.JoinHorizontal(lipgloss.Top, left, " ", right), "\n"), "", "r refresh · Esc close"), width, height)
|
||||
}
|
||||
topHeight := max(4, (height-2)/2)
|
||||
left := panel(width, topHeight, []string{"Pipelines server"}, server, "", false)
|
||||
right := panel(width, max(4, height-topHeight-2), []string{"ntfy · phone connection"}, ntfy, "", false)
|
||||
return fitBlock(append(strings.Split(left+"\n"+right, "\n"), "r refresh · Esc close"), width, height)
|
||||
}
|
||||
|
||||
@@ -26,12 +26,15 @@ func TestStatusPalettePopupAndClosePreservesUnderlyingPage(t *testing.T) {
|
||||
updated, _ := m.Update(receivedMsg(protocol.Message{Type: protocol.Status, ID: "status-1", Status: &protocol.SystemStatus{Hostname: "test-machine", Server: protocol.ServiceStatus{Health: "healthy", Port: "8080"}, Ntfy: protocol.ServiceStatus{Health: "healthy", URL: "http://192.0.2.2:8090", Port: "8090"}, Addresses: []protocol.NetworkAddress{{Interface: "en0", IP: "192.0.2.2"}}}}))
|
||||
m = updated.(Model)
|
||||
view := ansi.Strip(m.View())
|
||||
for _, text := range []string{"Pipelines server", "ntfy", "test-machine", "8080", "8090", "192.0.2.2"} {
|
||||
for _, text := range []string{"Pipelines server", "ntfy", "8080", "8090", "192.0.2.2"} {
|
||||
if !strings.Contains(view, text) {
|
||||
t.Fatal("missing status info", text, view)
|
||||
}
|
||||
}
|
||||
m = press(m, "esc")
|
||||
if strings.Contains(view, "test-machine") || strings.Contains(view, "Client connection:") {
|
||||
t.Fatal("status includes unnecessary metadata", view)
|
||||
}
|
||||
if m.statusOpen || m.runDetail.ID != 42 {
|
||||
t.Fatal("status destroyed run selection")
|
||||
}
|
||||
|
||||
@@ -56,7 +56,9 @@ func (m Model) updateTemplates(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
case "e":
|
||||
if m.pendingDraft != nil {
|
||||
return m, editDraftMode(m.pendingDraft.name, m.pendingDraft.source, true, m.pendingDraft.createOnly, draft.Draft{Server: m.url, BaseVersion: m.pendingDraft.baseVersion})
|
||||
return m.confirmMutation("Edit retained draft?", func() tea.Cmd {
|
||||
return editDraftMode(m.pendingDraft.name, m.pendingDraft.source, true, m.pendingDraft.createOnly, draft.Draft{Server: m.url, BaseVersion: m.pendingDraft.baseVersion})
|
||||
})
|
||||
}
|
||||
case "esc":
|
||||
m.templateOpen = false
|
||||
|
||||
Reference in New Issue
Block a user