Skip to content

Comments

Ensure and enforce that configs are loaded before options are accesse…#8

Open
MitchLewis930 wants to merge 1 commit intopr_058_beforefrom
pr_058_after
Open

Ensure and enforce that configs are loaded before options are accesse…#8
MitchLewis930 wants to merge 1 commit intopr_058_beforefrom
pr_058_after

Conversation

@MitchLewis930
Copy link

PR_058

@MitchLewis930 MitchLewis930 requested a review from Copilot January 31, 2026 01:35
Copy link

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 refactors Puma's configuration system to enforce that configurations are properly loaded and clamped before options are accessed. The change introduces a more explicit initialization flow where clamp must be called before accessing configuration options, preventing premature access to unfinalized configuration state.

Changes:

  • Added error guards to prevent accessing options before clamp is called
  • Replaced conf.load calls with conf.clamp throughout the test suite
  • Refactored the Binder class to accept options hash instead of Configuration object
  • Updated hook processing to store metadata for cluster-only hooks and defer warnings until clamp

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/puma/configuration.rb Introduces NotLoadedError and NotClampedError exceptions; adds guards to options and config_files accessors; refactors clamp to call load internally and validate hooks
lib/puma/binder.rb Changes constructor to accept options hash instead of Configuration object
lib/puma/launcher.rb Updates initialization sequence to call clamp before accessing options; adjusts Binder instantiation
lib/puma/dsl.rb Refactors hook processing to store cluster_only metadata and defer warnings to clamp time
lib/puma/server.rb Updates Binder instantiation to pass options hash
lib/rack/handler/puma.rb Changes log_writer keyword argument syntax from hash rocket to colon
test/test_config.rb Updates all tests to call clamp before accessing options; adds tests for NotLoadedError and NotClampedError
test/test_cli.rb Adds clamp calls before accessing configuration properties
test/test_binder.rb Updates Binder instantiation in setup and tests to pass options hash
test/test_launcher.rb Changes direct options manipulation to use configure block with DSL
test/test_rack_handler.rb Replaces all conf.load calls with conf.clamp
test/test_web_concurrency_auto.rb Wraps Configuration instantiation in assert_raises block and calls clamp
lib/puma/control_cli.rb Adds clamp call before accessing configuration options
benchmarks/local/puma_info.rb Replaces load with clamp for configuration

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


def process_hook(options_key, key, block, meth)
raise ArgumentError, "expected #{meth} to be given a block" unless block
def process_hook(options_key, key, block, method, cluster_only: false)
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The parameter name 'method' is misleading as it stores the hook name string, not a method object. Consider renaming to 'hook_name' or 'method_name' for clarity.

Copilot uses AI. Check for mistakes.

conf.run_hooks(hook_name, 'ARG', Puma::LogWriter.strings)
assert_equal messages, ["#{hook_name} is called with ARG"]
assert_equal ["#{hook_name} is called with ARG"], messages
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The assertion order has been reversed from the previous assert_equal messages, [...] pattern. For consistency with Ruby/Minitest conventions, consider keeping the expected value as the first argument: assert_equal [expected], actual.

Copilot uses AI. Check for mistakes.

conf.run_hooks(hook_name, 'ARG', Puma::LogWriter.strings)
assert_equal messages, ["#{hook_name} is called with ARG one time", "#{hook_name} is called with ARG a second time"]
assert_equal ["#{hook_name} is called with ARG one time", "#{hook_name} is called with ARG a second time"], messages
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The assertion order has been reversed from the previous assert_equal messages, [...] pattern. For consistency with Ruby/Minitest conventions, consider keeping the expected value as the first argument.

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