Skip to content

Commit 5da0748

Browse files
committed
fix(version): satisfy errcheck + make broker_egress test platform-correct
- check fmt.Fprintln/Fprintf returns (errcheck under golangci-lint v2.11) - assert broker_egress matches the compile-time capability (true on unix, false on windows) instead of hard-asserting true, which failed the windows build
1 parent 25d5da8 commit 5da0748

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

internal/cli/version.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func newVersionCmd() *cobra.Command {
2424
Use: "version",
2525
Short: "Print version information",
2626
Run: func(cmd *cobra.Command, args []string) {
27+
out := cmd.OutOrStdout()
2728
// A structured (--json / --output-format) request emits a
2829
// machine-readable object that includes broker_egress, the capability
2930
// the runner probes before advertising broker mode to safari. An older
@@ -38,13 +39,13 @@ func newVersionCmd() *cobra.Command {
3839
"broker_egress": brokerEgressCapable,
3940
})
4041
if err != nil {
41-
fmt.Fprintln(cmd.ErrOrStderr(), err)
42+
_, _ = fmt.Fprintln(cmd.ErrOrStderr(), err)
4243
return
4344
}
44-
fmt.Fprintln(cmd.OutOrStdout(), string(b))
45+
_, _ = fmt.Fprintln(out, string(b))
4546
return
4647
}
47-
fmt.Fprintf(cmd.OutOrStdout(), "flashduty version %s (%s) built %s\n", versionStr, commitStr, dateStr)
48+
_, _ = fmt.Fprintf(out, "flashduty version %s (%s) built %s\n", versionStr, commitStr, dateStr)
4849
},
4950
}
5051
}

internal/cli/version_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ func TestVersionPlainOutput(t *testing.T) {
2020
}
2121

2222
// TestVersionJSONAdvertisesBrokerEgress locks the capability contract the runner
23-
// depends on: `fduty version --json` must emit a broker_egress field that is true
24-
// on this (unix) build. If this regresses, broker-capable runners would stop
25-
// advertising broker mode and silently fall back to the legacy env-key path.
23+
// depends on: `fduty version --json` must emit a broker_egress field whose value
24+
// matches this build's compile-time capability (true on unix, false elsewhere).
25+
// If the field went missing, broker-capable runners would stop advertising
26+
// broker mode and silently fall back to the legacy env-key path.
2627
func TestVersionJSONAdvertisesBrokerEgress(t *testing.T) {
2728
origJSON := flagJSON
2829
flagJSON = true
@@ -33,14 +34,15 @@ func TestVersionJSONAdvertisesBrokerEgress(t *testing.T) {
3334
cmd.SetOut(&buf)
3435
cmd.Run(cmd, nil)
3536

36-
var got struct {
37-
Version string `json:"version"`
38-
BrokerEgress bool `json:"broker_egress"`
39-
}
37+
var got map[string]any
4038
if err := json.Unmarshal(buf.Bytes(), &got); err != nil {
4139
t.Fatalf("version --json must be valid JSON, got %q: %v", buf.String(), err)
4240
}
43-
if !got.BrokerEgress {
44-
t.Fatalf("broker_egress must be true on a unix build, got: %q", buf.String())
41+
v, ok := got["broker_egress"]
42+
if !ok {
43+
t.Fatalf("version --json must include the broker_egress field, got: %q", buf.String())
44+
}
45+
if v != brokerEgressCapable {
46+
t.Fatalf("broker_egress = %v, want %v (compile-time capability)", v, brokerEgressCapable)
4547
}
4648
}

0 commit comments

Comments
 (0)