Offer nvim or OpenCode when creating a pipeline

This commit is contained in:
2026-10-09 20:53:00 +01:00
parent a50e8648f6
commit dd50344170
10 changed files with 102 additions and 16 deletions
+8 -2
View File
@@ -40,8 +40,14 @@ func TestCreateAndSubmit(t *testing.T) {
var editor tea.Cmd
updated, editor = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'n'}})
m = updated.(Model)
if editor == nil {
t.Fatal("n should launch authoring directly, without a questionnaire")
if editor == nil || !m.editorOpen || !m.editorDraft.createOnly {
t.Fatal("n should offer an editor for a new create-only draft")
}
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")
}
// Editor lifecycle is smoke-tested separately; feed its completion here.
source := pipeline.Template([]string{"a", "b"}, true)
+22 -1
View File
@@ -8,6 +8,19 @@ import (
"github.com/sahilm/fuzzy"
)
func (m Model) openAuthorPicker(edit editedMsg) (tea.Model, tea.Cmd) {
m.editorOpen = true
m.editorIndex = 0
m.editorInput = newInput()
m.editorInput.Placeholder = "Search nvim or OpenCode…"
m.editorDraft = &edit
return m, m.editorInput.Focus()
}
func (m Model) newPipeline(source string) (tea.Model, tea.Cmd) {
return m.openAuthorPicker(editedMsg{source: source, createOnly: true})
}
func (m Model) editorChoices() []string {
choices := []string{"nvim", "OpenCode"}
if query := strings.TrimSpace(m.editorInput.Value()); query != "" {
@@ -45,7 +58,7 @@ 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, false, draft.Draft{Server: m.url, BaseVersion: d.baseVersion})
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})
}
var cmd tea.Cmd
m.editorInput, cmd = m.editorInput.Update(msg)
@@ -57,9 +70,17 @@ func (m Model) editorPickerView(height int) string {
input := m.editorInput
input.Width = max(1, min(60, m.width-12))
lines := []string{"Edit pipeline with…", input.View(), "Tab/Shift+Tab choose · type to search · Enter open · Esc cancel", ""}
if m.editorDraft != nil && m.editorDraft.createOnly {
lines[0] = "New pipeline with…"
}
choices := m.editorChoices()
for i, choice := range choices {
lines = append(lines, menuOption(choice, i == m.editorIndex))
if choice == "nvim" {
lines = append(lines, " Write the pipeline Markdown in a retained draft file.")
} else {
lines = append(lines, " Open the OpenCode harness to write it together.")
}
}
if len(choices) == 0 {
lines = append(lines, "No matching editor.")
+41
View File
@@ -60,6 +60,47 @@ func TestPipelineEditPickerHasTabNavigationFuzzySearchAndRetainedDraft(t *testin
}
}
func TestNewPickerSupportsBothEditorsWithoutCreatingDraftOnCancel(t *testing.T) {
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
source := pipeline.Template([]string{"worker"}, true)
for _, choice := range []string{"nv", "ocd"} {
m := New(context.Background(), "ws://example/connect")
m.width = 120
updated, _ := m.newPipeline(source)
m = updated.(Model)
view := ansi.Strip(m.editorPickerView(30))
for _, text := range []string{"New pipeline with", "nvim", "OpenCode", "retained draft file", "write it together"} {
if !strings.Contains(view, text) {
t.Fatal("missing new authoring choice", text, view)
}
}
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")
}
}
items, err := draft.List()
if err != nil || len(items) != 2 {
t.Fatal("new choices did not retain drafts", items, err)
}
for _, item := range items {
text, err := draft.Read(item.Path)
if err != nil || text != source || !item.CreateOnly || item.BaseVersion != 0 || item.Server != "ws://example/connect" {
t.Fatal("new draft lost source/create-only/server metadata", item, err)
}
}
m := New(context.Background(), "")
updated, _ := m.newPipeline(source)
m = updated.(Model)
m = press(m, "esc")
after, _ := draft.List()
if m.editorOpen || len(after) != 2 {
t.Fatal("canceling New created a draft")
}
}
func TestDraftCleanupRequiresConfirmationAndPreservesOtherDraft(t *testing.T) {
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
a, _ := draft.Create("discard", "discard", "server", true, 0)
+1 -1
View File
@@ -554,7 +554,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.appendLine("not connected")
return m, nil
}
return m, editDraftMode("", pipeline.Template([]string{"worker"}, true), true, true, draft.Draft{Server: m.url})
return m.newPipeline(pipeline.Template([]string{"worker"}, true))
case m.homePage() && key.Matches(msg, m.keys.ping):
if m.conn == nil {
m.appendLine("not connected")
+2 -8
View File
@@ -194,13 +194,7 @@ func (m Model) editPipeline() (tea.Model, tea.Cmd) {
m.appendLine("submission already in progress")
return m, nil
}
m.editorOpen = true
m.editorIndex = 0
m.editorInput = newInput()
m.editorInput.Placeholder = "Search nvim or OpenCode…"
m.editorInput.Focus()
m.editorDraft = &editedMsg{name: m.detail.Name, source: pipeline.ExecutionSource(m.detail.Source), baseVersion: m.detail.LatestVersion}
return m, m.editorInput.Focus()
return m.openAuthorPicker(editedMsg{name: m.detail.Name, source: pipeline.ExecutionSource(m.detail.Source), baseVersion: m.detail.LatestVersion})
}
func (m Model) updatePipeline(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
@@ -329,7 +323,7 @@ func (m Model) updateConfirm(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
func (m Model) confirmView(height int) string {
lines := []string{"Submit edited pipeline", m.pendingDraft.name, "", "Creates a new immutable version.", "s submit · e edit again · Esc keep draft"}
if m.pendingDraft.createOnly {
lines[0] = "Create pipeline from template"
lines[0] = "Create pipeline"
lines[3] = "Creates a NEW pipeline only when you submit."
}
if strings.Contains(m.pendingDraft.source, "```schedule") {
+1 -1
View File
@@ -89,7 +89,7 @@ func (m Model) updateTemplates(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
m.templateTop = len(m.templateLines)
case "enter":
if len(m.templates) > 0 {
return m, editDraftMode("", m.templates[m.templateIndex].Source, true, true, draft.Draft{Server: m.url})
return m.newPipeline(m.templates[m.templateIndex].Source)
}
}
m.templateTop = max(0, min(m.templateTop, max(0, len(m.templateLines)-max(1, m.height-10))))
+6 -2
View File
@@ -40,8 +40,12 @@ func TestTemplateMarkdownPreviewDraftAndKeyboardScope(t *testing.T) {
m = press(m, "v")
updated, cmd := m.updateTemplates(tea.KeyMsg{Type: tea.KeyEnter})
m = updated.(Model)
if cmd == nil {
t.Fatal("template should launch authoring directly")
if cmd == nil || !m.editorOpen || !m.editorDraft.createOnly || m.editorDraft.source != m.templates[m.templateIndex].Source {
t.Fatal("template should offer an editor without losing the selected source")
}
m = press(m, "esc")
if m.editorOpen || !m.templateOpen {
t.Fatal("canceling editor picker should return to template gallery")
}
m = press(m, "esc")
if m.templateOpen {