@@ -366,58 +366,3 @@ func scopeChallengeContextWithScopes(ctx context.Context, activeScopes []string)
366366 ctx = ghcontext .WithTokenScopes (ctx , activeScopes )
367367 return ctx
368368}
369-
370- func BenchmarkWithScopeChallengeDynamicPolicy (b * testing.B ) {
371- scopes .SetGlobalToolScopeMap (scopes.ToolScopeMap {
372- "write_file" : scopes .DynamicChallenge (
373- []scopes.Scope {scopes .Repo , scopes .Workflow },
374- func ([]string ) bool { return true },
375- func (arguments map [string ]any , activeScopes []string ) []string {
376- if path , _ := arguments ["path" ].(string ); strings .HasPrefix (path , ".github/workflows/" ) {
377- return scopes .ChallengeAll (activeScopes , scopes .Repo , scopes .Workflow )
378- }
379- return scopes .ChallengeAll (activeScopes , scopes .Repo )
380- },
381- ),
382- })
383- b .Cleanup (func () { scopes .SetGlobalToolScopeMap (nil ) })
384-
385- for _ , payload := range []struct {
386- name string
387- size int
388- }{
389- {name : "small_arguments" , size : 256 },
390- {name : "large_arguments" , size : 32 * 1024 },
391- } {
392- body := `{"jsonrpc":"2.0","method":"tools/call","params":{"name":"write_file","arguments":{"path":"README.md","nested":[{"payload":"` +
393- strings .Repeat ("x" , payload .size ) + `"},[1,2,3]]}}}`
394- next := http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
395- var downstreamRequest mcpJSONRPCRequest
396- _ = json .NewDecoder (r .Body ).Decode (& downstreamRequest )
397- var arguments map [string ]any
398- _ = json .Unmarshal (downstreamRequest .Params .Arguments , & arguments )
399- w .WriteHeader (http .StatusNoContent )
400- })
401- handler := WithMCPParse ()(WithScopeChallenge (& oauth.Config {}, & mockScopeFetcher {})(next ))
402-
403- b .Run (payload .name , func (b * testing.B ) {
404- for _ , benchmark := range []struct {
405- name string
406- activeScopes []string
407- }{
408- {name : "maximum_scopes_fast_path" , activeScopes : []string {"repo" , "workflow" }},
409- {name : "call_specific_decode" , activeScopes : []string {"repo" }},
410- } {
411- b .Run (benchmark .name , func (b * testing.B ) {
412- b .ReportAllocs ()
413- b .SetBytes (int64 (len (body )))
414- for b .Loop () {
415- request := httptest .NewRequest (http .MethodPost , "/mcp" , strings .NewReader (body ))
416- request = request .WithContext (scopeChallengeContextWithScopes (request .Context (), benchmark .activeScopes ))
417- handler .ServeHTTP (httptest .NewRecorder (), request )
418- }
419- })
420- }
421- })
422- }
423- }
0 commit comments