Commit f0fef19
authored
rust-guard: consolidate github-baseline match arms + add Display for ScopeKind (#2640)
Seven match arms in `apply_tool_labels` repeated identical
`baseline_scope = "github"` and `integrity = project_github_label(ctx)`
assignments, differing only in `secrecy`. `ScopeKind` had no `Display`
impl, forcing a private 5-arm match in `normalized_scope_kind` just to
stringify variants.
### `tool_rules.rs` — merge 7 arms into 2
Group by secrecy value; eliminate ~40 lines of near-identical code:
```rust
// Before: 7 separate arms, each repeating baseline_scope + integrity
// After:
"get_me" | "get_teams" | "get_team_members"
| "list_starred_repositories"
| "get_copilot_space" | "list_copilot_spaces" => {
secrecy = private_user_label();
baseline_scope = "github".to_string();
integrity = project_github_label(ctx);
}
"search_orgs"
| "list_global_security_advisories" | "get_global_security_advisory"
| "github_support_docs_search" => {
secrecy = vec![];
baseline_scope = "github".to_string();
integrity = project_github_label(ctx);
}
```
### `helpers.rs` — add `Display` for `ScopeKind`
Moves variant→string conversion onto the type where it belongs, making
it available to any future caller via `.to_string()` or `{}` formatting.
### `lib.rs` — simplify `normalized_scope_kind`
Replaces the 5-arm match with a single
`scopes[0].scope_kind.to_string()` call.
> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `example.com`
> - Triggering command: `/tmp/go-build2380398191/b334/launcher.test
/tmp/go-build2380398191/b334/launcher.test
-test.testlogfile=/tmp/go-build2380398191/b334/testlog.txt
-test.paniconexit0 -test.timeout=10m0s ache�� g_.a rg x_amd64/vet` (dns
block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build2380398191/b319/config.test
/tmp/go-build2380398191/b319/config.test
-test.testlogfile=/tmp/go-build2380398191/b319/testlog.txt
-test.paniconexit0 -test.timeout=10m0s conf��
ternal/engine/interpreter/compiler.go
ternal/engine/interpreter/format.go x_amd64/compile` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build2380398191/b334/launcher.test
/tmp/go-build2380398191/b334/launcher.test
-test.testlogfile=/tmp/go-build2380398191/b334/testlog.txt
-test.paniconexit0 -test.timeout=10m0s ache�� g_.a rg x_amd64/vet` (dns
block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build2380398191/b334/launcher.test
/tmp/go-build2380398191/b334/launcher.test
-test.testlogfile=/tmp/go-build2380398191/b334/testlog.txt
-test.paniconexit0 -test.timeout=10m0s ache�� g_.a rg x_amd64/vet` (dns
block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build2380398191/b343/mcp.test
/tmp/go-build2380398191/b343/mcp.test
-test.testlogfile=/tmp/go-build2380398191/b343/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -o /proxy/graphql.go
/proxy/graphql_rewrite.go x_amd64/vet -p syscall -lang=go1.25
x_amd64/vet -I g_.a 5678121/b151/ x_amd64/vet --gdwarf-5
ernal/middleware-qE` (dns block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/github/gh-aw-mcpg/settings/copilot/coding_agent)
(admins only)
>
> </details>
<!-- START COPILOT CODING AGENT TIPS -->
---
🔒 GitHub Advanced Security automatically protects Copilot coding agent
pull requests. You can protect all pull requests by enabling Advanced
Security for your repositories. [Learn more about Advanced
Security.](https://gh.io/cca-advanced-security)3 files changed
Lines changed: 31 additions & 63 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
57 | 70 | | |
58 | 71 | | |
59 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
481 | 486 | | |
482 | 487 | | |
483 | 488 | | |
484 | 489 | | |
485 | 490 | | |
486 | 491 | | |
487 | 492 | | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
510 | 500 | | |
511 | 501 | | |
512 | 502 | | |
513 | 503 | | |
514 | 504 | | |
515 | 505 | | |
516 | 506 | | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
526 | | - | |
| 507 | + | |
527 | 508 | | |
528 | 509 | | |
529 | 510 | | |
| |||
533 | 514 | | |
534 | 515 | | |
535 | 516 | | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | 517 | | |
557 | 518 | | |
558 | 519 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
| 463 | + | |
470 | 464 | | |
471 | 465 | | |
472 | 466 | | |
| |||
0 commit comments