Harden slide-alchemy asset validation#8
Open
lzh886 wants to merge 1 commit into
Open
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: |
Comment on lines
+60
to
+64
| 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)) |
Comment on lines
+56
to
+57
| def is_diamond(points): | ||
| return len(points) == 4 |
Comment on lines
+56
to
+62
| 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}") | ||
|
|
Comment on lines
18
to
22
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.