From 1348ec0003ecc5c225ebaa561f261307bfafd50b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 11 Nov 2026 12:35:29 -0800 Subject: [PATCH] Guides: the ruler guide export test leaves out the PDF's dates exports_and_fit_all_are_the_same_with_ruler_guides compared PDF exports byte for byte, but each export carries the time it was written in /ModDate and the XMP packet. Two exports in different seconds differed, so the test failed now and then in CI. The test now drops the dated lines from the PDF before comparing, as undated in the envelope tests does. SVG, PNG and PSD are still compared whole. --- crates/engine/tests/it/ruler_guide_nodes.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/engine/tests/it/ruler_guide_nodes.rs b/crates/engine/tests/it/ruler_guide_nodes.rs index 95625d65d..950da2f06 100644 --- a/crates/engine/tests/it/ruler_guide_nodes.rs +++ b/crates/engine/tests/it/ruler_guide_nodes.rs @@ -257,14 +257,25 @@ fn guides_made_while_editing_a_mask_a_pattern_or_a_symbol_stay() { assert!(!in_symbol, "the guide is not part of the symbol"); } +/// `bytes` without the lines that depend on when the file was written: the PDF dates, and the XMP +/// packet (one line, with its dates and IDs) and trailer `/ID`. +fn undated(bytes: &[u8]) -> Vec { + let stamps: [&[u8]; 5] = [b"CreationDate", b"ModDate", b"xmp:CreateDate", b"xmp:ModifyDate", b"/ID["]; + let dated = |line: &&[u8]| stamps.iter().any(|s| line.windows(s.len()).any(|w| w == *s)); + bytes.split(|b| *b == b'\n').filter(|l| !dated(l)).flat_map(|l| l.iter().copied().chain(*b"\n")).collect() +} + /// The bytes of each export format (PDF without the embedded native document, which keeps the -/// guides), and the box Fit All in Window fits (the art and every artboard). -fn exports(s: &mut Session) -> (Vec<(String, String)>, Option) { +/// guides, and without its dates), and the box Fit All in Window fits (the art and every artboard). +fn exports(s: &mut Session) -> (Vec<(String, Vec)>, Option) { let files = [json!({"format": "svg"}), json!({"format": "pdf", "preserveEditing": false}), json!({"format": "png"}), json!({"format": "psd"})] .iter() .map(|p| { let out = s.execute("document.export", p).unwrap(); - (p["format"].as_str().unwrap().to_string(), out["dataBase64"].as_str().unwrap().to_string()) + let bytes = vectorcraft_format::base64_decode(out["dataBase64"].as_str().unwrap()).unwrap(); + let format = p["format"].as_str().unwrap().to_string(); + let bytes = if format == "pdf" { undated(&bytes) } else { bytes }; + (format, bytes) }) .collect(); let d = &s.doc().unwrap().doc;