From cd79530cdac6bb96de2dde3eec2cade549dff6f6 Mon Sep 17 00:00:00 2001 From: Willie Date: Mon, 21 Sep 2026 15:50:19 +0800 Subject: [PATCH] fix(plugins): read the Pi version from stderr Pi prints its version to stderr, so the host showed an empty version. The fallback applies only to --version with empty stdout, so commands whose stdout is parsed never see stderr noise. --- internal/plugin/host_status_test.go | 13 +++++++++++++ internal/plugin/native.go | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/internal/plugin/host_status_test.go b/internal/plugin/host_status_test.go index bcca3dfa6..5a4262189 100644 --- a/internal/plugin/host_status_test.go +++ b/internal/plugin/host_status_test.go @@ -3,8 +3,10 @@ package plugin import ( "context" "errors" + "os" "os/exec" "path/filepath" + "strings" "sync/atomic" "testing" ) @@ -47,6 +49,17 @@ func TestRunCommandMarksAnAbsentBinary(t *testing.T) { } } +func TestRunCommandReadsVersionFromStderr(t *testing.T) { + dir := t.TempDir() + if err := os.WriteFile(filepath.Join(dir, "pi"), []byte("#!/bin/sh\necho 0.73.1 >&2\n"), 0755); err != nil { + t.Fatal(err) + } + out, err := runCommand(context.Background(), dir, filepath.Join(dir, "pi"), "--version") + if err != nil || strings.TrimSpace(string(out)) != "0.73.1" { + t.Fatalf("version = %q %v", out, err) + } +} + func TestHostReportsReadyWhenTheCLIAnswers(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) diff --git a/internal/plugin/native.go b/internal/plugin/native.go index 40d04f5a9..7feac3c19 100644 --- a/internal/plugin/native.go +++ b/internal/plugin/native.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "path/filepath" + "slices" "strings" "sync" "time" @@ -53,6 +54,10 @@ func runCommand(ctx context.Context, dir, bin string, args ...string) ([]byte, e // Native output can contain credentials or command-source scripts. return nil, agentError{key: "plugins.error.commandFailed", message: fmt.Sprintf("%s command failed; open the native client to resolve authentication, trust, or configuration", bin)} } + // Some CLIs (Pi) print their version to stderr. + if stdout.Len() == 0 && slices.Equal(args, []string{"--version"}) { + return stderr.Bytes(), nil + } return stdout.Bytes(), nil }