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:
@@ -404,6 +404,13 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
return err
|
||||
}
|
||||
defer c.Close()
|
||||
// Report at most one build/protocol warning per invocation on stderr, so
|
||||
// stdout stays parseable JSON; an unsafe newer server fails the command.
|
||||
c.Report(func(relationship buildinfo.Relationship) {
|
||||
if relationship.Message != "" {
|
||||
a.notice("warning: " + relationship.Message)
|
||||
}
|
||||
})
|
||||
call := func(request protocol.Message) (protocol.Message, error) {
|
||||
requestCtx, cancel := context.WithTimeout(ctx, o.timeout)
|
||||
defer cancel()
|
||||
@@ -684,11 +691,19 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
} else {
|
||||
fmt.Fprintln(a.Out, "Server build: unavailable (older server)")
|
||||
}
|
||||
build := buildinfo.Current()
|
||||
fmt.Fprintf(a.Out, "Client: %s (commit %s)\n", build.Version, build.Commit)
|
||||
if note := identityNote(r); note != "" {
|
||||
fmt.Fprintln(a.Out, "Note:", note)
|
||||
}
|
||||
case "connection":
|
||||
fmt.Fprintln(a.Out, "Server:", o.url)
|
||||
for _, n := range r.NotificationEndpoints {
|
||||
fmt.Fprintf(a.Out, "ntfy: %s · topic %s\n", n.ServerURL, n.Topic)
|
||||
}
|
||||
if note := identityNote(r); note != "" {
|
||||
fmt.Fprintln(a.Out, "Note:", note)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "export":
|
||||
@@ -888,6 +903,23 @@ func (a App) output(value any) error {
|
||||
return encoder.Encode(value)
|
||||
}
|
||||
|
||||
// notice writes one non-fatal line to stderr so machine-readable stdout stays
|
||||
// intact. It never falls back to stdout, where it could corrupt --json output
|
||||
// for an embedder that does not configure Err.
|
||||
func (a App) notice(line string) {
|
||||
w := a.Err
|
||||
if w == nil {
|
||||
w = os.Stderr
|
||||
}
|
||||
fmt.Fprintln(w, line)
|
||||
}
|
||||
|
||||
// identityNote describes how this client build relates to a server response for
|
||||
// human output; it is empty when both peers match.
|
||||
func identityNote(response protocol.Message) string {
|
||||
return buildinfo.Compare(buildinfo.Current(), protocol.MaxSupportedProtocol, response.Protocol, response.Build).Message
|
||||
}
|
||||
|
||||
type callFunc func(protocol.Message) (protocol.Message, error)
|
||||
type resolveFunc func(string) (protocol.PipelineSummary, error)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user