Skip to content

Fix five real bugs found in an adversarial code-review pass - #24

Merged
luisriverag merged 1 commit into
mainfrom
claude/continue-port
Aug 29, 2026
Merged

luisriverag merged 1 commit into
mainfrom
claude/continue-port

Conversation

@luisriverag

@luisriverag luisriverag commented Aug 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adversarial code-review pass, in two rounds: the Edit Movie dialog (most recently changed code), then the higher-risk native.py/storage.py byte-parsing code. Five real bugs found, each verified empirically before and after the fix, each with a regression test confirmed to fail against the pre-fix code.

Round 1 — gui.py (Edit Movie dialog):

  1. Scrollbar floated away from its canvas. Its grid column also holds the Save button (a different row), which is wider — so the column widened to fit the button, and without an explicit horizontal sticky the scrollbar centered in that wider column instead of hugging the canvas edge. Verified with real Tk geometry introspection (winfo_x()/winfo_width()): a consistent 46px gap at 900px width, reproduced again at 500px. Fixed with sticky="nsw".
  2. A magic-string landmine. The "Checked" checkbox was attached to its group by matching the literal "Classification" against _EDIT_FIELD_GROUPS' titles in two separate places. Renaming that group anywhere would silently break dialog construction. Extracted _EDIT_CHECKED_GROUP_TITLE so both sites read from one constant.

Round 2 — storage.py (interchange formats):

  1. copy_catalog silently corrupted every XML/CSV backup/restore. It validates through a same-directory temporary file whose name is always a UUID-qualified .tmp (unique_temporary_path), never the catalog's real suffix. load()'s dispatch is suffix-based for everything except native .amc (content-sniffed) and JSON (the fallback) — so a byte-identical copy of a valid XML or CSV catalog was always misread as JSON and rejected with a JSONDecodeError. amc backup/amc restore (and the desktop's Backup/Restore actions) were completely broken for any catalog opened directly from .xml or .csv. Fixed with an explicit suffix_hint parameter on load(), passed as the source's own suffix.
  2. Invalid CSS in every default HTML export. The built-in default template is a plain string substituted with .replace(), not str.format() — the doubled braces in its CSS (body{{font-family:...}}) were never collapsed to single braces, so every default (no custom template) export shipped literally invalid CSS: unstyled tables, no borders, no header background. Fixed by writing the CSS with single braces.
  3. _camel_to_snake/_snake_to_camel were not true inverses. _snake_to_camel already special-cased renames a generic regex can't produce (extension↔Ext, field_type↔Type, gui_properties↔GUIProperties, etc.), but _camel_to_snake had no matching table — it inserted an underscore before every capital letter unconditionally, turning GUIProperties into g_u_i_properties. A native-loaded catalog stores this under the correct gui_properties key, so exporting it to XML silently dropped the GUIProperties/Type/etc. attributes — masked in every existing test because an XML-to-XML round trip applies the same broken function on both sides and agrees with itself on the wrong key. Fixed by giving _camel_to_snake the same special-case table, inverted, falling back to an acronym-aware regex otherwise.

Verified but not fixed, flagged for a separate decision: write_native_catalog base64-decodes every movie's (and supplementary record's) picture twice per save — once during pre-write budget validation, once again inside _write_movie_42. Confirmed real via code inspection, but it's a performance-only issue (same bytes, decoded twice — no functional bug) on a well-tested, budget-sensitive hot path. Didn't want to restructure that code without a separate check-in.

Test plan

  • test_edit_dialog_scrollbar_has_no_gap_from_its_canvas — confirmed to fail against the pre-fix code (reproducing the exact 46px gap) and pass against the fix.
  • test_copy_catalog_validates_non_json_formats_by_their_real_suffix (parametrized XML/CSV) — confirmed to fail with the original JSONDecodeError against the pre-fix code.
  • test_html_export_default_template_has_valid_css — confirmed to fail (doubled braces present) against the pre-fix code.
  • Strengthened test_xml_roundtrip_preserves_catalog_and_custom_field_metadata to assert exact key names (gui_properties, field_type), not just XML-to-XML self-consistency.
  • Added test_xml_export_writes_gui_properties_from_a_native_loaded_catalog — a cross-format case a self-consistent-but-wrong round trip cannot satisfy.
  • tools/check.py — 670 tests pass, ruff/mypy/format clean, 88% coverage.

…alog

1. The scrollbar visibly floated ~46px away from the canvas it scrolls at
   any dialog width. Its grid column also holds the Save button (a
   different row), which is wider than the scrollbar itself, so the
   column widens to fit the button — and without an explicit horizontal
   sticky, the scrollbar centered in that wider column instead of hugging
   the canvas. Fixed by sticking it to the column's west edge, verified
   empirically at two widths (900px, 500px) via real Tk geometry
   introspection, not visual inspection.

2. The "Checked" checkbox was attached to its group by matching the
   literal string "Classification" against _EDIT_FIELD_GROUPS' titles in
   two separate places. Renaming that group anywhere would silently break
   dialog construction (an assert failure, or a bare TclError under
   python -O). Extracted _EDIT_CHECKED_GROUP_TITLE so both sites read from
   one constant that can't desync.

Added a regression test for (1), confirmed to fail against the
pre-fix code and pass against the fix.
@luisriverag
luisriverag merged commit a400938 into main Aug 29, 2026
0 of 16 checks passed
@luisriverag luisriverag changed the title Fix two real bugs found in an adversarial review of the Edit Movie dialog Fix five real bugs found in an adversarial code-review pass Aug 30, 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.

2 participants