[Repo Assist] perf(rust-guard): add ORDER_LOW_TO_HIGH_PIPED const and direct tests for parse_integrity/scope_string#5468
Conversation
…for parse_integrity/scope_string Closes #5459 - Add ORDER_LOW_TO_HIGH_PIPED constant to policy_integrity module in constants.rs, eliminating the runtime Vec<&str> allocation and String heap allocation in the parse_integrity error arm. - Replace the 7-step iterator chain (.iter().rev().copied().collect().join()) with a direct compile-time constant reference. - Add parse_integrity_accepts_all_valid_values: verifies all four valid integrity tokens are accepted. - Add parse_integrity_rejects_unknown_value: verifies the error message includes the valid options. - Add scope_string_all_arms: covers all ScopeKind variants including the None-fallback arms (Owner/Repo/RepoPrefix with missing owner/repo). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves the Rust GitHub guard’s policy parsing by removing a runtime allocation-heavy iterator chain from parse_integrity’s error message construction, replacing it with a compile-time constant, and adding direct unit tests for parse_integrity and scope_string to cover previously untested branches.
Changes:
- Added
policy_integrity::ORDER_LOW_TO_HIGH_PIPEDas a compile-time"none|unapproved|approved|merged"string. - Updated
parse_integrityto use the new constant instead of building the string via iterator/allocations. - Added focused unit tests for
parse_integrity(valid + invalid) andscope_string(all match arms).
Show a summary per file
| File | Description |
|---|---|
| guards/github-guard/rust-guard/src/lib.rs | Uses the new const for parse_integrity error formatting; adds direct unit tests for parse_integrity and scope_string. |
| guards/github-guard/rust-guard/src/labels/constants.rs | Introduces ORDER_LOW_TO_HIGH_PIPED constant for integrity option formatting. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 2
| pub const ORDER_HIGH_TO_LOW: [&str; 4] = [MERGED, APPROVED, UNAPPROVED, NONE]; | ||
| /// Low-to-high order joined with `|`, ready for use in error messages. | ||
| pub const ORDER_LOW_TO_HIGH_PIPED: &str = "none|unapproved|approved|merged"; |
| assert!(err.contains("none"), "error should mention \"none\": {err}"); | ||
| assert!(err.contains("merged"), "error should mention \"merged\": {err}"); |
|
@copilot address the review feedback and fix this ci check https://github.com/github/gh-aw-mcpg/actions/runs/25673919245/job/75366898011?pr=5468 |
…rror-message tests per review
Done in commit CI failure: Review feedback addressed:
All 387 Rust tests pass. |
🤖 This PR was created by Repo Assist, an automated AI assistant.
Root Cause
parse_integrityinlib.rsbuilt an error message string at runtime via a 7-step iterator chain:This allocates a temporary
Vec<&str>and a heapStringeach time an invalidmin-integrityvalue is supplied, even though the result is the compile-time constant"none|unapproved|approved|merged".Additionally,
parse_integrityandscope_stringhad no direct unit tests — they were only covered indirectly through integration tests, leaving the error message text and None-fallback arms ofscope_stringunverified.Changes
guards/github-guard/rust-guard/src/labels/constants.rsORDER_LOW_TO_HIGH_PIPED: &str = "none|unapproved|approved|merged"to thepolicy_integritymodule — a compile-time constant replacing the runtime chain.order_low_to_high_piped_matches_order_high_to_low: a consistency test that derives the piped string fromORDER_HIGH_TO_LOWat test time and asserts it equalsORDER_LOW_TO_HIGH_PIPED, preventing silent drift if integrity levels are ever added or reordered.guards/github-guard/rust-guard/src/lib.rsparse_integritywithpolicy_integrity::ORDER_LOW_TO_HIGH_PIPED.parse_integrity_accepts_all_valid_values: verifies all four valid tokens are accepted.parse_integrity_rejects_unknown_value: verifies the error message contains the fullORDER_LOW_TO_HIGH_PIPEDconstant string (not just individual tokens), locking down the exact error message content.scope_string_all_arms: covers all 8ScopeKindarms including None-fallback cases for Owner/Repo/RepoPrefix.Test Status
Rust tests: ✅ 387/387 passed (
cargo testinguards/github-guard/rust-guard/)Go build/tests:⚠️ Infrastructure issue —
go 1.25.0toolchain download blocked by network firewall (proxy.golang.orgforbidden). No Go files were changed.