Repository navigation
fix(catalog-ui): reject invalid numeric settings - #325
kstonekuan merged 2 commits into
Conversation
|
👋 Hi @Ftgn-dpA — thank you so much for your first contribution to HFlow! A maintainer will review your pull request as soon as possible. In the meantime:
💡 Tip: one open pull request per contributor at a time. Issues with an assignee are taken; everything else is fair game. We are excited to have you here and appreciate your help making the project better! 🙌 |
kstonekuan
left a comment
There was a problem hiding this comment.
LGTM, merging. Welcome.
Validated on your branch: ruff check, ruff format --check, ty check clean, 1267 passed / 6 skipped.
Pushed one fixup, 4c494d0: hoisted replace and IntEnum to module scope. Nothing wrong with it, just house style.
Testing the wrong-type cases through replace() was a good instinct. It keeps ty honest about the direct constructor while still exercising the guard, and since replace() re-runs __post_init__, the invariant now covers mutation too, not only construction.
Worth knowing where this actually earns its keep: the CLI already declares --port with type=int and has no flag for the poll interval, so argparse was covering the command line. The hole was SDK callers building CatalogUiSettings directly, which is why the boundary belongs on the dataclass.
Summary
Reject invalid Catalog UI numeric settings at construction, before they can reach socket setup or the polling wait loop.
Closes #297
Why
CatalogUiSettingspreviously relied only on range comparisons. Becauseboolsubclassesint,port=Truewas accepted as port 1; floating-point ports were also accepted. For the polling interval,NaN, positive infinity, andTruebypassed the existing non-positive check. Positive infinity can later raiseOverflowErrorinsideEvent.wait.This change keeps valid behavior unchanged while enforcing the field contracts described in the issue:
portis anintother thanbool, in the inclusive range 1-65535.catalog_poll_interval_secondsis anintorfloatother thanbool, finite, and greater than zero.IntEnumport values remain accepted.Validation
python -m pytest -q tests/test_catalog_ui.py— 20 passedruff check src/hflow/catalog_ui.py tests/test_catalog_ui.py— passedruff format --check src/hflow/catalog_ui.py tests/test_catalog_ui.py— 2 files already formattedty check src/hflow/catalog_ui.py tests/test_catalog_ui.py— passedmainfirst and failed for the reported boundaries.Checklist