You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improvement 1: Gate three test-only pub functions with #[cfg(test)]
Category: API Surface File(s): guards/github-guard/rust-guard/src/labels/helpers.rs, guards/github-guard/rust-guard/src/labels/mod.rs Effort: Small (< 15 min) Risk: Low
Problem
Three functions in helpers.rs are declared pub but are only ever called from test code:
Function
Line
Current visibility
has_approval_label
409
pub fn
has_promotion_label
510
pub fn
has_demotion_label
516
pub fn
Their sibling has_refusal_label (line 432) is already correctly gated with #[cfg(test)]. All three functions above are re-exported from mod.rs only inside its #[cfg(test)] block (lines 53–54 of mod.rs), yet the definitions themselves lack the gate. This inconsistency widens the compiled WASM surface and misleads readers into thinking these predicates are part of the production API.
The production code never calls has_approval_label directly — it goes through the private helper first_matching_approval_label instead. Similarly, has_promotion_label and has_demotion_label are called only from within helpers.rs itself (apply_promotion_label_promotion / apply_demotion_label_demotion) and from mod.rs tests.
Suggested Change
Add #[cfg(test)] to all three function definitions, mirroring the existing pattern for has_refusal_label.
Before
// helpers.rs, line 409pubfnhas_approval_label(item:&Value,ctx:&PolicyContext) -> bool{first_matching_approval_label(item, ctx).is_some()}// helpers.rs, line 510pubfnhas_promotion_label(item:&Value,ctx:&PolicyContext) -> bool{item_has_config_label(item,&ctx.promotion_label)}// helpers.rs, line 516pubfnhas_demotion_label(item:&Value,ctx:&PolicyContext) -> bool{item_has_config_label(item,&ctx.demotion_label)}
After
// helpers.rs, line 409#[cfg(test)]pubfnhas_approval_label(item:&Value,ctx:&PolicyContext) -> bool{first_matching_approval_label(item, ctx).is_some()}// helpers.rs, line 510#[cfg(test)]pubfnhas_promotion_label(item:&Value,ctx:&PolicyContext) -> bool{item_has_config_label(item,&ctx.promotion_label)}// helpers.rs, line 516#[cfg(test)]pubfnhas_demotion_label(item:&Value,ctx:&PolicyContext) -> bool{item_has_config_label(item,&ctx.demotion_label)}
No changes needed in mod.rs — its #[cfg(test)] pub(crate) use helpers::{..., has_approval_label, has_demotion_label, has_promotion_label, ...} re-exports are already gated.
Verification
cargo test --target wasm32-wasip1 2>&1| grep -E "FAILED|ok"# All tests should still pass
cargo build --target wasm32-wasip1 --release 2>&1# Production build should succeed (functions removed from non-test compilation)
Why This Matters
Consistency: has_refusal_label already has #[cfg(test)] — these three should match
Smaller WASM binary: Test-only symbols are excluded from release builds
Clearer API contract: Readers can immediately see these are test utilities, not production predicates
No dead-code warnings risk: A future linter pass won't flag these as unused pub symbols in production builds
Areas with no further improvements: labels/constants.rs (only constants, well-organized), tools.rs (already well-scoped after recent is_lock_operation/is_unlock_operation fix)
Generated by Rust Guard Improver • Run: §29405404976
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
awmgmcpg
To allow these domains, add them to the network.allowed list in your workflow frontmatter:
🦀 Rust Guard Improvement Report
Improvement 1: Gate three test-only
pubfunctions with#[cfg(test)]Category: API Surface
File(s):
guards/github-guard/rust-guard/src/labels/helpers.rs,guards/github-guard/rust-guard/src/labels/mod.rsEffort: Small (< 15 min)
Risk: Low
Problem
Three functions in
helpers.rsare declaredpubbut are only ever called from test code:has_approval_labelpub fnhas_promotion_labelpub fnhas_demotion_labelpub fnTheir sibling
has_refusal_label(line 432) is already correctly gated with#[cfg(test)]. All three functions above are re-exported frommod.rsonly inside its#[cfg(test)]block (lines 53–54 ofmod.rs), yet the definitions themselves lack the gate. This inconsistency widens the compiled WASM surface and misleads readers into thinking these predicates are part of the production API.The production code never calls
has_approval_labeldirectly — it goes through the private helperfirst_matching_approval_labelinstead. Similarly,has_promotion_labelandhas_demotion_labelare called only from withinhelpers.rsitself (apply_promotion_label_promotion/apply_demotion_label_demotion) and frommod.rstests.Suggested Change
Add
#[cfg(test)]to all three function definitions, mirroring the existing pattern forhas_refusal_label.Before
After
No changes needed in
mod.rs— its#[cfg(test)] pub(crate) use helpers::{..., has_approval_label, has_demotion_label, has_promotion_label, ...}re-exports are already gated.Verification
Why This Matters
has_refusal_labelalready has#[cfg(test)]— these three should matchCodebase Health Summary
lib.rs,tools.rs,labels/helpers.rs,labels/mod.rs,labels/tool_rules.rs,labels/response_items.rs,labels/response_paths.rs,labels/backend.rs,labels/constants.rslabels/constants.rs(only constants, well-organized),tools.rs(already well-scoped after recentis_lock_operation/is_unlock_operationfix)Generated by Rust Guard Improver • Run: §29405404976
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
awmgmcpgSee Network Configuration for more information.