8000 Reject bad numbers before any edit, with GIMP's own ranges (#152, #160) by tomerkon · Pull Request #190 · gimp-mcp/gimp-mcp · GitHub
[go: up one dir, main page]

Skip to content

Reject bad numbers before any edit, with GIMP's own ranges (#152, #160) - #190

Merged
tomerkon merged 1 commit into
mainfrom
numeric-arg-ranges
Dec 3, 2026
Merged

tomerkon merged 1 commit into
mainfrom
numeric-arg-ranges

Conversation

@tomerkon
@tomerkon tomerkon commented Dec 3, 2026 •
Copy link
Copy Markdown
Collaborator

Fixes #152. Fixes #160.

Problem

Change

One check, with ranges read from GIMP:

  • _number(value, name, lo, hi, scale): a finite number within [lo, hi], or a ValueError naming the tool's parameter, e.g. hue must be between -180 and 180, got 500. scale covers tools that convert the value (sharpen's amount / 100), so the message uses the tool's scale. Ends GIMP marks as unbounded (G_MAXDOUBLE / G_MAXINT) are left out of the message unless the value is past them.
  • _pdb_number(proc, arg, ...) reads the bounds from the PDB argument (proc.find_argument). _gegl_number(op, key, ...) reads them from the GEGL property (Gimp.DrawableFilter.operation_get_pspecs), without creating a filter.

All 16 affected tools now check before the undo group opens, or before any other change:

Tool Parameters Before
adjust_hue_saturation hue, saturation, lightness success; the value became the argument's minimum
adjust_color_balance cyan_red, magenta_green, yellow_blue same
sharpen, blur, apply_gaussian_blur, apply_pixelate, apply_emboss, apply_vignette, apply_noise their numbers error after the image was marked as changed, quoting GEGL
denoise strength (0-100, as documented) 101-659 worked; NaN gave cannot convert float NaN to integer
select_rectangle, select_ellipse feather NaN meant no feather; a negative value was ignored
draw_line x1, 10000 y1, x2, y2 NaN or inf: drew nothing, success, image marked as changed
gradient_fill x1, y1, x2, y2 GIMP's error after the image was marked as changed
create_layer opacity constructor returned NULL
add_text size (above 0 and at most 8192, as in edit_text) 0, negative or above 8192: a text layer of size 0

_apply_gegl_filter's own check is kept as a backstop. edit_text keeps the 8192 limit from #150. warp_region, listed in #152, already checks its values since the #63 port.

Tests

  • tests/test_number_ranges.py (offline): 41 bad values across the 16 tools each return an error naming the parameter, with no undo group, selection, paint or filter call; values at the ends of each range pass; unit tests for the helper. All 41 fail on main. The gi stub in test_pdb_status.py gains Gimp.DrawableFilter.operation_get_pspecs and FakeProc.find_argument, with GIMP 3.2.8's ranges.
  • tests/test_number_ranges_live.py: the same 41 bad values on GIMP 3.2.8 leave the image clean (dirty flag, layers, selection, pixels), and values at the ends of the ranges work. On main's plugin, 34 of them changed the image (40 probed; block_size=2**31 was added later, after CodeRabbit's CLI review).
  • All offline tests pass, and so do all 31 live tests on GIMP 3.2.8 (Snap).

Summary by CodeRabbit

  • Bug Fixes
    • Numeric tool parameters are now checked for valid types, finite values, and allowed ranges before image changes are made. Invalid values—including NaN, infinity, fractional values where integers are required, and out-of-range values—return an error identifying the affected parameter.
    • Validation now covers image adjustments, filters, selections, layers, drawing and gradient coordinates, and text sizing. Valid boundary values continue to be accepted.

A PDB config given a number outside its argument's range, NaN included,
keeps the argument's default (for hue-offset, -180) and the procedure
returns SUCCESS. NaN and inf also got past several tools' checks, and the
GEGL filter tools checked their values only inside the undo group.

_number() checks a tool parameter: a finite number within [lo, hi], with
an error naming the parameter. _pdb_number() and _gegl_number() read the
bounds from the PDB argument or GEGL property the value is sent as. All
16 affected tools check before the undo group opens.
@github-actions github-actions Bot added bug Something isn't working documentation Improvements or additions to documentation labels Dec 3, 2026
@coderabbitai
coderabbitai Bot commented Dec 3, 2026 •
Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The plugin now validates numeric inputs for image tools against finite-value, integer, and GIMP or GEGL parameter bounds before image changes. Offline and live regression tests cover invalid inputs and selected valid boundary values.

Changes

Numeric Parameter Validation

Layer / File(s) Summary
Numeric validation and parameter bounds
gimp-mcp-plugin.py, tests/test_pdb_status.py, tests/test_number_ranges.py
The plugin adds shared numeric validation helpers that obtain limits from PDB arguments and GEGL properties. Offline tests cover conversions, bounds, errors, and parameter lookup stubs.
Validate tool inputs before image changes
gimp-mcp-plugin.py, CHANGELOG.md, tests/test_number_ranges.py
Image adjustment, selection, drawing, layer, text, and filter tools validate numeric parameters before applying changes. Offline tests check invalid inputs, selected boundaries, and that invalid calls make no recorded edits.
Verify validation against a live plugin
tests/test_number_ranges_live.py
The live test checks parameter-specific errors and unchanged image state for invalid inputs, then checks selected boundary values and attempts test-image cleanup.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • gimp-mcp/gimp-mcp#165: Changes the warp_region code path whose validation this PR notes was added by the #63 port.

Suggested labels: bug

Suggested reviewers: vicarc, iyuzhang

Merge Risk: Minimal · up to b118b

Numeric tool inputs are now checked against GIMP's own ranges before any edit, so bad values return a clear error instead of silently falling back to defaults or failing after the image has changed. No outstanding merge-blocking risk was found in the supplied context.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states the main change: numeric tool parameters are rejected before any edit, using GIMP's own allowed ranges. The changeset matches this. It adds validation helpers (_number, _pdb_number, _…
Linked Issues check Passed [#152, #160] Objective: reject non-finite and out-of-range numbers before any undo group opens or any edit is made, with an error that names the tool parameter and the allowed range. The change adds o…
Out of Scope Changes check Passed The listed changes stay within the two issues. Changes: a CHANGELOG Fixed entry for the numeric validation; the validation helpers _number, _pdb_number, _gegl_number in gimp-mcp-plugin.py; the…
Full details: Title check

Explanation

The title states the main change: numeric tool parameters are rejected before any edit, using GIMP's own allowed ranges. The changeset matches this. It adds validation helpers (_number, _pdb_number, _gegl_number), applies them to many tools before edits, and adds tests that check invalid values make no edits. The issue references (#152, #160) identify the linked issues. The title is one clear sentence, but it is a little long and uses issue numbers that add no meaning for a reader scanning history.

Full details: Linked Issues check

Explanation

[#152, #160] Objective: reject non-finite and out-of-range numbers before any undo group opens or any edit is made, with an error that names the tool parameter and the allowed range. The change adds one shared helper, _number. _pdb_number reads bounds from proc.find_argument. _gegl_number reads bounds from Gimp.DrawableFilter.operation_get_pspecs. The PR summary lists the 16 affected tools and their parameters, and the change covers each one. Examples: adjust_hue_saturation (hue, saturation, lightness), adjust_color_balance (three parameters), the GEGL filter tools (sharpen, blur, apply_gaussian_blur, apply_pixelate, apply_emboss, apply_vignette, apply_noise), denoise, select_rectangle and select_ellipse (feather), draw_line (x1, y1, x2, y2), gradient_fill, create_layer (opacity), and add_text (size). The #152 blur case (horizontal/vertical from radius) is covered by the GEGL blur path. warp_region already validates its values, as the issue notes. edit_text keeps its 8192 limit. #152 asks for an offline stub param-spec test and a live unchanged-image check. The PR adds tests/test_number_ranges.py (41 invalid values, all failing on main) and tests/test_number_ranges_live.py (image-clean checks on GIMP 3.2.8). The stub in tests/test_pdb_status.py gains find_argument and operation_get_pspecs. The #160 table items (silent success, error after the image is marked changed, unclear constructor returned NULL) are each addressed in the change table. Limit: this assessment relies on the PR summary and description. Source hunks were not inspected in this pass.

Full details: Out of Scope Changes check

Explanation

The listed changes stay within the two issues. Changes: a CHANGELOG Fixed entry for the numeric validation; the validation helpers _number, _pdb_number, _gegl_number in gimp-mcp-plugin.py; the per-tool checks for the 16 tools; the offline and live test files; and the test stub additions FakePspec, FakePspecArray, find_argument, and operation_get_pspecs. The stub and test changes support the required tests. The emboss depth rounding and the rejection of booleans and fractional integers are part of the same validation helper. They do not add unrelated behavior. No change addresses unrelated tools or features. Limit: this assessment relies on the PR summary; source hunks were not inspected in this pass.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4f4b862 and b118bbd.

Files selected for processing: 5

  • CHANGELOG.md
  • gimp-mcp-plugin.py
  • tests/test_number_ranges.py
  • tests/test_number_ranges_live.py
  • tests/test_pdb_status.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@tomerkon
tomerkon merged commit 0c6572a into main Dec 3, 2026
6 checks passed
@tomerkon
tomerkon deleted the numeric-arg-ranges branch December 3, 2026 14:51
tomerkon added a commit that referenced this pull request Dec 3, 2026
* Document the number ranges the tools check since #190

sharpen's amount said 0-500 and apply_emboss's elevation 0-90, while the
tools accept GIMP's ranges, 0-30000 and 0-180. The blur radii,
block_size, feather and the text sizes had no range in their description.

* apply_pixelate: give block_size's upper bound too
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation

Projects

None yet

1 participant

0