Skip to content

Comments

Add test coverage for auto-attestation skipping on non-rubygems.org hosts and JRuby#9326

Merged
hsbt merged 3 commits intopush-with-attestationfrom
copilot/sub-pr-9325
Feb 10, 2026
Merged

Add test coverage for auto-attestation skipping on non-rubygems.org hosts and JRuby#9326
hsbt merged 3 commits intopush-with-attestationfrom
copilot/sub-pr-9325

Conversation

Copy link
Contributor

Copilot AI commented Feb 10, 2026

What was the end-user or developer problem that led to this PR?

The auto-attestation feature in the push command has branching logic to skip attestation on JRuby and non-rubygems.org hosts, but test coverage only verified the happy path and error fallback. Missing tests for the conditional skipping paths.

What is your fix for the problem, implemented in this PR?

Added two test cases to verify auto-attestation is correctly skipped:

  • test_execute_attestation_skipped_on_non_rubygems_host: Verifies attest! is not called when pushing to a private gem server. Uses allowed_push_host metadata to simulate a non-rubygems.org host, stubs attest! with a flag, and asserts raw application/octet-stream push succeeds.

  • test_execute_attestation_skipped_on_jruby: Verifies attest! is not called on JRuby. Temporarily modifies RUBY_ENGINE constant to simulate JRuby environment, stubs attest! with a flag, and asserts raw push succeeds with proper cleanup in ensure block.

Both tests follow the existing pattern of using boolean flags with method stubs to track invocations, ensuring the branching logic in send_push_request works correctly.

Make sure the following tasks are checked


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 10, 2026 10:18
Co-authored-by: hsbt <12301+hsbt@users.noreply.github.com>
Co-authored-by: hsbt <12301+hsbt@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issues based on review feedback for push PR Add test coverage for auto-attestation skipping on non-rubygems.org hosts and JRuby Feb 10, 2026
Copilot AI requested a review from hsbt February 10, 2026 10:21
@hsbt hsbt marked this pull request as ready for review February 10, 2026 10:22
Copilot AI review requested due to automatic review settings February 10, 2026 10:22
@hsbt hsbt merged commit 8330423 into push-with-attestation Feb 10, 2026
2 checks passed
@hsbt hsbt deleted the copilot/sub-pr-9325 branch February 10, 2026 10:22
Copy link
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

Adds missing test coverage for the push command’s auto-attestation branching logic, specifically the cases where attestation should be skipped on JRuby and when pushing to non-rubygems.org hosts.

Changes:

  • Add a test asserting attest! is skipped when the gem’s allowed_push_host causes pushes to a non-rubygems.org host.
  • Add a test asserting attest! is skipped when RUBY_ENGINE is jruby.

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

@cmd.options[:args] = [@path]

attest_called = false
@cmd.stub(:attest!, proc { attest_called = true }) do
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The attest! stub returns true, so if the code path regresses and attest! is invoked, the test will likely fail with an unrelated Gem.read_binary(true) type error before reaching the refute attest_called assertion. Consider making the stub explicitly fail (e.g., raising/flunking) to produce a clearer failure reason tied to the behavior being tested.

Suggested change
@cmd.stub(:attest!, proc { attest_called = true }) do
@cmd.stub(:attest!, proc {
attest_called = true
flunk "attest! should not be called for non-rubygems.org hosts"
}) do

Copilot uses AI. Check for mistakes.
Comment on lines +187 to +191
engine = RUBY_ENGINE
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, "jruby"

begin
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

RUBY_ENGINE is modified outside the begin/ensure region, so if an unexpected exception occurs during the constant swap, the original value may not be restored and could leak into other tests. Consider moving the constant swap inside the begin/ensure (or using the existing helper methods in test/rubygems/helper.rb that manage Ruby version/engine constants) to guarantee cleanup.

Suggested change
engine = RUBY_ENGINE
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, "jruby"
begin
begin
engine = RUBY_ENGINE
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, "jruby"

Copilot uses AI. Check for mistakes.
Comment on lines +192 to +194
@cmd.stub(:attest!, proc { attest_called = true }) do
@cmd.execute
end
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

Same issue as above: the attest! stub returns true, so if attest! is unexpectedly called this test will likely error out during request construction rather than failing with a clear assertion message. Prefer a stub that explicitly fails if invoked so the failure points directly at the regression.

Copilot uses AI. Check for mistakes.
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.

2 participants