Skip to content

[rust-guard] Move test-only function out of production code; add missing field_names constants#3096

Merged
lpcox merged 3 commits intomainfrom
copilot/remove-dead-code-is-forked-pull-request
Apr 3, 2026
Merged

[rust-guard] Move test-only function out of production code; add missing field_names constants#3096
lpcox merged 3 commits intomainfrom
copilot/remove-dead-code-is-forked-pull-request

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

Two small code quality improvements to the Rust guard: dead production code inflating the WASM binary, and JSON field strings scattered as raw literals instead of using the existing field_names convention.

Changes

1. is_forked_pull_request_with_callback#[cfg(test)] only (backend.rs)

The function was pub in production code with #[allow(dead_code)] suppressing the warning, but was only ever called from tests. Moved it into the #[cfg(test)] mod tests block as a private fn, removing the suppression annotation and eliminating the dead WASM binary code.

// Before: production code
#[allow(dead_code)]
pub fn is_forked_pull_request_with_callback(...) -> Option<bool> { ... }

// After: test-only
#[cfg(test)]
mod tests {
    fn is_forked_pull_request_with_callback(...) -> Option<bool> { ... }
}

2. New field_names constants + replacement of raw literals (constants.rs, helpers.rs, response_items.rs, response_paths.rs)

Added FULL_NAME, NUMBER, PRIVATE, and LOGIN to the field_names module alongside the existing OWNER, REPO, SHA, etc. Replaced all production-code JSON field string lookups with the new constants across the four affected files. Added use super::constants::field_names; to response_items.rs and response_paths.rs which previously lacked the import.

Note: "private".to_string() in secrecy label constructions (not field lookups) are intentionally left as-is.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /tmp/go-build3562526043/b336/launcher.test /tmp/go-build3562526043/b336/launcher.test -test.testlogfile=/tmp/go-build3562526043/b336/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/net 64/src/mime/encodedword.go x_amd64/vet -p crypto/internal/-atomic -lang=go1.25 x_amd64/vet -o ify@v1.11.1/asse-errorsas -trimpath (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3562526043/b318/config.test /tmp/go-build3562526043/b318/config.test -test.testlogfile=/tmp/go-build3562526043/b318/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/runtime/cgo 2zQN/vEak0ZJ9yzSgbLLs2zQN x_amd64/vet guard.3t4ldemkr1/opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linux_amd64/vet mcpgodebug /home/REDACTED/.ru-unreachable=false x_amd64/vet 1226�� 122696/b119/_pkg_.a nn_n/bFgeOALOdCKszpT-nn_n x_amd64/vet /home/REDACTED/wor/opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linux_amd64/vet /home/REDACTED/wor-unsafeptr=false /home/REDACTED/wor-unreachable=false x_amd64/vet (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build3562526043/b336/launcher.test /tmp/go-build3562526043/b336/launcher.test -test.testlogfile=/tmp/go-build3562526043/b336/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/net 64/src/mime/encodedword.go x_amd64/vet -p crypto/internal/-atomic -lang=go1.25 x_amd64/vet -o ify@v1.11.1/asse-errorsas -trimpath (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build3562526043/b336/launcher.test /tmp/go-build3562526043/b336/launcher.test -test.testlogfile=/tmp/go-build3562526043/b336/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/net 64/src/mime/encodedword.go x_amd64/vet -p crypto/internal/-atomic -lang=go1.25 x_amd64/vet -o ify@v1.11.1/asse-errorsas -trimpath (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3562526043/b345/mcp.test /tmp/go-build3562526043/b345/mcp.test -test.testlogfile=/tmp/go-build3562526043/b345/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true _.a 58122696/b151//_-ifaceassert x_amd64/vet go1.25.8 ternal/engine/wa--version 122696/b151/ x_amd64/vet ctor�� .cfg 122696/b151/ x_amd64/vet --gdwarf-5 ut-1903621372.c -o x_amd64/vet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Remove dead code for is_forked_pull_request_with_callback [rust-guard] Move test-only function out of production code; add missing field_names constants Apr 3, 2026
Copilot finished work on behalf of lpcox April 3, 2026 05:12
Copilot AI requested a review from lpcox April 3, 2026 05:12
@lpcox lpcox marked this pull request as ready for review April 3, 2026 05:14
Copilot AI review requested due to automatic review settings April 3, 2026 05:14
@lpcox lpcox merged commit df3bb25 into main Apr 3, 2026
9 checks passed
@lpcox lpcox deleted the copilot/remove-dead-code-is-forked-pull-request branch April 3, 2026 05:14
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 code quality and consistency in the Rust GitHub guard by removing dead production code (reducing WASM binary size) and centralizing commonly used JSON field name strings into the existing field_names constants module.

Changes:

  • Moved is_forked_pull_request_with_callback out of production code and into #[cfg(test)] scope in backend.rs.
  • Added missing field_names constants (FULL_NAME, NUMBER, PRIVATE, LOGIN) and replaced raw JSON field string literals with these constants across labeling modules.
  • Added missing field_names imports where needed (response_items.rs, response_paths.rs).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
guards/github-guard/rust-guard/src/labels/backend.rs Removes test-only helper from production and rehomes it under #[cfg(test)].
guards/github-guard/rust-guard/src/labels/constants.rs Adds new field_names constants for commonly accessed JSON fields.
guards/github-guard/rust-guard/src/labels/helpers.rs Switches JSON field access to use field_names constants (e.g., NUMBER, FULL_NAME, LOGIN).
guards/github-guard/rust-guard/src/labels/response_items.rs Replaces raw "private" / "full_name" lookups with field_names constants and adds the needed import.
guards/github-guard/rust-guard/src/labels/response_paths.rs Replaces raw "private" / "full_name" lookups with field_names constants and adds the needed import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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: Dead production code + missing field name constants

3 participants