Merge remote-tracking branch 'origin/main' into repin/craft-libs-next-home

This commit is contained in:
David Mann committed 2026-11-20 18:53:14 +01:00
commit 3c22f8962c
8 files changed
+131 -9

No files matched your search

+2
View File
@@ -1,5 +1,7 @@
[alias]
xtask = "run -p xtask --"
# Archive and doctest jobs do not need the framework's lockfile and translation checks.
xtask-gate = "run --locked -p xtask --no-default-features -- ci"
# wgpu's GL backend (glutin_wgl_sys) imports opengl32.dll, so every binary that links wgpu loads
# it at start, and a process that has loaded it takes about 60 ms longer to exit (#15444): every
+4 -4
View File
@@ -192,8 +192,8 @@ jobs:
# missing-translations report (`cargo xtask ci lint`, xtask/src/main.rs), and the CI scripts'
# own tests.
lint-command: python3 scripts/test-ci-gpu-lavapipe.py && python3 scripts/test-ci-windows-gpu-tests.py && python3 scripts/test-ci-test-times.py && cargo xtask ci lint
archive-command: cargo xtask ci archive --gpu-shard
after-archive-command: cargo xtask ci doctest
archive-command: cargo xtask-gate archive --gpu-shard
after-archive-command: cargo xtask-gate doctest
test-shards: 4
shard-archives: true
# The tests and panic_hunt with `--locked --features heif` (TEST_TARGETS in xtask/src/main.rs).
@@ -243,8 +243,8 @@ jobs:
PHOTOCRAFT_CI_EXCLUDE=photocraft-web photocraft-web-boot ${{ needs.platforms.outputs.windows_gpu == 'false' && 'photocraft-gpu' || '' }} ${{ needs.platforms.outputs.windows_skip }}
timeout-minutes: 100
lint-command: cargo xtask ci clippy
archive-command: cargo xtask ci archive
after-archive-command: cargo xtask ci doctest
archive-command: cargo xtask-gate archive
after-archive-command: cargo xtask-gate doctest
test-shards: 6
shard-archives: true
shard-command: bash scripts/ci-test-shard.sh
+7
View File
@@ -238,6 +238,13 @@ fn brst_round_trip() {
assert_eq!(super::brst_data(0), None);
}
#[test]
fn brst_ignores_truncated_and_trailing_bytes() {
assert_eq!(super::parse_brst(&[]), 0);
assert_eq!(super::parse_brst(&[0, 0, 0]), 0);
assert_eq!(super::parse_brst(&[0, 0, 0, 2, 0xff, 0xee]), 0b100);
}
#[test]
fn placed_layer_warp_is_read() {
use craft_psd::descriptor::ObjectArray;
+33
View File
@@ -127,6 +127,39 @@ fn clipping_path_resource_2999_unchanged_flatness_only_and_new_export() {
assert_eq!(legacy_2999.data, b"\x07Outline\x00\x01\x80\x00");
}
#[test]
fn clipping_path_resource_2999_duplicate_and_rename_parity() {
let mut d = doc();
d.paths.push(NamedPath { name: "Outline".into(), path: path(), psd_raw: None });
d.paths.push(NamedPath { name: "Other".into(), path: path(), psd_raw: None });
d.clipping_path = Some(photocraft_doc::ClippingPath { name: "Outline".into(), flatness: 1.0 });
let fresh_bytes = export(&d, "x.psd", &ExportOptions::default()).unwrap().bytes;
let mut file = craft_psd::PsdFile::from_bytes(&fresh_bytes).unwrap();
let last_payload = b"\x07Outline\x00\x03\x00\x00\x00\x00\x00\x01".to_vec();
file.resources.push(craft_psd::ImageResource::new(2999, last_payload.clone()));
let mut imported = import("x.psd", &file.to_bytes().unwrap()).unwrap().document;
assert_eq!(imported.clipping_path.as_ref().unwrap().flatness, 3.0);
// Unchanged relative to the last matching 2999 resource preserves its bytes.
let unchanged = export(&imported, "x.psd", &ExportOptions::default()).unwrap().bytes;
let unchanged_2999: Vec<_> = craft_psd::PsdFile::from_bytes(&unchanged).unwrap().resources.into_iter().filter(|r| r.id == 2999).map(|r| r.data).collect();
assert_eq!(unchanged_2999.last().unwrap(), &last_payload);
// Flatness edit updates the fixed-point field while preserving the trailing fill-rule bytes.
imported.clipping_path.as_mut().unwrap().flatness = 4.0;
let edited = export(&imported, "x.psd", &ExportOptions::default()).unwrap().bytes;
let edited_2999: Vec<_> = craft_psd::PsdFile::from_bytes(&edited).unwrap().resources.into_iter().filter(|r| r.id == 2999).map(|r| r.data).collect();
assert_eq!(edited_2999.last().unwrap(), b"\x07Outline\x00\x04\x00\x00\x00\x00\x00\x01");
// Renaming the clipping path drops the old 2999 resources and emits a fresh one.
imported.clipping_path = Some(photocraft_doc::ClippingPath { name: "Other".into(), flatness: 2.0 });
let renamed = export(&imported, "x.psd", &ExportOptions::default()).unwrap().bytes;
let renamed_2999: Vec<_> = craft_psd::PsdFile::from_bytes(&renamed).unwrap().resources.into_iter().filter(|r| r.id == 2999).map(|r| r.data).collect();
assert_eq!(renamed_2999, vec![b"\x05Other\x00\x02\x00\x00".to_vec()]);
}
#[test]
fn shape_layer_typed_roundtrip() {
let mut d = doc();
@@ -105,6 +105,46 @@ fn point_clicks_toggle_members_but_keep_the_singleton_and_plain_multi_selection(
assert_eq!(f.bounds(), before, "selection-only gestures move no pixels");
}
#[test]
fn group_auto_select_picks_and_moves_the_enclosing_group() {
let mut f = Fixture::new();
let [a, b, _] = f.layers;
f.select(&[a]);
let group = LayerId(f.app.run("layer.new.groupFromLayers", json!({"name": "G"})).unwrap()["layer"].as_u64().unwrap());
f.select(&[b]);
f.app.ui.tool_options.move_target = "group".into();
let before = f.bounds();
f.gesture([14.0, 14.0], [20.0, 16.0], Modifiers::NONE);
f.assert_selected(&[group]);
assert_eq!(f.bounds()[1], before[1].translate(6, 2), "the group moves its child");
assert_eq!(f.bounds()[2], before[2], "the other layer stays put");
}
#[test]
fn dragging_a_selected_layer_moves_the_whole_selection() {
let mut f = Fixture::new();
let [a, b, _] = f.layers;
f.select(&[a, b]);
let before = f.bounds();
f.gesture([14.0, 14.0], [20.0, 16.0], Modifiers::NONE);
f.assert_selected(&[a, b]);
assert_eq!(f.bounds()[1], before[1].translate(6, 2));
assert_eq!(f.bounds()[2], before[2].translate(6, 2));
}
#[test]
fn shift_click_adds_shape_layers_one_after_another() {
let mut f = Fixture::new();
let ids = [10, 34, 58].map(|x| {
let layer = f.app.run("shape.create", json!({"kind": "rect", "rect": [x, 35, 10, 10], "fill": "#ff0000"})).unwrap();
LayerId(layer["layer"].as_u64().unwrap())
});
f.gesture([15.0, 40.0], [15.0, 40.0], Modifiers::NONE);
f.gesture([39.0, 40.0], [39.0, 40.0], Modifiers::SHIFT);
f.gesture([63.0, 40.0], [63.0, 40.0], Modifiers::SHIFT);
f.assert_selected(&ids);
}
/// Shift-press changes the selected set immediately, and only that set moves on drag (#11102).
#[test]
fn shift_drag_moves_the_layers_selected_after_the_press() {
@@ -89,8 +89,12 @@ fn a_click_on_another_layers_pixels_commits_and_keeps_the_selection() {
app.ui.extras.rulers = false;
app.ui.extras.snap = false;
// "Other" has a blue block at x 120..160, y 120..160; "Paint" a red one at x 20..60, y 20..60.
let mut other = None;
for (name, at, color) in [("Other", 120, "#0000ff"), ("Paint", 20, "#ff0000")] {
let id = app.run("layer.new.layer", json!({"name": name})).unwrap()["layer"].as_u64().unwrap();
if name == "Other" {
other = Some(LayerId(id));
}
app.run("layer.select", json!({"layer": id})).unwrap();
app.run("select.rect", json!({"x": at, "y": at, "width": 40, "height": 40})).unwrap();
app.run("edit.fill", json!({"contents": "color", "color": color})).unwrap();
@@ -99,13 +103,20 @@ fn a_click_on_another_layers_pixels_commits_and_keeps_the_selection() {
let paint = app.session.active().unwrap().active_layer.unwrap();
let app_ctx = app.ctx().clone();
crate::menus::invoke(&mut app, &app_ctx, "edit.freeTransform", json!({})).unwrap();
shift_right(&mut app);
app.ui.transform.as_mut().unwrap().edit_box(|b| *b = b.scaled_about_pivot(2.0, 2.0));
let before = steps(&app);
click(&mut app, [140.0, 140.0]);
assert!(app.ui.transform.is_none(), "committed");
assert_eq!(steps(&app), before + 1);
let bounds = app.session.active().unwrap().doc.layer(paint).unwrap().surface().unwrap().content_bounds();
assert_eq!(bounds, photocraft_geom::Rect::new(0, 0, 80, 80), "the resized pixels are committed");
assert_eq!(app.session.active().unwrap().history.entries().last().map(ToString::to_string).as_deref(), Some("Free Transform"));
assert_eq!(app.session.active().unwrap().selected_layers(), vec![paint], "the selection doesn't change");
app.ui.tool = crate::state::Tool::Move;
app.ui.tool_options.move_auto_select = true;
app.ui.tool_options.move_target = "layer".into();
click(&mut app, [140.0, 140.0]);
assert_eq!(app.session.active().unwrap().selected_layers(), vec![other.unwrap()], "the second click picks the other layer");
}
/// A layer linked to the transformed one after the box opened moves with the commit
+6 -2
View File
@@ -8,6 +8,10 @@ publish = false
[lints]
workspace = true
[features]
default = ["framework-checks"]
framework-checks = ["dep:craft", "dep:craft-i18n"]
[dependencies]
serde_json = { workspace = true }
serde = { workspace = true }
@@ -15,9 +19,9 @@ chrono = { workspace = true }
# perf/budgets.toml and scorecard/*.toml (MIT OR Apache-2.0).
toml = "1"
# `i18n-report` looks the UI strings up in the craft-i18n catalogs as the app does.
craft-i18n = { workspace = true }
craft-i18n = { workspace = true, optional = true }
# `egui-fork` checks Cargo.lock against `craft::egui_fork`.
craft = { workspace = true }
craft = { workspace = true, optional = true }
[dev-dependencies]
tempfile = "3"
+27 -2
View File
@@ -7,6 +7,7 @@ mod cache_units;
mod cargo_env;
mod corpus;
mod corpus_pins;
#[cfg(feature = "framework-checks")]
mod i18n_report;
mod ico;
mod layers;
@@ -95,7 +96,7 @@ fn main() -> ExitCode {
Some("test-corpus") => corpus::test_cmd(&rest),
Some("stats") => stats::run(&root(), rest.contains(&"--exact")),
Some("parity") => cmd_parity(),
Some("i18n-report") => i18n_report::run(&root()),
Some("i18n-report") => cmd_i18n_report(),
Some("perf") => perf::run(&root(), &rest),
Some("scorecard") => scorecard::run(&root(), &rest),
Some("version") => version::run(&root(), &rest),
@@ -151,6 +152,7 @@ pub fn target_dir() -> Result<PathBuf, String> {
/// Two egui revisions in one build give two incompatible `Ui` types, so the workspace's egui
/// `[patch]` must name the revision the craft framework is built with.
#[cfg(feature = "framework-checks")]
fn cmd_egui_fork() -> Result<(), String> {
let path = root().join("Cargo.lock");
let lock = std::fs::read_to_string(&path).map_err(|e| format!("{}: {e}", path.display()))?;
@@ -159,6 +161,29 @@ fn cmd_egui_fork() -> Result<(), String> {
Ok(())
}
#[cfg(feature = "framework-checks")]
fn cmd_i18n_report() -> Result<(), String> {
i18n_report::run(&root())
}
// An explicitly minimal xtask can still run either check when asked for it.
#[cfg(not(feature = "framework-checks"))]
fn run_framework_check(name: &str) -> Result<(), String> {
let mut c = cargo();
c.args(["run", "--locked", "-p", "xtask", "--features", "framework-checks", "--", name]);
run(c, name)
}
#[cfg(not(feature = "framework-checks"))]
fn cmd_egui_fork() -> Result<(), String> {
run_framework_check("egui-fork")
}
#[cfg(not(feature = "framework-checks"))]
fn cmd_i18n_report() -> Result<(), String> {
run_framework_check("i18n-report")
}
fn cmd_layers() -> Result<(), String> {
let crates = layers::from_metadata(&metadata()?)?;
println!("Dependency layering (docs/architecture.md §3)\n");
@@ -364,7 +389,7 @@ fn step_doctest(o: &CiOptions) -> Result<(), String> {
fn step_i18n(_: &CiOptions) -> Result<(), String> {
// Lists missing translations for the log; a missing string shows in English, so it never fails CI.
if let Err(e) = i18n_report::run(&root()) {
if let Err(e) = cmd_i18n_report() {
eprintln!("warning: i18n report failed: {e}");
}
Ok(())