Commit f010749
authored
[Repo Assist] perf(rust-guard): add ORDER_LOW_TO_HIGH_PIPED const and direct tests for parse_integrity/scope_string (#5468)
🤖 *This PR was created by Repo Assist, an automated AI assistant.*
## Root Cause
`parse_integrity` in `lib.rs` built an error message string at runtime
via a 7-step iterator chain:
```rust
policy_integrity::ORDER_HIGH_TO_LOW
.iter()
.rev()
.copied()
.collect::<Vec<_>>()
.join("|")
```
This allocates a temporary `Vec<&str>` and a heap `String` each time an
invalid `min-integrity` value is supplied, even though the result is the
compile-time constant `"none|unapproved|approved|merged"`.
Additionally, `parse_integrity` and `scope_string` had no direct unit
tests — they were only covered indirectly through integration tests,
leaving the error message text and None-fallback arms of `scope_string`
unverified.
## Changes
**`guards/github-guard/rust-guard/src/labels/constants.rs`**
- Added `ORDER_LOW_TO_HIGH_PIPED: &str =
"none|unapproved|approved|merged"` to the `policy_integrity` module — a
compile-time constant replacing the runtime chain.
- Added `order_low_to_high_piped_matches_order_high_to_low`: a
consistency test that derives the piped string from `ORDER_HIGH_TO_LOW`
at test time and asserts it equals `ORDER_LOW_TO_HIGH_PIPED`, preventing
silent drift if integrity levels are ever added or reordered.
**`guards/github-guard/rust-guard/src/lib.rs`**
- Replaced the 7-step iterator chain in `parse_integrity` with
`policy_integrity::ORDER_LOW_TO_HIGH_PIPED`.
- Added `parse_integrity_accepts_all_valid_values`: verifies all four
valid tokens are accepted.
- Added `parse_integrity_rejects_unknown_value`: verifies the error
message contains the full `ORDER_LOW_TO_HIGH_PIPED` constant string (not
just individual tokens), locking down the exact error message content.
- Added `scope_string_all_arms`: covers all 8 `ScopeKind` arms including
None-fallback cases for Owner/Repo/RepoPrefix.
## Test Status
**Rust tests**: ✅ 387/387 passed (`cargo test` in
`guards/github-guard/rust-guard/`)
**Go build/tests**: 2 files changed
Lines changed: 56 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
32 | 56 | | |
33 | 57 | | |
34 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
443 | 443 | | |
444 | 444 | | |
445 | 445 | | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
| 446 | + | |
452 | 447 | | |
453 | 448 | | |
454 | 449 | | |
| |||
1347 | 1342 | | |
1348 | 1343 | | |
1349 | 1344 | | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
1350 | 1376 | | |
0 commit comments