mbox series

[wic,0/5] ksparser: four argparse-type fixes plus unit coverage

Message ID 20260715223226.3371498-1-twoerner@gmail.com
Headers show
Series ksparser: four argparse-type fixes plus unit coverage | expand

Message

Trevor Woerner July 15, 2026, 10:32 p.m. UTC
This series continues the standalone unit-test work, this time over the
custom argparse types in ksparser.py: sizetype(), overheadtype(), and
systemidtype(). It keeps the shape the suite settled on: each source fix
is its own standalone commit, and the green test module lands last, so
the suite passes at every commit.

Four fixes come first, each independent of the others:

  - sizetype() accepted a leading minus, so "-1M" returned -1024 and
    "-5" returned -5120. A negative size is meaningless for every
    consumer (--size, --fixed-size, --offset, --extra-*-space, the empty
    source plugin's size=/bs=); reject it.
  - overheadtype()'s below-1.0 error path did "...message..." % arg with
    no %-placeholder, so every out-of-range value crashed with an opaque
    TypeError instead of the intended ArgumentTypeError. Add the missing
    placeholder.
  - overheadtype() let float('nan') and float('inf') slip past the < 1.0
    guard, which then multiplied the rootfs size by nan/inf downstream.
    Reject any non-finite factor up front.
  - systemidtype() converted with int(arg, 16), which also accepts a
    bare "82" (hex 130) and a signed "+0x82", contradicting its
    documented "hex between 0x1 and 0xFF" contract. Require an explicit
    0x prefix.

The final commit adds tests/unit/test_ksparser_types.py, covering the
three types' accepted forms, boundaries, and rejected inputs, and
locking in the four fixes. Backing any fix out turns the matching test
red. The suite is green at every commit and ruff-clean.

Trevor Woerner (5):
  ksparser: reject negative sizes in sizetype()
  ksparser: fix crash on out-of-range overhead factor
  ksparser: reject non-finite overhead factors
  ksparser: require an explicit 0x prefix for --system-id
  tests/unit/test_ksparser_types: cover ksparser's argparse types

 src/wic/ksparser.py               |  15 +-
 tests/unit/test_ksparser_types.py | 226 ++++++++++++++++++++++++++++++
 2 files changed, 236 insertions(+), 5 deletions(-)
 create mode 100644 tests/unit/test_ksparser_types.py

Comments

Paul Barker July 16, 2026, 7:37 a.m. UTC | #1
On Wed, 2026-07-15 at 18:32 -0400, Trevor Woerner via
lists.yoctoproject.org wrote:
> This series continues the standalone unit-test work, this time over the
> custom argparse types in ksparser.py: sizetype(), overheadtype(), and
> systemidtype(). It keeps the shape the suite settled on: each source fix
> is its own standalone commit, and the green test module lands last, so
> the suite passes at every commit.
> 
> Four fixes come first, each independent of the others:
> 
>   - sizetype() accepted a leading minus, so "-1M" returned -1024 and
>     "-5" returned -5120. A negative size is meaningless for every
>     consumer (--size, --fixed-size, --offset, --extra-*-space, the empty
>     source plugin's size=/bs=); reject it.
>   - overheadtype()'s below-1.0 error path did "...message..." % arg with
>     no %-placeholder, so every out-of-range value crashed with an opaque
>     TypeError instead of the intended ArgumentTypeError. Add the missing
>     placeholder.
>   - overheadtype() let float('nan') and float('inf') slip past the < 1.0
>     guard, which then multiplied the rootfs size by nan/inf downstream.
>     Reject any non-finite factor up front.
>   - systemidtype() converted with int(arg, 16), which also accepts a
>     bare "82" (hex 130) and a signed "+0x82", contradicting its
>     documented "hex between 0x1 and 0xFF" contract. Require an explicit
>     0x prefix.
> 
> The final commit adds tests/unit/test_ksparser_types.py, covering the
> three types' accepted forms, boundaries, and rejected inputs, and
> locking in the four fixes. Backing any fix out turns the matching test
> red. The suite is green at every commit and ruff-clean.
> 
> Trevor Woerner (5):
>   ksparser: reject negative sizes in sizetype()
>   ksparser: fix crash on out-of-range overhead factor
>   ksparser: reject non-finite overhead factors
>   ksparser: require an explicit 0x prefix for --system-id
>   tests/unit/test_ksparser_types: cover ksparser's argparse types
> 
>  src/wic/ksparser.py               |  15 +-
>  tests/unit/test_ksparser_types.py | 226 ++++++++++++++++++++++++++++++
>  2 files changed, 236 insertions(+), 5 deletions(-)
>  create mode 100644 tests/unit/test_ksparser_types.py

Hi Trevor,

This all looks good to me!

Reviewed-by: Paul Barker <paul@pbarker.dev>

Best regards,