Expand pipeline panes and select the verified Docker client endpoint

This commit is contained in:
2026-10-10 00:56:55 +01:00
parent 2cc703b8a5
commit 7565693957
13 changed files with 352 additions and 8 deletions
+17
View File
@@ -257,6 +257,23 @@ func (a App) Run(ctx context.Context, args []string) error {
_, err := fmt.Fprintln(a.Out, "Deleted draft:", pos[0])
return err
}
if command != "drafts" && os.Getenv("PIPELINES_URL") == "" {
explicit := false
f.Visit(func(value *flag.Flag) {
if value.Name == "url" {
explicit = true
}
})
if !explicit {
configured, err := client.ConfiguredURL()
if err != nil {
return err
}
if configured != "" {
o.url = configured
}
}
}
if command == "tui" {
if len(pos) > 0 {
return fmt.Errorf("tui takes no arguments")
+74
View File
@@ -0,0 +1,74 @@
package cli_test
import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
"time"
"git.a-wan.net/alan/pipelines/internal/cli"
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/coder/websocket"
"github.com/coder/websocket/wsjson"
)
func TestInstalledDockerDefaultAvoidsUnconfiguredServerAndHonorsOverrides(t *testing.T) {
endpoint := func(health string) string {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
conn, err := websocket.Accept(w, r, nil)
if err != nil {
return
}
defer conn.CloseNow()
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
defer cancel()
var request protocol.Message
if err := wsjson.Read(ctx, conn, &request); err != nil {
return
}
wsjson.Write(ctx, conn, protocol.Message{Type: protocol.Status, ID: request.ID, Status: &protocol.SystemStatus{Ntfy: protocol.ServiceStatus{Health: health}}})
}))
t.Cleanup(srv.Close)
return "ws" + strings.TrimPrefix(srv.URL, "http") + "/connect"
}
docker, native := endpoint("healthy"), endpoint("not configured")
directory := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", directory)
t.Setenv("PIPELINES_URL", "")
path := filepath.Join(directory, "pipelines", "client.json")
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
t.Fatal(err)
}
data, _ := json.Marshal(map[string]string{"server_url": docker})
if err := os.WriteFile(path, data, 0600); err != nil {
t.Fatal(err)
}
check := func(want string, args ...string) {
t.Helper()
var out, stderr bytes.Buffer
if err := (cli.App{Out: &out, Err: &stderr}).Run(context.Background(), args); err != nil {
t.Fatal(err, stderr.String())
}
var status protocol.SystemStatus
if json.Unmarshal(out.Bytes(), &status) != nil || status.Ntfy.Health != want {
t.Fatal("wrong server selected", out.String())
}
}
check("healthy", "status", "--json")
check("not configured", "--url", native, "status", "--json")
t.Setenv("PIPELINES_URL", native)
check("not configured", "status", "--json")
check("healthy", "status", "--url", docker, "--json")
// An explicit selector must still work even if a saved file is malformed.
if err := os.WriteFile(path, []byte("broken"), 0600); err != nil {
t.Fatal(err)
}
t.Setenv("PIPELINES_URL", "")
check("healthy", "status", "--url", docker, "--json")
}