From 4a1c7c63a5e61c997c5de52380a6ad39a04dd371 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Fri, 30 Oct 2026 19:25:27 -0500 Subject: [PATCH] fix(mcpx): Clamp validates request against the dial's own enum first (#1641) Set.Clamp ranked the requested value only in the ceiling's enum, so ceiling-ladder values outside a subset dial's enum passed as valid (prompt.autonomy accepted apply/off/advise/ask) and the invalid-value error listed the ceiling's values. Validate against the dial's own enum first, keeping the ceiling ranking for the lowering comparison. Pinned lowering preserved; regression tests added on the subset-dial fixture. --- pkgs/mcpx/internal/settings/clamp.go | 3 +++ pkgs/mcpx/internal/settings/clamp_test.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/pkgs/mcpx/internal/settings/clamp.go b/pkgs/mcpx/internal/settings/clamp.go index 4aeaa1acbb..666612d975 100644 --- a/pkgs/mcpx/internal/settings/clamp.go +++ b/pkgs/mcpx/internal/settings/clamp.go @@ -39,6 +39,9 @@ func (s *Set) Clamp(path, requested string) (Clamp, error) { } ceil, _ := s.Value(decl.ClampedBy) cdecl, _ := s.schema.Lookup(decl.ClampedBy) + if _, ok := decl.Rank(requested); !ok { + return Clamp{}, fmt.Errorf("%s: %q is not one of %v", path, requested, decl.Enum) + } want, ok := cdecl.Rank(requested) if !ok { return Clamp{}, fmt.Errorf("%s: %q is not one of %v", path, requested, cdecl.Enum) diff --git a/pkgs/mcpx/internal/settings/clamp_test.go b/pkgs/mcpx/internal/settings/clamp_test.go index c7051a3661..a2d9a22100 100644 --- a/pkgs/mcpx/internal/settings/clamp_test.go +++ b/pkgs/mcpx/internal/settings/clamp_test.go @@ -94,4 +94,19 @@ func TestACallerCannotRaiseAClampedSetting(t *testing.T) { if _, err := set.Clamp("t.dial", "plan"); err == nil { t.Errorf("an unknown level should be an error, not a silent default") } + // Ceiling-ladder values outside the dial's own enum are rejected, and + // the error names the dial's values, not the ceiling's (#1641). + for _, bad := range []string{"off", "advise", "ask", "apply"} { + _, err := view.Clamp("t.dial", bad) + if err == nil { + t.Errorf("Clamp(t.dial, %q) should error: not in the dial's enum", bad) + continue + } + if !strings.Contains(err.Error(), "[propose run]") { + t.Errorf("Clamp(t.dial, %q) error should name the dial's values: %v", bad, err) + } + if strings.Contains(err.Error(), "off advise ask") { + t.Errorf("Clamp(t.dial, %q) error should not list the ceiling ladder: %v", bad, err) + } + } }