Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Align overlapping CI repairs with upstream while retaining regression coverage

skylar taylor-barrick67ca74fe182c
diff --git a/apps/photocraft-cli/tests/cli.rs b/apps/photocraft-cli/tests/cli.rs
index 9000cc35e..5baa83fde 100644
--- a/apps/photocraft-cli/tests/cli.rs
+++ b/apps/photocraft-cli/tests/cli.rs
@@ -189,10 +189,11 @@ fn run_commands_and_save() {
let lines: Vec<Value> = out.lines().map(|l| serde_json::from_str(l).unwrap()).collect();
assert_eq!(lines.len(), 3);
assert_eq!(lines[2]["command"], "document.inspect");
- assert_eq!(lines[2]["result"]["name"], "Run", "inspecting before --out retains the document title");
+ assert_eq!(lines[2]["result"]["name"], "Run");
let (info, _) = ok(bin().arg("info").arg(&out_pc));
let v: Value = serde_json::from_str(&info).unwrap();
- assert_eq!(v["name"], "r.pcraft", "a native bundle stores its destination filename");
+ // Saving a native document gives the reopened bundle its output filename.
+ assert_eq!(v["name"], "r.pcraft");
let names: Vec<&str> = v["layers"].as_array().unwrap().iter().filter_map(|l| l["name"].as_str()).collect();
assert_eq!(names, ["Ink", "Background"]);
// Continue from the saved file and export PNG.
diff --git a/apps/photocraft-cli/tests/orientation.rs b/apps/photocraft-cli/tests/orientation.rs
index e13319207..101195581 100644
--- a/apps/photocraft-cli/tests/orientation.rs
+++ b/apps/photocraft-cli/tests/orientation.rs
@@ -121,14 +121,15 @@ fn orientation_6_jpeg_converts_upright_and_rotates_back() {
assert!(near(at(28, 12), upright_color(12, 4)), "{:?}", at(28, 12));
assert!(near(at(4, 8), upright_color(8, 28)), "{:?}", at(4, 8));
- // .pcraft save, reopen and save again: destination names follow Save As; other metadata and pixels match.
+ // .pcraft save, reopen and save again: identical document and pixels.
let (a, b) = (d.join("a.pcraft"), d.join("b.pcraft"));
ok(bin().arg("convert").arg(&jpg).arg(&a));
ok(bin().arg("convert").arg(&a).arg(&b));
- // Check destination names explicitly, then compare the remaining metadata.
+ // Everything but the file's own path and saved document name must match.
let info = |p: &Path| {
let mut v = serde_json::from_str::<Value>(&ok(bin().arg("info").arg(p))).unwrap();
v.as_object_mut().unwrap().remove("file");
+ v.as_object_mut().unwrap().remove("path");
v
};
let (mut ia, mut ib) = (info(&a), info(&b));
diff --git a/crates/engine/src/adjust_params.rs b/crates/engine/src/adjust_params.rs
index 4b2f3c79c..5885f0cdb 100644
--- a/crates/engine/src/adjust_params.rs
+++ b/crates/engine/src/adjust_params.rs
@@ -1624,12 +1624,10 @@ mod tests {
#[test]
fn destructive_levels_dont_clip_in_32_bit() {
- // Input 15..230, gamma 1.3, output 10..245: black and white land on the output range in
- // integer documents. Float32 keeps HDR values outside 0..1, as the compositor's real-file
- // Levels oracle does. These independently calculated endpoints use the signed-power
- // curve at black and white, not display-clipped values.
+ // Input 15..230, gamma 1.3, output 10..245: integer documents stop at the output range,
+ // while float documents preserve the curve's signed and HDR values beyond it.
let params = json!({"inBlack": 15, "inWhite": 230, "gamma": 1.3, "outBlack": 10, "outWhite": 245});
- for (depth, low, high, tolerance) in [(8, 10.0, 245.0, 0.6), (16, 10.0, 245.0, 0.6), (32, -20.308_89, 265.750_3, 0.01)] {
+ for depth in [8, 16, 32] {
let mut s = crate::Session::new();
s.execute("file.new", json!({"width": 16, "height": 16, "depth": depth, "background": "white"})).unwrap();
s.execute("select.rect", json!({"x": 0, "y": 0, "width": 8, "height": 16})).unwrap();
@@ -1637,10 +1635,12 @@ mod tests {
s.execute("select.deselect", json!({})).unwrap();
s.execute("image.adjustments.levels", params.clone()).unwrap();
let px = pixels(&s);
- assert!((px[0][0] * 255.0 - low).abs() < tolerance, "black @{depth}: {:?}", px[0]);
- assert!((px[1][0] * 255.0 - high).abs() < tolerance, "white @{depth}: {:?}", px[1]);
if depth == 32 {
- assert!(px[0][0] < 0.0 && px[1][0] > 1.0, "HDR endpoints must remain unclipped");
+ assert!(px[0][0].is_finite() && px[0][0] < 0.0, "float black keeps its signed result: {:?}", px[0]);
+ assert!(px[1][0].is_finite() && px[1][0] > 1.0, "float white keeps its HDR result: {:?}", px[1]);
+ } else {
+ assert!((px[0][0] * 255.0 - 10.0).abs() < 0.6, "black @{depth}: {:?}", px[0]);
+ assert!((px[1][0] * 255.0 - 245.0).abs() < 0.6, "white @{depth}: {:?}", px[1]);
}
}
}
@@ -1706,4 +1706,26 @@ mod tests {
}
}
}
+ #[test]
+ fn destructive_levels_match_independent_signed_hdr_endpoints() {
+ // Input 15..230, gamma 1.3, output 10..245: black and white land on the output range in
+ // integer documents. Float32 keeps HDR values outside 0..1, as the compositor's real-file
+ // Levels oracle does. These independently calculated endpoints use the signed-power
+ // curve at black and white, not display-clipped values.
+ let params = json!({"inBlack": 15, "inWhite": 230, "gamma": 1.3, "outBlack": 10, "outWhite": 245});
+ for (depth, low, high, tolerance) in [(8, 10.0, 245.0, 0.6), (16, 10.0, 245.0, 0.6), (32, -20.308_89, 265.750_3, 0.01)] {
+ let mut s = crate::Session::new();
+ s.execute("file.new", json!({"width": 16, "height": 16, "depth": depth, "background": "white"})).unwrap();
+ s.execute("select.rect", json!({"x": 0, "y": 0, "width": 8, "height": 16})).unwrap();
+ s.execute("edit.fill", json!({"color": "#000000"})).unwrap();
+ s.execute("select.deselect", json!({})).unwrap();
+ s.execute("image.adjustments.levels", params.clone()).unwrap();
+ let px = pixels(&s);
+ assert!((px[0][0] * 255.0 - low).abs() < tolerance, "black @{depth}: {:?}", px[0]);
+ assert!((px[1][0] * 255.0 - high).abs() < tolerance, "white @{depth}: {:?}", px[1]);
+ if depth == 32 {
+ assert!(px[0][0] < 0.0 && px[1][0] > 1.0, "HDR endpoints must remain unclipped");
+ }
+ }
+ }
}
diff --git a/xtask/src/i18n_coverage.rs b/xtask/src/i18n_coverage.rs
index 984d8c5ce..ca2787b82 100644
--- a/xtask/src/i18n_coverage.rs
+++ b/xtask/src/i18n_coverage.rs
@@ -185,13 +185,10 @@ fn plural_keys(sources: &[(PathBuf, String)]) -> BTreeSet<Key> {
rest = rest.get(at + 4..).unwrap_or("");
let Some(end) = call_end(rest) else { break };
let args = rest.get(..end).unwrap_or("");
- let args = split_arguments(args);
- let literal = |arg: &&str| {
- let arg = arg.trim();
- let strings = quoted_strings(arg);
- if arg.starts_with('"') && arg.ends_with('"') && strings.len() == 1 { strings.into_iter().next() } else { None }
- };
- if let Some((one, other)) = args.get(2).and_then(literal).zip(args.get(3).and_then(literal)) {
+ // `trn(lang, n, one, other)`: the forms are the last two literals, so a string in the
+ // count expression (`r["files"].len()`) is not mistaken for one.
+ let forms = quoted_strings(args);
+ if let [.., one, other] = forms.as_slice() {
keys.insert(Key { context: "@plural".into(), source: format!("{one}|{other}") });
}
rest = rest.get(end + 1..).unwrap_or("");
@@ -548,17 +545,11 @@ mod tests {
fn plural_keys_come_from_source_calls() {
let sources = vec![(PathBuf::from("ui.rs"), r#"trn(lang, count, "{n} layer", "{n} layers");"#.into())];
assert!(plural_keys(&sources).contains(&Key { context: "@plural".into(), source: "{n} layer|{n} layers".into() }));
- }
-
- #[test]
- fn plural_forms_follow_count_expressions_and_dynamic_forms_are_not_literal_keys() {
- let sources = vec![(
- PathBuf::from("ui.rs"),
- r#"trn(lang, r["files"].as_array().map_or(0, Vec::len) as u64, "Saved {n} file", "Saved {n} files");
- trn(lang, count, one, other);"#
- .into(),
- )];
- assert_eq!(plural_keys(&sources), BTreeSet::from([Key { context: "@plural".into(), source: "Saved {n} file|Saved {n} files".into() }]));
+ // A string literal in the count expression is not one of the forms.
+ let sources = vec![(PathBuf::from("ui.rs"), r#"trn(lang, r["files"].len() as u64, "{n} file", "{n} files");"#.into())];
+ let keys = plural_keys(&sources);
+ assert!(keys.contains(&Key { context: "@plural".into(), source: "{n} file|{n} files".into() }), "{keys:?}");
+ assert_eq!(keys.len(), 1, "{keys:?}");
}
#[test]
@@ -576,7 +567,6 @@ mod tests {
fn source_key_set_is_covered_by_complete_catalogs() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap_or(Path::new("."));
let keys = source_keys(root).unwrap_or_default();
- let mut gaps = Vec::new();
for (code, path) in [
("ja", "ja.tsv"),
("zh-hant", "zh-hant.tsv"),
@@ -594,10 +584,17 @@ mod tests {
let text = fs::read_to_string(&catalog_path).unwrap_or_default();
let translations = parse_catalog(&catalog_path, &text).unwrap_or_default();
let missing: Vec<_> = keys.difference(&translations).collect();
- if !missing.is_empty() {
- gaps.push(format!("{code}: missing source keys: {missing:#?}"));
- }
+ assert!(missing.is_empty(), "{code}: missing source keys: {missing:#?}");
}
- assert!(gaps.is_empty(), "{}", gaps.join("\n"));
+ }
+ #[test]
+ fn plural_forms_follow_count_expressions_and_dynamic_forms_are_not_literal_keys() {
+ let sources = vec![(
+ PathBuf::from("ui.rs"),
+ r#"trn(lang, r["files"].as_array().map_or(0, Vec::len) as u64, "Saved {n} file", "Saved {n} files");
+ trn(lang, count, one, other);"#
+ .into(),
+ )];
+ assert_eq!(plural_keys(&sources), BTreeSet::from([Key { context: "@plural".into(), source: "Saved {n} file|Saved {n} files".into() }]));
}
}