Skip to content

openai-image-gen: validate --background and --style options#36762

Merged
vincentkoc merged 5 commits intoopenclaw:mainfrom
shuofengzhang:fix/openai-image-gen-validate-background-style
Mar 6, 2026
Merged

openai-image-gen: validate --background and --style options#36762
vincentkoc merged 5 commits intoopenclaw:mainfrom
shuofengzhang:fix/openai-image-gen-validate-background-style

Conversation

@shuofengzhang
Copy link
Copy Markdown
Contributor

@shuofengzhang shuofengzhang commented Mar 5, 2026

What changed

  • Added validation for --background and --style in skills/openai-image-gen/scripts/gen.py.
  • Normalized accepted values to lowercase before sending requests.
  • Warned and ignored those flags when the selected model does not support them instead of silently discarding them.
  • Added unit tests for valid, invalid, empty-input, and incompatible-model warning paths in skills/openai-image-gen/scripts/test_gen.py.
  • Added a changelog entry with contributor attribution.

Why

  • Invalid values previously failed late with API errors.
  • Incompatible models could silently drop --background / --style, which is confusing CLI behavior.
  • Early validation and explicit warnings make the tool behavior predictable and avoid unnecessary failed requests.

Testing

  • python3 -m ruff check skills/openai-image-gen/scripts/test_gen.py
  • python3 -m pytest -q skills/openai-image-gen/scripts/test_gen.py (14 passed)

Fixes #36763

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 5, 2026

Greptile Summary

This PR adds early CLI validation for the --background and --style flags in skills/openai-image-gen/scripts/gen.py, preventing unnecessary API calls and surfacing clearer error messages when invalid values are supplied. The implementation is straightforward and correct, with appropriate case-normalization before forwarding values to the API.

Key changes:

  • normalize_background: validates --background (transparent/opaque/auto) only for gpt-image-* models; silently no-ops for other models.
  • normalize_style: validates --style (vivid/natural) only for dall-e-3; silently no-ops for other models.
  • Both functions are called once in main() before the generation loop, exiting with code 2 on validation failure.
  • Six new unit tests added covering valid, normalized-case, and invalid inputs.

Minor issue:

  • The test suite does not cover the empty-string input code path (if not value: return "") that is present in both helper functions. This is a real code path that executes when the user omits the flag (default empty string), and should be explicitly tested.

Confidence Score: 4/5

  • Safe to merge; validation logic is correct with appropriate error handling, though test coverage for empty-input code paths should be added.
  • The implementation correctly validates and normalizes --background and --style flags with appropriate model-specific logic. The code handles both valid and invalid inputs correctly, with defensive error messages. The primary gap is incomplete test coverage: the empty-string code path (present in both normalize functions at lines 84-85 and 101-102) is not covered by tests, though this represents real usage when flags are omitted. This is a test completeness issue rather than a logic bug, hence a 4/5 rather than 5/5.
  • skills/openai-image-gen/scripts/test_gen.py — add tests for empty and whitespace inputs on supported models

Last reviewed commit: 0677a5f

@vincentkoc vincentkoc force-pushed the fix/openai-image-gen-validate-background-style branch from 323c010 to 9d232d2 Compare March 6, 2026 15:54
@vincentkoc vincentkoc self-assigned this Mar 6, 2026
@vincentkoc
Copy link
Copy Markdown
Member

Pushed a follow-up cleanup to this branch.

The diff now includes the added empty-input coverage, warning coverage for incompatible models, a changelog entry with attribution, and the Python import-order fix that was tripping skills-python. I reran python3 -m ruff check skills/openai-image-gen/scripts/test_gen.py and python3 -m pytest -q skills/openai-image-gen/scripts/test_gen.py locally before pushing.

@vincentkoc vincentkoc merged commit 20038fb into openclaw:main Mar 6, 2026
23 checks passed
mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Mar 6, 2026
* main:
  Mattermost: harden interaction callback binding (openclaw#38057)
  WhatsApp: honor outbound mediaMaxMb (openclaw#38097)
  openai-image-gen: validate --background and --style options (openclaw#36762)
  Docs: align BlueBubbles media cap wording
  Telegram/Discord: honor outbound mediaMaxMb uploads (openclaw#38065)
  CI: run changed-scope on main pushes
  Skills/nano-banana-pro: clarify MEDIA token comment (openclaw#38063)
  nano-banana-pro: respect explicit --resolution when editing images (openclaw#36880)
  CI: drop unused install-smoke bootstrap
  fix(nano-banana-pro): remove space after MEDIA: token in generate_image.py (openclaw#18706)
  docs: context engine
  docs(config): list the context engine plugin slot
  docs(plugins): add context-engine manifest kind example
  docs(plugins): document context engine slots and registration
  docs(protocol): document slash-delimited schema lookup plugin ids
  docs(tools): document slash-delimited config schema lookup paths
  fix(session): tighten direct-session webchat routing matching (openclaw#37867)
  feature(context): extend plugin system to support custom context management (openclaw#22201)
  Gateway: allow slash-delimited schema lookup paths
ant1eicher pushed a commit to ant1eicher/openclaw that referenced this pull request Mar 6, 2026
…#36762)

* openai-image-gen: validate --background and --style inputs

* Skills/openai-image-gen: warn on ignored background and style flags

* Skills/openai-image-gen: cover empty and warning cases

* Changelog: note openai image flag validation

* Skills/openai-image-gen: fix Python import order

---------

Co-authored-by: Vincent Koc <[email protected]>
Saitop pushed a commit to NomiciAI/openclaw that referenced this pull request Mar 8, 2026
…#36762)

* openai-image-gen: validate --background and --style inputs

* Skills/openai-image-gen: warn on ignored background and style flags

* Skills/openai-image-gen: cover empty and warning cases

* Changelog: note openai image flag validation

* Skills/openai-image-gen: fix Python import order

---------

Co-authored-by: Vincent Koc <[email protected]>
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
…#36762)

* openai-image-gen: validate --background and --style inputs

* Skills/openai-image-gen: warn on ignored background and style flags

* Skills/openai-image-gen: cover empty and warning cases

* Changelog: note openai image flag validation

* Skills/openai-image-gen: fix Python import order

---------

Co-authored-by: Vincent Koc <[email protected]>
dhoman pushed a commit to dhoman/chrono-claw that referenced this pull request Mar 11, 2026
…#36762)

* openai-image-gen: validate --background and --style inputs

* Skills/openai-image-gen: warn on ignored background and style flags

* Skills/openai-image-gen: cover empty and warning cases

* Changelog: note openai image flag validation

* Skills/openai-image-gen: fix Python import order

---------

Co-authored-by: Vincent Koc <[email protected]>
senw-developers pushed a commit to senw-developers/va-openclaw that referenced this pull request Mar 17, 2026
…#36762)

* openai-image-gen: validate --background and --style inputs

* Skills/openai-image-gen: warn on ignored background and style flags

* Skills/openai-image-gen: cover empty and warning cases

* Changelog: note openai image flag validation

* Skills/openai-image-gen: fix Python import order

---------

Co-authored-by: Vincent Koc <[email protected]>
V-Gutierrez pushed a commit to V-Gutierrez/openclaw-vendor that referenced this pull request Mar 17, 2026
…#36762)

* openai-image-gen: validate --background and --style inputs

* Skills/openai-image-gen: warn on ignored background and style flags

* Skills/openai-image-gen: cover empty and warning cases

* Changelog: note openai image flag validation

* Skills/openai-image-gen: fix Python import order

---------

Co-authored-by: Vincent Koc <[email protected]>
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 20, 2026
…#36762)

Co-authored-by: Vincent Koc <[email protected]>
(cherry picked from commit 20038fb9556b8f46e6a4eec8f8cd0b1e3cb12c87)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 20, 2026
…#36762)

Co-authored-by: Vincent Koc <[email protected]>
(cherry picked from commit 20038fb9556b8f46e6a4eec8f8cd0b1e3cb12c87)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openai-image-gen: validate --background and --style CLI options

2 participants