Files
pipelines/internal/tui/template_submit_test.go
T
alan c9b904186a Update templates and authoring skill to the current pipeline contract
Bring the packaged starters and the pipelines skill up to the guidelines the
project now works to.

Templates:
- task and three-stage now end in a committer stage that stages the union of the
  runner's captured input.server_changed_files and the producer's declared
  changed_files, runs the repository's checks, commits locally and never pushes;
  their producers no longer commit.
- Every model/agent prompt states the line-oriented result contract (outcome on the
  first non-empty line, "# output" JSON map, other "# <heading>" sections kept
  verbatim as evidence) and an "# evidence" section for exact commands and results,
  with proportionate verification and no fabricated checks.
- Stages that can write save their reports, logs and screenshots into the runtime
  artifacts directory.
- Remove the summary starter: a tool-free single-prompt text transform with no
  repository interaction, artifact or commit is a format demonstration, not a
  reusable workflow. No starter invents a pretend approval stage; a decision point
  is a type=human stage.

Skill:
- references/format.md gains a Result format section (line form, legacy JSON
  precedence, result_parse, raw-output.md, artifacts) and a Committer stages
  section with the pre-commit checklist; the role-split and envelope notes mention
  the line form and the committer.
- orchestration.md points at the checklist and records that a genuine gate is a
  human stage; operations.md and the SKILL.md index drop the removed starter and
  name the result format and committer. No new reference, so the managed inventory
  is unchanged.

Docs/tests: examples/README, README, docs/cli, docs/first-version-testing, the CLI
help example and the smoke script track the four starters; catalog, tool-role,
server, tui and pipeline tests are updated, with a new test pinning the committer
ending and server-captured change set.

Commands run: go build ./...; go vet ./...; go test ./...; python3 -m unittest
discover -s scripts -p 'test_*.py'; python3 scripts/smoke-first-install.py. All
passed. Templates inspected through an isolated CLI server (pipelines templates;
pipelines template KEY --source). No server, service or device was restarted, and
nothing was pushed.
2026-10-17 01:09:42 +01:00

165 lines
5.9 KiB
Go

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 == "review" {
m.templateIndex = i
}
}
m.renderTemplate()
if !strings.Contains(m.templatesView(30), "Create pipeline") {
t.Fatal("missing visible create 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 !m.confirmOpen || m.editorOpen || m.pendingDraft.name != m.templates[m.templateIndex].Name || m.draftNameInput.Value() != m.pendingDraft.name || m.pendingDraft.path != "" || !m.pendingDraft.createOnly {
t.Fatal("Create button did not open prefilled confirmation without 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.KeyCtrlA})
m = updated.(Model)
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyCtrlK})
m = updated.(Model)
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("Simple review")})
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("single create confirmation did not send or failed to retain draft")
}
retained, err := draft.Load(m.pendingDraft.path)
if err != nil || retained.Name != "Simple review" || 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)
}
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)
}
// Unchanged defaults also work in one confirmation; duplicate names must never update.
for attempt := 0; attempt < 2; attempt++ {
m.templateOpen, m.keys.templates = true, true
updated, _ = m.updateTemplates(tea.KeyMsg{Type: tea.KeyEnter})
m = updated.(Model)
defaultName := m.templates[m.templateIndex].Name
if m.draftNameInput.Value() != defaultName {
t.Fatal("template name not prefilled")
}
updated, send := m.updateConfirm(tea.KeyMsg{Type: tea.KeyEnter})
m = updated.(Model)
if send == nil {
t.Fatal("default name needed extra confirmation")
}
send()
updated, _ = m.Update(m.read()())
m = updated.(Model)
if attempt == 0 && m.confirmOpen {
t.Fatal("default-name creation failed", m.submitNotice)
}
if attempt == 1 && (!m.confirmOpen || !strings.Contains(m.submitNotice, "already exists")) {
t.Fatal("duplicate name did not stay editable", m.submitNotice)
}
}
items, _ = store.List(ctx)
if len(items) != 2 {
t.Fatal("duplicate creation changed pipelines", items)
}
for _, item := range items {
if item.Version != 1 {
t.Fatal("template silently updated existing pipeline")
}
}
}
func TestPublicationWordingDistinguishesCreateAndUpdate(t *testing.T) {
m := New(context.Background(), "")
m.width = 120
for _, test := range []struct {
createOnly bool
base int
want string
}{{true, 0, "Create pipeline"}, {false, 3, "Update pipeline"}} {
m.pendingDraft = &editedMsg{name: "Workflow", createOnly: test.createOnly, baseVersion: test.base}
view := m.confirmView(24)
if !strings.Contains(view, test.want) || strings.Contains(view, "Submit edited pipeline") || strings.Contains(view, "s submit") {
t.Fatal("wrong publication wording", view)
}
m.confirmOpen = true
if !strings.Contains(m.footerContent(), strings.ToLower(test.want)) {
t.Fatal("wrong publication footer")
}
}
}