Skip to content

multi(core): Various fixes to the Settings system#465

Merged
dazuma merged 1 commit intomainfrom
pr/settings-review
Mar 19, 2026
Merged

multi(core): Various fixes to the Settings system#465
dazuma merged 1 commit intomainfrom
pr/settings-review

Conversation

@dazuma
Copy link
Owner

@dazuma dazuma commented Mar 18, 2026

fix(core): Block certain reserved names from being used as Settings field names
fix(core): Fixed Settings#load_data! when subclassing another settings class
fix(core): Reject non-String values in Settings regexp type spec
fix(core): Settings guards against unknown classes when loading YAML on older Ruby versions
fix(core): Settings guards against ILLEGAL_VALUE being passed to range.member?
fix(core): Settings does a better job choosing exact-match values when using a union type
fix(core): Settings reject non-numeric strings in Integer and Float converters
fix(core): Settings propagates nested group errors in Settings#load_data!

@dazuma dazuma force-pushed the pr/settings-review branch from 405faf8 to d76a3c9 Compare March 19, 2026 00:02
@dazuma dazuma requested a review from Copilot March 19, 2026 00:02
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 improves the robustness and safety of Toys::Settings type validation and data loading, adding guards for edge cases (e.g., inherited fields, YAML loading, and stricter conversions) and expanding test coverage to lock in the behavior.

Changes:

  • Add reserved settings field name blocking and improve type matching/conversion behavior (ranges, regexps, unions, numeric parsing).
  • Fix settings field inheritance for subclasses and propagate nested-group loading errors correctly (including raise_on_failure behavior).
  • Switch YAML loading to Psych.safe_load (disallowing arbitrary Ruby object deserialization) while permitting symbols.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
toys-core/lib/toys/settings.rb Core fixes: reserved names, safer YAML loading, improved converters/type matching, inherited fields, and nested error propagation.
toys-core/test/test_settings.rb Adds regression tests for reserved names, subclass field inheritance, stricter conversions, union prioritization, ranges, YAML safety, and nested error propagation.
Comments suppressed due to low confidence (1)

toys-core/lib/toys/settings.rb:910

  • interpret_name only checks public_instance_methods(false) for duplicates, so with the new inherited fields behavior a subclass can re-declare a field name that already exists in the superclass without raising, silently overwriting the inherited field definition and accessor methods. Consider also checking fields.key?(name.to_sym) and/or using public_instance_methods (including inherited) so redefinitions are rejected consistently across inheritance.
      def interpret_name(name)
        name = name.to_s
        if name !~ /^[a-zA-Z]\w*$/ || RESERVED_FIELD_NAMES.include?(name)
          raise ::ArgumentError, "Illegal settings field name: #{name}"
        end
        existing = public_instance_methods(false)
        if existing.include?(name.to_sym) || existing.include?(:"#{name}=") ||
           existing.include?(:"#{name}_set?") || existing.include?(:"#{name}_unset!")
          raise ::ArgumentError, "Settings field already exists: #{name}"

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

fix(core): Block certain reserved names from being used as Settings field names
fix(core): Fixed Settings#load_data! when subclassing another settings class
fix(core): Reject non-String values in Settings regexp type spec
fix(core): Settings guards against unknown classes when loading YAML on older Ruby versions
fix(core): Settings guards against ILLEGAL_VALUE being passed to range.member?
fix(core): Settings does a better job choosing exact-match values when using a union type
fix(core): Settings reject non-numeric strings in Integer and Float converters
fix(core): Settings propagates nested group errors in Settings#load_data!

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dazuma dazuma force-pushed the pr/settings-review branch from d76a3c9 to 654bac0 Compare March 19, 2026 00:23
@dazuma dazuma merged commit 1f2cd7b into main Mar 19, 2026
15 checks passed
@dazuma dazuma deleted the pr/settings-review branch March 19, 2026 05:38
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