Skip to content

fix(render_gui): reject an odd count of width/height arguments - #200

Closed
harsh-thakkar7 wants to merge 2 commits into
LeyckerS:mainfrom
harsh-thakkar7:fix/render-gui-odd-size-args
Closed

harsh-thakkar7 wants to merge 2 commits into
LeyckerS:mainfrom
harsh-thakkar7:fix/render-gui-odd-size-args

Conversation

@harsh-thakkar7

@harsh-thakkar7 harsh-thakkar7 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

python render_gui.py shots 1440 — any odd count of trailing width/height arguments — silently produced zero screenshots and exited 0, printing [OK] as if the page had rendered fine.

The arg loop range(0, len(raw) - 1, 2) just drops the unpaired last value (or everything, when only one is given):

$ python render_gui.py shots 1440
[OK]
$ echo $?   # 0 — and the shots/ dir is empty

Because web-syntax-check.yml runs render_gui.py as a quality gate on every web change, a size list this tool silently misreads is a gate that can turn green without anyone having looked at a single viewport. A typo'd CI invocation would ship a visually broken GUI.

Fix

main() now validates the argument count before doing anything: an odd count prints an explicit width×height pairs error to stderr and exits 2, so a malformed invocation can no longer masquerade as a passed render check.

$ python render_gui.py shots 1440
error: sizes come in width×height pairs; odd argument count ['1440']
$ echo $?   # 2

Tests

New tests/test_render_gui_args.py (4 tests): odd counts (1 and 3 args) are refused with exit 2 and shoot() never runs; paired sizes pass through unchanged; no-arg runs still use the default viewports. The duff test fails on origin/main (it returns 0 and shoots []). Full suite 174 passed; ruff clean. Five mutants of the guard (removed check, inverted polarity, kept exit-0, wrong modulus, suppressed message) are all killed.

Note

The two playwright imports now happen inside shoot(), so the argument validation — and tests importing render_gui — work in the pytest CI job, which does not install the browser driver.

`render_gui.py shots 1440` — or any odd number of trailing arguments —
silently built an empty viewport list: the range() pair loop drops the
last size, so main() called shoot(out, []) and exited 0 after printing
"[OK]" with zero screenshots. The web CI gate (web-syntax-check.yml)
would then report a green render for a page nobody looked at.

main() now refuses an odd argument count with a usage error (exit 2)
before any rendering happens. Four tests in tests/test_render_gui_args.py
cover the odd-count refusal, a trailing-size round trip, and the default
viewport pair; five mutants of the guard are all killed.
main() only needs the browser stack when it actually renders, but the
two playwright imports ran at import time, so the module could not be
imported without the driver installed -- which the pytest job does not
do. That made the argument validation (and its tests) unimportable in
CI. The imports now live inside shoot(), where they are used.
@harsh-thakkar7

Copy link
Copy Markdown
Contributor Author

Closing this one for now — happy to reopen or resubmit if it's still useful.

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