Expand pipeline panes and select the verified Docker client endpoint
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// ConfiguredURL is a client-only default. Explicit --url and PIPELINES_URL
|
||||
// always take precedence; no server/provider configuration is changed.
|
||||
func ConfiguredURL() (string, error) {
|
||||
directory := os.Getenv("XDG_CONFIG_HOME")
|
||||
if directory == "" {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
directory = filepath.Join(home, ".config")
|
||||
}
|
||||
path := filepath.Join(directory, "pipelines", "client.json")
|
||||
data, err := os.ReadFile(path)
|
||||
if os.IsNotExist(err) {
|
||||
return "", nil
|
||||
}
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("read client configuration %s: %w", path, err)
|
||||
}
|
||||
var config struct {
|
||||
ServerURL string `json:"server_url"`
|
||||
}
|
||||
if len(data) > 64<<10 || json.Unmarshal(data, &config) != nil {
|
||||
return "", fmt.Errorf("invalid client configuration %s; use --url to override", path)
|
||||
}
|
||||
if config.ServerURL == "" {
|
||||
return "", nil
|
||||
}
|
||||
u, err := url.Parse(config.ServerURL)
|
||||
if err != nil || (u.Scheme != "ws" && u.Scheme != "wss") || u.Hostname() == "" || u.User != nil || u.Fragment != "" {
|
||||
return "", fmt.Errorf("invalid server_url in %s; use --url to override", path)
|
||||
}
|
||||
return config.ServerURL, nil
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfiguredURLValidationAndMissingConfig(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
t.Setenv("XDG_CONFIG_HOME", directory)
|
||||
if value, err := ConfiguredURL(); err != nil || value != "" {
|
||||
t.Fatal(value, err)
|
||||
}
|
||||
path := filepath.Join(directory, "pipelines", "client.json")
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, test := range []struct {
|
||||
text string
|
||||
valid bool
|
||||
}{
|
||||
{`{"server_url":"ws://127.0.0.1:8081/connect","custom":"keep"}`, true},
|
||||
{`{"server_url":"wss://server.example/connect"}`, true},
|
||||
{`{"server_url":"http://wrong/connect"}`, false},
|
||||
{`{"server_url":"ws://secret:token@server/connect"}`, false},
|
||||
{`not JSON`, false},
|
||||
} {
|
||||
if err := os.WriteFile(path, []byte(test.text), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
value, err := ConfiguredURL()
|
||||
if (err == nil) != test.valid || (test.valid && value == "") {
|
||||
t.Fatal(test, value, err)
|
||||
}
|
||||
if data, _ := os.ReadFile(path); string(data) != test.text {
|
||||
t.Fatal("configuration mutated")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func NtfyLines(s *protocol.SystemStatus) []string {
|
||||
lines = append(lines, "Login: "+s.NtfyUser, "Use the password set during installation.")
|
||||
}
|
||||
if s.Ntfy.Health == "not configured" {
|
||||
lines = append(lines, "On the server: rerun ./install.sh.")
|
||||
lines = append(lines, "The connected Pipelines server has no ntfy publishing configuration.", "For Docker: check docker compose port pipelines 8080.", "Connect the TUI to that port; check --url / PIPELINES_URL.", "If this is the intended server: run ./install.sh there.")
|
||||
} else if s.Ntfy.Health == "unreachable" || s.Ntfy.Health == "unhealthy" {
|
||||
lines = append(lines, "On the server: docker compose logs ntfy")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package statusview
|
||||
|
||||
import (
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -19,3 +20,12 @@ func TestOfflineStatusIncludesBothServicesAndRedactsURLCredentials(t *testing.T)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnconfiguredNtfyExplainsConnectedServerAndEndpointMismatch(t *testing.T) {
|
||||
text := strings.Join(NtfyLines(&protocol.SystemStatus{Ntfy: protocol.ServiceStatus{Health: "not configured"}}), "\n")
|
||||
for _, want := range []string{"connected Pipelines server", "docker compose port pipelines 8080", "--url / PIPELINES_URL"} {
|
||||
if !strings.Contains(text, want) {
|
||||
t.Fatal("missing endpoint diagnosis", want, text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,12 @@ type paneGeometry struct {
|
||||
func (m Model) pipelineGeometry(height int) paneGeometry {
|
||||
remaining := max(0, height-3)
|
||||
if remaining >= 15 {
|
||||
bottom := remaining / 2
|
||||
graph := remaining * 3 / 4
|
||||
if m.stageFocus {
|
||||
bottom = remaining - max(6, remaining/3)
|
||||
graph = remaining / 4
|
||||
}
|
||||
graph = max(6, min(remaining-8, graph))
|
||||
bottom := remaining - graph
|
||||
return paneGeometry{graphWidth: m.width, graphHeight: remaining - bottom, stageWidth: m.width, stageHeight: bottom}
|
||||
}
|
||||
if m.stageFocus {
|
||||
@@ -203,7 +205,7 @@ func graphViewport(label string, lines []string, width, height, scrollTop, pan i
|
||||
if pan+inner < graphWidth {
|
||||
label += " →"
|
||||
}
|
||||
headers := []string{bar(label, fmt.Sprintf("%d–%d / %d", min(top+1, len(lines)), end, len(lines)), inner, focused), ""}
|
||||
headers := []string{runPaneTitle(strings.TrimPrefix(label, "▸ "), fmt.Sprintf("%d–%d / %d", min(top+1, len(lines)), end, len(lines)), inner, focused), ""}
|
||||
if graphWidth > inner {
|
||||
footer = "←/→ pan · " + footer
|
||||
}
|
||||
@@ -418,7 +420,7 @@ func (m Model) stagePanel(width, height int) string {
|
||||
if m.stageFocus {
|
||||
label = "▸ " + label
|
||||
}
|
||||
headers := []string{bar(label, fmt.Sprintf("%d / %d · rows %d–%d/%d", m.stageIndex+1, len(m.detail.Graph.Stages), min(top+1, len(lines)), min(len(lines), top+rows), len(lines)), inner, m.stageFocus), m.stageTabs(inner), columns}
|
||||
headers := []string{runPaneTitle(strings.TrimPrefix(label, "▸ "), fmt.Sprintf("%d / %d · rows %d–%d/%d", m.stageIndex+1, len(m.detail.Graph.Stages), min(top+1, len(lines)), min(len(lines), top+rows), len(lines)), inner, m.stageFocus), m.stageTabs(inner), columns}
|
||||
return panel(width, height, headers, lines[top:min(len(lines), top+rows)], "n/p stage · Tab pane · j/k scroll · PgUp/Dn page", m.stageFocus)
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +129,25 @@ func TestPanelResponsiveLayout(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPipelineTabExpandsFocusedPane(t *testing.T) {
|
||||
m := panelModel(t)
|
||||
m.width, m.height = 120, 48
|
||||
g := m.pipelineGeometry(44)
|
||||
if g.graphHeight <= g.stageHeight*2 {
|
||||
t.Fatal("pipeline graph does not occupy most height", g)
|
||||
}
|
||||
m = press(m, "tab")
|
||||
g = m.pipelineGeometry(44)
|
||||
if !m.stageFocus || g.stageHeight <= g.graphHeight*2 {
|
||||
t.Fatal("pipeline stage pane did not expand", g)
|
||||
}
|
||||
m = press(m, "tab")
|
||||
g = m.pipelineGeometry(44)
|
||||
if m.stageFocus || g.graphHeight <= g.stageHeight*2 {
|
||||
t.Fatal("pipeline graph did not re-expand", g)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStageCapabilitiesAndScrolledHeadings(t *testing.T) {
|
||||
m := panelModel(t)
|
||||
m.detail.Graph.Stages[0].Notify = &protocol.NotificationPolicy{On: []string{"failure"}, Destination: "system"}
|
||||
|
||||
Reference in New Issue
Block a user