05ae530442
Install current verified harness releases inside Docker, preserve persistent accounts and settings, and provide separate interactive and pipeline model defaults with terminal onboarding and fuzzy pickers. Add Docker-aware authoring transport, Pi stage execution, bounded workflow controls, reliable final-result readback and usage settlement, and finite short-lived CLI pipe draining. Keep dated installation evidence and packaged authoring guidance consistent. Verified with a real Docker installation, both harness stages and interactive authors, the built-in plan/implement/review starter, independent host race/vet checks, installer tests, and packaged skill tests. Generated release receipts stay ignored in clean checkouts.
150 lines
5.3 KiB
Go
150 lines
5.3 KiB
Go
package tui
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"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/x/ansi"
|
|
)
|
|
|
|
func TestPipelineEditPickerHasTabNavigationFuzzySearchAndRetainedDraft(t *testing.T) {
|
|
configureTestHarness(t)
|
|
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
|
|
m := New(context.Background(), "ws://example/connect")
|
|
m.width = 120
|
|
m.height = 35
|
|
m.keys.detail = true
|
|
source := pipeline.Template([]string{"one"}, true)
|
|
m.detail = &protocol.PipelineDetail{PipelineSummary: protocol.PipelineSummary{Name: "workflow", Version: 2}, LatestVersion: 4, Source: source}
|
|
updated, _ := m.editPipeline()
|
|
m = updated.(Model)
|
|
if !m.editorOpen || m.editorDraft.baseVersion != 4 || m.editorDraft.source != pipeline.ExecutionSource(source) {
|
|
t.Fatal("edit did not ask which editor or lost version guard")
|
|
}
|
|
if items, _ := draft.List(); len(items) != 0 {
|
|
t.Fatal("opening/canceling picker should not create a draft")
|
|
}
|
|
if view := ansi.Strip(m.editorPickerView(30)); !strings.Contains(view, "nvim") || !strings.Contains(view, "OpenCode") {
|
|
t.Fatal("editor options missing", view)
|
|
}
|
|
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyTab})
|
|
m = updated.(Model)
|
|
if m.editorIndex != 1 {
|
|
t.Fatal("Tab did not select OpenCode")
|
|
}
|
|
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyShiftTab})
|
|
m = updated.(Model)
|
|
if m.editorIndex != 0 {
|
|
t.Fatal("Shift+Tab did not select nvim")
|
|
}
|
|
m.editorInput.SetValue("ocd")
|
|
if choices := m.editorChoices(); len(choices) != 1 || choices[0] != "OpenCode" {
|
|
t.Fatal("fuzzy editor search failed", choices)
|
|
}
|
|
m.editorInput.SetValue("nv")
|
|
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
|
m = updated.(Model)
|
|
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 {
|
|
t.Fatal("edit did not retain guarded draft", items, err)
|
|
}
|
|
if m.confirmOpen || m.submitID != "" {
|
|
t.Fatal("editor selection bypassed explicit submission")
|
|
}
|
|
}
|
|
|
|
func TestNewPickerSupportsBothEditorsWithoutCreatingDraftOnCancel(t *testing.T) {
|
|
configureTestHarness(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.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()
|
|
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)
|
|
b, _ := draft.Create("keep", "keep", "server", true, 0)
|
|
m := New(context.Background(), "server")
|
|
updated, _ := m.openDrafts()
|
|
m = updated.(Model)
|
|
for i, d := range m.draftItems {
|
|
if d.Path == a.Path {
|
|
m.draftIndex = i
|
|
}
|
|
}
|
|
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'x'}})
|
|
m = updated.(Model)
|
|
if m.draftDeletingPath != a.Path {
|
|
t.Fatal("delete confirmation not opened")
|
|
}
|
|
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyEsc})
|
|
m = updated.(Model)
|
|
if _, err := draft.Read(a.Path); err != nil {
|
|
t.Fatal("cancel deleted draft", err)
|
|
}
|
|
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'x'}})
|
|
m = updated.(Model)
|
|
m.pendingDraft = &editedMsg{path: a.Path}
|
|
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'y'}})
|
|
m = updated.(Model)
|
|
if m.pendingDraft != nil || m.draftDeletingPath != "" || len(m.draftItems) != 1 || m.draftItems[0].Path != b.Path {
|
|
t.Fatal("cleanup did not clear selected draft/refresh browser")
|
|
}
|
|
}
|