Claude commited on
Commit
89cae6c
·
1 Parent(s): 13e0c0c

feat: self-contained edits export + /edit page to reopen a shared JSON

Browse files

Makes the editor's JSON export a true handoff artifact: one file that
someone else can open and keep editing, with no accompanying images and
no live job.

Self-contained export (review.html):
* readState now embeds each segment's current image as a data URI (and
audio when inlined), so "Save edits (JSON)" carries the slides, not
just references to them. The primary <img> src is already a data URI
in review mode (even after alt-switching), so it's captured verbatim;
a non-data src is omitted rather than saved broken.
* downloadZIP strips those embedded URIs before POSTing (it sends images
separately + keeps audio server-side) so the ZIP request doesn't carry
the image bytes twice.
* applyState restores the <img> from image_data_uri when a self-contained
JSON is loaded into a live editor, so a file from another session shows
the right slides.

Data model (metadata.py, html_gen.py):
* SegmentMetadata gains optional image_data_uri / audio_data_uri;
migration + round-trip covered.
* metadata_to_segment uses the inlined URIs verbatim when present and
never touches frames_dir — which is what lets the editor be rebuilt
from a single JSON with no image files on disk.

/edit (main.py, edit.html):
* GET /edit — a small upload page.
* POST /edit — reads the uploaded edits JSON, validates (with v1
migration), verifies every segment embeds an image (else a clear "not
self-contained, re-save it" error), and returns a fully rebuilt review
editor via render_from_metadata. The browser navigates straight into
the editor.
* Discoverable via cross-links on the video and images upload pages.

Tests: render_from_metadata rebuilds the editor from inlined images with
a bogus frames_dir (no disk read), and the image/audio data URIs
round-trip through save/load.

https://claude.ai/code/session_01EM8jiYxdVFy1w3LeJ9GBJg

app/main.py CHANGED
@@ -28,7 +28,7 @@ from .pipeline.llm_extract import (
28
  extract_topics,
29
  is_valid_video_type,
30
  )
31
- from .pipeline.metadata import PageMetadata
32
  from .pipeline.orchestrator import (
33
  PipelineError,
34
  PipelineInputs,
@@ -192,6 +192,61 @@ async def images_page(request: Request) -> HTMLResponse:
192
  return templates.TemplateResponse(request, "images.html", {})
193
 
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  def _safe_filename(title: str) -> str:
196
  safe = "".join(c if c.isalnum() or c in "-_ " else "-" for c in title).strip()
197
  safe = safe.replace(" ", "-")
 
28
  extract_topics,
29
  is_valid_video_type,
30
  )
31
+ from .pipeline.metadata import CURRENT_SCHEMA_VERSION, PageMetadata, migrate_v1_to_v2
32
  from .pipeline.orchestrator import (
33
  PipelineError,
34
  PipelineInputs,
 
192
  return templates.TemplateResponse(request, "images.html", {})
193
 
194
 
195
+ @app.get("/edit", response_class=HTMLResponse)
196
+ async def edit_page(request: Request) -> HTMLResponse:
197
+ return templates.TemplateResponse(request, "edit.html", {})
198
+
199
+
200
+ # A self-contained editor export embeds the slide images as base64, so the
201
+ # JSON can be several MB. Cap generously; well above a normal deck.
202
+ MAX_EDIT_JSON_BYTES = _size_limit("MAX_EDIT_MB", 150)
203
+
204
+
205
+ @app.post("/edit", response_class=HTMLResponse)
206
+ async def edit_from_json(edits: UploadFile = File(...)) -> HTMLResponse:
207
+ """Rebuild a full editor from a single self-contained edits JSON.
208
+
209
+ The editor's 'Save edits (JSON)' now embeds each slide as a data URI,
210
+ so one file carries everything needed to reconstitute the editor —
211
+ no job, no image files. This lets an author hand the JSON to someone
212
+ else who opens it here and keeps editing. Returns the editor HTML
213
+ directly so the browser navigates straight into it.
214
+ """
215
+ raw = await edits.read()
216
+ if MAX_EDIT_JSON_BYTES is not None and len(raw) > MAX_EDIT_JSON_BYTES:
217
+ limit_mb = MAX_EDIT_JSON_BYTES // (1024 * 1024)
218
+ raise HTTPException(413, f"Edits file exceeds the {limit_mb} MB limit.")
219
+ try:
220
+ data = json.loads(raw.decode("utf-8"))
221
+ except Exception:
222
+ raise HTTPException(400, "That file isn't valid JSON. Upload an edits file saved from the editor.")
223
+ if not isinstance(data, dict):
224
+ raise HTTPException(400, "The JSON must be an editor export object.")
225
+ if int(data.get("schema_version", 1) or 1) < CURRENT_SCHEMA_VERSION:
226
+ data = migrate_v1_to_v2(data)
227
+ try:
228
+ page = PageMetadata.model_validate(data)
229
+ except Exception as exc:
230
+ raise HTTPException(422, f"Not a valid editor export: {exc}")
231
+
232
+ if not page.segments:
233
+ raise HTTPException(400, "This export has no segments to edit.")
234
+ missing = [s.index for s in page.segments if not (s.image_data_uri or "").strip()]
235
+ if missing:
236
+ raise HTTPException(
237
+ 400,
238
+ "This edits file doesn't embed its slide images, so the editor "
239
+ "can't be rebuilt from it alone. Re-save it from the editor's "
240
+ "'Save edits (JSON)' button (which now embeds the slides) and "
241
+ "upload that file.",
242
+ )
243
+
244
+ # frames_dir is never read: every segment carries an inlined
245
+ # image_data_uri, so metadata_to_segment short-circuits the disk path.
246
+ html = render_from_metadata(page, Path("."), mode="review")
247
+ return HTMLResponse(html)
248
+
249
+
250
  def _safe_filename(title: str) -> str:
251
  safe = "".join(c if c.isalnum() or c in "-_ " else "-" for c in title).strip()
252
  safe = safe.replace(" ", "-")
app/pipeline/html_gen.py CHANGED
@@ -302,6 +302,11 @@ def metadata_to_segment(seg_meta: Any, frames_dir: Path, *, inline_images: bool)
302
  is True (we need to read bytes for the data URI). The corresponding
303
  audio clip is looked up in a sibling 'audio/' directory next to
304
  `frames_dir`, mirroring the on-disk layout the orchestrator writes.
 
 
 
 
 
305
  """
306
  image_path = Path(frames_dir) / seg_meta.image_filename
307
  alt_filenames = list(getattr(seg_meta, "alt_image_filenames", []) or [])
@@ -315,12 +320,18 @@ def metadata_to_segment(seg_meta: Any, frames_dir: Path, *, inline_images: bool)
315
  candidate = Path(frames_dir) / audio_filename
316
  legacy = Path(frames_dir).parent / "audio" / audio_filename
317
  audio_path = candidate if candidate.exists() else legacy
 
 
 
318
  return Segment(
319
  index=seg_meta.index,
320
  start_seconds=seg_meta.start_seconds,
321
  end_seconds=seg_meta.end_seconds,
322
  image_filename=seg_meta.image_filename,
323
- image_data_uri=_image_data_uri(image_path) if inline_images else None,
 
 
 
324
  narration=list(seg_meta.narration),
325
  ocr_text=seg_meta.ocr_text,
326
  alt_draft=seg_meta.alt_text,
@@ -330,12 +341,16 @@ def metadata_to_segment(seg_meta: Any, frames_dir: Path, *, inline_images: bool)
330
  include=seg_meta.include,
331
  alt_image_filenames=alt_filenames,
332
  alt_image_data_uris=(
333
- [_image_data_uri(p) for p in alt_paths if p.exists()] if inline_images else []
 
 
 
334
  ),
335
  alt_ocr_texts=list(getattr(seg_meta, "alt_ocr_texts", []) or []),
336
  audio_filename=audio_filename,
337
  audio_data_uri=(
338
- _audio_data_uri(audio_path) if (inline_images and audio_path is not None) else None
 
339
  ),
340
  alt_text_reviewed=bool(getattr(seg_meta, "alt_text_reviewed", False)),
341
  summary=getattr(seg_meta, "summary", "") or "",
 
302
  is True (we need to read bytes for the data URI). The corresponding
303
  audio clip is looked up in a sibling 'audio/' directory next to
304
  `frames_dir`, mirroring the on-disk layout the orchestrator writes.
305
+
306
+ When the metadata already carries inlined `image_data_uri` /
307
+ `audio_data_uri` (the self-contained editor export consumed by /edit),
308
+ those are used verbatim and `frames_dir` is never touched — so the
309
+ editor can be rebuilt from a single JSON with no image files on disk.
310
  """
311
  image_path = Path(frames_dir) / seg_meta.image_filename
312
  alt_filenames = list(getattr(seg_meta, "alt_image_filenames", []) or [])
 
320
  candidate = Path(frames_dir) / audio_filename
321
  legacy = Path(frames_dir).parent / "audio" / audio_filename
322
  audio_path = candidate if candidate.exists() else legacy
323
+
324
+ inlined_image = getattr(seg_meta, "image_data_uri", None) or None
325
+ inlined_audio = getattr(seg_meta, "audio_data_uri", None) or None
326
  return Segment(
327
  index=seg_meta.index,
328
  start_seconds=seg_meta.start_seconds,
329
  end_seconds=seg_meta.end_seconds,
330
  image_filename=seg_meta.image_filename,
331
+ image_data_uri=(
332
+ inlined_image if inlined_image
333
+ else (_image_data_uri(image_path) if inline_images else None)
334
+ ),
335
  narration=list(seg_meta.narration),
336
  ocr_text=seg_meta.ocr_text,
337
  alt_draft=seg_meta.alt_text,
 
341
  include=seg_meta.include,
342
  alt_image_filenames=alt_filenames,
343
  alt_image_data_uris=(
344
+ # Only when disk-backed; the self-contained export doesn't carry
345
+ # alt frames (no alt-switching in the /edit editor).
346
+ [_image_data_uri(p) for p in alt_paths if p.exists()]
347
+ if (inline_images and not inlined_image) else []
348
  ),
349
  alt_ocr_texts=list(getattr(seg_meta, "alt_ocr_texts", []) or []),
350
  audio_filename=audio_filename,
351
  audio_data_uri=(
352
+ inlined_audio if inlined_audio
353
+ else (_audio_data_uri(audio_path) if (inline_images and audio_path is not None) else None)
354
  ),
355
  alt_text_reviewed=bool(getattr(seg_meta, "alt_text_reviewed", False)),
356
  summary=getattr(seg_meta, "summary", "") or "",
app/pipeline/metadata.py CHANGED
@@ -86,6 +86,13 @@ class SegmentMetadata(BaseModel):
86
  on_screen_text_included: bool = True
87
  transcript_included: bool = True
88
  audio_included: bool = True
 
 
 
 
 
 
 
89
 
90
 
91
  class SourceInfo(BaseModel):
@@ -163,6 +170,8 @@ def migrate_v1_to_v2(raw: dict[str, Any]) -> dict[str, Any]:
163
  s.setdefault("on_screen_text_included", True)
164
  s.setdefault("transcript_included", True)
165
  s.setdefault("audio_included", True)
 
 
166
  narration = s.get("narration", [])
167
  if isinstance(narration, str):
168
  s["narration"] = [narration] if narration else []
 
86
  on_screen_text_included: bool = True
87
  transcript_included: bool = True
88
  audio_included: bool = True
89
+ # Inlined asset bytes (base64 data URIs) for the self-contained editor
90
+ # export. When set, the renderer uses these directly instead of reading
91
+ # image_filename / audio_filename off disk — which is what lets the
92
+ # /edit page rebuild a full editor from a single shared JSON with no
93
+ # accompanying image files. Normally None (disk-backed render paths).
94
+ image_data_uri: str | None = None
95
+ audio_data_uri: str | None = None
96
 
97
 
98
  class SourceInfo(BaseModel):
 
170
  s.setdefault("on_screen_text_included", True)
171
  s.setdefault("transcript_included", True)
172
  s.setdefault("audio_included", True)
173
+ s.setdefault("image_data_uri", None)
174
+ s.setdefault("audio_data_uri", None)
175
  narration = s.get("narration", [])
176
  if isinstance(narration, str):
177
  s["narration"] = [narration] if narration else []
app/templates/edit.html ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Video Guide Maker — open a shared edit file</title>
7
+ <style>
8
+ :root {
9
+ --banner: #750014; --banner-text: #fff; --bg: #fff; --text: #1a1a1a;
10
+ --muted: #555; --border: #d0d0d0; --surface: #f5f5f5; --radius: 6px;
11
+ --font: 'Source Sans 3', 'Segoe UI', system-ui, sans-serif;
12
+ }
13
+ * { box-sizing: border-box; }
14
+ body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.6; }
15
+ a { color: var(--banner); }
16
+ .skip-link { position: absolute; left: -999px; top: 0; background: #1a1a1a; color: #fff; padding: .5rem 1rem; z-index: 10; }
17
+ .skip-link:focus { left: 1rem; top: 1rem; }
18
+ header.page { background: var(--banner); color: var(--banner-text); padding: 2rem 1.25rem; text-align: center; }
19
+ header.page h1 { margin: 0 0 .25rem; font-size: 1.6rem; }
20
+ header.page p { margin: 0; opacity: .9; font-size: .98rem; }
21
+ header.page .switch { margin-top: .75rem; font-size: .9rem; }
22
+ header.page .switch a { color: #f5d5db; }
23
+ main { max-width: 42rem; margin: 0 auto; padding: 1.75rem 1.25rem 3rem; }
24
+ .card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.25rem 1.5rem; }
25
+ .card h2 { margin: 0 0 .5rem; font-size: 1.15rem; }
26
+ .field { margin: 1rem 0; }
27
+ .field > label { display: block; font-weight: 600; margin-bottom: .3rem; }
28
+ input[type="file"] { width: 100%; padding: .5rem; border: 1px solid var(--border); border-radius: 4px; font: inherit; }
29
+ .hint { font-size: .9rem; color: var(--muted); }
30
+ button.submit {
31
+ background: var(--banner); color: var(--banner-text); border: 0;
32
+ padding: .7rem 1.4rem; font: inherit; font-weight: 600; border-radius: var(--radius); cursor: pointer;
33
+ }
34
+ button.submit:hover { filter: brightness(1.1); }
35
+ :focus-visible { outline: 2px solid #1a1a1a; outline-offset: 2px; }
36
+ .note { background: var(--surface); border-left: 4px solid var(--banner); padding: .75rem 1rem; border-radius: 0 var(--radius) var(--radius) 0; font-size: .92rem; margin-top: 1.25rem; }
37
+ </style>
38
+ </head>
39
+ <body>
40
+ <a href="#main" class="skip-link">Skip to main content</a>
41
+ <header class="page" role="banner">
42
+ <h1>Open a shared edit file</h1>
43
+ <p>Continue editing a study guide someone shared with you.</p>
44
+ <p class="switch">Starting fresh? <a href="/">Build from a video</a> or <a href="/images">from slide images</a>.</p>
45
+ </header>
46
+
47
+ <main id="main">
48
+ <div class="card">
49
+ <h2>Upload an edits file</h2>
50
+ <p class="hint">Drop in a <code>.json</code> file saved from the editor's <strong>Save edits (JSON)</strong> button. It contains the slides and all the edits, so the editor opens right where they left off — nothing else to upload.</p>
51
+ <form action="/edit" method="post" enctype="multipart/form-data">
52
+ <div class="field">
53
+ <label for="edits">Edits file (.json)</label>
54
+ <input type="file" id="edits" name="edits" accept="application/json,.json" required>
55
+ </div>
56
+ <button type="submit" class="submit">Open in editor</button>
57
+ </form>
58
+ <p class="note">
59
+ The editor opens in this tab. To keep your changes, use <strong>Save edits (JSON)</strong>
60
+ again — that file is the shareable, re-openable copy. <strong>Download final HTML</strong> /
61
+ <strong>Markdown</strong> give you the finished guide.
62
+ </p>
63
+ </div>
64
+ </main>
65
+ </body>
66
+ </html>
app/templates/images.html CHANGED
@@ -61,7 +61,7 @@
61
  <header class="page" role="banner">
62
  <h1>Video Guide Maker</h1>
63
  <p>Build an accessible study guide from slide images and a transcript — no video needed.</p>
64
- <p class="switch">Have the source video instead? <a href="/">Use the video uploader</a>.</p>
65
  </header>
66
 
67
  <main id="main">
 
61
  <header class="page" role="banner">
62
  <h1>Video Guide Maker</h1>
63
  <p>Build an accessible study guide from slide images and a transcript — no video needed.</p>
64
+ <p class="switch">Have the source video instead? <a href="/">Use the video uploader</a>. &nbsp;·&nbsp; Got a shared edits file? <a href="/edit">Open it to keep editing</a>.</p>
65
  </header>
66
 
67
  <main id="main">
app/templates/index.html CHANGED
@@ -923,7 +923,7 @@
923
  </div>
924
  <div class="vgm-drop__meta" data-meta-for="video"></div>
925
  </label>
926
- <p class="vgm-hint">No video, just slide exports? <a href="/images">Build from slide images + a transcript</a> instead.</p>
927
  </div>
928
 
929
  <div class="vgm-field">
 
923
  </div>
924
  <div class="vgm-drop__meta" data-meta-for="video"></div>
925
  </label>
926
+ <p class="vgm-hint">No video, just slide exports? <a href="/images">Build from slide images + a transcript</a> instead. &nbsp;·&nbsp; Have a shared edits file? <a href="/edit">Open it to keep editing</a>.</p>
927
  </div>
928
 
929
  <div class="vgm-field">
app/templates/review.html CHANGED
@@ -695,8 +695,18 @@
695
  }));
696
  const mainImg = s.querySelector('[data-bind="image"]');
697
  const imageFilename = (mainImg && mainImg.getAttribute('data-image-filename')) || '';
 
 
 
 
 
 
 
 
698
  const audioEl = s.querySelector('[data-bind="audio"]');
699
  const audioFilename = (audioEl && audioEl.getAttribute('data-audio-filename')) || '';
 
 
700
  return {
701
  index: parseInt(s.getAttribute('data-segment-index'), 10),
702
  // start/end are stamped on the <section> by the template;
@@ -711,7 +721,9 @@
711
  include: s.querySelector('input[data-bind="include"]').checked,
712
  alt_text_reviewed: s.getAttribute('data-alt-reviewed') === 'true',
713
  image_filename: imageFilename,
 
714
  audio_filename: audioFilename,
 
715
  description: readEditableText(s.querySelector('[data-bind="description"]')),
716
  // Per-element include flags — mirror the data-include attributes
717
  // the toggles drive so Save/Load JSON round-trips them AND the
@@ -794,6 +806,13 @@
794
  (state.segments || []).forEach(s => {
795
  const sec = byIndex.get(s.index);
796
  if (!sec) return;
 
 
 
 
 
 
 
797
  if ('section_title' in s) {
798
  const el = sec.querySelector('input[data-bind="section_title"]');
799
  el.value = s.section_title;
@@ -1412,6 +1431,15 @@
1412
  const src = img.getAttribute('src') || '';
1413
  if (fn && src.startsWith('data:')) primaryImageDataUris[fn] = src;
1414
  });
 
 
 
 
 
 
 
 
 
1415
  let resp;
1416
  try {
1417
  resp = await fetch(zipUrl, {
 
695
  }));
696
  const mainImg = s.querySelector('[data-bind="image"]');
697
  const imageFilename = (mainImg && mainImg.getAttribute('data-image-filename')) || '';
698
+ // Capture the currently-shown image as a data URI so the saved
699
+ // JSON is self-contained — one file that /edit can rebuild the
700
+ // whole editor from, with no separate image files. The primary
701
+ // <img> src is a data: URI in review mode (even after switching
702
+ // to an alt frame, which loads as a data URI); a non-data src is
703
+ // omitted rather than saved as a broken reference.
704
+ const mainImgSrc = (mainImg && mainImg.getAttribute('src')) || '';
705
+ const imageDataUri = mainImgSrc.startsWith('data:') ? mainImgSrc : null;
706
  const audioEl = s.querySelector('[data-bind="audio"]');
707
  const audioFilename = (audioEl && audioEl.getAttribute('data-audio-filename')) || '';
708
+ const audioSrc = (audioEl && audioEl.getAttribute('src')) || '';
709
+ const audioDataUri = audioSrc.startsWith('data:') ? audioSrc : null;
710
  return {
711
  index: parseInt(s.getAttribute('data-segment-index'), 10),
712
  // start/end are stamped on the <section> by the template;
 
721
  include: s.querySelector('input[data-bind="include"]').checked,
722
  alt_text_reviewed: s.getAttribute('data-alt-reviewed') === 'true',
723
  image_filename: imageFilename,
724
+ image_data_uri: imageDataUri,
725
  audio_filename: audioFilename,
726
+ audio_data_uri: audioDataUri,
727
  description: readEditableText(s.querySelector('[data-bind="description"]')),
728
  // Per-element include flags — mirror the data-include attributes
729
  // the toggles drive so Save/Load JSON round-trips them AND the
 
806
  (state.segments || []).forEach(s => {
807
  const sec = byIndex.get(s.index);
808
  if (!sec) return;
809
+ // Self-contained JSON carries the image as a data URI. When loading
810
+ // into a live editor, refresh the <img> from it so a JSON saved
811
+ // elsewhere (different session/machine) shows the right slide.
812
+ if (s.image_data_uri) {
813
+ const img = sec.querySelector('[data-bind="image"]');
814
+ if (img) img.setAttribute('src', s.image_data_uri);
815
+ }
816
  if ('section_title' in s) {
817
  const el = sec.querySelector('input[data-bind="section_title"]');
818
  el.value = s.section_title;
 
1431
  const src = img.getAttribute('src') || '';
1432
  if (fn && src.startsWith('data:')) primaryImageDataUris[fn] = src;
1433
  });
1434
+ // readState now embeds per-segment image/audio data URIs (for the
1435
+ // self-contained Save/Load + /edit flow). The ZIP endpoint gets the
1436
+ // images separately via primary_image_data_uris and keeps audio in
1437
+ // server memory, so drop the embedded copies here to avoid POSTing
1438
+ // the image bytes twice.
1439
+ (state.segments || []).forEach(seg => {
1440
+ delete seg.image_data_uri;
1441
+ delete seg.audio_data_uri;
1442
+ });
1443
  let resp;
1444
  try {
1445
  resp = await fetch(zipUrl, {
tests/test_html_gen.py CHANGED
@@ -574,6 +574,64 @@ def test_metadata_round_trip_preserves_description(tmp_path):
574
  assert loaded.segments[0].description_reviewed is True
575
 
576
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
577
  def test_metadata_round_trip_preserves_include_flags(tmp_path):
578
  """The per-element include flags must survive a Save → Load cycle so
579
  the editor's toggle choices carry into the server-side ZIP re-render."""
 
574
  assert loaded.segments[0].description_reviewed is True
575
 
576
 
577
+ def test_render_from_metadata_rebuilds_editor_from_inlined_images(tmp_path):
578
+ """The /edit flow: a self-contained export (each segment carries an
579
+ inlined image_data_uri) must rebuild the review editor WITHOUT reading
580
+ any image files off disk — frames_dir is intentionally bogus here."""
581
+ from app.pipeline.html_gen import render_from_metadata
582
+ from app.pipeline.metadata import PageMetadata, SegmentMetadata
583
+
584
+ tiny = (
585
+ "data:image/png;base64,"
586
+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
587
+ )
588
+ page = PageMetadata(
589
+ title="Shared Guide",
590
+ segments=[
591
+ SegmentMetadata(
592
+ index=0, start_seconds=0.0, end_seconds=5.0,
593
+ image_filename="00-00-00.png", section_title="Intro",
594
+ alt_text="", narration=["Hello."], ocr_text="",
595
+ description="A described slide.",
596
+ image_data_uri=tiny,
597
+ )
598
+ ],
599
+ )
600
+ # frames_dir does not exist; must not be touched because images inline.
601
+ html = render_from_metadata(page, tmp_path / "does-not-exist", mode="review")
602
+ assert 'data-vgm-review="1"' in html # it's the editor
603
+ assert tiny in html # the inlined image is used
604
+ assert "Shared Guide" in html
605
+ assert "A described slide." in html
606
+
607
+
608
+ def test_metadata_round_trip_preserves_inlined_image_uri(tmp_path):
609
+ """image_data_uri / audio_data_uri survive a Save -> Load cycle so the
610
+ self-contained export stays self-contained."""
611
+ from app.pipeline.metadata import (
612
+ PageMetadata,
613
+ SegmentMetadata,
614
+ dump_metadata,
615
+ load_metadata,
616
+ )
617
+ page = PageMetadata(
618
+ title="t",
619
+ segments=[
620
+ SegmentMetadata(
621
+ index=0, start_seconds=0.0, end_seconds=5.0,
622
+ image_filename="00-00-00.png", section_title="s", alt_text="",
623
+ image_data_uri="data:image/png;base64,AAAA",
624
+ audio_data_uri="data:audio/mpeg;base64,BBBB",
625
+ )
626
+ ],
627
+ )
628
+ path = tmp_path / "meta.json"
629
+ dump_metadata(path, page)
630
+ seg = load_metadata(path).segments[0]
631
+ assert seg.image_data_uri == "data:image/png;base64,AAAA"
632
+ assert seg.audio_data_uri == "data:audio/mpeg;base64,BBBB"
633
+
634
+
635
  def test_metadata_round_trip_preserves_include_flags(tmp_path):
636
  """The per-element include flags must survive a Save → Load cycle so
637
  the editor's toggle choices carry into the server-side ZIP re-render."""