From a5b8390aeee3950551b9df28edf64ce3c3a928cd Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 23 Nov 2026 22:12:49 -0600 Subject: [PATCH] mcpx: fix golangci-lint basic failures (errcheck, govet, ineffassign, staticcheck, unused) Fixes the 20 findings from run 45181183106: check Close returns, inline reflect.Pointer, drop dead RocModule assignment, reword CloseWasm comment, De Morgan, tagged switches, remove unused decision audit tables (spec lives in decision_boundary_test.go), and assert the e2e event-stream error instead of discarding it. Lint: nix develop .#mcpx-lint --command 'cd pkgs/mcpx && golangci-lint run ./...' -> 0 issues. --- pkgs/mcpx/internal/api/decision_boundary.go | 42 ++----------------- .../internal/api/decision_boundary_test.go | 2 +- pkgs/mcpx/internal/catalog/embeddings.go | 7 ++-- pkgs/mcpx/internal/codegen/roc_test.go | 3 +- .../daemon/transport_systemd_linux.go | 2 +- .../daemon/transport_systemd_linux_test.go | 18 ++++---- pkgs/mcpx/internal/e2e/effect_test.go | 6 ++- pkgs/mcpx/internal/e2e/remote_test.go | 4 +- pkgs/mcpx/internal/runner/dispatch.go | 2 +- pkgs/mcpx/internal/runner/roc_test.go | 6 +-- pkgs/mcpx/tools/docs-twins/chapter_links.go | 5 ++- 11 files changed, 32 insertions(+), 65 deletions(-) diff --git a/pkgs/mcpx/internal/api/decision_boundary.go b/pkgs/mcpx/internal/api/decision_boundary.go index 9f2ec47aea..8fde454d07 100644 --- a/pkgs/mcpx/internal/api/decision_boundary.go +++ b/pkgs/mcpx/internal/api/decision_boundary.go @@ -42,45 +42,9 @@ package api // never contain them — including content from a denied (low-scored) // trace or any other sensitive content the caller retained. // -// The forbidden-field list below is what the tests iterate: a new field on -// Decision whose JSON name appears here fails the guard, present or future. - -// decisionAuditAllowedJSONFields is the closed set of top-level JSON field -// names a marshalled Decision may carry (via encoding/json default keying: -// exported Go field name with first letter lowered). -var decisionAuditAllowedJSONFields = map[string]bool{ - "principal": true, - "surface": true, // nested under principal - "id": true, // nested under principal (descriptive ID, not a credential) - "owner": true, // nested under principal - "op": true, - "permission": true, - "allowed": true, - "at": true, -} - -// feedbackPayloadJSONFieldsExcludedFromDecisions lists JSON field names that -// belong to retained feedback / interaction payloads and must never appear -// in the decision audit export. The guard test iterates this table, so a -// future Decision field that reuses one of these names fails closed. -var feedbackPayloadJSONFieldsExcludedFromDecisions = []string{ - "traceId", - "timestamp", - "sessionId", - "source", - "input", - "output", - "toolsUsed", - "score", - "target", - "retrievalScore", - "executionScore", - "scoresJson", - "feedbackNotes", - "feedbackAt", - "notes", - "query", -} +// The forbidden-field lists live in decision_boundary_test.go, which iterates +// the Decision struct: a new field whose name reuses a feedback-payload or +// secret fragment fails the guard, present or future. // DecisionRetentionBound reports the bounded window the decision record // keeps: the most recent N decisions. It is the spec value the retention diff --git a/pkgs/mcpx/internal/api/decision_boundary_test.go b/pkgs/mcpx/internal/api/decision_boundary_test.go index 607574726b..e3d2f6069a 100644 --- a/pkgs/mcpx/internal/api/decision_boundary_test.go +++ b/pkgs/mcpx/internal/api/decision_boundary_test.go @@ -43,7 +43,7 @@ func TestDecisionAuditCarriesNoFeedbackPayloadFields(t *testing.T) { } } ft := f.Type - for ft.Kind() == reflect.Ptr || ft.Kind() == reflect.Slice || ft.Kind() == reflect.Array || ft.Kind() == reflect.Map { + for ft.Kind() == reflect.Pointer || ft.Kind() == reflect.Slice || ft.Kind() == reflect.Array || ft.Kind() == reflect.Map { ft = ft.Elem() } if ft.Kind() == reflect.Struct && ft.Name() != "Time" && ft.PkgPath() != "time" { diff --git a/pkgs/mcpx/internal/catalog/embeddings.go b/pkgs/mcpx/internal/catalog/embeddings.go index f3653cf1c9..b63a754a1a 100644 --- a/pkgs/mcpx/internal/catalog/embeddings.go +++ b/pkgs/mcpx/internal/catalog/embeddings.go @@ -267,10 +267,9 @@ func (c *CascadeEmbedder) Backend() string { return c.backend } -// WasmPath is unexported; CloseWasm lets the registry retire the replaced -// embedder's wazero runtime after a hot swap (#13616). It blocks until an -// in-flight Embed holding the wasm mutex finishes, and is a no-op when the -// cascade holds no wasm module. +// CloseWasm lets the registry retire the replaced embedder's wazero runtime +// after a hot swap (#13616). It blocks until an in-flight Embed holding the +// wasm mutex finishes, and is a no-op when the cascade holds no wasm module. func (c *CascadeEmbedder) CloseWasm(ctx context.Context) { if c == nil { return diff --git a/pkgs/mcpx/internal/codegen/roc_test.go b/pkgs/mcpx/internal/codegen/roc_test.go index 2f51e0068f..ebe54c52cb 100644 --- a/pkgs/mcpx/internal/codegen/roc_test.go +++ b/pkgs/mcpx/internal/codegen/roc_test.go @@ -89,10 +89,9 @@ func TestRocModulePassesCompiler(t *testing.T) { nss := []codegen.Namespace{{Name: "demo", Server: "demo-server", Tools: []codegen.Tool{{ Name: "say-hi", InputSchema: []byte(`{"type":"object","properties":{"name":{"type":"string"},"count":{"type":"integer"}}}`), }}}} - client := codegen.RocModule(nss, "http://127.0.0.1:1", "test-session") main := "app [main!] { pf: platform \"https://github.com/roc-lang/basic-cli/releases/download/0.28.1/7brgwR8YUqfeGrkdfF1V4GPPN7DnP7ftqub9KcrTEZtr.tar.zst\", http: \"https://github.com/roc-lang/http/releases/download/1.0.0/6ZUwqYhCS8PU9Mo6MF7oV82ET2o7KYb57CLKDq4cq4sS.tar.zst\" }\n\nimport Mcpx\n\nmain! = |_args| {\n _ = Mcpx.demo_say_hi!({ name: \"hello\", count: 1 })\n _ = Mcpx.demo_empty!({})\n _ = Mcpx.demo_raw!({ payload: { nested: { flag: True, count: 1, text: \"x\" } } })\n Ok({})\n}\n" nss[0].Tools = append(nss[0].Tools, codegen.Tool{Name: "empty", InputSchema: []byte(`{"type":"object"}`)}, codegen.Tool{Name: "raw", InputSchema: []byte(`{"type":"object","required":["payload"],"properties":{"payload":{"description":"any JSON value"}}}`)}) - client = codegen.RocModule(nss, "http://127.0.0.1:1", "test-session") + client := codegen.RocModule(nss, "http://127.0.0.1:1", "test-session") if err := os.WriteFile(filepath.Join(dir, "Mcpx.roc"), []byte(client), 0o600); err != nil { t.Fatal(err) } diff --git a/pkgs/mcpx/internal/daemon/transport_systemd_linux.go b/pkgs/mcpx/internal/daemon/transport_systemd_linux.go index 67613ef32c..21ed90ec33 100644 --- a/pkgs/mcpx/internal/daemon/transport_systemd_linux.go +++ b/pkgs/mcpx/internal/daemon/transport_systemd_linux.go @@ -40,7 +40,7 @@ func adoptSystemdTCP(address string) (net.Listener, error) { // original even if conversion or address validation later fails. unix.CloseOnExec(fd) f := os.NewFile(fd, "systemd listener") - defer f.Close() + defer func() { _ = f.Close() }() ln, err := net.FileListener(f) if err != nil { return nil, fmt.Errorf("systemd TCP activation: adopt fd 3: %w", err) diff --git a/pkgs/mcpx/internal/daemon/transport_systemd_linux_test.go b/pkgs/mcpx/internal/daemon/transport_systemd_linux_test.go index 4cc407caa9..1a86ac31a1 100644 --- a/pkgs/mcpx/internal/daemon/transport_systemd_linux_test.go +++ b/pkgs/mcpx/internal/daemon/transport_systemd_linux_test.go @@ -23,30 +23,30 @@ func TestTCPSystemd(t *testing.T) { if err != nil { t.Fatal(err) } - defer listener.Close() + defer func() { _ = listener.Close() }() f, err := listener.File() if err != nil { t.Fatal(err) } - defer f.Close() + defer func() { _ = f.Close() }() if mode == "file" { f, err = os.Open(os.DevNull) if err != nil { t.Fatal(err) } - defer f.Close() + defer func() { _ = f.Close() }() } if mode == "unix" { other, err := net.ListenUnix("unix", &net.UnixAddr{Name: filepath.Join(t.TempDir(), "listener.sock"), Net: "unix"}) if err != nil { t.Fatal(err) } - defer other.Close() + defer func() { _ = other.Close() }() f, err = other.File() if err != nil { t.Fatal(err) } - defer f.Close() + defer func() { _ = f.Close() }() } cmd := exec.Command(os.Args[0], "-test.run=^TestTCPSystemdChild$") for _, entry := range os.Environ() { @@ -107,7 +107,7 @@ func TestTCPSystemdChild(t *testing.T) { switch mode { case "bad-pid", "missing-pid", "bad-count", "missing-count", "file", "unix", "closed", "address", "port": if err == nil { - listener.Close() + _ = listener.Close() t.Fatal("activation silently succeeded or fell back") } expected := map[string]string{"bad-pid": "LISTEN_PID", "missing-pid": "LISTEN_PID", "bad-count": "LISTEN_FDS", "missing-count": "LISTEN_FDS", "file": "inspect fd 3", "unix": "not a TCP listener", "closed": "inspect fd 3", "address": "does not match", "port": "does not match"}[mode] @@ -123,7 +123,7 @@ func TestTCPSystemdChild(t *testing.T) { return } default: - defer listener.Close() + defer func() { _ = listener.Close() }() if mode == "absent" { if listener.Addr().String() == target { t.Fatal("adopted without activation") @@ -154,12 +154,12 @@ func TestTCPSystemdChild(t *testing.T) { if err != nil { t.Fatal(err) } - defer client.Close() + defer func() { _ = client.Close() }() server, err := listener.Accept() if err != nil { t.Fatal(err) } - defer server.Close() + defer func() { _ = server.Close() }() if _, err := fmt.Fprintln(server, "ok"); err != nil { t.Fatal(err) } diff --git a/pkgs/mcpx/internal/e2e/effect_test.go b/pkgs/mcpx/internal/e2e/effect_test.go index b8d56d86c1..c78ac7d936 100644 --- a/pkgs/mcpx/internal/e2e/effect_test.go +++ b/pkgs/mcpx/internal/e2e/effect_test.go @@ -4,6 +4,7 @@ import ( "bufio" "context" "encoding/json" + "errors" "fmt" "io" "net" @@ -2038,7 +2039,10 @@ func TestEventsReconnectWaitsForTheConfiguredDelay(t *testing.T) { t.Fatal("client did not process the event delivered on reconnect") } select { - case <-streamDone: + case err := <-streamDone: + if err != nil && !errors.Is(err, context.Canceled) { + t.Fatalf("event stream returned unexpected error: %v", err) + } case <-time.After(3 * time.Second): t.Fatal("event stream did not stop after cancellation") } diff --git a/pkgs/mcpx/internal/e2e/remote_test.go b/pkgs/mcpx/internal/e2e/remote_test.go index ae1c72a2fe..29902f5859 100644 --- a/pkgs/mcpx/internal/e2e/remote_test.go +++ b/pkgs/mcpx/internal/e2e/remote_test.go @@ -172,7 +172,7 @@ func addRemoteServer(t *testing.T, name string, body map[string]any) string { if err != nil { t.Fatalf("add remote server %s: %v", full, err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode < 200 || resp.StatusCode > 299 { msg, _ := io.ReadAll(io.LimitReader(resp.Body, 4096)) t.Fatalf("add remote server %s: %s: %s", full, resp.Status, strings.TrimSpace(string(msg))) @@ -187,7 +187,7 @@ func addRemoteServer(t *testing.T, name string, body map[string]any) string { t.Logf("cleanup: remove remote server %s: %v", full, err) return } - resp.Body.Close() + _ = resp.Body.Close() }) return full } diff --git a/pkgs/mcpx/internal/runner/dispatch.go b/pkgs/mcpx/internal/runner/dispatch.go index 1b9938d355..9fb9adb31f 100644 --- a/pkgs/mcpx/internal/runner/dispatch.go +++ b/pkgs/mcpx/internal/runner/dispatch.go @@ -929,7 +929,7 @@ func runDispatched(ctx context.Context, opts Options, d *dispatch) (*Result, err return nil, err } dir = applyChdir(dir, d.chdir) - if d.lookupBin != "" && !(devshellIsFlake(opts.Devshell) && isRocInterpreter(d.lookupBin)) { + if d.lookupBin != "" && (!devshellIsFlake(opts.Devshell) || !isRocInterpreter(d.lookupBin)) { // The interpreter a shebang names is resolved here, against // the directory the run actually moves to: deciding earlier // would check relative PATH entries against mcpx's own diff --git a/pkgs/mcpx/internal/runner/roc_test.go b/pkgs/mcpx/internal/runner/roc_test.go index 157a145c99..0fae4ac054 100644 --- a/pkgs/mcpx/internal/runner/roc_test.go +++ b/pkgs/mcpx/internal/runner/roc_test.go @@ -205,10 +205,10 @@ func TestRocWireSerializationProperties(t *testing.T) { call.args["required-key"] = requiredValue presentFields := make([]bool, len(keys)) for j, key := range keys { - switch { - case i == 0: + switch i { + case 0: // First schema/call proves all optional fields may be absent. - case i == 1: + case 1: required = append(required, key) presentFields[j] = true default: diff --git a/pkgs/mcpx/tools/docs-twins/chapter_links.go b/pkgs/mcpx/tools/docs-twins/chapter_links.go index 4fe538decb..696e26381c 100644 --- a/pkgs/mcpx/tools/docs-twins/chapter_links.go +++ b/pkgs/mcpx/tools/docs-twins/chapter_links.go @@ -124,9 +124,10 @@ func (links chapterLinks) markdown(content, origin, output string) string { out.WriteString(piece) } ticks := line[run[0]:run[1]] - if span == ticks { + switch span { + case ticks: span = "" - } else if span == "" { + case "": span = ticks } out.WriteString(ticks)