Replace niche templates with simple starters and direct template submission
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestShowcaseGraphsRender(t *testing.T) {
|
||||
for _, name := range []string{"bug-fix", "new-feature", "dashboard-screenshots", "dependency-upgrade", "incident-diagnosis"} {
|
||||
for _, name := range []string{"task", "summary", "review", "research", "three-stage"} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
source, err := os.ReadFile(filepath.Join("..", "..", "examples", name+".md"))
|
||||
if err != nil {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func nestedForkGraph(t *testing.T) protocol.Graph {
|
||||
t.Helper()
|
||||
source, err := os.ReadFile("../../examples/nested-forks.md")
|
||||
source, err := os.ReadFile("../pipeline/testdata/nested-forks.md")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func (k keyMap) ShortHelp() []key.Binding {
|
||||
return []key.Binding{k.enter, k.cancel}
|
||||
}
|
||||
if k.templates {
|
||||
return []key.Binding{key.NewBinding(key.WithKeys("n", "p"), key.WithHelp("n/p", "template")), key.NewBinding(key.WithKeys("v"), key.WithHelp("v", "render/source")), key.NewBinding(key.WithKeys("enter"), key.WithHelp("Enter", "use template")), k.cancel}
|
||||
return []key.Binding{key.NewBinding(key.WithKeys("s", "enter"), key.WithHelp("s/Enter", "submit")), key.NewBinding(key.WithKeys("e"), key.WithHelp("e", "customize")), key.NewBinding(key.WithKeys("n", "p"), key.WithHelp("n/p", "template")), key.NewBinding(key.WithKeys("v"), key.WithHelp("v", "render/source")), k.cancel}
|
||||
}
|
||||
if k.runs {
|
||||
bindings := []key.Binding{k.commands, key.NewBinding(key.WithKeys("n", "p"), key.WithHelp("n/p", "next/prev stage")), key.NewBinding(key.WithKeys("g"), key.WithHelp("g", "graph")), key.NewBinding(key.WithKeys("D"), key.WithHelp("D", "debug")), key.NewBinding(key.WithKeys("P"), key.WithHelp("P", "pipeline"))}
|
||||
|
||||
@@ -301,7 +301,14 @@ func (m Model) updateConfirm(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.submitNotice = "Name must be 1–200 bytes without line breaks or NUL."
|
||||
return m, nil
|
||||
}
|
||||
if m.pendingDraft.path != "" {
|
||||
if m.pendingDraft.path == "" {
|
||||
d, err := draft.Create(name, m.pendingDraft.source, m.url, m.pendingDraft.createOnly, m.pendingDraft.baseVersion)
|
||||
if err != nil {
|
||||
m.submitNotice = "Could not retain draft: " + err.Error()
|
||||
return m, nil
|
||||
}
|
||||
m.pendingDraft.path = d.Path
|
||||
} else {
|
||||
if err := draft.SetName(m.pendingDraft.path, name); err != nil {
|
||||
m.submitNotice = "Could not save draft name: " + err.Error()
|
||||
return m, nil
|
||||
@@ -352,7 +359,11 @@ func (m Model) confirmView(height int) string {
|
||||
field.Focus()
|
||||
}
|
||||
field.Width = max(1, min(60, m.width-12))
|
||||
return popup(m.width, height, 76, []string{"Name this pipeline", "", field.View(), m.submitNotice, "Enter save name and review · Esc keep draft"})
|
||||
hint := "Enter save name and review · Esc keep draft"
|
||||
if m.pendingDraft.path == "" {
|
||||
hint = "Enter save draft and review · Esc back"
|
||||
}
|
||||
return popup(m.width, height, 76, []string{"Name this pipeline", "", field.View(), m.submitNotice, hint})
|
||||
}
|
||||
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 {
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/examples"
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/server"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
func TestTemplateSubmitNamesRetainsAndExplicitlyPublishesSelectedTemplate(t *testing.T) {
|
||||
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
store, err := pipeline.Open(filepath.Join(t.TempDir(), "templates.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
srv := httptest.NewServer(server.Handler(ctx, store))
|
||||
defer srv.Close()
|
||||
url := "ws" + strings.TrimPrefix(srv.URL, "http") + "/connect"
|
||||
m := New(ctx, url)
|
||||
connected := m.connect()().(connectedMsg)
|
||||
defer connected.conn.CloseNow()
|
||||
updated, read := m.Update(connected)
|
||||
m = updated.(Model)
|
||||
updated, _ = m.Update(read())
|
||||
m = updated.(Model)
|
||||
m.templates = examples.Catalog()
|
||||
m.templateOpen, m.keys.templates = true, true
|
||||
m.defaultModel = "fixture/model"
|
||||
for i, item := range m.templates {
|
||||
if item.Key == "summary" {
|
||||
m.templateIndex = i
|
||||
}
|
||||
}
|
||||
m.renderTemplate()
|
||||
if !strings.Contains(m.templatesView(30), "Submit template") {
|
||||
t.Fatal("missing visible submit button")
|
||||
}
|
||||
stale, err := draft.Create("unrelated", "unrelated draft source", url, true, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m.pendingDraft = &editedMsg{name: stale.Name, source: "unrelated draft source", path: stale.Path, createOnly: true}
|
||||
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'s'}})
|
||||
m = updated.(Model)
|
||||
if cmd != nil || !m.confirmOpen || m.editorOpen || m.pendingDraft.name != "" || m.pendingDraft.path != "" || !m.pendingDraft.createOnly {
|
||||
t.Fatal("Submit button did not open naming flow without launching an editor", m.pendingDraft)
|
||||
}
|
||||
expected := pipeline.WithDefaultModel(m.templates[m.templateIndex].Source, m.defaultModel)
|
||||
if m.pendingDraft.source != expected {
|
||||
t.Fatal("selected template/model lost; unrelated draft reused")
|
||||
}
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyEsc})
|
||||
m = updated.(Model)
|
||||
drafts, _ := draft.List()
|
||||
if len(drafts) != 1 || !m.templateOpen || m.confirmOpen {
|
||||
t.Fatal("canceling template naming created a draft or left gallery")
|
||||
}
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("Simple summary")})
|
||||
m = updated.(Model)
|
||||
updated, cmd = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
items, _ := store.List(ctx)
|
||||
if cmd != nil || len(items) != 0 || !m.confirmOpen || m.pendingDraft.path == "" {
|
||||
t.Fatal("naming published before confirmation or failed to retain draft")
|
||||
}
|
||||
retained, err := draft.Load(m.pendingDraft.path)
|
||||
if err != nil || retained.Name != "Simple summary" || retained.Server != url || !retained.CreateOnly || retained.BaseVersion != 0 {
|
||||
t.Fatal("template draft metadata lost", retained, err)
|
||||
}
|
||||
text, err := draft.Read(retained.Path)
|
||||
if err != nil || text != expected {
|
||||
t.Fatal("template draft source lost", err)
|
||||
}
|
||||
updated, cmd = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if cmd == nil {
|
||||
t.Fatal("publication confirmation did not send")
|
||||
}
|
||||
if _, ok := cmd().(sentMsg); !ok {
|
||||
t.Fatal("publication send failed")
|
||||
}
|
||||
updated, _ = m.Update(m.read()())
|
||||
m = updated.(Model)
|
||||
items, _ = store.List(ctx)
|
||||
if len(items) != 1 || items[0].Name != retained.Name || items[0].Version != 1 || m.confirmOpen {
|
||||
t.Fatal("template submission failed", items, m.submitNotice)
|
||||
}
|
||||
detail, err := store.Get(ctx, items[0].ID, 0)
|
||||
if err != nil || detail.Source != expected {
|
||||
t.Fatal("published wrong template", err)
|
||||
}
|
||||
text, err = draft.Read(stale.Path)
|
||||
if err != nil || text != "unrelated draft source" {
|
||||
t.Fatal("template submission damaged unrelated draft", err)
|
||||
}
|
||||
if _, err := draft.Load(retained.Path); err != nil {
|
||||
t.Fatal("publication deleted retained draft", err)
|
||||
}
|
||||
}
|
||||
+20
-20
@@ -2,7 +2,7 @@ package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/glamour"
|
||||
@@ -33,7 +33,8 @@ func (m *Model) renderTemplate() {
|
||||
return
|
||||
}
|
||||
t := m.templates[m.templateIndex]
|
||||
source := ansi.Strip(t.Source)
|
||||
display := ansi.Strip(pipeline.WithDefaultModel(t.Source, m.defaultModel))
|
||||
source := display
|
||||
if !m.templateRaw {
|
||||
renderer, err := glamour.NewTermRenderer(glamour.WithStandardStyle("dark"), glamour.WithWordWrap(max(1, m.width-8)))
|
||||
if err == nil {
|
||||
@@ -41,7 +42,7 @@ func (m *Model) renderTemplate() {
|
||||
}
|
||||
if err != nil {
|
||||
m.templateError = "Markdown rendering failed; showing source."
|
||||
source = t.Source
|
||||
source = display
|
||||
}
|
||||
}
|
||||
m.templateLines = strings.Split(source, "\n")
|
||||
@@ -49,16 +50,19 @@ func (m *Model) renderTemplate() {
|
||||
|
||||
func (m Model) updateTemplates(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
switch msg.String() {
|
||||
case "s":
|
||||
if m.pendingDraft != nil {
|
||||
m.confirmOpen = true
|
||||
m.keys.confirm = true
|
||||
case "s", "enter":
|
||||
if len(m.templates) == 0 || m.submitID != "" {
|
||||
return m, nil
|
||||
}
|
||||
m.pendingDraft = &editedMsg{source: pipeline.WithDefaultModel(m.templates[m.templateIndex].Source, m.defaultModel), createOnly: true}
|
||||
m.confirmOpen = true
|
||||
m.keys.confirm = true
|
||||
m.submitNotice = ""
|
||||
m.draftNameInput = newInput()
|
||||
return m, nil
|
||||
case "e":
|
||||
if m.pendingDraft != nil {
|
||||
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})
|
||||
})
|
||||
if len(m.templates) > 0 {
|
||||
return m.newPipeline(m.templates[m.templateIndex].Source)
|
||||
}
|
||||
case "esc":
|
||||
m.templateOpen = false
|
||||
@@ -89,12 +93,8 @@ func (m Model) updateTemplates(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.templateTop = 0
|
||||
case "end":
|
||||
m.templateTop = len(m.templateLines)
|
||||
case "enter":
|
||||
if len(m.templates) > 0 {
|
||||
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))))
|
||||
m.templateTop = max(0, min(m.templateTop, max(0, len(m.templateLines)-max(1, m.height-11))))
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -108,17 +108,17 @@ func (m Model) templatesView(height int) string {
|
||||
mode = "Markdown source"
|
||||
}
|
||||
title := fmt.Sprintf("Templates · %d/%d · %s", m.templateIndex+1, len(m.templates), t.Name)
|
||||
note := "Preview only · Enter creates an editable draft, not a submission."
|
||||
note := "Preview only · choose a name, then confirm publication."
|
||||
if t.Scheduled {
|
||||
note = "SCHEDULED: submission activates its schedule; edit/remove settings first."
|
||||
}
|
||||
rows := max(0, height-6)
|
||||
rows := max(0, height-7)
|
||||
top := max(0, min(m.templateTop, max(0, len(m.templateLines)-rows)))
|
||||
end := min(len(m.templateLines), top+rows)
|
||||
headers := []string{bar(title, mode, max(1, m.width-4), true), lipgloss.NewStyle().Foreground(themeMuted).Render(note), bar("", fmt.Sprintf("%d–%d / %d", min(top+1, len(m.templateLines)), end, len(m.templateLines)), max(1, m.width-4), false)}
|
||||
headers := []string{bar(title, mode, max(1, m.width-4), true), action("s Submit template", true) + " " + action("e Customize", false), lipgloss.NewStyle().Foreground(themeMuted).Render(note), bar("", fmt.Sprintf("%d–%d / %d", min(top+1, len(m.templateLines)), end, len(m.templateLines)), max(1, m.width-4), false)}
|
||||
body := m.templateLines[top:end]
|
||||
if m.templateError != "" {
|
||||
body = append([]string{m.templateError}, body...)
|
||||
}
|
||||
return panel(m.width, height, headers, body, "n/p template · v rendered/source · j/k scroll · Enter use · Esc back", true)
|
||||
return panel(m.width, height, headers, body, "s/Enter submit · e customize · n/p template · v source · j/k scroll · Esc back", true)
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestTemplateMarkdownPreviewDraftAndKeyboardScope(t *testing.T) {
|
||||
t.Fatal("raw Markdown not available")
|
||||
}
|
||||
m = press(m, "v")
|
||||
updated, cmd := m.updateTemplates(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
updated, cmd := m.updateTemplates(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'e'}})
|
||||
m = updated.(Model)
|
||||
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")
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestUIUXReviewSnapshots(t *testing.T) {
|
||||
if err := os.MkdirAll(directory, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source, err := os.ReadFile("../../examples/anime-today.md")
|
||||
source, err := os.ReadFile("../../examples/three-stage.md")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func TestUIUXReviewSnapshots(t *testing.T) {
|
||||
m.loaded = true
|
||||
m.status = "127.0.0.1:8080"
|
||||
m.notificationEndpoints = []protocol.NotificationEndpoint{{Destination: "system", ServerURL: "http://100.85.25.33:8090", Topic: "pipelines"}}
|
||||
m.pipelines = []protocol.PipelineSummary{{ID: 8, Name: "anime episodes today", Version: 1, Stages: 4, CreatedAt: "2026-10-08T20:00:00Z", UpdatedAt: "2026-10-08T20:00:00Z"}}
|
||||
m.pipelines = []protocol.PipelineSummary{{ID: 8, Name: "Plan, implement, review", Version: 1, Stages: 3, CreatedAt: "2026-10-08T20:00:00Z", UpdatedAt: "2026-10-08T20:00:00Z"}}
|
||||
save := func(name string) {
|
||||
t.Helper()
|
||||
view := ansi.Strip(m.View())
|
||||
@@ -62,12 +62,12 @@ func TestUIUXReviewSnapshots(t *testing.T) {
|
||||
}
|
||||
save("scrolled-stage")
|
||||
m = press(m, "tab")
|
||||
m = press(m, "4")
|
||||
save("delivery-stage")
|
||||
m = press(m, "3")
|
||||
save("review-stage")
|
||||
m.runOpen = true
|
||||
m.keys.runs = true
|
||||
m.runDetail = &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 1, Name: "anime episodes today", PipelineID: 8, Version: 1, Status: "succeeded", CreatedAt: "2026-10-08T20:00:00Z", FinishedAt: "2026-10-08T20:01:00Z"}, Steps: []protocol.RunStep{{Sequence: 1, Stage: "discover", Status: "completed", Outcome: "success", Target: "verify"}, {Sequence: 2, Stage: "verify", Status: "completed", Outcome: "success", Target: "report"}, {Sequence: 3, Stage: "report", Status: "completed", Outcome: "success", Target: "notify", Output: map[string]any{"markdown": "# Anime episodes today\n\n[Source](https://www.livechart.me/schedule)"}}, {Sequence: 4, Stage: "notify", Status: "completed", Outcome: "success", Target: protocol.SuccessEnd, Output: map[string]any{"delivery": map[string]any{"attachment_url": "http://100.85.25.33:8090/file/report.md"}}}}}
|
||||
m.runStepIndex = 4
|
||||
m.runDetail = &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 1, Name: "Plan, implement, review", PipelineID: 8, Version: 1, Status: "succeeded", CreatedAt: "2026-10-08T20:00:00Z", FinishedAt: "2026-10-08T20:01:00Z"}, Graph: graph, Steps: []protocol.RunStep{{Sequence: 1, Stage: "planner", Status: "completed", Outcome: "success", Target: "implementer"}, {Sequence: 2, Stage: "implementer", Status: "completed", Outcome: "success", Target: "reviewer"}, {Sequence: 3, Stage: "reviewer", Status: "completed", Outcome: "success", Target: protocol.SuccessEnd, Output: map[string]any{"summary": "Fixture review report", "findings": "Fixture findings"}}}}
|
||||
m.runStepIndex = 3
|
||||
save("run")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user