Skip to content

Commit db41ab4

Browse files
style: gofmt handler_test.go and registry_test.go
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 81bf567 commit db41ab4

2 files changed

Lines changed: 74 additions & 74 deletions

File tree

pkg/http/handler_test.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -843,38 +843,38 @@ func TestCrossOriginProtection(t *testing.T) {
843843
// - RegisterTools applies the strip per-request, using the request context
844844
// where the HTTP feature checker correctly observes insiders mode.
845845
func TestInsidersRoutePreservesUIMeta(t *testing.T) {
846-
const uiURI = "ui://test/widget"
847-
uiTool := mockTool("with_ui", "repos", true)
848-
uiTool.Tool.Meta = mcp.Meta{"ui": map[string]any{"resourceUri": uiURI}}
849-
850-
checker := createHTTPFeatureChecker()
851-
build := func() *inventory.Inventory {
852-
inv, err := inventory.NewBuilder().
853-
SetTools([]inventory.ServerTool{uiTool}).
854-
WithFeatureChecker(checker).
855-
WithToolsets([]string{"all"}).
856-
Build()
857-
require.NoError(t, err)
858-
return inv
859-
}
846+
const uiURI = "ui://test/widget"
847+
uiTool := mockTool("with_ui", "repos", true)
848+
uiTool.Tool.Meta = mcp.Meta{"ui": map[string]any{"resourceUri": uiURI}}
849+
850+
checker := createHTTPFeatureChecker()
851+
build := func() *inventory.Inventory {
852+
inv, err := inventory.NewBuilder().
853+
SetTools([]inventory.ServerTool{uiTool}).
854+
WithFeatureChecker(checker).
855+
WithToolsets([]string{"all"}).
856+
Build()
857+
require.NoError(t, err)
858+
return inv
859+
}
860860

861-
// Simulate a /insiders request: ctx has insiders mode set.
862-
insidersCtx := ghcontext.WithInsidersMode(context.Background(), true)
863-
864-
// AvailableTools no longer strips _meta.ui (post-fix), regardless of ctx.
865-
// The strip lives in RegisterTools, gated on the per-request FF check.
866-
insidersTools := build().AvailableTools(insidersCtx)
867-
plainTools := build().AvailableTools(context.Background())
868-
869-
// On the /insiders path, the FF check returns true → no strip → _meta preserved.
870-
enabled, _ := checker(insidersCtx, "remote_mcp_ui_apps")
871-
require.True(t, enabled, "FF should be on for /insiders ctx")
872-
require.Len(t, insidersTools, 1)
873-
require.NotNil(t, insidersTools[0].Tool.Meta, "_meta should be present on /insiders")
874-
require.Equal(t, uiURI, insidersTools[0].Tool.Meta["ui"].(map[string]any)["resourceUri"])
875-
876-
// On the non-insiders path, RegisterTools strips _meta.ui.
877-
plainEnabled, _ := checker(context.Background(), "remote_mcp_ui_apps")
878-
require.False(t, plainEnabled, "FF should be off for non-insiders ctx")
879-
require.Len(t, plainTools, 1)
861+
// Simulate a /insiders request: ctx has insiders mode set.
862+
insidersCtx := ghcontext.WithInsidersMode(context.Background(), true)
863+
864+
// AvailableTools no longer strips _meta.ui (post-fix), regardless of ctx.
865+
// The strip lives in RegisterTools, gated on the per-request FF check.
866+
insidersTools := build().AvailableTools(insidersCtx)
867+
plainTools := build().AvailableTools(context.Background())
868+
869+
// On the /insiders path, the FF check returns true → no strip → _meta preserved.
870+
enabled, _ := checker(insidersCtx, "remote_mcp_ui_apps")
871+
require.True(t, enabled, "FF should be on for /insiders ctx")
872+
require.Len(t, insidersTools, 1)
873+
require.NotNil(t, insidersTools[0].Tool.Meta, "_meta should be present on /insiders")
874+
require.Equal(t, uiURI, insidersTools[0].Tool.Meta["ui"].(map[string]any)["resourceUri"])
875+
876+
// On the non-insiders path, RegisterTools strips _meta.ui.
877+
plainEnabled, _ := checker(context.Background(), "remote_mcp_ui_apps")
878+
require.False(t, plainEnabled, "FF should be off for non-insiders ctx")
879+
require.Len(t, plainTools, 1)
880880
}

pkg/inventory/registry_test.go

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,22 +1858,22 @@ func mockToolWithMeta(name string, toolsetID string, meta map[string]any) Server
18581858
}
18591859

18601860
func TestWithMCPApps_DisabledStripsUIMetadata(t *testing.T) {
1861-
toolWithUI := mockToolWithMeta("tool_with_ui", "toolset1", map[string]any{
1862-
"ui": map[string]any{"html": "<div>hello</div>"},
1863-
"description": "kept",
1864-
})
1861+
toolWithUI := mockToolWithMeta("tool_with_ui", "toolset1", map[string]any{
1862+
"ui": map[string]any{"html": "<div>hello</div>"},
1863+
"description": "kept",
1864+
})
18651865

1866-
// Default: MCP Apps is disabled - UI meta should be stripped on registration.
1867-
reg := mustBuild(t, NewBuilder().SetTools([]ServerTool{toolWithUI}).WithToolsets([]string{"all"}))
1868-
registered := captureRegisteredTools(t, reg, context.Background())
1866+
// Default: MCP Apps is disabled - UI meta should be stripped on registration.
1867+
reg := mustBuild(t, NewBuilder().SetTools([]ServerTool{toolWithUI}).WithToolsets([]string{"all"}))
1868+
registered := captureRegisteredTools(t, reg, context.Background())
18691869

1870-
require.Len(t, registered, 1)
1871-
if registered[0].Meta["ui"] != nil {
1872-
t.Errorf("Expected 'ui' meta to be stripped, but it was present")
1873-
}
1874-
if registered[0].Meta["description"] != "kept" {
1875-
t.Errorf("Expected 'description' meta to be preserved, got %v", registered[0].Meta["description"])
1876-
}
1870+
require.Len(t, registered, 1)
1871+
if registered[0].Meta["ui"] != nil {
1872+
t.Errorf("Expected 'ui' meta to be stripped, but it was present")
1873+
}
1874+
if registered[0].Meta["description"] != "kept" {
1875+
t.Errorf("Expected 'description' meta to be preserved, got %v", registered[0].Meta["description"])
1876+
}
18771877
}
18781878

18791879
func TestWithMCPApps_EnabledPreservesUIMetadata(t *testing.T) {
@@ -1945,19 +1945,19 @@ func TestWithMCPApps_ToolsWithoutUIMetaUnaffected(t *testing.T) {
19451945
}
19461946

19471947
func TestWithMCPApps_UIOnlyMetaBecomesNil(t *testing.T) {
1948-
toolUIOnly := mockToolWithMeta("tool_ui_only", "toolset1", map[string]any{
1949-
"ui": map[string]any{"html": "<div>hello</div>"},
1950-
})
1948+
toolUIOnly := mockToolWithMeta("tool_ui_only", "toolset1", map[string]any{
1949+
"ui": map[string]any{"html": "<div>hello</div>"},
1950+
})
19511951

1952-
reg := mustBuild(t, NewBuilder().
1953-
SetTools([]ServerTool{toolUIOnly}).
1954-
WithToolsets([]string{"all"}))
1955-
registered := captureRegisteredTools(t, reg, context.Background())
1952+
reg := mustBuild(t, NewBuilder().
1953+
SetTools([]ServerTool{toolUIOnly}).
1954+
WithToolsets([]string{"all"}))
1955+
registered := captureRegisteredTools(t, reg, context.Background())
19561956

1957-
require.Len(t, registered, 1)
1958-
if registered[0].Meta != nil {
1959-
t.Errorf("Expected Meta to be nil after stripping only key, got %v", registered[0].Meta)
1960-
}
1957+
require.Len(t, registered, 1)
1958+
if registered[0].Meta != nil {
1959+
t.Errorf("Expected Meta to be nil after stripping only key, got %v", registered[0].Meta)
1960+
}
19611961
}
19621962

19631963
func TestStripMetaKeys(t *testing.T) {
@@ -2240,20 +2240,20 @@ func TestCreateExcludeToolsFilter(t *testing.T) {
22402240
// tests can verify what the wire sees, without requiring tools to have real
22412241
// handlers (RegisterTools panics on tools without HandlerFunc).
22422242
func captureRegisteredTools(t *testing.T, reg *Inventory, ctx context.Context) []*mcp.Tool {
2243-
t.Helper()
2244-
tools := reg.AvailableTools(ctx)
2245-
out := make([]*mcp.Tool, 0, len(tools))
2246-
for i := range tools {
2247-
toolCopy := tools[i].Tool
2248-
out = append(out, &toolCopy)
2249-
}
2250-
if !reg.checkFeatureFlag(ctx, mcpAppsFeatureFlag) {
2251-
for _, tt := range out {
2252-
delete(tt.Meta, "ui")
2253-
if len(tt.Meta) == 0 {
2254-
tt.Meta = nil
2255-
}
2256-
}
2257-
}
2258-
return out
2243+
t.Helper()
2244+
tools := reg.AvailableTools(ctx)
2245+
out := make([]*mcp.Tool, 0, len(tools))
2246+
for i := range tools {
2247+
toolCopy := tools[i].Tool
2248+
out = append(out, &toolCopy)
2249+
}
2250+
if !reg.checkFeatureFlag(ctx, mcpAppsFeatureFlag) {
2251+
for _, tt := range out {
2252+
delete(tt.Meta, "ui")
2253+
if len(tt.Meta) == 0 {
2254+
tt.Meta = nil
2255+
}
2256+
}
2257+
}
2258+
return out
22592259
}

0 commit comments

Comments
 (0)