Report a stale client and refuse an unreadable newer server

Exchange a build/protocol identity so an older CLI can no longer talk to a
newer native server silently:

- protocol carries ProtocolVersion and every server frame (including the
  unsolicited welcome) is stamped with the server build and protocol, so a
  client that never pings still learns the server identity.
- buildinfo.Compare classifies the relationship as InSync/Warn/Refuse and
  names both builds; the client Watch reports one warning per connection and
  returns a hard error when the server speaks a newer, uninterpretable
  protocol so the caller never acts on the frame.
- client.ReceiveNotice decodes the raw frame so an unmodeled top-level field
  produces a one-time "unrecognized field(s)" notice instead of being dropped
  silently (the case that hid the artifacts field).
- CLI routes warnings to stderr, keeps machine JSON stdout clean and fails
  non-zero on a refused mismatch; ping/connection print the client/server
  relationship. The TUI surfaces the same notices through the shared log.
- scripts/setup-native.py now warns when an older `pipelines` earlier on PATH
  shadows prefix/bin/pipelines, naming both paths and versions, without
  installing or modifying anything else.
- Docs, the packaged debugging skill reference and README no longer imply the
  installed CLI always matches the server.

Tests cover the comparison table, unknown-field detection and caching, the
server identity stamping on pong and welcome, the CLI/TUI reporting paths and
the installer PATH shadowing warning.
This commit is contained in:
2026-10-16 18:37:01 +01:00
parent 98bbc2deac
commit 8c1eea53a9
25 changed files with 1239 additions and 81 deletions
+40
View File
@@ -5,6 +5,7 @@ import (
"context"
"log"
"net/http/httptest"
"path/filepath"
"strings"
"sync"
"testing"
@@ -14,6 +15,7 @@ import (
"github.com/coder/websocket/wsjson"
"git.a-wan.net/alan/pipelines/internal/buildinfo"
"git.a-wan.net/alan/pipelines/internal/pipeline"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
@@ -77,6 +79,9 @@ func TestPersistentConnection(t *testing.T) {
if response.Build == nil || response.Build.Version != wantBuild.Version || response.Build.Commit != wantBuild.Commit {
t.Fatalf("pong missing server build identity: %+v", response.Build)
}
if response.Protocol != protocol.ProtocolVersion {
t.Fatalf("pong protocol = %d, want %d", response.Protocol, protocol.ProtocolVersion)
}
stamp, err := time.Parse(time.RFC3339, response.Time)
if err != nil {
t.Fatal(err)
@@ -97,3 +102,38 @@ func TestPersistentConnection(t *testing.T) {
}
}
}
// TestWelcomeEnvelopeCarriesServerIdentity proves a client that never pings
// still learns the server build and protocol from the unsolicited welcome.
func TestWelcomeEnvelopeCarriesServerIdentity(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
store, err := pipeline.Open(filepath.Join(t.TempDir(), "identity.db"))
if err != nil {
t.Fatal(err)
}
defer store.Close()
handler := Handler(ctx, store)
srv := httptest.NewServer(handler)
defer srv.Close()
defer func() { cancel(); WaitRuns(handler) }()
conn, _, err := websocket.Dial(ctx, "ws"+strings.TrimPrefix(srv.URL, "http")+"/connect", nil)
if err != nil {
t.Fatal(err)
}
defer conn.CloseNow()
var welcome protocol.Message
if err := wsjson.Read(ctx, conn, &welcome); err != nil {
t.Fatal(err)
}
if welcome.Type != protocol.PipelineList {
t.Fatalf("first frame = %q, want welcome pipelines list", welcome.Type)
}
wantBuild := buildinfo.Current()
if welcome.Build == nil || welcome.Build.Version != wantBuild.Version || welcome.Build.Commit != wantBuild.Commit {
t.Fatalf("welcome missing server build identity: %+v", welcome.Build)
}
if welcome.Protocol != protocol.ProtocolVersion {
t.Fatalf("welcome protocol = %d, want %d", welcome.Protocol, protocol.ProtocolVersion)
}
}