Skip to content

rust-guard: sort BLOCKED_TOOLS, use binary_search, promote login to #[cfg(test)]#6913

Merged
lpcox merged 3 commits into
mainfrom
copilot/rust-guard-sort-blocked-tools
Jun 2, 2026
Merged

rust-guard: sort BLOCKED_TOOLS, use binary_search, promote login to #[cfg(test)]#6913
lpcox merged 3 commits into
mainfrom
copilot/rust-guard-sort-blocked-tools

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 2, 2026

BLOCKED_TOOLS was the only slice in tools.rs without sorted order or binary_search, and CollaboratorPermission.login was silencing a dead-code lint rather than actually removing the field from production builds.

tools.rs

  • Sort BLOCKED_TOOLS alphabetically to match WRITE_OPERATIONS / READ_WRITE_OPERATIONS
  • Switch is_blocked_tool to binary_search (O(log n) vs O(n) .contains())
  • Trim the 15-line doc block to a one-liner — the inline comments on each const entry already carry the detail
  • Add blocked_tools_are_sorted test — mirrors the existing sorted-order tests for the other two slices

labels/backend.rs

  • Promote CollaboratorPermission.login from #[cfg_attr(not(test), allow(dead_code))] to #[cfg(test)] — removes the field and its allocations from the WASM binary entirely
  • Gate both struct-literal assignments with #[cfg(test)]: cache-hit path and API-call path
// Before
#[cfg_attr(not(test), allow(dead_code))]
pub login: Option<String>,

// After
#[cfg(test)]
pub login: Option<String>,

All three "blocked/write/read-write" slices now follow the same sorted + binary_search + sorted-test pattern. The login field now matches the #[cfg(test)] pattern already used by other test-only fields in the codebase.

… to cfg(test)

- Sort BLOCKED_TOOLS alphabetically to match WRITE_OPERATIONS/READ_WRITE_OPERATIONS convention
- Switch is_blocked_tool to binary_search (O(log n)) instead of .contains() (O(n))
- Trim verbose redundant doc comment on is_blocked_tool to a concise one-liner
- Add blocked_tools_are_sorted test mirroring write_operations_are_sorted
- Change CollaboratorPermission.login from cfg_attr(not(test), allow(dead_code))
  to #[cfg(test)], removing the field and its two allocations from production/WASM builds
Copilot AI changed the title [WIP] Sort BLOCKED_TOOLS and promote CollaboratorPermission.login rust-guard: sort BLOCKED_TOOLS, use binary_search, promote login to #[cfg(test)] Jun 2, 2026
Copilot finished work on behalf of lpcox June 2, 2026 23:13
Copilot AI requested a review from lpcox June 2, 2026 23:13
@lpcox lpcox marked this pull request as ready for review June 2, 2026 23:21
Copilot AI review requested due to automatic review settings June 2, 2026 23:21
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 aligns the Rust guard’s tool-classification and test-only metadata patterns by making BLOCKED_TOOLS match the existing sorted + binary_search approach used elsewhere, and by moving CollaboratorPermission.login fully behind #[cfg(test)] to avoid carrying the field in production builds.

Changes:

  • Sort BLOCKED_TOOLS and switch is_blocked_tool from .contains() to binary_search, adding a sorted-order unit test.
  • Shorten the BLOCKED_TOOLS doc comment now that per-entry inline comments carry the detail.
  • Make CollaboratorPermission.login test-only and gate struct-literal initialization accordingly.
Show a summary per file
File Description
guards/github-guard/rust-guard/src/tools.rs Sorts BLOCKED_TOOLS, uses binary_search, and adds a sorted-order test for correctness.
guards/github-guard/rust-guard/src/labels/backend.rs Makes CollaboratorPermission.login test-only and updates construction sites to compile without the field in production.

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

Comment on lines +576 to +580
Some(CollaboratorPermission {
permission,
#[cfg(test)]
login,
})
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented Jun 2, 2026

@copilot address review feedback

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 2, 2026

@copilot address review feedback

Done — the login extraction and the log line referencing it are now both gated behind #[cfg(test)]. A separate non-test log line omits login, so no String allocation or formatting for it occurs in the WASM binary. Committed in the latest push.

Copilot finished work on behalf of lpcox June 2, 2026 23:27
@lpcox lpcox merged commit c030ff4 into main Jun 2, 2026
16 checks passed
@lpcox lpcox deleted the copilot/rust-guard-sort-blocked-tools branch June 2, 2026 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[rust-guard] Rust Guard: Sort BLOCKED_TOOLS + promote CollaboratorPermission.login to cfg(test)

3 participants