a37a6e0934
- CLI: empty list/runs/drafts/skills say so on stderr with the next command (stdout and --json unchanged); empty stats skip the zero table; connection shows ntfy not configured. - CLI: a refused or unresolvable server says where it dialled and how to start it (pipelines start/doctor, or pipelines serve), redacting the URL. - skills list/show/import dial the saved client.json address like every other server command instead of always 127.0.0.1:8080. - Status: an unreachable server says how to start it; unconfigured ntfy reads as optional phone notifications rather than a Docker misconfiguration. - Installer: missing tools name where to get them; Docker missing vs not running are told apart; the summary ends with numbered next steps (open the URL, sign in with the password just chosen, set up harnesses, start a chat or example pipeline). - README: prerequisites, password and a short First steps; install docs updated (password rule was stale). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
2.9 KiB
Go
89 lines
2.9 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"syscall"
|
|
"testing"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/cli"
|
|
)
|
|
|
|
// A brand-new server has no pipelines, runs, drafts or skills. Human output
|
|
// says so with a next step on stderr; stdout stays empty for scripts and
|
|
// --json output carries no prose.
|
|
func TestEmptyListsExplainNextStepOnStderrOnly(t *testing.T) {
|
|
t.Setenv("PIPELINES_NTFY_URL", "")
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
_, _, url := setup(t)
|
|
invoke := func(args ...string) (string, string) {
|
|
t.Helper()
|
|
var out, stderr bytes.Buffer
|
|
if err := (cli.App{Out: &out, Err: &stderr, In: strings.NewReader("")}).Run(context.Background(), args); err != nil {
|
|
t.Fatal(args, err)
|
|
}
|
|
return out.String(), stderr.String()
|
|
}
|
|
for _, c := range []struct {
|
|
args []string
|
|
hint string
|
|
}{
|
|
{[]string{"--url", url, "list"}, "No pipelines yet. See starting points with `pipelines templates`"},
|
|
{[]string{"--url", url, "list", "--archived"}, "No archived pipelines."},
|
|
{[]string{"--url", url, "runs"}, "No runs yet. Start one with: pipelines run <pipeline>"},
|
|
{[]string{"--url", url, "drafts"}, "No drafts."},
|
|
{[]string{"skills", "list", "--url", url}, "No library skills yet."},
|
|
} {
|
|
out, hint := invoke(c.args...)
|
|
if out != "" || !strings.Contains(hint, c.hint) {
|
|
t.Fatalf("%v: stdout %q stderr %q", c.args, out, hint)
|
|
}
|
|
out, hint = invoke(append(c.args, "--json")...)
|
|
if hint != "" || strings.Contains(out, "No ") {
|
|
t.Fatalf("%v --json: stdout %q stderr %q", c.args, out, hint)
|
|
}
|
|
}
|
|
out, _ := invoke("--url", url, "stats")
|
|
if !strings.Contains(out, "0 runs") || !strings.Contains(out, "No runs yet") || strings.Contains(out, "Daily activity") {
|
|
t.Fatalf("empty stats: %q", out)
|
|
}
|
|
out, _ = invoke("--url", url, "connection")
|
|
if !strings.Contains(out, "ntfy: not configured") {
|
|
t.Fatalf("connection without ntfy: %q", out)
|
|
}
|
|
}
|
|
|
|
func TestUnreachableServerSaysHowToStartIt(t *testing.T) {
|
|
const closed = "ws://user:secret@127.0.0.1:1/connect?token=secret"
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("PIPELINES_URL", "")
|
|
for _, c := range []struct {
|
|
app cli.App
|
|
args []string
|
|
}{
|
|
{cli.App{}, []string{"--url", closed, "runs"}},
|
|
{cli.App{}, []string{"skills", "list", "--url", closed}},
|
|
} {
|
|
var out, stderr bytes.Buffer
|
|
c.app.Out, c.app.Err, c.app.In = &out, &stderr, strings.NewReader("")
|
|
err := c.app.Run(context.Background(), c.args)
|
|
if err == nil {
|
|
t.Fatal("closed port connected")
|
|
}
|
|
text := err.Error()
|
|
for _, want := range []string{"cannot reach the Pipelines server at ws://127.0.0.1:1/connect (connection refused)", "pipelines serve", "--url or set PIPELINES_URL"} {
|
|
if !strings.Contains(text, want) {
|
|
t.Fatalf("%v: missing %q in %q", c.args, want, text)
|
|
}
|
|
}
|
|
if strings.Contains(text, "secret") {
|
|
t.Fatalf("credentials exposed: %q", text)
|
|
}
|
|
if !errors.Is(err, syscall.ECONNREFUSED) {
|
|
t.Fatalf("transport error not wrapped: %v", err)
|
|
}
|
|
}
|
|
}
|