Skip to content

[Repo Assist] perf(rust-guard): add ORDER_LOW_TO_HIGH_PIPED const and direct tests for parse_integrity/scope_string#5468

Merged
lpcox merged 2 commits into
mainfrom
repo-assist/fix-issue-5459-rust-guard-order-low-high-piped-const-f0f8da59ca31bab6
May 11, 2026
Merged

[Repo Assist] perf(rust-guard): add ORDER_LOW_TO_HIGH_PIPED const and direct tests for parse_integrity/scope_string#5468
lpcox merged 2 commits into
mainfrom
repo-assist/fix-issue-5459-rust-guard-order-low-high-piped-const-f0f8da59ca31bab6

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 11, 2026

🤖 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:

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: ⚠️ Infrastructure issue — go 1.25.0 toolchain download blocked by network firewall (proxy.golang.org forbidden). No Go files were changed.

[!WARNING]

Generated by Repo Assist · ● 2.2M ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@851905c06e905bf362a9f6cc54f912e3df747d55

…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>
@lpcox lpcox marked this pull request as ready for review May 11, 2026 13:45
Copilot AI review requested due to automatic review settings May 11, 2026 13:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_PIPED as a compile-time "none|unapproved|approved|merged" string.
  • Updated parse_integrity to use the new constant instead of building the string via iterator/allocations.
  • Added focused unit tests for parse_integrity (valid + invalid) and scope_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

Comment on lines 31 to +33
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";
Comment on lines +1358 to +1359
assert!(err.contains("none"), "error should mention \"none\": {err}");
assert!(err.contains("merged"), "error should mention \"merged\": {err}");
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 11, 2026

@copilot address the review feedback and fix this ci check https://github.com/github/gh-aw-mcpg/actions/runs/25673919245/job/75366898011?pr=5468

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

@copilot address the review feedback and fix this ci check https://github.com/github/gh-aw-mcpg/actions/runs/25673919245/job/75366898011?pr=5468

Done in commit fix(rust-guard): fix dead-code CI error; strengthen consistency and error-message tests per review.

CI failure: ORDER_HIGH_TO_LOW had no remaining usages after the previous change, triggering a -D dead-code compile error. Fixed by adding a test that uses it.

Review feedback addressed:

  • constants.rs: added order_low_to_high_piped_matches_order_high_to_low — 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 change.
  • lib.rs: strengthened parse_integrity_rejects_unknown_value to assert the full policy_integrity::ORDER_LOW_TO_HIGH_PIPED constant appears in the error message, rather than just checking for individual tokens.

All 387 Rust tests pass.

Copilot AI requested a review from lpcox May 11, 2026 14:42
Copilot finished work on behalf of lpcox May 11, 2026 14:42
@lpcox lpcox merged commit f010749 into main May 11, 2026
28 checks passed
@lpcox lpcox deleted the repo-assist/fix-issue-5459-rust-guard-order-low-high-piped-const-f0f8da59ca31bab6 branch May 11, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants