Skip to content

feat(internal/testhelper): check managed protoc in RequireCommand - #7521

Open
Bhaumik-99 wants to merge 6 commits into
googleapis:mainfrom
Bhaumik-99:fix/7493-remove-install-protoc
Open

Bhaumik-99 wants to merge 6 commits into
googleapis:mainfrom
Bhaumik-99:fix/7493-remove-install-protoc

Conversation

@Bhaumik-99

Copy link
Copy Markdown

RequireCommand now checks for a librarian-managed protoc binary in the cache bin directory before skipping tests when protoc is not on the system PATH. This allows tests relying on protoc to run without requiring a global protoc installation.

Fixes #7493

RequireCommand now checks for a librarian-managed protoc binary in the cache
bin directory before skipping tests when protoc is not on the system PATH.
This allows tests relying on protoc to run without requiring a global protoc
installation.

Fixes googleapis#7493
@Bhaumik-99
Bhaumik-99 requested a review from a team as a code owner September 6, 2026 18:49

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates RequireCommand to support librarian-managed protoc installations, preventing tests from being skipped if a managed binary is available. The review feedback points out that simply not skipping the test is insufficient because subsequent executions of protoc will still fail if it is not in the system PATH. The reviewer suggests updating RequireCommand to temporarily add the managed protoc directory to the PATH environment variable using t.Setenv, using absolute paths for reliability, and adding tests to verify this behavior.

Comment thread internal/testhelper/testhelper.go
Comment thread internal/testhelper/testhelper_test.go
Comment thread internal/testhelper/testhelper_test.go Outdated
Update findManagedProtoc to return the absolute binary path and boolean status.
Ensure RequireCommand prepends the managed protoc directory to PATH via
t.Setenv so subsequent executions within the test can discover and invoke it.

Update unit tests to verify protoc discovery on PATH.
@sofisl

sofisl commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates RequireCommand in internal/testhelper/testhelper.go to locate a librarian-managed protoc binary in the cache directory and prepend its path to the PATH environment variable for tests, with accompanying unit tests added in internal/testhelper_test.go. Feedback recommends documenting that tests using RequireCommand for protoc cannot be run in parallel due to the use of t.Setenv. Additionally, it is suggested to replace filepath.Glob with os.ReadDir in findManagedProtoc to more robustly find and prefer the latest version of protoc without glob escaping issues.

Comment thread internal/testhelper/testhelper.go
Comment thread internal/testhelper/testhelper.go Outdated
@Bhaumik-99

Copy link
Copy Markdown
Author

Hi maintainers,

I’ve addressed the review feedback and updated the implementation and tests for managed protoc lookup.

The focused tests and lint checks are passing. The remaining blockers appear to be the required internal approvals and approval of the pending workflows from the fork.

Could a maintainer please approve the pending workflows and review the PR when available?

Thank you!

@Bhaumik-99

Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the test helper to locate and use librarian-managed protoc binaries when they are not present in the system PATH, including logic to parse, compare, and select the newest installed version. The review feedback suggests several important improvements to make this logic more robust: avoiding a trailing path separator when PATH is empty to prevent security risks, and extending the version parsing and comparison logic to support 3-component semantic versions (e.g., v3.20.3) rather than assuming exactly two components.

Comment thread internal/testhelper/testhelper.go
Comment thread internal/testhelper/testhelper.go
Comment thread internal/testhelper/testhelper.go
Comment thread internal/testhelper/testhelper.go
@Bhaumik-99

Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for locating and using a librarian-managed protoc binary from the cache directory when it is not found in the system PATH. It introduces version parsing and comparison logic to select the newest installed version, along with comprehensive unit tests. The review feedback highlights an issue in the version comparison logic where lexicographical comparison of prerelease tags (e.g., "-rc2" vs "-rc10") incorrectly ranks them, and suggests parsing trailing numeric suffixes numerically. Additionally, it recommends adding a test case to verify double-digit release candidate comparisons.

Comment thread internal/testhelper/testhelper.go
Comment thread internal/testhelper/testhelper_test.go
@Bhaumik-99

Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the RequireCommand helper in internal/testhelper/testhelper.go to automatically locate and use a librarian-managed protoc binary from the cache directory if it is not found in the system PATH. It introduces robust version parsing and comparison logic to ensure the newest installed version is selected, and updates the test environment's PATH accordingly. Additionally, a comprehensive suite of unit tests has been added in internal/testhelper/testhelper_test.go to verify this behavior. There are no review comments, so I have no feedback to provide.

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.

librarian(ci): eval if actions/install-protoc can be deleted

2 participants