Commit df3bb25
authored
[rust-guard] Move test-only function out of production code; add missing field_names constants (#3096)
Two small code quality improvements to the Rust guard: dead production
code inflating the WASM binary, and JSON field strings scattered as raw
literals instead of using the existing `field_names` convention.
## Changes
### 1. `is_forked_pull_request_with_callback` → `#[cfg(test)]` only
(`backend.rs`)
The function was `pub` in production code with `#[allow(dead_code)]`
suppressing the warning, but was only ever called from tests. Moved it
into the `#[cfg(test)] mod tests` block as a private `fn`, removing the
suppression annotation and eliminating the dead WASM binary code.
```rust
// Before: production code
#[allow(dead_code)]
pub fn is_forked_pull_request_with_callback(...) -> Option<bool> { ... }
// After: test-only
#[cfg(test)]
mod tests {
fn is_forked_pull_request_with_callback(...) -> Option<bool> { ... }
}
```
### 2. New `field_names` constants + replacement of raw literals
(`constants.rs`, `helpers.rs`, `response_items.rs`, `response_paths.rs`)
Added `FULL_NAME`, `NUMBER`, `PRIVATE`, and `LOGIN` to the `field_names`
module alongside the existing `OWNER`, `REPO`, `SHA`, etc. Replaced all
production-code JSON field string lookups with the new constants across
the four affected files. Added `use super::constants::field_names;` to
`response_items.rs` and `response_paths.rs` which previously lacked the
import.
Note: `"private".to_string()` in secrecy label constructions (not field
lookups) are intentionally left as-is.
> [!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-build3562526043/b336/launcher.test
/tmp/go-build3562526043/b336/launcher.test
-test.testlogfile=/tmp/go-build3562526043/b336/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/net
64/src/mime/encodedword.go x_amd64/vet -p crypto/internal/-atomic
-lang=go1.25 x_amd64/vet -o ify@v1.11.1/asse-errorsas -trimpath` (dns
block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build3562526043/b318/config.test
/tmp/go-build3562526043/b318/config.test
-test.testlogfile=/tmp/go-build3562526043/b318/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/runtime/cgo
2zQN/vEak0ZJ9yzSgbLLs2zQN x_amd64/vet
guard.3t4ldemkr1/opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linux_amd64/vet
mcpgodebug /home/REDACTED/.ru-unreachable=false x_amd64/vet 1226��
122696/b119/_pkg_.a nn_n/bFgeOALOdCKszpT-nn_n x_amd64/vet
/home/REDACTED/wor/opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linux_amd64/vet
/home/REDACTED/wor-unsafeptr=false /home/REDACTED/wor-unreachable=false
x_amd64/vet` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build3562526043/b336/launcher.test
/tmp/go-build3562526043/b336/launcher.test
-test.testlogfile=/tmp/go-build3562526043/b336/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/net
64/src/mime/encodedword.go x_amd64/vet -p crypto/internal/-atomic
-lang=go1.25 x_amd64/vet -o ify@v1.11.1/asse-errorsas -trimpath` (dns
block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build3562526043/b336/launcher.test
/tmp/go-build3562526043/b336/launcher.test
-test.testlogfile=/tmp/go-build3562526043/b336/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/net
64/src/mime/encodedword.go x_amd64/vet -p crypto/internal/-atomic
-lang=go1.25 x_amd64/vet -o ify@v1.11.1/asse-errorsas -trimpath` (dns
block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build3562526043/b345/mcp.test
/tmp/go-build3562526043/b345/mcp.test
-test.testlogfile=/tmp/go-build3562526043/b345/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true _.a
58122696/b151//_-ifaceassert x_amd64/vet go1.25.8
ternal/engine/wa--version 122696/b151/ x_amd64/vet ctor�� .cfg
122696/b151/ x_amd64/vet --gdwarf-5 ut-1903621372.c -o 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>5 files changed
Lines changed: 98 additions & 91 deletions
File tree
- guards/github-guard/rust-guard/src/labels
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | 267 | | |
337 | 268 | | |
338 | 269 | | |
| |||
674 | 605 | | |
675 | 606 | | |
676 | 607 | | |
| 608 | + | |
677 | 609 | | |
678 | 610 | | |
679 | 611 | | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
680 | 680 | | |
681 | 681 | | |
682 | 682 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
301 | | - | |
| 301 | + | |
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
| |||
603 | 603 | | |
604 | 604 | | |
605 | 605 | | |
606 | | - | |
| 606 | + | |
607 | 607 | | |
608 | 608 | | |
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
612 | | - | |
| 612 | + | |
613 | 613 | | |
614 | 614 | | |
615 | 615 | | |
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
621 | | - | |
| 621 | + | |
622 | 622 | | |
623 | 623 | | |
624 | 624 | | |
| |||
627 | 627 | | |
628 | 628 | | |
629 | 629 | | |
630 | | - | |
| 630 | + | |
631 | 631 | | |
632 | 632 | | |
633 | 633 | | |
| |||
925 | 925 | | |
926 | 926 | | |
927 | 927 | | |
928 | | - | |
| 928 | + | |
929 | 929 | | |
930 | 930 | | |
931 | 931 | | |
932 | 932 | | |
933 | | - | |
| 933 | + | |
934 | 934 | | |
935 | 935 | | |
936 | 936 | | |
| |||
1036 | 1036 | | |
1037 | 1037 | | |
1038 | 1038 | | |
1039 | | - | |
| 1039 | + | |
1040 | 1040 | | |
1041 | 1041 | | |
1042 | 1042 | | |
| |||
1062 | 1062 | | |
1063 | 1063 | | |
1064 | 1064 | | |
1065 | | - | |
| 1065 | + | |
1066 | 1066 | | |
1067 | 1067 | | |
1068 | 1068 | | |
| |||
1176 | 1176 | | |
1177 | 1177 | | |
1178 | 1178 | | |
1179 | | - | |
| 1179 | + | |
1180 | 1180 | | |
1181 | 1181 | | |
1182 | 1182 | | |
| |||
1192 | 1192 | | |
1193 | 1193 | | |
1194 | 1194 | | |
1195 | | - | |
| 1195 | + | |
1196 | 1196 | | |
1197 | 1197 | | |
1198 | 1198 | | |
| |||
Lines changed: 7 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | | - | |
57 | | - | |
| 57 | + | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
165 | 166 | | |
166 | 167 | | |
167 | 168 | | |
168 | | - | |
| 169 | + | |
169 | 170 | | |
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
173 | | - | |
| 174 | + | |
174 | 175 | | |
175 | 176 | | |
176 | 177 | | |
| |||
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
195 | | - | |
| 196 | + | |
196 | 197 | | |
197 | 198 | | |
198 | 199 | | |
199 | 200 | | |
200 | | - | |
| 201 | + | |
201 | 202 | | |
202 | 203 | | |
203 | 204 | | |
| |||
Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
74 | | - | |
| 74 | + | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
171 | 172 | | |
172 | 173 | | |
173 | 174 | | |
174 | | - | |
| 175 | + | |
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
180 | | - | |
| 181 | + | |
181 | 182 | | |
182 | 183 | | |
183 | 184 | | |
| |||
0 commit comments