DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge storytold/main into linked-path-checks
skylar taylor-barrick9fd0a881f746
diff --cc crates/engine/src/cmd/links.rsindex 9aa23cbfa,eca813b88..d77db3ea8--- a/crates/engine/src/cmd/links.rs+++ b/crates/engine/src/cmd/links.rs@@@ -349,10 -325,32 +349,35 @@@ fn reload(path: impl AsRef<Path>) -> Re}#[cfg(target_arch = "wasm32")]-fn reload(path: &str) -> Result<(Vec<u8>, (u32, u32))> {- Err(EngineError::Other(format!("{path}: files can't be read on the web")))+fn reload(path: impl AsRef<Path>) -> Result<(Vec<u8>, (u32, u32))> {+ Err(EngineError::Other(format!("{}: files can't be read on the web", path.as_ref().display())))}-fn relinked_asset(a: &designcraft_doc::Asset, path: &str) -> Result<Arc<designcraft_doc::Asset>> {- let (bytes, px) = reload(path)?;++/// The replacement for `a`: bytes read from `read`, with `link` recorded as the stored link.++/// Relink passes the file the user chose as both. Update passes the path the stored link resolved++/// to and the stored link itself, so refreshing a link never rewrites what the document holds.++fn relinked_asset(a: &designcraft_doc::Asset, read: &Path, link: &str) -> Result<Arc<designcraft_doc::Asset>> {++ let (bytes, px) = reload(read)?;+ let page = if designcraft_render::is_pdf(&bytes) { a.page } else { 0 };+ let px = if page > 0 {+ designcraft_render::pdf_page_size(&bytes, page as usize)+ .map(|(w, h)| (w.round().max(1.0) as u32, h.round().max(1.0) as u32))- .ok_or_else(|| bad("links", format!("{path}: can't read PDF page {}", u64::from(page) + 1)))?++ .ok_or_else(|| bad("links", format!("{}: can't read PDF page {}", read.display(), u64::from(page) + 1)))?+ } else {+ px+ };+ let mut a = a.clone();+ a.mime = designcraft_render::image_mime(&bytes).to_string();+ a.data = Arc::new(bytes);+ a.pixels = Some(px);+ a.page = page;- a.name = std::path::Path::new(path).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| path.to_string());- a.link = Some(path.to_string());++ a.name = Path::new(link).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| link.to_string());++ a.link = Some(link.to_string());+ // A placed PDF keeps its crop choice; its box is found on the new file.+ super::file::crop_pdf(&mut a);+ Ok(Arc::new(a))+ }+fn relink(s: &mut Session, p: &Value) -> Result<Value> {let path = str_param(p, "path").ok_or_else(|| bad("links.relink", "missing path"))?.to_string();if let Some(sid) = story_param(p) {@@@ -364,18 -362,12 +389,12 @@@});}let aid = asset_param(p, "links.relink")?;- let (bytes, px) = reload(&path)?;- let name = std::path::Path::new(&path).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| path.clone());+ let a = s.doc()?.doc.assets.get(&aid).ok_or_else(|| bad("links.relink", "no such graphic"))?;+ // Build the replacement before the edit: a file that cannot be read leaves the document as it was.- let fresh = relinked_asset(a, &path)?;++ let fresh = relinked_asset(a, Path::new(&path), &path)?;s.edit(|d, _| {- let a = d.assets.get_mut(&aid).ok_or_else(|| bad("links.relink", "no such graphic"))?;- let a = Arc::make_mut(a);- a.mime = designcraft_render::image_mime(&bytes).to_string();- a.data = Arc::new(bytes.clone());- a.pixels = Some(px);- a.name = name.clone();- a.link = Some(path.clone());- // A placed PDF keeps its crop choice; its box is found on the new file.- super::file::crop_pdf(a);+ let name = fresh.name.clone();+ d.assets.insert(aid, fresh);Ok(json!({"name": name}))})}@@@ -419,10 -407,21 +441,21 @@@ fn relink_folder(s: &mut Session, p: &Vnot_found.push(name.to_string_lossy().to_string());}}- let mut n = 0;+ // Load every replacement before committing any of them: a bad file must not leave an+ // unrecorded partial edit. Successful batches commit once and have one undo step.+ let mut fresh = Vec::new();for (aid, path) in todo {- relink(s, &json!({"asset": aid.0, "path": path.to_string_lossy()}))?;- n += 1;+ let a = d.assets.get(&aid).ok_or_else(|| bad("links.relinkFolder", "no such graphic"))?;- fresh.push((aid, relinked_asset(a, &path.to_string_lossy())?));++ fresh.push((aid, relinked_asset(a, &path, &path.to_string_lossy())?));+ }+ let n = fresh.len();+ if n > 0 {+ s.edit(|d, _| {+ for (aid, a) in fresh {+ d.assets.insert(aid, a);+ }+ Ok(())+ })?;}Ok(json!({"relinked": n, "notFound": not_found}))}@@@ -436,31 -431,21 +469,28 @@@ fn update(s: &mut Session, p: &Value) -let checks = &mut s.text_link_checks;let (only_asset, only_story) = (p.get("asset").and_then(Value::as_u64), story_param(p));let all = only_asset.is_none() && only_story.is_none();- // "modified" means the link resolved: refused links are missing.- let texts: Vec<(StoryId, String)> = d++ // A link craft-docpath refuses is missing, so it is never read or refreshed.+ let resolved = |link: &str| crate::io::document_path(link, document).ok();- let which: Vec<(AssetId, std::path::PathBuf)> = d- .assets- .values()- .filter(|a| all || only_asset == Some(a.id.0))- .filter(|a| status(a, document) == "modified")- .filter_map(|a| a.link.as_deref().and_then(resolved).map(|l| (a.id, l)))- .collect();+ let texts: Vec<(StoryId, String, std::path::PathBuf)> = d.stories.values().filter(|st| all || only_story == Some(st.id))- .filter_map(|st| st.file_link.as_ref().filter(|l| text_status(l, checks) == "modified").map(|l| (st.id, l.path.clone())))+ .filter_map(|st| {+ let l = st.file_link.as_ref().filter(|l| text_status(l, checks, document) == "modified")?;+ Some((st.id, l.path.clone(), resolved(&l.path)?))+ }).collect();let mut fresh = Vec::new();- for (aid, path) in which {- fresh.push((aid, reload(&path)?));- for a in d.assets.values().filter(|a| all || only_asset == Some(a.id.0)).filter(|a| status(a) == "modified") {- if let Some(path) = &a.link {- fresh.push((a.id, relinked_asset(a, path)?));++ for a in d.assets.values().filter(|a| all || only_asset == Some(a.id.0)).filter(|a| status(a, document) == "modified") {++ // The bytes come from where the stored link resolves; the link itself stays as the++ // document stored it, so refreshing never rewrites a relative link to an absolute one.++ if let Some((link, at)) = a.link.as_deref().and_then(|l| resolved(l).map(|at| (l, at))) {++ fresh.push((a.id, relinked_asset(a, &at, link)?));+ }}let mut fresh_texts = Vec::new();- for (sid, path) in texts {- let (bytes, before) = read_text(&path)?;+ for (sid, path, at) in texts {+ let (bytes, before) = read_text(&at)?;fresh_texts.push((sid, path, bytes, before));}let n = fresh.len() + fresh_texts.len();@@@ -492,6 -472,289 +517,290 @@@ mod testsdesigncraft_render::Rendered { width: w, height: h, pixels: vec![200u8; (w * h * 4) as usize] }.to_png()}+ fn pdf(sizes: &[(u32, u32)]) -> Vec<u8> {+ let mut s = Session::new();+ s.execute("file.new", &json!({"pages": sizes.len(), "facingPages": false})).unwrap();+ for (i, (width, height)) in sizes.iter().enumerate() {+ s.execute("layout.pageSize", &json!({"pages": [i + 1], "width": width, "height": height})).unwrap();+ }+ let result = s.execute("file.exportPdf", &json!({})).unwrap();+ super::super::file::base64_decode(result["base64"].as_str().unwrap())+ }++ #[test]+ fn eps_web_exports_convert_tiff_and_skip_bad_used_assets() {+ use std::io::Read;+ let bytes = super::super::file::eps_place_tests::tiff_eps();+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let placed = s.execute("file.place", &json!({"base64":super::super::file::base64_encode(&bytes),"name":"logo.eps"})).unwrap();+ let aid = AssetId(placed["asset"].as_u64().unwrap());+ let before = s.doc().unwrap().doc.clone();+ let html = s.execute("file.exportHtml", &json!({})).unwrap();+ let encoded = html["text"].as_str().unwrap().split("data:image/png;base64,").nth(1).unwrap().split('"').next().unwrap();+ let png = super::super::file::base64_decode(encoded);+ assert!(png.starts_with(b"\x89PNG"));+ assert_eq!(designcraft_render::image_size(&png), Some((2, 2)));+ assert_eq!(designcraft_render::decode_pixmap(&png).unwrap().data()[0], designcraft_render::decode_pixmap(&bytes).unwrap().data()[0]);+ let result = s.execute("file.exportEpub", &json!({})).unwrap();+ let mut z = zip::ZipArchive::new(std::io::Cursor::new(super::super::file::base64_decode(result["base64"].as_str().unwrap()))).unwrap();+ let mut image = Vec::new();+ z.by_name(&format!("OEBPS/images/logo-{}.png", aid.0)).unwrap().read_to_end(&mut image).unwrap();+ assert_eq!(image, png);+ let mut opf = String::new();+ z.by_name("OEBPS/content.opf").unwrap().read_to_string(&mut opf).unwrap();+ assert!(opf.contains("media-type=\"image/png\""));+ assert!(!opf.contains("image/tiff"));+ assert!(Arc::ptr_eq(&before, &s.doc().unwrap().doc));+ s.edit(|d, _| {+ Arc::make_mut(d.assets.get_mut(&aid).unwrap()).data = Arc::new(b"%!PS-Adobe-3.0 EPSF-3.0\n%%EOF\n".to_vec());+ Ok(())+ })+ .unwrap();+ let before = s.doc().unwrap().doc.clone();+ for command in ["file.exportHtml", "file.exportEpub"] {+ let result = s.execute(command, &json!({})).unwrap();+ assert_eq!(result["warnings"].as_array().unwrap().len(), 1, "{command}");+ if command == "file.exportHtml" {+ assert!(!result["text"].as_str().unwrap().contains("<img "));+ }+ }+ assert!(Arc::ptr_eq(&before, &s.doc().unwrap().doc));+ s.execute("edit.clear", &json!({})).unwrap();+ assert!(s.doc().unwrap().doc.assets.contains_key(&aid));+ for command in ["file.exportHtml", "file.exportEpub"] {+ let result = s.execute(command, &json!({})).unwrap();+ assert!(result["warnings"].as_array().unwrap().is_empty(), "unused EPS: {command}");+ }+ }++ #[test]+ fn eps_status_tracks_source_bytes_across_save_update_relink_and_embed() {+ let dir = std::env::temp_dir().join(format!("dc-eps-status-{}", std::process::id()));+ std::fs::create_dir_all(&dir).unwrap();+ let path = dir.join("logo.eps");+ let first = b"%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 20 10\n0 0 0 setrgbcolor\n%%EOF\n";+ let changed = b"%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 20 10\n1 0 0 setrgbcolor\n%%EOF\n";+ assert_eq!(first.len(), changed.len());+ assert_eq!(designcraft_images::eps_proxy(first), designcraft_images::eps_proxy(changed), "same preview, different source");+ std::fs::write(&path, first).unwrap();+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let aid = AssetId(s.execute("file.place", &json!({"path": path.to_string_lossy()})).unwrap()["asset"].as_u64().unwrap());+ assert_eq!(s.execute("links.list", &json!({})).unwrap()[0]["status"], "ok");+ let before = s.doc().unwrap().doc.clone();+ assert_eq!(s.execute("links.update", &json!({})).unwrap()["updated"], 0);+ assert!(Arc::ptr_eq(&s.doc().unwrap().doc, &before), "unchanged EPS must not create an edit");+ let saved = designcraft_format::save(&before).unwrap();+ let reopened = designcraft_format::load(&saved).unwrap();+ assert_eq!(reopened.assets[&aid].data.as_slice(), first);+ let mut s = Session::new();+ s.add_document(crate::DocState::new(reopened, None));+ assert_eq!(s.execute("links.list", &json!({})).unwrap()[0]["status"], "ok");+ std::fs::write(&path, changed).unwrap();+ assert_eq!(s.execute("links.list", &json!({})).unwrap()[0]["status"], "modified");+ assert_eq!(s.execute("links.update", &json!({})).unwrap()["updated"], 1);+ assert_eq!(s.execute("links.list", &json!({})).unwrap()[0]["status"], "ok");+ assert_eq!(s.doc().unwrap().doc.assets[&aid].data.as_slice(), changed);+ std::fs::remove_file(&path).unwrap();+ assert_eq!(s.execute("links.list", &json!({})).unwrap()[0]["status"], "missing");+ let replacement = dir.join("replacement.eps");+ std::fs::write(&replacement, changed).unwrap();+ s.execute("links.relink", &json!({"asset": aid.0, "path": replacement.to_string_lossy()})).unwrap();+ assert_eq!(s.execute("links.list", &json!({})).unwrap()[0]["status"], "ok");+ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!(s.execute("links.list", &json!({})).unwrap()[0]["status"], "missing");+ s.execute("edit.redo", &json!({})).unwrap();+ assert_eq!(s.execute("links.list", &json!({})).unwrap()[0]["status"], "ok");+ s.execute("links.embed", &json!({"asset": aid.0})).unwrap();+ assert_eq!(s.execute("links.list", &json!({})).unwrap()[0]["status"], "embedded");+ std::fs::remove_file(&replacement).unwrap();+ let embedded = designcraft_format::load(&designcraft_format::save(&s.doc().unwrap().doc).unwrap()).unwrap();- assert_eq!(status(&embedded.assets[&aid]), "embedded");++ // The asset is embedded, so no link is followed and the document is irrelevant.++ assert_eq!(status(&embedded.assets[&aid], None), "embedded");+ assert_eq!(embedded.assets[&aid].data.as_slice(), changed);+ assert!(designcraft_render::decode_pixmap(&embedded.assets[&aid].data).is_some());+ let _ = std::fs::remove_dir_all(dir);+ }++ #[test]+ fn eps_legacy_preview_document_is_upgraded_by_update() {+ let dir = std::env::temp_dir().join(format!("dc-eps-legacy-{}", std::process::id()));+ std::fs::create_dir_all(&dir).unwrap();+ let path = dir.join("logo.eps");+ let source = b"%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 20 10\n%%EOF\n";+ std::fs::write(&path, source).unwrap();+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let aid = AssetId(s.execute("file.place", &json!({"path": path.to_string_lossy()})).unwrap()["asset"].as_u64().unwrap());+ let proxy = designcraft_images::eps_proxy(source).unwrap().0;+ s.edit(|d, _| {+ let a = Arc::make_mut(d.assets.get_mut(&aid).unwrap());+ a.data = Arc::new(proxy);+ a.mime = "image/png".into();+ Ok(())+ })+ .unwrap();+ let old = designcraft_format::load(&designcraft_format::save(&s.doc().unwrap().doc).unwrap()).unwrap();+ let mut s = Session::new();+ s.add_document(crate::DocState::new(old, None));+ assert_eq!(s.execute("links.update", &json!({})).unwrap()["updated"], 1);+ assert_eq!(s.execute("links.list", &json!({})).unwrap()[0]["status"], "ok");+ assert_eq!(s.doc().unwrap().doc.assets[&aid].data.as_slice(), source);+ s.execute("edit.undo", &json!({})).unwrap();+ assert!(designcraft_render::decode_pixmap(&s.doc().unwrap().doc.assets[&aid].data).is_some(), "old preview remains renderable");+ s.execute("edit.redo", &json!({})).unwrap();+ assert_eq!(s.execute("links.list", &json!({})).unwrap()[0]["status"], "ok");+ let _ = std::fs::remove_dir_all(dir);+ }++ #[test]+ fn eps_source_exports_preview_to_pdf_html_and_epub_without_editing_document() {+ use hayro_syntax::object::Name;+ use std::io::Read;++ let source = b"%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 20 10\n%%EOF\n";+ let proxy = designcraft_images::eps_proxy(source).unwrap().0;+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let aid = AssetId(+ s.execute("file.place", &json!({"base64": super::super::file::base64_encode(source), "name": "logo.eps"})).unwrap()["asset"]+ .as_u64()+ .unwrap(),+ );+ // A document retaining the original EPS rather than the legacy preview-only asset.+ s.edit(|d, _| {+ let a = Arc::make_mut(d.assets.get_mut(&aid).unwrap());+ a.data = Arc::new(source.to_vec());+ a.mime = "application/postscript".into();+ Ok(())+ })+ .unwrap();+ let before = s.doc().unwrap().doc.clone();+ let result = s.execute("file.exportPdf", &json!({})).unwrap();+ assert!(result["warnings"].as_array().unwrap().is_empty(), "{:?}", result["warnings"]);+ let pdf = hayro_syntax::Pdf::new(super::super::file::base64_decode(result["base64"].as_str().unwrap())).unwrap();+ assert_eq!(+ pdf.objects()+ .into_iter()+ .filter_map(|o| o.into_stream())+ .filter(|st| st.dict().get::<Name>("Subtype").is_some_and(|n| n.as_str() == "Image"))+ .count(),+ 1+ );+ let result = s.execute("file.exportHtml", &json!({})).unwrap();+ let encoded = result["text"].as_str().unwrap().split("data:image/png;base64,").nth(1).unwrap().split('"').next().unwrap();+ assert_eq!(super::super::file::base64_decode(encoded), proxy);+ let result = s.execute("file.exportEpub", &json!({})).unwrap();+ let bytes = super::super::file::base64_decode(result["base64"].as_str().unwrap());+ let mut archive = zip::ZipArchive::new(std::io::Cursor::new(bytes)).unwrap();+ let mut image = Vec::new();+ archive.by_name(&format!("OEBPS/images/logo-{}.png", aid.0)).unwrap().read_to_end(&mut image).unwrap();+ assert_eq!(image, proxy);+ let mut opf = String::new();+ archive.by_name("OEBPS/content.opf").unwrap().read_to_string(&mut opf).unwrap();+ assert!(opf.contains("media-type=\"image/png\""));+ assert!(!opf.contains("application/postscript"));+ assert!(Arc::ptr_eq(&s.doc().unwrap().doc, &before), "exports must leave the source document intact");+ assert_eq!(before.assets[&aid].data.as_slice(), source);+ }++ #[test]+ fn eps_relink_update_and_folder_relink_retain_source() {+ let dir = std::env::temp_dir().join(format!("dc-links-eps-{}", std::process::id()));+ std::fs::create_dir_all(dir.join("new")).unwrap();+ let eps = |w: u32| format!("%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 {w} 10\n%%EOF\n");+ let original = dir.join("original.eps");+ let replacement = dir.join("replacement.eps");+ std::fs::write(&original, eps(10)).unwrap();+ std::fs::write(&replacement, eps(30)).unwrap();+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ s.execute("file.place", &json!({"path": original.to_string_lossy()})).unwrap();+ let aid = s.doc().unwrap().doc.assets.keys().next().copied().unwrap();+ std::fs::write(&original, eps(20)).unwrap();+ assert_eq!(s.execute("links.update", &json!({})).unwrap()["updated"], 1);+ assert_eq!(s.doc().unwrap().doc.assets[&aid].pixels, Some((40, 20)));+ s.execute("links.relink", &json!({"asset": aid.0, "path": replacement.to_string_lossy()})).unwrap();+ let a = &s.doc().unwrap().doc.assets[&aid];+ assert_eq!(a.pixels, Some((60, 20)));+ assert_eq!(a.mime, "application/postscript");+ assert_eq!(a.data.as_slice(), eps(30).as_bytes());+ let moved = dir.join("new/replacement.eps");+ std::fs::rename(&replacement, &moved).unwrap();+ assert_eq!(s.execute("links.relinkFolder", &json!({"dir": dir.join("new").to_string_lossy()})).unwrap()["relinked"], 1);+ assert_eq!(s.doc().unwrap().doc.assets[&aid].link.as_deref(), moved.to_str());+ assert_eq!(s.execute("links.list", &json!({})).unwrap()[0]["status"], "ok");+ let _ = std::fs::remove_dir_all(dir);+ }++ #[test]+ fn pdf_relink_and_update_preserve_selected_page_size() {+ let dir = std::env::temp_dir().join(format!("dc-links-pdf-size-{}", std::process::id()));+ std::fs::create_dir_all(&dir).unwrap();+ let original = dir.join("original.pdf");+ let replacement = dir.join("replacement.pdf");+ std::fs::write(&original, pdf(&[(10, 10), (20, 30)])).unwrap();+ std::fs::write(&replacement, pdf(&[(40, 40), (50, 60)])).unwrap();+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ s.execute("file.place", &json!({"path": original.to_string_lossy(), "pdfPage": 2})).unwrap();+ let aid = s.doc().unwrap().doc.assets.keys().next().copied().unwrap();+ s.execute("links.relink", &json!({"asset": aid.0, "path": replacement.to_string_lossy()})).unwrap();+ let a = &s.doc().unwrap().doc.assets[&aid];+ assert_eq!(a.page, 1);+ assert_eq!(a.pixels, Some((50, 60)));+ assert!(designcraft_render::render_pdf_page(&a.data, a.page as usize, 64).is_some());+ std::fs::write(&replacement, pdf(&[(70, 70), (80, 90)])).unwrap();+ assert_eq!(s.execute("links.update", &json!({})).unwrap()["updated"], 1);+ assert_eq!(s.doc().unwrap().doc.assets[&aid].pixels, Some((80, 90)));+ let raster = dir.join("replacement.png");+ std::fs::write(&raster, png(4, 5)).unwrap();+ s.execute("links.relink", &json!({"asset": aid.0, "path": raster.to_string_lossy()})).unwrap();+ assert_eq!(s.doc().unwrap().doc.assets[&aid].page, 0);+ let _ = std::fs::remove_dir_all(dir);+ }++ #[test]+ fn pdf_reload_rejects_missing_page_without_edit() {+ let full = pdf(&[(10, 10), (20, 30)]);+ let short = pdf(&[(10, 10)]);+ let dir = std::env::temp_dir().join(format!("dc-links-pdf-page-{}", std::process::id()));+ std::fs::create_dir_all(dir.join("new")).unwrap();+ let original = dir.join("book.pdf");+ let replacement = dir.join("new/book.pdf");+ std::fs::write(&replacement, short.clone()).unwrap();+ for command in ["links.relink", "links.relinkFolder", "links.update"] {+ std::fs::write(&original, &full).unwrap();+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ s.execute("file.place", &json!({"path": original.to_string_lossy(), "pdfPage": 2})).unwrap();+ let aid = s.doc().unwrap().doc.assets.keys().next().copied().unwrap();+ if command == "links.update" {+ std::fs::write(&original, &short).unwrap();+ }+ let st = s.doc().unwrap();+ let before = st.doc.clone();+ let revision = st.revision;+ let undo = st.history.undo.len();+ let journal = s.journal.len();+ let params = match command {+ "links.relinkFolder" => json!({"dir": dir.join("new").to_string_lossy(), "missingOnly": false}),+ "links.update" => json!({"asset": aid.0}),+ _ => json!({"asset": aid.0, "path": replacement.to_string_lossy()}),+ };+ let err = s.execute(command, ¶ms).unwrap_err();+ assert!(err.to_string().contains("PDF page 2"), "{command}: {err}");+ let st = s.doc().unwrap();+ assert!(Arc::ptr_eq(&st.doc, &before), "{command}");+ assert_eq!(st.revision, revision);+ assert_eq!(st.history.undo.len(), undo);+ assert_eq!(s.journal.len(), journal);+ assert!(designcraft_render::render_pdf_page(&st.doc.assets[&aid].data, 1, 64).is_some());+ }+ let _ = std::fs::remove_dir_all(dir);+ }+#[test]fn link_status_relink_update_embed() {let dir = std::env::temp_dir().join(format!("dc-links-{}", std::process::id()));