Files
pipelines/internal/server/templates_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

75 lines
2.3 KiB
Go

package server
import (
"context"
"git.a-wan.net/alan/pipelines/internal/pipeline"
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/coder/websocket"
"github.com/coder/websocket/wsjson"
"net/http/httptest"
"path/filepath"
"strings"
"testing"
"time"
)
func TestTemplatesDoNotSeedDatabaseAndCreateOnlyPreservesExisting(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
store, err := pipeline.Open(filepath.Join(t.TempDir(), "empty.db"))
if err != nil {
t.Fatal(err)
}
defer store.Close()
handler := Handler(ctx, store)
defer func() { cancel(); WaitRuns(handler) }()
srv := httptest.NewServer(handler)
defer srv.Close()
conn, _, err := websocket.Dial(ctx, "ws"+strings.TrimPrefix(srv.URL, "http")+"/connect", nil)
if err != nil {
t.Fatal(err)
}
defer conn.CloseNow()
conn.SetReadLimit(8 << 20)
var response protocol.Message
if err := wsjson.Read(ctx, conn, &response); err != nil {
t.Fatal(err)
}
if len(response.Pipelines) != 0 {
t.Fatal("new install seeded pipelines")
}
if err := wsjson.Write(ctx, conn, protocol.Message{Type: protocol.ListTemplates, ID: "templates"}); err != nil {
t.Fatal(err)
}
if err := wsjson.Read(ctx, conn, &response); err != nil {
t.Fatal(err)
}
if response.Type != protocol.Templates || len(response.Templates) != 4 {
t.Fatal("missing catalog", response.Type, len(response.Templates))
}
items, err := store.List(ctx)
if err != nil || len(items) != 0 {
t.Fatal("browsing created pipelines", err)
}
source := response.Templates[0].Source
for i := 0; i < 2; i++ {
if err := wsjson.Write(ctx, conn, protocol.Message{Type: protocol.Submit, ID: "create", Name: "template copy", Source: source, CreateOnly: true}); err != nil {
t.Fatal(err)
}
if err := wsjson.Read(ctx, conn, &response); err != nil {
t.Fatal(err)
}
if i == 0 && response.Type != protocol.Submitted {
t.Fatal("new pipeline failed", response)
}
if i == 1 && (response.Type != protocol.Error || !strings.Contains(response.Error, "already exists")) {
t.Fatal("template overwrote existing pipeline", response)
}
}
items, _ = store.List(ctx)
detail, _ := store.Get(ctx, items[0].ID, 0)
if detail.Version != 1 || detail.Source != source {
t.Fatal("immutable source changed")
}
}