-
Notifications
You must be signed in to change notification settings - Fork 0
Barn 77 allow context overrides in helper methods #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Barn 77 allow context overrides in helper methods #70
Conversation
There was a problem hiding this 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 the parameter override mechanism in helper methods by replacing separate parameter_start and parameter_end arguments with a unified context_overrides hash parameter. This change improves the API design by consolidating context configuration into a single parameter, making it easier to extend with additional overrides in the future. This is a breaking change warranting the major version bump from 2.1.0 to 3.0.0.
Key Changes:
- Replaced
parameter_startandparameter_endparameters withcontext_overrideshash infind_tokens,find_formatters, andfind_warningsmethods - Added new private
build_contexthelper method to construct context objects with optional overrides - Fixed typo in test variable name (
expression_with_bad_paramss→expression_with_bad_params)
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/parameter_substitution.rb | Refactored helper methods to accept context_overrides hash instead of individual parameters; added build_context helper method |
| lib/parameter_substitution/version.rb | Bumped version to 3.0.0-0 for breaking API change |
| spec/lib/parameter_substitution_spec.rb | Updated all test cases to use new context_overrides parameter; fixed typo in variable name |
| CHANGELOG.md | Documented breaking changes for version 3.0.0 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
lib/parameter_substitution.rb
Outdated
| mapping: mapping | ||
| } | ||
|
|
||
| ParameterSubstitution::Context.new(**base_options.merge(context_overrides || {})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Explicit Parameters Silently Overridden
The context_overrides hash can silently override the explicit string_with_tokens and mapping parameters due to incorrect merge order. If a caller passes context_overrides: {input: 'x'} or context_overrides: {mapping: {...}}, these will override the method's positional and keyword arguments, causing the explicit parameters to be ignored without any error or warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ty, robot. Fixed.
|
|
||
| class ParameterSubstitution | ||
| VERSION = "2.1.0" | ||
| VERSION = "3.0.0-1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a prerelease shorthand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, when you bundle install it appears in the lockfile as 3.0.0.pre.1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🆒 😎
ebertz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a reasonable change. Might make sense to add add tests for overriding allow_unmatched_delimiter_end since that is one of the intended use cases, and maybe a test for the behavior when other unsupported options are passed in the overrides hash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| class ParameterSubstitution | ||
| VERSION = "2.1.0" | ||
| VERSION = "3.0.0-2" |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version string 3.0.0-2 does not follow semantic versioning prerelease format. Should be 3.0.0.pre.2 or 3.0.0-pre.2 to match the pattern mentioned in PR description (3.0.0.pre.0).
| VERSION = "3.0.0-2" | |
| VERSION = "3.0.0.pre.2" |
lib/parameter_substitution.rb
Outdated
| end | ||
| end | ||
|
|
||
|
|
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line should be removed to maintain consistent spacing in the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/parameter_substitution.rb
Outdated
| valid_keys = %i[ | ||
| required_parameters | ||
| parameter_start | ||
| parameter_end | ||
| destination_encoding | ||
| allow_unknown_replacement_parameters | ||
| allow_nil | ||
| allow_unmatched_parameter_end | ||
| ].to_set |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The list of valid context override keys is hardcoded here, creating a maintenance burden. If new attributes are added to the Context class, this list must be manually updated. Consider deriving valid keys from the Context class itself (e.g., using Context's initializer parameters) to ensure consistency.
| valid_keys = %i[ | |
| required_parameters | |
| parameter_start | |
| parameter_end | |
| destination_encoding | |
| allow_unknown_replacement_parameters | |
| allow_nil | |
| allow_unmatched_parameter_end | |
| ].to_set | |
| valid_keys = ParameterSubstitution::Context | |
| .instance_method(:initialize) | |
| .parameters | |
| .select { |type, _| type == :key || type == :keyreq } | |
| .map { |_, name| name } | |
| .to_set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This almost sounds like a cool idea, except for that fact that the list of parameters for initialize is not the same as the list of keys being validated against here....
|
@ebertz I added an explicit validation for accepted override keys. I also consolidated the override tests into some shared examples for each method affected. |
lib/parameter_substitution.rb
Outdated
| valid_keys = %i[ | ||
| required_parameters | ||
| parameter_start | ||
| parameter_end | ||
| destination_encoding | ||
| allow_unknown_replacement_parameters | ||
| allow_nil | ||
| allow_unmatched_parameter_end | ||
| ].to_set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cgaroutte It would be better if this was defined as a class constant, so that it only needs to be processed once (array of symbols is instantiated, and then converted to a Set), instead of every time this method is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Good point.
| end | ||
| end | ||
| end | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cgaroutte Nice use of shared examples here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def validate_context_overrides!(context_overrides) | ||
| return if context_overrides.empty? | ||
|
|
||
| invalid_keys = context_overrides.keys.reject { |key| VALID_CONTEXT_OVERRIDE_KEYS.include?(key.to_sym) } |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation allows both string and symbol keys in context_overrides, but the merge operation at line 109 (**context_overrides.merge(base_options)) will create duplicate keys if string keys are used. For example, if context_overrides contains {'input' => 'value'}, this validation will pass (because line 117 converts it to :input), but line 109 will result in both :input and 'input' keys being passed to Context.new. Consider either converting all keys to symbols before validation and merge, or explicitly rejecting string versions of reserved keys.
| context 'when context_overrides attempts to override base options' do | ||
| context "when input is provided in context_overrides" do | ||
| let(:test_context_overrides) { { input: "<different>" } } | ||
| it "raises error" do | ||
| expect { subject }.to raise_error(ArgumentError, /Invalid context_overrides keys: input/) | ||
| end | ||
| end | ||
|
|
||
| context "when mapping is provided in context_overrides" do | ||
| let(:test_context_overrides) { { mapping: { 'different' => 'value' } } } | ||
| it "raises error" do |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test expects input to be rejected as an invalid key, but input is not listed in VALID_CONTEXT_OVERRIDE_KEYS (lines 84-92 in parameter_substitution.rb), so it would already be rejected by the general validation logic. The current implementation doesn't specifically check for 'base options' (input and mapping); it only validates against the allowed keys list. This test will pass, but for the wrong reason. Consider either adding explicit validation for base options that provides a clearer error message, or updating the test description to reflect that these are simply invalid keys rather than special 'base options'.
| context 'when context_overrides attempts to override base options' do | |
| context "when input is provided in context_overrides" do | |
| let(:test_context_overrides) { { input: "<different>" } } | |
| it "raises error" do | |
| expect { subject }.to raise_error(ArgumentError, /Invalid context_overrides keys: input/) | |
| end | |
| end | |
| context "when mapping is provided in context_overrides" do | |
| let(:test_context_overrides) { { mapping: { 'different' => 'value' } } } | |
| it "raises error" do | |
| context 'when context_overrides contains disallowed keys' do | |
| context "when input is provided in context_overrides" do | |
| let(:test_context_overrides) { { input: "<different>" } } | |
| it "raises error for invalid key" do | |
| expect { subject }.to raise_error(ArgumentError, /Invalid context_overrides keys: input/) | |
| end | |
| end | |
| context "when mapping is provided in context_overrides" do | |
| let(:test_context_overrides) { { mapping: { 'different' => 'value' } } } | |
| it "raises error for invalid key" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # @raise [ArgumentError] if context_overrides contains invalid keys | ||
| def validate_context_overrides!(context_overrides) | ||
| return if context_overrides.empty? | ||
|
|
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation allows 'input' and 'mapping' keys to pass through if they're present in context_overrides, but these should be rejected since they're provided as base_options. Add explicit validation to reject these reserved keys before checking against VALID_CONTEXT_OVERRIDE_KEYS.
| reserved_keys = %i[input mapping] | |
| present_reserved_keys = context_overrides.keys.map(&:to_sym) & reserved_keys | |
| if present_reserved_keys.any? | |
| raise ArgumentError, "context_overrides contains reserved keys: #{present_reserved_keys.join(', ')}. These keys are not allowed." | |
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 They aren't included in VALID_CONTEXT_OVERRIDE_KEYS though so they're going to be rejected regardless...I don't think the extra complexity is warranted here for a slightly more specific error message.
In a previous PR, I had added the ability to plumb the
parameter_startandparameter_endarguments through thefind_tokens,find_formatters, andfind_warningsmethodsin order to override parameter on the underlyingContextobject used by these methods. In this current PR, I realized I also needed to override anotherContextparameter:allow_unmatched_delimiter_end. Instead of adding yet another set of parameters to these methods, I created a generalized hash parameter that can be used to selectively overrideContext` parameters.Note
Adds
context_overridestofind_tokens,find_formatters, andfind_warnings(removingparameter_start/parameter_end), updates specs/docs, and bumps to a 3.0.0 prerelease.context_overridestoParameterSubstitution.find_tokens,find_formatters,find_warningsfor overridingContextattributes.parameter_startandparameter_endargs from these methods.build_contextto constructContextwith overrides.context_overridesfor non-default delimiters; fix a typo in variable name.CHANGELOG.mdwith 3.0.0 (unreleased) notes reflecting the API changes.3.0.0-0and updateGemfile.lockto3.0.0.pre.0.Written by Cursor Bugbot for commit c271a17. This will update automatically on new commits. Configure here.