mirror of
https://github.com/storytold/photocraft.git
synced 2026-10-29 02:32:01 +01:00
`compose::flatten` returns an empty buffer for canvases over MAX_RENDER_PIXELS. Trim (Top Left) indexed `px[0]` of it and Duplicate › Merged Layers Only fed it to `write_region`'s length assert: both panicked; Trim's other modes reported "nothing to trim to". Both now return a "too large to flatten" error first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
31 lines
1.2 KiB
Rust
31 lines
1.2 KiB
Rust
//! Trim and Duplicate › Merged Layers Only flatten the document; on a canvas over the compositor's
|
||
//! render cap the flatten comes back empty, and both must report it instead of panicking (#7223).
|
||
|
||
use photocraft_engine::Session;
|
||
use serde_json::json;
|
||
|
||
/// 1.2e9 px: within File › New's per-side limit, over `MAX_RENDER_PIXELS` (2^30).
|
||
fn huge() -> Session {
|
||
let mut s = Session::new();
|
||
s.execute("file.new", json!({"width": 40000, "height": 30000, "background": "transparent"})).unwrap();
|
||
s
|
||
}
|
||
|
||
#[test]
|
||
fn trim_on_a_document_too_large_to_flatten_is_an_error() {
|
||
for based in ["topLeft", "bottomRight", "transparent"] {
|
||
let mut s = huge();
|
||
let err = s.execute("image.trim", json!({"basedOn": based})).unwrap_err().to_string();
|
||
assert!(err.contains("too large"), "{based}: {err}");
|
||
assert_eq!(s.active().unwrap().doc.size.width, 40000, "{based}: the document is untouched");
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn merged_duplicate_of_a_document_too_large_to_flatten_is_an_error() {
|
||
let mut s = huge();
|
||
let err = s.execute("image.duplicate", json!({"mergedOnly": true})).unwrap_err().to_string();
|
||
assert!(err.contains("too large"), "{err}");
|
||
assert_eq!(s.documents().len(), 1, "no half-built copy is added");
|
||
}
|