Skip to content

Harden slide-alchemy asset validation#8

Open
lzh886 wants to merge 1 commit into
CodingFeng101:mainfrom
lzh886:main
Open

Harden slide-alchemy asset validation#8
lzh886 wants to merge 1 commit into
CodingFeng101:mainfrom
lzh886:main

Conversation

@lzh886

@lzh886 lzh886 commented Jun 20, 2026

Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings June 20, 2026 03:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py to 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.py with 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:
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