Skip to content

Fix comparison bugs and modernize#15

Merged
andiwand merged 1 commit into
mainfrom
fix-bugs-and-cleanup
Jul 4, 2026
Merged

Fix comparison bugs and modernize#15
andiwand merged 1 commit into
mainfrom
fix-bugs-and-cleanup

Conversation

@andiwand

@andiwand andiwand commented Jul 4, 2026

Copy link
Copy Markdown
Member

Bug fixes, a server threading fix, and small cleanups found while auditing the codebase. All 3 tests pass (including the Chrome/Firefox render tests), and each fix was verified end-to-end.

Bugs

  • False "identical" matches (common.py): filecmp.cmp defaulted to shallow=True, comparing only os.stat (size + mtime) rather than content. Two differently-rendered files with matching stat signatures compared as equal, silently skipping the render diff that is the whole point of the tool. Now shallow=False. Reproduced and confirmed fixed.
  • --driver none crash (common.py): with no browser, a byte-differing HTML file routed into compare_html, whose fallback get_browser() was called with no driver argument (required) → confusing TypeError, contradicting the documented "compares only JSON and byte-identical files". The no-browser case now reports such files as different (they already differ at the byte level and can't be rendered). The broken auto-create fallback is also repaired for direct callers.
  • --max-width/--max-height crashed when passed (html_render_diff.py): missing type=int, so values arrived as strings and tripped the isinstance(..., int) guard in get_browser. Defaults worked; only explicit use was broken.
  • Wrong Python floor (pyproject.toml): declared >=3.7, but the code uses PEP 604 unions (str | None) as runtime-evaluated annotations, which need ≥3.10 — the package wouldn't import on 3.7–3.9. Bumped to >=3.10.

Server

  • Thread-unsafe shared browser (compare_output_server.py): the single Config.browser is used from Flask's threaded request handlers in /image_diff; Selenium drivers aren't thread-safe, so concurrent diff requests could interleave on one driver. Access is now serialized with a lock.
  • --host wired through args: the bind host was hardcoded to 0.0.0.0; it's now a --host argument (default kept at 0.0.0.0 so the Docker use-case still works).

Cleanups

  • Simplified a redundant True if … else False and the awkward name→path reconstruction loops in tidy_output.py.

🤖 Generated with Claude Code

Bug fixes:
- common.py: use filecmp.cmp(shallow=False) so files with matching
  size+mtime but different content are no longer falsely reported as
  identical, which would skip the render diff entirely.
- common.py: --driver none no longer crashes on byte-differing HTML.
  The no-browser case now reports such files as different (they already
  differ at the byte level and cannot be rendered) instead of raising a
  confusing TypeError from get_browser() called without a driver.
- html_render_diff.py: add type=int to --max-width/--max-height, which
  otherwise arrived as strings and failed the int type check in
  get_browser().
- pyproject.toml: bump requires-python to >=3.10; the code uses PEP 604
  unions (str | None) as runtime-evaluated annotations, so it cannot
  import on 3.7-3.9.

Server:
- compare_output_server.py: serialize access to the single shared
  Selenium browser with a lock; Flask serves /image_diff from a thread
  pool and webdrivers are not thread-safe.
- compare_output_server.py: wire the bind host through a --host argument
  (default 0.0.0.0) instead of hardcoding it.

Cleanups:
- Simplify a redundant boolean and tidy_output.py's file/dir loops.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SujCMUVctCunqAft7ttLFd
@andiwand andiwand merged commit 9572a9e into main Jul 4, 2026
6 checks passed
@andiwand andiwand deleted the fix-bugs-and-cleanup branch July 4, 2026 20:44
@andiwand andiwand mentioned this pull request Jul 5, 2026
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