Skip to content

fix(cli): default unset optional flags to InferenceSettings values#233

Open
mountarreat wants to merge 1 commit intonikopueringer:mainfrom
mountarreat:fix/cli-headless-none-defaults
Open

fix(cli): default unset optional flags to InferenceSettings values#233
mountarreat wants to merge 1 commit intonikopueringer:mainfrom
mountarreat:fix/cli-headless-none-defaults

Conversation

@mountarreat
Copy link
Copy Markdown
Contributor

What does this change?

The headless branch of run-inference
(corridorkey_cli.py:369-379) constructs InferenceSettings(...)
directly when the four required flags (--linear/--srgb,
--despill, --despeckle, --refiner) are all provided. Four
optional flags (--comp, --gpu-post, --image-size, --tile)
were forwarded as-is, so a None from Typer's default flowed
straight into dataclass fields typed bool or int.

Running the new regression test against unfixed code confirmed the
resulting settings object as:

InferenceSettings(..., generate_comp=None, gpu_post_processing=None,
    image_size=None, tiled_inference=None)

which silently breaks downstream code treating those fields as
bool/int. The interactive branch
(_prompt_inference_settings, lines 161-164) already handled this
by falling back to InferenceSettings.<field> when a default was
None.

This PR applies the same pattern to the headless branch and adds
test_headless_optional_flags_use_dataclass_defaults in the
existing TestNonInteractiveFlags class to prevent regression.

How was it tested?

TDD: wrote the regression test first, observed it fail against the
bug on upstream/main, applied the fix, observed the test pass.
Then full-suite regression check.

  • uv run ruff format --check: clean
  • uv run ruff check: clean
  • uv run pytest -q --tb=short -m "not gpu": 364 passed, 1 skipped
    (MLX), 4 deselected (GPU). The +1 pass vs upstream's 363 is the
    new regression test.
  • The two warnings in the suite output (PytestConfigWarning: Unknown config option: env and a torch autocast warning on a
    no-CUDA machine) are both pre-existing on upstream/main and not
    introduced by this change.
  • uv run corridorkey --help: exits 0

Checklist

  • uv run pytest passes
  • uv run ruff check passes
  • uv run ruff format --check passes

The headless branch of `run-inference` (`corridorkey_cli.py:369-379`)
constructs `InferenceSettings(...)` directly when the four required
flags (--linear/--srgb, --despill, --despeckle, --refiner) are all
provided. Four optional flags (--comp, --gpu-post, --image-size,
--tile) were forwarded as-is, so a `None` from Typer's default flowed
straight into dataclass fields typed `bool` or `int`.

Running the new regression test (committed in the same change)
against unfixed code confirmed the resulting settings object as:

    InferenceSettings(..., generate_comp=None,
        gpu_post_processing=None, image_size=None,
        tiled_inference=None)

which silently breaks downstream code that treats these fields as
bool/int. The interactive branch (`_prompt_inference_settings` at
lines 161-164) already handled this correctly by falling back to
`InferenceSettings.<field>` when a default is None.

Apply the same pattern to the headless branch: for each of the four
optional flags, fall back to the class-level dataclass default when
the CLI-provided value is None. The class-attribute access is
preferred over hardcoded defaults because it tracks any future
change to the dataclass automatically.

Add `test_headless_optional_flags_use_dataclass_defaults` in the
existing `TestNonInteractiveFlags` class; it invokes the CLI with
only the four required flags and asserts the four optional fields
inherit their dataclass defaults (True, False, 2048, False).

Verified locally on Windows with Python 3.13.11:
- uv run ruff format --check: clean
- uv run ruff check: clean
- New test fails on upstream/main without the fix, passes with it.
- uv run pytest -q --tb=short -m "not gpu": 364 passed, 1 skipped
  (MLX), 4 deselected (GPU), 2 warnings. The +1 pass vs upstream's
  363 is the new regression test. Both warnings are pre-existing on
  upstream/main: the unknown-option `env` warning (addressed on a
  separate branch) and a torch autocast warning on a no-CUDA
  machine. Neither is introduced by this change.
@mountarreat mountarreat marked this pull request as ready for review April 18, 2026 02:04
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.

1 participant