Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 3 additions & 39 deletions pkgs/mcpx/internal/api/decision_boundary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/api/decision_boundary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
7 changes: 3 additions & 4 deletions pkgs/mcpx/internal/catalog/embeddings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkgs/mcpx/internal/codegen/roc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/daemon/transport_systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions pkgs/mcpx/internal/daemon/transport_systemd_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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]
Expand All @@ -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")
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 5 additions & 1 deletion pkgs/mcpx/internal/e2e/effect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions pkgs/mcpx/internal/e2e/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/runner/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkgs/mcpx/internal/runner/roc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions pkgs/mcpx/tools/docs-twins/chapter_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down