Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

fix(edit-native): support explicit Morph pairs whose endpoint page is unchanged

hugohe3604ecdec8dd6
diff --git a/skills/ppt-master/scripts/docs/pptx-transitions.md b/skills/ppt-master/scripts/docs/pptx-transitions.md
index 6800072d..e9db0cb3 100644
--- a/skills/ppt-master/scripts/docs/pptx-transitions.md
+++ b/skills/ppt-master/scripts/docs/pptx-transitions.md
@@ -212,7 +212,7 @@ failure rather than a silent downgrade.
### 3.2 Deterministic Morph Identity
-The generated route may add an explicit `slides.<destination>.morph` block to
+Generate and Edit Native PPTX may add an explicit `slides.<destination>.morph` block to
bind direct-root SVG groups across adjacent slides. The sidecar stable key is
lowered to the same top-level `p:cNvPr@name="!!<key>"` on both final
Slide-local objects. This does not create an Animation Pane row and does not
@@ -231,8 +231,14 @@ roster expectations are then refreshed. Package read-back requires:
undeclared shared `!!` name on a Morph edge.
Morph without an explicit pair block retains PowerPoint's automatic matching
-behavior. Explicit pairing is generated-route authoring; source-preserving
-round-trip export keeps existing object names and transition XML.
+behavior. Round-trip export preserves source names unless an explicit pair
+assigns a new identity. An endpoint on an unchanged page resolves through its
+imported Slide-local shape id and counts as `patched`, including planned copies.
+When only identity changes, export replaces only the `cNvPr@name` attribute
+value; every other slide XML byte and its relationships stay unchanged. Notes
+and requested motion remain separate overlays. An endpoint without a unique
+native identity fails with its page/object and instructions to edit that page
+as well or pair two edited pages.
---
diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py
index 4308b492..3bf5170f 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py
@@ -21,6 +21,7 @@ from datetime import datetime, timezone
from pathlib import Path, PurePosixPath, PureWindowsPath
from typing import Any
from xml.etree import ElementTree as ET
+from xml.parsers import expat
from xml.sax.saxutils import escape, quoteattr
from pptx import Presentation
@@ -606,11 +607,94 @@ def _set_shape_name(elem: ET.Element, name: str) -> None:
)
+def _roundtrip_morph_shape_ids(svg_path: Path, group_ids: set[str]) -> dict[tuple[str, str], int]:
+ """Resolve preserved endpoints from imported identity, never SVG id spelling."""
+ if not group_ids:
+ return {}
+ root = ET.parse(svg_path).getroot()
+ result: dict[tuple[str, str], int] = {}
+ for group_id in sorted(group_ids):
+ groups = [node for node in root if node.tag == '{http://www.w3.org/2000/svg}g'
+ and node.get('id') == group_id]
+ shape_id = groups[0].get('data-pptx-shape-id', '') if len(groups) == 1 else ''
+ if (not shape_id.isdecimal()
+ or groups[0].get('data-pptx-shape-scope') != 'slide'):
+ raise TemplateStructureError(
+ f'Morph target "{svg_path.stem}/{group_id}" has no unique imported '
+ 'Slide-local shape identity; edit this endpoint page as well, or '
+ 'pair groups on two edited pages'
+ )
+ result[(svg_path.stem, group_id)] = int(shape_id)
+ return result
+
+
+_XML_START_TAG_RE = re.compile(r'''<(?:"[^"]*"|'[^']*'|[^'">])*>''')
+_XML_ATTRIBUTE_RE = re.compile(r'''\s+([^\s=/>]+)\s*=\s*(["'])(.*?)\2''', re.DOTALL)
+
+
+def _patch_morph_name_bytes(
+ source: bytes,
+ assignments: dict[str, tuple[str, str]],
+ slide_number: int,
+) -> bytes:
+ """Replace only cNvPr name values, retaining all other source XML bytes."""
+ parser = expat.ParserCreate(namespace_separator='}')
+ offsets: dict[str, list[tuple[int, str | None]]] = {}
+ encoding = 'utf-8'
+
+ def declaration(_version: str, declared_encoding: str | None, _standalone: int) -> None:
+ nonlocal encoding
+ encoding = declared_encoding or encoding
+
+ def start(name: str, attributes: dict[str, str]) -> None:
+ shape_id = attributes.get('id')
+ if name == f'{PML_NS}}}cNvPr' and shape_id in assignments:
+ offsets.setdefault(shape_id, []).append((parser.CurrentByteIndex, attributes.get('name')))
+
+ parser.XmlDeclHandler = declaration
+ parser.StartElementHandler = start
+ parser.Parse(source, True)
+ # Byte offsets come from Expat; encode individual spans without a BOM.
+ if source.startswith((b'\xff\xfe', b'<\x00')):
+ encoding = 'utf-16-le'
+ elif source.startswith((b'\xfe\xff', b'\x00<')):
+ encoding = 'utf-16-be'
+ replacements: list[tuple[int, int, bytes]] = []
+ for shape_id, (name, group_id) in assignments.items():
+ locations = offsets.get(shape_id, [])
+ error = (
+ f'Morph target "{group_id}" on slide {slide_number} cannot patch '
+ f'cNvPr@name for source shape {shape_id} without rewriting XML; '
+ 'edit this endpoint page as well, or pair groups on two edited pages'
+ )
+ if len(locations) != 1:
+ raise TemplateStructureError(error)
+ offset, existing_name = locations[0]
+ if existing_name == name:
+ continue
+ tag = _XML_START_TAG_RE.match(source[offset:].decode(encoding))
+ attribute = next(
+ (match for match in _XML_ATTRIBUTE_RE.finditer(tag.group()) if match[1] == 'name'),
+ None,
+ ) if tag is not None else None
+ if attribute is None:
+ raise TemplateStructureError(error)
+ start_offset = offset + len(tag.group()[:attribute.start(3)].encode(encoding))
+ end_offset = offset + len(tag.group()[:attribute.end(3)].encode(encoding))
+ escaped = escape(name, {'"': '&quot;', "'": '&apos;'})
+ replacements.append((start_offset, end_offset, escaped.encode(encoding, errors='xmlcharrefreplace')))
+ for start_offset, end_offset, value in sorted(replacements, reverse=True):
+ source = source[:start_offset] + value + source[end_offset:]
+ return source
+
+
def _apply_morph_shape_names(
extract_dir: Path,
pairs: tuple[MorphPair, ...],
slide_numbers: dict[str, int],
shape_ids: dict[tuple[str, str], int],
+ *,
+ preserved_slides: set[int],
) -> dict[int, dict[str, str]]:
"""Write forced-Morph names after all structure transformations finish."""
assignments: dict[int, dict[str, tuple[str, str]]] = {}
@@ -621,14 +705,21 @@ def _apply_morph_shape_names(
(pair.destination_slide, pair.destination_group_id),
):
slide_number = slide_numbers[slide_name]
- shape_id = str(shape_ids[(slide_name, group_id)])
+ resolved_id = shape_ids.get((slide_name, group_id))
+ if resolved_id is None:
+ raise TemplateStructureError(
+ f'Morph target "{slide_name}/{group_id}" has no exported '
+ 'Slide-local shape identity; edit this endpoint page as well, '
+ 'or pair groups on two edited pages'
+ )
+ shape_id = str(resolved_id)
slide_assignments = assignments.setdefault(slide_number, {})
previous = slide_assignments.setdefault(
shape_id,
(pair.shape_name, group_id),
)
if previous[0] != pair.shape_name:
- raise RuntimeError(
+ raise TemplateStructureError(
f'Morph target "{slide_name}/{group_id}" resolves to shape '
f'{shape_id} with conflicting names "{previous[0]}" and '
f'"{pair.shape_name}"'
@@ -636,7 +727,7 @@ def _apply_morph_shape_names(
slide_names = names_by_slide.setdefault(slide_number, {})
previous_group = slide_names.setdefault(pair.shape_name, group_id)
if previous_group != group_id:
- raise RuntimeError(
+ raise TemplateStructureError(
f'Morph name "{pair.shape_name}" maps to multiple objects '
f'on slide "{slide_name}"'
)
@@ -661,7 +752,7 @@ def _apply_morph_shape_names(
c_nv_pr.get("name") if c_nv_pr is not None else None
)
if existing_name in desired_names:
- raise RuntimeError(
+ raise TemplateStructureError(
f'Morph name "{existing_name}" already belongs to an '
f'unmapped object on slide {slide_number}'
)
@@ -669,13 +760,18 @@ def _apply_morph_shape_names(
for shape_id, (shape_name, group_id) in slide_assignments.items():
shape = top_level_shapes.get(shape_id)
if shape is None:
- raise RuntimeError(
+ raise TemplateStructureError(
f'Morph target "{group_id}" no longer resolves to a '
f'Slide-local shape on slide {slide_number}'
)
_set_shape_name(shape, shape_name)
trace_names.setdefault(slide_number, {})[group_id] = shape_name
- _write_xml_tree(slide_path, tree)
+ if slide_number in preserved_slides:
+ slide_path.write_bytes(_patch_morph_name_bytes(
+ slide_path.read_bytes(), slide_assignments, slide_number,
+ ))
+ else:
+ _write_xml_tree(slide_path, tree)
return trace_names
@@ -6892,6 +6988,7 @@ def create_pptx_with_native_svg(
set(),
).add(pair.destination_group_id)
morph_shape_ids: dict[tuple[str, str], int] = {}
+ morph_preserved_slides: set[int] = set()
if definition_svg_files and pptx_structure != "structured":
raise ValueError(
"unselected Layout prototypes require pptx_structure='structured'"
@@ -7305,6 +7402,10 @@ def create_pptx_with_native_svg(
raise TemplateStructureError(
"Internal Layout definitions cannot use source-slide passthrough"
)
+ morph_shape_ids.update(_roundtrip_morph_shape_ids(
+ svg_path, morph_group_overrides_by_slide.get(svg_path.stem, set()),
+ ))
+ morph_preserved_slides.add(slide_num)
if verbose:
print(
f" {progress_label} {svg_path.name} "
@@ -7422,21 +7523,25 @@ def create_pptx_with_native_svg(
continue
if (
slide_patch is not None
- and slide_patch.notes_changed
and not slide_patch.visual_changed
and not slide_patch.motion_changed
+ and (slide_patch.notes_changed or morph_group_overrides_by_slide.get(svg_path.stem))
):
- notes_content = (
- notes.get(svg_path.stem, '') if notes else ''
- )
- notes_master = _apply_slide_notes(
- extract_dir,
- rels_path,
- slide_num,
- notes_content,
- primary_language,
- enable_notes=enable_notes,
- )
+ morph_shape_ids.update(_roundtrip_morph_shape_ids(
+ svg_path, morph_group_overrides_by_slide.get(svg_path.stem, set()),
+ ))
+ morph_preserved_slides.add(slide_num)
+ notes_master = None
+ if slide_patch.notes_changed:
+ notes_content = notes.get(svg_path.stem, '') if notes else ''
+ notes_master = _apply_slide_notes(
+ extract_dir,
+ rels_path,
+ slide_num,
+ notes_content,
+ primary_language,
+ enable_notes=enable_notes,
+ )
if notes_master is not None:
notes_slides_created.add(slide_num)
notes_master_parts_used.add(notes_master.package_part)
@@ -7447,7 +7552,7 @@ def create_pptx_with_native_svg(
if verbose:
print(
f" {progress_label} {svg_path.name} "
- "(Source slide notes overlay)"
+ "(Source slide notes / identity overlay)"
)
success_count += 1
continue
@@ -8339,6 +8444,7 @@ def create_pptx_with_native_svg(
morph_pairs,
public_slide_numbers,
morph_shape_ids,
+ preserved_slides=morph_preserved_slides,
)
if template_shape_roster_expectations is not None:
for slide_number in morph_trace_names:
diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py
index 4ca3b066..c17252d1 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py
@@ -134,6 +134,7 @@ from .template_structure import (
from ..animation_config import (
animation_group_effect_entries,
load_animation_config,
+ resolve_morph_pairs,
resolve_slide_animation_config,
validate_animation_config,
validate_animation_config_errors,
@@ -440,6 +441,18 @@ def _roundtrip_passthrough_candidates(
current_animation_config,
pages,
)
+ # Explicit identity edits also touch the source endpoint, whose own motion
+ # row may still match the import baseline. Classify both ends as patches.
+ morph_slides = {
+ stem
+ for pair in resolve_morph_pairs(
+ [page.svg_stem for page in pages], expanded_animation_config,
+ )
+ for stem in (pair.source_slide, pair.destination_slide)
+ }
+ candidates.difference_update(
+ page.output_index for page in pages if page.svg_stem in morph_slides
+ )
pages_by_output = {page.output_index: page for page in pages}
for index in tuple(candidates):
page = pages_by_output[index]
@@ -2892,7 +2905,7 @@ Recorded narration:
authoring_report=authoring_roundtrip_report,
changed_resource_pages=changed_resource_pages,
)
- except RuntimeError as exc:
+ except (RuntimeError, ValueError) as exc:
print(f"Error: {exc}", file=sys.stderr)
return 1
if roundtrip_passthrough_slides:
diff --git a/skills/ppt-master/scripts/tests/test_roundtrip_morph_passthrough.py b/skills/ppt-master/scripts/tests/test_roundtrip_morph_passthrough.py
new file mode 100644
index 00000000..21e4afa0
--- /dev/null
+++ b/skills/ppt-master/scripts/tests/test_roundtrip_morph_passthrough.py
@@ -0,0 +1,278 @@
+#!/usr/bin/env python3
+"""PPT Master - Round-trip Morph Passthrough Regression Tests
+
+Exercise explicit pairing through the public exporter with preserved endpoints.
+
+Usage:
+ python3 -m unittest tests.test_roundtrip_morph_passthrough
+
+Examples:
+ Run the module from the scripts directory.
+
+Dependencies:
+ Standard library and the local PPTX/SVG converters.
+"""
+
+from __future__ import annotations
+
+import io
+import json
+import tempfile
+import unittest
+from contextlib import redirect_stderr, redirect_stdout
+from pathlib import Path
+from xml.etree import ElementTree as ET
+from xml.sax.saxutils import escape
+from zipfile import ZIP_DEFLATED, ZipFile
+
+from pptx_to_svg.converter import ConvertOptions, convert_pptx_to_svg
+from pptx_transitions import MorphPairExpectation, validate_pptx_morph_pairs
+from svg_to_pptx.pptx_package.builder import create_pptx_with_native_svg
+from svg_to_pptx.pptx_package.cli import main
+
+
+NS = {
+ 's': 'http://www.w3.org/2000/svg',
+ 'p': 'http://schemas.openxmlformats.org/presentationml/2006/main',
+}
+
+
+class RoundtripMorphPassthroughTests(unittest.TestCase):
+ def setUp(self) -> None:
+ temporary = tempfile.TemporaryDirectory()
+ self.addCleanup(temporary.cleanup)
+ self.root = Path(temporary.name)
+ self.workspace = self.root / 'workspace'
+ self.key = 'hero'
+
+ def _import(
+ self, *, count: int = 2, formatted: bool = False, encoding: str = 'utf-8',
+ transition: str | None = 'morph', collision: bool = False,
+ ) -> None:
+ files = []
+ for index in range(1, count + 1):
+ path = self.root / f'page_{index:02}.svg'
+ path.write_text(
+ f'<svg xmlns="{NS["s"]}" viewBox="0 0 960 540" lang="en-US">'
+ '<g id="hero" data-pptx-bounds="50 50 100 80">'
+ '<rect x="50" y="50" width="100" height="80" fill="#123456"/>'
+ '<rect x="60" y="60" width="20" height="20" fill="#ABCDEF"/></g>'
+ '<g id="other" data-pptx-bounds="250 50 100 80">'
+ '<rect x="250" y="50" width="100" height="80" fill="#654321"/>'
+ '<rect x="260" y="60" width="20" height="20" fill="#FEDCBA"/></g>'
+ '</svg>', encoding='utf-8',
+ )
+ files.append(path)
+ source = self.root / 'source.pptx'
+ with redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()):
+ self.assertTrue(create_pptx_with_native_svg(
+ files, source, resource_root=self.root, pptx_structure='flat',
+ use_compat_mode=False, transition=transition, workers=1, verbose=False,
+ ))
+ with ZipFile(source) as archive:
+ parts = {name: archive.read(name) for name in archive.namelist()}
+ for index in range(1, count + 1):
+ part = f'ppt/slides/slide{index}.xml'
+ xml = parts[part].decode('utf-8')
+ original_id = next(node.get('id') for node in ET.fromstring(xml).findall('.//p:cNvPr', NS)
+ if node.get('name') == 'hero')
+ xml = xml.replace(f'id="{original_id}" name="hero"', 'id="29" name="hero"')
+ if collision:
+ xml = xml.replace('name="other"', 'name="!!hero"')
+ if formatted:
+ xml = xml.replace('xmlns:p=', 'xmlns:z=').replace('<p:', '<z:').replace('</p:', '</z:')
+ xml = xml.replace('name="hero"', 'descr="literal > name=\'decoy\'" name = \'hero\'')
+ xml = xml.replace('</z:spTree>', '<!-- <z:cNvPr id="29" name="decoy"/> --></z:spTree>')
+ xml = xml.replace('><', '>\r\n<')
+ if encoding != 'utf-8':
+ xml = xml.replace('encoding="UTF-8"', f'encoding="{encoding}"')
+ xml = xml.replace("encoding='utf-8'", f"encoding='{encoding}'")
+ parts[part] = xml.encode(encoding)
+ with ZipFile(source, 'w', ZIP_DEFLATED) as archive:
+ for name, payload in parts.items():
+ archive.writestr(name, payload)
+ self.source_parts = parts
+ with redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()):
+ convert_pptx_to_svg(
+ source, self.workspace, ConvertOptions(inheritance_mode='both', roundtrip=True),
+ )
+
+ def _pair(self, *, count: int = 2, stems: list[str] | None = None) -> None:
+ stems = stems or [f'slide_{index:02}' for index in range(1, count + 1)]
+ path = self.workspace / 'animations.json'
+ config = json.loads(path.read_text(encoding='utf-8'))
+ for source, destination in zip(stems, stems[1:]):
+ row = config['slides'].setdefault(destination, {})
+ row.setdefault('transition', {'effect': 'morph', 'duration': 0.6})
+ row['morph'] = {'from': source, 'pairs': {self.key: {'from': 'shape-29', 'to': 'shape-29'}}}
+ path.write_text(json.dumps(config), encoding='utf-8')
+
+ def _edit(self, index: int) -> None:
+ path = self.workspace / 'authoring-svg-flat' / f'slide_{index:02}.svg'
+ source = path.read_text(encoding='utf-8')
+ self.assertIn('#123456', source)
+ path.write_text(source.replace('#123456', '#135790'), encoding='utf-8')
+
+ def _export(self, *flags: str, expected_exit: int = 0) -> dict[str, bytes]:
+ path = self.root / 'output.pptx'
+ stdout, stderr = io.StringIO(), io.StringIO()
+ with redirect_stdout(stdout), redirect_stderr(stderr):
+ result = main([str(self.workspace), '--roundtrip', '-o', str(path), *flags])
+ self.stdout, self.stderr = stdout.getvalue(), stderr.getvalue()
+ self.assertEqual(result, expected_exit, self.stdout + self.stderr)
+ self.assertNotIn('Traceback', self.stderr)
+ if expected_exit:
+ self.assertFalse(path.exists())
+ return {}
+ self.output = path
+ report = json.loads((self.workspace / 'validation/output.report.json').read_text(encoding='utf-8'))
+ self.summary = report['source']['authoring_roundtrip']['export_summary']
+ with ZipFile(path) as archive:
+ return {name: archive.read(name) for name in archive.namelist()}
+
+ def _assert_names(self, parts: dict[str, bytes], count: int = 2) -> None:
+ for index in range(1, count + 1):
+ root = ET.fromstring(parts[f'ppt/slides/slide{index}.xml'])
+ names = [node.get('name') for node in root.findall('.//p:cNvPr', NS) if node.get('id') == '29']
+ self.assertEqual(names, ['!!' + self.key])
+ validate_pptx_morph_pairs(self.output, [
+ MorphPairExpectation(index, index + 1, self.key) for index in range(1, count)
+ ])
+
+ def _assert_only_name_changed(
+ self, parts: dict[str, bytes], index: int, *, formatted: bool = False, encoding: str = 'utf-8',
+ ) -> None:
+ part = f'ppt/slides/slide{index}.xml'
+ old = "name = 'hero'" if formatted else 'name="hero"'
+ quoted = escape('!!' + self.key, {'"': '&quot;', "'": '&apos;'})
+ new = f"name = '{quoted}'" if formatted else f'name="{quoted}"'
+ # Replace the known fixture attribute, without reserializing either side.
+ codec = 'utf-16-le' if encoding == 'UTF-16' else encoding
+ self.assertEqual(parts[part], self.source_parts[part].replace(old.encode(codec), new.encode(codec)))
+ rels = f'ppt/slides/_rels/slide{index}.xml.rels'
+ self.assertEqual(parts[rels], self.source_parts[rels])
+
+ def test_preserved_source_and_rebuilt_destination(self) -> None:
+ self._import()
+ self._edit(2)
+ self._pair()
+ parts = self._export()
+ self._assert_names(parts)
+ self._assert_only_name_changed(parts, 1)
+ self.assertEqual(self.summary, {
+ 'output_pages': 2, 'passthrough': 0, 'cloned_passthrough': 0, 'patched': 1, 'rebuilt': 1,
+ })
+ self.assertIn('patched=1 rebuilt=1', self.stdout)
+
+ def test_rebuilt_source_and_preserved_destination(self) -> None:
+ self._import()
+ self._edit(1)
+ self._pair()
+ parts = self._export()
+ self._assert_names(parts)
+ self._assert_only_name_changed(parts, 2)
+ self.assertEqual((self.summary['patched'], self.summary['rebuilt']), (1, 1))
+
+ def test_both_preserved_with_escaped_name_and_original_markup(self) -> None:
+ self._import(formatted=True)
+ self.key = '身份 & "quote" <tag> \'single\''
+ self._pair()
+ parts = self._export()
+ self._assert_names(parts)
+ for index in (1, 2):
+ self._assert_only_name_changed(parts, index, formatted=True)
+ self.assertEqual((self.summary['patched'], self.summary['rebuilt']), (2, 0))
+
+ def test_preserved_utf16_xml_keeps_encoding_and_bytes(self) -> None:
+ self._import(encoding='UTF-16')
+ self._pair()
+ parts = self._export()
+ self._assert_names(parts)
+ for index in (1, 2):
+ self._assert_only_name_changed(parts, index, encoding='UTF-16')
+
+ def test_chain_patches_middle_endpoint_once(self) -> None:
+ self._import(count=3)
+ self._edit(3)
+ self._pair(count=3)
+ parts = self._export()
+ self._assert_names(parts, count=3)
+ for index in (1, 2):
+ self._assert_only_name_changed(parts, index)
+ self.assertEqual((self.summary['patched'], self.summary['rebuilt']), (2, 1))
+
+ def test_planned_copy_is_patched_by_output_identity(self) -> None:
+ self._import()
+ directory = self.workspace / 'authoring-svg-flat'
+ (directory / 'copy.svg').write_bytes((directory / 'slide_01.svg').read_bytes())
+ (self.workspace / 'page_plan.json').write_text(json.dumps({
+ 'schema': 'ppt-master.roundtrip-page-plan.v1',
+ 'pages': [{'source_slide': 1, 'svg': 'copy.svg'}, {'source_slide': 2}],
+ }), encoding='utf-8')
+ self._pair(stems=['copy', 'slide_02'])
+ self._edit(2)
+ parts = self._export()
+ self._assert_names(parts)
+ # Clone relationship targets have their own names; slide XML is still exact.
+ self.assertEqual(parts['ppt/slides/slide1.xml'], self.source_parts['ppt/slides/slide1.xml'].replace(
+ b'name="hero"', b'name="!!hero"',
+ ))
+ self.assertEqual((self.summary['cloned_passthrough'], self.summary['patched']), (0, 1))
+
+ def test_no_explicit_morph_preserves_source_xml(self) -> None:
+ self._import(transition=None)
+ parts = self._export()
+ for index in (1, 2):
+ part = f'ppt/slides/slide{index}.xml'
+ self.assertEqual(parts[part], self.source_parts[part])
+ self.assertEqual((self.summary['passthrough'], self.summary['patched']), (2, 0))
+
+ def test_new_transition_preserves_source_endpoint_bytes(self) -> None:
+ self._import(transition=None)
+ self._pair()
+ parts = self._export()
+ self._assert_names(parts)
+ self._assert_only_name_changed(parts, 1)
+ self.assertEqual((self.summary['patched'], self.summary['rebuilt']), (2, 0))
+
+ def test_notes_overlay_and_pairing_keep_slide_bytes(self) -> None:
+ self._import()
+ self._pair()
+ notes = self.workspace / 'notes'
+ notes.mkdir(exist_ok=True)
+ (notes / 'slide_01.md').write_text('New speaker note.', encoding='utf-8')
+ parts = self._export()
+ self._assert_names(parts)
+ self.assertEqual(parts['ppt/slides/slide1.xml'], self.source_parts['ppt/slides/slide1.xml'].replace(
+ b'name="hero"', b'name="!!hero"',
+ ))
+ self.assertTrue(any(b'New speaker note.' in payload for name, payload in parts.items()
+ if name.startswith('ppt/notesSlides/')))
+ self.assertEqual((self.summary['patched'], self.summary['rebuilt']), (2, 0))
+
+ def test_name_collision_fails_without_traceback_or_delivery(self) -> None:
+ self._import(collision=True)
+ self._pair()
+ self._export(expected_exit=1)
+ self.assertIn('!!hero', self.stderr)
+ self.assertIn('unmapped object on slide 1', self.stderr)
+
+ def test_both_rebuilt_remain_supported(self) -> None:
+ self._import()
+ self._edit(1)
+ self._edit(2)
+ self._pair()
+ parts = self._export()
+ self._assert_names(parts)
+ self.assertEqual((self.summary['patched'], self.summary['rebuilt']), (0, 2))
+
+ def test_invalid_pair_fails_without_traceback_or_delivery(self) -> None:
+ self._import()
+ self._pair()
+ path = self.workspace / 'animations.json'
+ config = json.loads(path.read_text(encoding='utf-8'))
+ config['slides']['slide_02']['morph']['pairs'][self.key]['from'] = 'missing'
+ path.write_text(json.dumps(config), encoding='utf-8')
+ self._export(expected_exit=1)
+ self.assertIn('slide_01', self.stderr)
+ self.assertIn('missing', self.stderr)