Harden slide-alchemy asset validation#8
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the “slide-alchemy” asset/script validation layer by adding guard-rail checks to multiple CLI scripts (cropping, preview comparison, edge inspection, contact sheets, element analysis validation, and SVG→PPTX conversion) and introducing a regression test suite that executes these scripts via subprocess.
Changes:
- Add new
tests/test_script_guards.pyto assert scripts fail safely on malformed inputs (path traversal IDs, empty crops, empty dirs, size mismatch, bad JSON types). - Strengthen validation across several scripts (type checks for
slides/instances/components, bbox sanity checks, empty-directory checks, output directory creation, and stricter preview-size handling). - Extend
simple_svg_to_pptx.pywith diamond polygon support and fill-opacity handling.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_script_guards.py | Adds subprocess-based tests covering “guard” failures for multiple scripts. |
| skill/slide-alchemy/scripts/validate_element_analysis.py | Adds robust type checks for components, slides, and instances. |
| skill/slide-alchemy/scripts/slice_asset_sheet.py | Adds safe filename validation and bbox/crop sanity checks for sheet slicing. |
| skill/slide-alchemy/scripts/simple_svg_to_pptx.py | Adds diamond support, fill-opacity mapping, and ensures output directory exists. |
| skill/slide-alchemy/scripts/inspect_edges.py | Fails explicitly on empty input sets; marks empty images as failures. |
| skill/slide-alchemy/scripts/compose_component_pptx.py | Adds bbox consistency validation and ensures output directory exists. |
| skill/slide-alchemy/scripts/compare_preview.py | Fails fast on size mismatch (no auto-resize). |
| skill/slide-alchemy/scripts/build_contact_sheet.py | Validates non-empty input and positive column count; ensures output directory exists. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ) | ||
| crop = sheet.crop((l, t, r, b)) | ||
| if args.trim: | ||
| bbox = crop.getbbox() |
| tb = min(crop.height, bbox[3] + args.pad) | ||
| crop = crop.crop((tl, tt, tr, tb)) | ||
| crop.save(out / f"{item['id']}.png") | ||
| if crop.getbbox() is None: |
| def opacity_to_transparency(value): | ||
| if value is None: | ||
| return None | ||
| opacity = max(0.0, min(1.0, float(value))) | ||
| return int(round((1.0 - opacity) * 100)) |
| def is_diamond(points): | ||
| return len(points) == 4 |
| if "bbox_px" in item and "bbox_frac" in item: | ||
| px = item["bbox_px"] | ||
| frac = item["bbox_frac"] | ||
| expected = [px[0] / ref_w, px[1] / ref_h, px[2] / ref_w, px[3] / ref_h] | ||
| if any(abs(expected[i] - frac[i]) > BBOX_EPSILON for i in range(4)): | ||
| raise ValueError(f"inconsistent bbox_px and bbox_frac for {item.get('id', '?')!r}") | ||
|
|
| out = Path(args.output_dir) | ||
| out.mkdir(parents=True, exist_ok=True) | ||
| src = Image.open(args.source_png).convert("RGB") | ||
| prv = Image.open(args.preview_png).convert("RGB") | ||
| if prv.size != src.size: |
|
Thanks for the PR. The overall hardening direction is valuable, but I found a few remaining behavior issues during local testing, so I’m not ready to merge it yet. Could you please address these points first: use the alpha channel for transparent crop checks; support diamond polygons with a repeated closing point; return clear validation errors for malformed bbox values; avoid creating the output directory in compare_preview before validation succeeds; and verify that fill-opacity is correctly written into the generated PPTX. Also, please make sure the new tests are discoverable and runnable by the default test command. Once updated, I’ll test it again and merge if everything passes. |
No description provided.