Files
pipelines/internal/cli/harness_test.go
T
alan 05ae530442 Make Pipelines Docker-only with OpenCode and Pi
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.
2026-10-11 23:00:25 +01:00

106 lines
5.4 KiB
Go

package cli
import (
"bytes"
"context"
"git.a-wan.net/alan/pipelines/internal/harness"
"os"
"path/filepath"
"strings"
"testing"
)
func TestHarnessSetupSeparateDefaultsAndNoInference(t *testing.T) {
root := t.TempDir()
t.Setenv("PIPELINES_HARNESS_CONFIG", filepath.Join(root, "harnesses.json"))
script := filepath.Join(root, "opencode")
if err := os.WriteFile(script, []byte("#!/bin/sh\ncase \"$*\" in\n'api get /api/integration') echo '{}' ;;\nmodels) printf '%s\\n' fixture/harness fixture/stages disconnected/model;;\n'auth list --format json') echo '[{\"id\":\"fixture\",\"connections\":[{}]}]' ;;\n*) exit 91;;\nesac\n"), 0700); err != nil {
t.Fatal(err)
}
var out bytes.Buffer
app := App{In: bytes.NewBuffer(nil), Out: &out, Err: &out}
if err := app.Run(context.Background(), []string{"harness", "setup", "opencode", "--executable", script, "--model", "fixture/harness", "--pipeline-model", "fixture/stages", "--default"}); err != nil {
t.Fatal(err)
}
c, err := harness.Load()
if err != nil || c.Default != "opencode" || c.Profiles["opencode"].PipelineModel != "fixture/stages" {
t.Fatal(c, err)
}
before, _ := os.ReadFile(filepath.Join(root, "harnesses.json"))
if err := app.Run(context.Background(), []string{"harness", "setup", "opencode", "--executable", script, "--model", "disconnected/model", "--pipeline-model", "fixture/stages"}); err == nil {
t.Fatal("disconnected model accepted")
}
after, _ := os.ReadFile(filepath.Join(root, "harnesses.json"))
if !bytes.Equal(before, after) {
t.Fatal("failed setup changed defaults")
}
}
func TestHarnessSetupNonTerminalMissingModelFailsClearly(t *testing.T) {
root := t.TempDir()
t.Setenv("PIPELINES_HARNESS_CONFIG", filepath.Join(root, "harnesses.json"))
script := filepath.Join(root, "opencode")
if err := os.WriteFile(script, []byte("#!/bin/sh\ncase \"$*\" in\n'api get /api/integration') echo '{}' ;;\nmodels) printf '%s\\n' fixture/harness fixture/stages ;;\n'auth list --format json') echo '[{\"id\":\"fixture\",\"connections\":[{}]}]' ;;\n*) exit 91;;\nesac\n"), 0700); err != nil {
t.Fatal(err)
}
var out bytes.Buffer
app := App{In: bytes.NewBuffer(nil), Out: &out, Err: &out}
err := app.Run(context.Background(), []string{"harness", "setup", "opencode", "--executable", script})
if err == nil || !strings.Contains(err.Error(), "requires a terminal") {
t.Fatalf("non-terminal missing-model error = %v", err)
}
if _, statErr := os.Stat(filepath.Join(root, "harnesses.json")); !os.IsNotExist(statErr) {
t.Fatal("failed non-terminal setup wrote defaults")
}
}
func TestPiLoginHandoffOpensFreshSessionWithoutTaskPrompt(t *testing.T) {
root := t.TempDir()
t.Setenv("PIPELINES_HARNESS_CONFIG", filepath.Join(root, "harnesses.json"))
t.Setenv("FIXTURE", root)
script := filepath.Join(root, "pi")
if err := os.WriteFile(script, []byte("#!/bin/sh\ncase \"$*\" in\n'--no-extensions --list-models') printf '%s\\n' provider/interactive provider/stages ;;\n'--tui-mode regular --no-extensions --no-skills --no-context-files --no-prompt-templates --no-tools') printf '%s\\n' \"$@\" >> \"$FIXTURE/pi-login\" ;;\n*) exit 91 ;;\nesac\n"), 0700); err != nil {
t.Fatal(err)
}
var out bytes.Buffer
app := App{In: bytes.NewBuffer(nil), Out: &out, Err: &out}
if err := app.Run(context.Background(), []string{"harness", "setup", "pi", "--executable", script, "--login", "--model", "provider/interactive", "--pipeline-model", "provider/stages", "--default"}); err != nil {
t.Fatal(err)
}
logged, err := os.ReadFile(filepath.Join(root, "pi-login"))
if err != nil {
t.Fatal("pi login session was not opened")
}
wantArgs := "--tui-mode regular --no-extensions --no-skills --no-context-files --no-prompt-templates --no-tools"
if got := strings.Join(strings.Fields(string(logged)), " "); got != wantArgs {
t.Fatalf("pi login args = %q; expected a fresh no-context, no-prompt, no-tools session", got)
}
text := out.String()
for _, want := range []string{"Pi sign-in", "/login", "authentication method", "Sign in with an API key", "ctrl+c/ctrl+d", "reuse them", "provider sign-in", "account/API key/Radius", "provider/interactive", "provider/stages", "Configuration complete"} {
if !strings.Contains(text, want) {
t.Fatalf("missing %q in handoff output:\n%s", want, text)
}
}
c, err := harness.Load()
if err != nil || c.Default != "pi" || c.Profiles["pi"].Model != "provider/interactive" || c.Profiles["pi"].PipelineModel != "provider/stages" {
t.Fatal(c, err)
}
}
func TestHarnessSetupShowsVerifiedVersions(t *testing.T) {
root := t.TempDir()
t.Setenv("PIPELINES_HARNESS_CONFIG", filepath.Join(root, "harnesses.json"))
script := filepath.Join(root, "opencode")
if err := os.WriteFile(script, []byte("#!/bin/sh\ncase \"$*\" in\n'api get /api/integration') echo '{}' ;;\nmodels) printf '%s\\n' fixture/harness fixture/stages ;;\n'auth list --format json') echo '[{\"id\":\"fixture\",\"connections\":[{}]}]' ;;\n*) exit 91;;\nesac\n"), 0700); err != nil {
t.Fatal(err)
}
var out bytes.Buffer
app := App{In: bytes.NewBuffer(nil), Out: &out, Err: &out}
if err := app.Run(context.Background(), []string{"harness", "setup", "opencode", "--executable", script, "--versions", "OpenCode 2.0.26 · Pi 1.1.0 · Node 22.19.0", "--model", "fixture/harness", "--pipeline-model", "fixture/stages"}); err != nil {
t.Fatal(err)
}
if text := out.String(); !strings.Contains(text, "OpenCode 2.0.26") || !strings.Contains(text, "Docker image harnesses:") {
t.Fatalf("verified versions not shown:\n%s", text)
}
}