Commit b0342d8
authored
Reduce duplication in write-op integrity classification and MinIntegrity conversion (#3534)
`label_resource` had four `if/else if` branches where the first two
(merge/delete) were identical and the last two (update/create +
catch-all) were identical. `MinIntegrity` lacked a string conversion
method, forcing callers to maintain parallel match arms.
- **Collapse integrity branches** in `lib.rs`: merge/delete →
`writer_integrity`, everything else → `reader_integrity`. Single
`!repo_id.is_empty()` guard wrapping a conditional.
- **Add `MinIntegrity::as_str()`** in `helpers.rs`: canonical `&'static
str` conversion using `policy_integrity` constants. Replaces the 5-line
match block in `label_agent` with
`integrity_floor.as_str().to_string()`.
- **Unit test** for `as_str()` covering all four variants.
```rust
// Before: 4 branches, 2 pairs of duplicates
if tools::is_merge_operation(&input.tool_name) {
if !repo_id.is_empty() { integrity = labels::writer_integrity(&repo_id, &ctx); }
} else if tools::is_delete_operation(&input.tool_name) {
if !repo_id.is_empty() { integrity = labels::writer_integrity(&repo_id, &ctx); }
} else if tools::is_update_operation(&input.tool_name) || tools::is_create_operation(&input.tool_name) {
if !repo_id.is_empty() { integrity = labels::reader_integrity(&repo_id, &ctx); }
} else if !repo_id.is_empty() {
integrity = labels::reader_integrity(&repo_id, &ctx);
}
// After
if !repo_id.is_empty() {
integrity = if tools::is_merge_operation(&input.tool_name)
|| tools::is_delete_operation(&input.tool_name)
{
labels::writer_integrity(&repo_id, &ctx)
} else {
labels::reader_integrity(&repo_id, &ctx)
};
}
```
> [!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-build1833741381/b514/launcher.test
/tmp/go-build1833741381/b514/launcher.test
-test.testlogfile=/tmp/go-build1833741381/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -W .cfg
olang.org/grpc@v-ifaceassert x_amd64/vet . --gdwarf2 --64 x_amd64/vet
.cfg�� 2245169/b376/_pkg_.a -I x_amd64/vet --gdwarf-5
g/grpc/internal//usr/bin/runc -o x_amd64/vet` (dns block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build1833741381/b496/config.test
/tmp/go-build1833741381/b496/config.test
-test.testlogfile=/tmp/go-build1833741381/b496/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build1833741381/b394/vet.cfg @v1.1.3/cpu/arm/-errorsas -trimpath
x_amd64/vet -p nal/encoding/tex-atomic -lang=go1.25 x_amd64/vet -I g_.a
-I x_amd64/vet --gdwarf-5 64 -o x_amd64/vet` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build1833741381/b514/launcher.test
/tmp/go-build1833741381/b514/launcher.test
-test.testlogfile=/tmp/go-build1833741381/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -W .cfg
olang.org/grpc@v-ifaceassert x_amd64/vet . --gdwarf2 --64 x_amd64/vet
.cfg�� 2245169/b376/_pkg_.a -I x_amd64/vet --gdwarf-5
g/grpc/internal//usr/bin/runc -o x_amd64/vet` (dns block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build1833741381/b514/launcher.test
/tmp/go-build1833741381/b514/launcher.test
-test.testlogfile=/tmp/go-build1833741381/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -W .cfg
olang.org/grpc@v-ifaceassert x_amd64/vet . --gdwarf2 --64 x_amd64/vet
.cfg�� 2245169/b376/_pkg_.a -I x_amd64/vet --gdwarf-5
g/grpc/internal//usr/bin/runc -o x_amd64/vet` (dns block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build1833741381/b523/mcp.test
/tmp/go-build1833741381/b523/mcp.test
-test.testlogfile=/tmp/go-build1833741381/b523/testlog.txt
-test.paniconexit0 -test.timeout=10m0s 2245�� .cfg
ache/go/1.25.8/x64/src/database/sql/driver/driver.go x_amd64/vet
--gdwarf-5 --64 -o x_amd64/vet .cfg��
/tmp/go-build4122245169/b223/_pk-errorsas uxII/pTQM0yfdla9bshGWuxII
x_amd64/vet -p 2245169/b468/ -lang=go1.24 x_amd64/vet` (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>File tree
3 files changed
+31
-35
lines changed- guards/github-guard/rust-guard/src
- labels
3 files changed
+31
-35
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
86 | 99 | | |
87 | 100 | | |
88 | 101 | | |
| |||
1427 | 1440 | | |
1428 | 1441 | | |
1429 | 1442 | | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
1430 | 1452 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
| 534 | + | |
540 | 535 | | |
541 | 536 | | |
542 | 537 | | |
| |||
619 | 614 | | |
620 | 615 | | |
621 | 616 | | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
641 | 625 | | |
642 | 626 | | |
643 | 627 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | 92 | | |
103 | 93 | | |
104 | 94 | | |
| |||
0 commit comments