@@ -2291,3 +2291,228 @@ func getLatestPendingReviewQuery(p getLatestPendingReviewQueryParams) githubv4mo
2291
2291
),
2292
2292
)
2293
2293
}
2294
+
2295
+ func TestMarkPullRequestReadyForReview (t * testing.T ) {
2296
+ t .Parallel ()
2297
+
2298
+ // Verify tool definition once
2299
+ mockClient := githubv4 .NewClient (nil )
2300
+ tool , _ := MarkPullRequestReadyForReview (stubGetGQLClientFn (mockClient ), translations .NullTranslationHelper )
2301
+
2302
+ assert .Equal (t , "mark_pr_ready_for_review" , tool .Name )
2303
+ assert .NotEmpty (t , tool .Description )
2304
+ assert .Contains (t , tool .InputSchema .Properties , "owner" )
2305
+ assert .Contains (t , tool .InputSchema .Properties , "repo" )
2306
+ assert .Contains (t , tool .InputSchema .Properties , "pullNumber" )
2307
+ assert .ElementsMatch (t , tool .InputSchema .Required , []string {"owner" , "repo" , "pullNumber" })
2308
+
2309
+ tests := []struct {
2310
+ name string
2311
+ mockedClient * http.Client
2312
+ requestArgs map [string ]any
2313
+ expectToolError bool
2314
+ expectedToolErrMsg string
2315
+ prIsDraft bool
2316
+ }{
2317
+ {
2318
+ name : "successful mark ready for review" ,
2319
+ mockedClient : githubv4mock .NewMockedHTTPClient (
2320
+ githubv4mock .NewQueryMatcher (
2321
+ struct {
2322
+ Repository struct {
2323
+ PullRequest struct {
2324
+ ID githubv4.ID
2325
+ IsDraft githubv4.Boolean
2326
+ } `graphql:"pullRequest(number: $prNum)"`
2327
+ } `graphql:"repository(owner: $owner, name: $repo)"`
2328
+ }{},
2329
+ map [string ]any {
2330
+ "owner" : githubv4 .String ("owner" ),
2331
+ "repo" : githubv4 .String ("repo" ),
2332
+ "prNum" : githubv4 .Int (42 ),
2333
+ },
2334
+ githubv4mock .DataResponse (
2335
+ map [string ]any {
2336
+ "repository" : map [string ]any {
2337
+ "pullRequest" : map [string ]any {
2338
+ "id" : "PR_kwDODKw3uc6WYN1T" ,
2339
+ "isDraft" : true ,
2340
+ },
2341
+ },
2342
+ },
2343
+ ),
2344
+ ),
2345
+ githubv4mock .NewMutationMatcher (
2346
+ struct {
2347
+ MarkPullRequestReadyForReview struct {
2348
+ PullRequest struct {
2349
+ ID githubv4.ID
2350
+ }
2351
+ } `graphql:"markPullRequestReadyForReview(input: $input)"`
2352
+ }{},
2353
+ githubv4.MarkPullRequestReadyForReviewInput {
2354
+ PullRequestID : githubv4 .ID ("PR_kwDODKw3uc6WYN1T" ),
2355
+ },
2356
+ nil ,
2357
+ githubv4mock .DataResponse (map [string ]any {}),
2358
+ ),
2359
+ ),
2360
+ requestArgs : map [string ]any {
2361
+ "owner" : "owner" ,
2362
+ "repo" : "repo" ,
2363
+ "pullNumber" : float64 (42 ),
2364
+ },
2365
+ expectToolError : false ,
2366
+ prIsDraft : true ,
2367
+ },
2368
+ {
2369
+ name : "PR already ready for review" ,
2370
+ mockedClient : githubv4mock .NewMockedHTTPClient (
2371
+ githubv4mock .NewQueryMatcher (
2372
+ struct {
2373
+ Repository struct {
2374
+ PullRequest struct {
2375
+ ID githubv4.ID
2376
+ IsDraft githubv4.Boolean
2377
+ } `graphql:"pullRequest(number: $prNum)"`
2378
+ } `graphql:"repository(owner: $owner, name: $repo)"`
2379
+ }{},
2380
+ map [string ]any {
2381
+ "owner" : githubv4 .String ("owner" ),
2382
+ "repo" : githubv4 .String ("repo" ),
2383
+ "prNum" : githubv4 .Int (42 ),
2384
+ },
2385
+ githubv4mock .DataResponse (
2386
+ map [string ]any {
2387
+ "repository" : map [string ]any {
2388
+ "pullRequest" : map [string ]any {
2389
+ "id" : "PR_kwDODKw3uc6WYN1T" ,
2390
+ "isDraft" : false ,
2391
+ },
2392
+ },
2393
+ },
2394
+ ),
2395
+ ),
2396
+ ),
2397
+ requestArgs : map [string ]any {
2398
+ "owner" : "owner" ,
2399
+ "repo" : "repo" ,
2400
+ "pullNumber" : float64 (42 ),
2401
+ },
2402
+ expectToolError : false ,
2403
+ prIsDraft : false ,
2404
+ },
2405
+ {
2406
+ name : "failure to get pull request" ,
2407
+ mockedClient : githubv4mock .NewMockedHTTPClient (
2408
+ githubv4mock .NewQueryMatcher (
2409
+ struct {
2410
+ Repository struct {
2411
+ PullRequest struct {
2412
+ ID githubv4.ID
2413
+ IsDraft githubv4.Boolean
2414
+ } `graphql:"pullRequest(number: $prNum)"`
2415
+ } `graphql:"repository(owner: $owner, name: $repo)"`
2416
+ }{},
2417
+ map [string ]any {
2418
+ "owner" : githubv4 .String ("owner" ),
2419
+ "repo" : githubv4 .String ("repo" ),
2420
+ "prNum" : githubv4 .Int (42 ),
2421
+ },
2422
+ githubv4mock .ErrorResponse ("expected test failure" ),
2423
+ ),
2424
+ ),
2425
+ requestArgs : map [string ]any {
2426
+ "owner" : "owner" ,
2427
+ "repo" : "repo" ,
2428
+ "pullNumber" : float64 (42 ),
2429
+ },
2430
+ expectToolError : true ,
2431
+ expectedToolErrMsg : "failed to get pull request: expected test failure" ,
2432
+ },
2433
+ {
2434
+ name : "failure to mark ready for review" ,
2435
+ mockedClient : githubv4mock .NewMockedHTTPClient (
2436
+ githubv4mock .NewQueryMatcher (
2437
+ struct {
2438
+ Repository struct {
2439
+ PullRequest struct {
2440
+ ID githubv4.ID
2441
+ IsDraft githubv4.Boolean
2442
+ } `graphql:"pullRequest(number: $prNum)"`
2443
+ } `graphql:"repository(owner: $owner, name: $repo)"`
2444
+ }{},
2445
+ map [string ]any {
2446
+ "owner" : githubv4 .String ("owner" ),
2447
+ "repo" : githubv4 .String ("repo" ),
2448
+ "prNum" : githubv4 .Int (42 ),
2449
+ },
2450
+ githubv4mock .DataResponse (
2451
+ map [string ]any {
2452
+ "repository" : map [string ]any {
2453
+ "pullRequest" : map [string ]any {
2454
+ "id" : "PR_kwDODKw3uc6WYN1T" ,
2455
+ "isDraft" : true ,
2456
+ },
2457
+ },
2458
+ },
2459
+ ),
2460
+ ),
2461
+ githubv4mock .NewMutationMatcher (
2462
+ struct {
2463
+ MarkPullRequestReadyForReview struct {
2464
+ PullRequest struct {
2465
+ ID githubv4.ID
2466
+ }
2467
+ } `graphql:"markPullRequestReadyForReview(input: $input)"`
2468
+ }{},
2469
+ githubv4.MarkPullRequestReadyForReviewInput {
2470
+ PullRequestID : githubv4 .ID ("PR_kwDODKw3uc6WYN1T" ),
2471
+ },
2472
+ nil ,
2473
+ githubv4mock .ErrorResponse ("expected test failure" ),
2474
+ ),
2475
+ ),
2476
+ requestArgs : map [string ]any {
2477
+ "owner" : "owner" ,
2478
+ "repo" : "repo" ,
2479
+ "pullNumber" : float64 (42 ),
2480
+ },
2481
+ expectToolError : true ,
2482
+ expectedToolErrMsg : "failed to mark pull request as ready for review: expected test failure" ,
2483
+ prIsDraft : true ,
2484
+ },
2485
+ }
2486
+
2487
+ for _ , tc := range tests {
2488
+ t .Run (tc .name , func (t * testing.T ) {
2489
+ t .Parallel ()
2490
+
2491
+ // Setup client with mock
2492
+ client := githubv4 .NewClient (tc .mockedClient )
2493
+ _ , handler := MarkPullRequestReadyForReview (stubGetGQLClientFn (client ), translations .NullTranslationHelper )
2494
+
2495
+ // Create call request
2496
+ request := createMCPRequest (tc .requestArgs )
2497
+
2498
+ // Call handler
2499
+ result , err := handler (context .Background (), request )
2500
+ require .NoError (t , err )
2501
+
2502
+ textContent := getTextResult (t , result )
2503
+
2504
+ if tc .expectToolError {
2505
+ require .True (t , result .IsError )
2506
+ assert .Contains (t , textContent .Text , tc .expectedToolErrMsg )
2507
+ return
2508
+ }
2509
+
2510
+ // Check for the appropriate success message
2511
+ if tc .prIsDraft {
2512
+ require .Equal (t , "Pull request successfully marked as ready for review" , textContent .Text )
2513
+ } else {
2514
+ require .Equal (t , "Pull request is already marked as ready for review" , textContent .Text )
2515
+ }
2516
+ })
2517
+ }
2518
+ }
0 commit comments