Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge upstream/main (#2710 one test binary per crate, #2713) into round3a-integration

francoisgnf74178cdae73
diff --cc apps/lightcraft/src/control_server.rs
index 12ee6db4e,c7244c703..f24b8b04e
--- a/apps/lightcraft/src/control_server.rs
+++ b/apps/lightcraft/src/control_server.rs
@@@ -245,11 -247,7 +247,10 @@@ mod tests
let mut client = TcpStream::connect(listener.local_addr().unwrap()).unwrap();
client.set_read_timeout(Some(Duration::from_secs(3))).unwrap();
let (stream, _) = listener.accept().unwrap();
+ // Small test messages must not wait for Nagle's algorithm or a delayed ACK.
+ client.set_nodelay(true).unwrap();
+ stream.set_nodelay(true).unwrap();
- // Queue initial input before starting the worker's short idle timeout.
- client.write_all(input.as_bytes()).unwrap();
+ before(&mut client);
let (tx, requests) = channel();
let worker = spawn_connection(stream, tx, egui::Context::default(), Arc::clone(open), idle).unwrap();
Self { client: BufReader::new(client), requests, worker: Some(worker) }
@@@ -302,25 -299,23 +302,34 @@@
#[test]
fn persistent_requests_and_slow_replies_outlive_the_idle_read_timeout() {
let open = Arc::new(AtomicUsize::new(0));
- let mut connection = Connection::new(&open, Duration::from_millis(100), "{\"id\":1,\"method\":\"engine.commands\"}\n");
+ let request = |id: u64| format!("{}\n", json!({"id": id, "method": "engine.commands"}));
+ // Each request reaches the socket before the worker reads it (the next one while the worker
+ // waits for the reply), so only the reply waits outlast the idle timeout, however slowly
+ // this thread runs.
+ let mut connection = Connection::new(&open, Duration::from_millis(100), |c| c.write_all(request(1).as_bytes()).unwrap());
for id in [1, 2] {
- let req = connection.requests.recv_timeout(Duration::from_secs(3)).unwrap();
+ let req = connection.requests.recv_timeout(Duration::from_secs(10)).unwrap();
assert_eq!(req.method, "engine.commands");
assert!(req.take());
+ if id == 1 {
+ connection.client.get_mut().write_all(request(2).as_bytes()).unwrap();
+ } else {
+ connection.client.get_mut().shutdown(std::net::Shutdown::Write).unwrap();
+ }
// A dispatched command waits for its reply, not for socket input.
std::thread::sleep(Duration::from_millis(250));
+ // Prepare the next read before releasing this reply. The client need not be
+ // scheduled again within the worker's short idle timeout.
+ if id == 1 {
+ writeln!(connection.client.get_mut(), "{}", json!({"id": 2, "method": "engine.commands"})).unwrap();
+ } else {
+ connection.client.get_mut().shutdown(std::net::Shutdown::Write).unwrap();
+ }
req.reply.send(json!({"ok": true, "result": id})).unwrap();
+ if id == 2 {
+ // The worker must reach EOF even before the client reads its final reply.
+ connection.join();
+ }
let mut reply = String::new();
connection.client.read_line(&mut reply).unwrap();
let reply: Value = serde_json::from_str(&reply).unwrap();
diff --cc docs/parity-checklist.md
index bd3b2f62a,21140ae26..a171dc7a7
--- a/docs/parity-checklist.md
+++ b/docs/parity-checklist.md
@@@ -479,9 -479,9 +479,9 @@@ differences and missing bindings are i
| LR-BEHAV-TOOLTIPS | Tooltips with shortcuts | P0 | βœ… | `crates/ui-egui/src/panels/bottombar.rs` | |
| LR-BEHAV-TEXTFIELD | Text fields behave alike | P1 | 🟑 | `crates/ui-egui/src/text_field.rs`, `crates/ui-egui/src/panels/topbar.rs`, `crates/ui-egui/src/widgets.rs`, `crates/ui-egui/src/panels/right.rs` (`meta_field`), `crates/ui-egui/src/panels/dialogs.rs`, `crates/ui-egui/src/panels/unnamed.rs` | one shared field: right-click Cut / Copy / Paste / Select All (no Paste in the browser), Esc gives back the text from before the edit, Return / leaving / Esc reported to the caller, optional select-on-focus; agents use `ui.clipboard` (MCP `clipboard`) and `ui.inspect` β†’ `copied`. Used by Search Photos, slider values, the Info panel's metadata fields (multi-line captions), the one-field dialogs (New / Rename Album, New Smart Album, Rename / Merge Keywords, text prompts) and the unnamed faces' name field so far; the other text fields (most dialogs, import, settings, masking, keywords …) still use egui's own and have no menu |
| LR-BEHAV-HEADLESS | Headless UI snapshots | P2 | βœ… | `apps/lightcraft-cli/src/main.rs`, `crates/ui-egui/src/headless.rs`, `docs/control-protocol.md` | `snapshot` rasterizes the UI and defaults photo development to the CPU before the first frame, without adapter discovery; scaled dimensions are validated before allocation, and UI zoom preserves the requested physical viewport; JSON-lines control scripts are supported |
- | LR-BEHAV-ACCESS | Accessibility | P2 | 🟑 | `crates/ui-egui/src/widgets.rs`, `crates/ui-egui/src/text_field.rs`, `crates/ui-egui/src/panels/grid.rs`, `crates/ui-egui/tests/accessibility.rs` | AccessKit (VoiceOver / Narrator / AT-SPI): sliders announce control, value, range and step and take Increment / Decrement, buttons / icon buttons / dropdowns / section headers / sources their labels and state, text fields their caption, grid thumbnails file name, rating, flag and label. `tests/accessibility.rs` fails on an unnamed control, a slider without range or an untitled dialog in every view, Develop tool and 13 dialogs, and checks that Crop and Remove sliders are reached with Tab and that Tab walks the right panels top to bottom. Canvas tools by keyboard (`crates/ui-egui/src/canvas_keys.rs`, `crates/ui-egui/src/tests_canvas_keys.rs`): crop corners, edges and box, spot targets and sources, a New spot point (Return adds), radial / linear gradient handles and mask pins take the focus, are announced with their position and move with the arrows (Shift: further). Brush strokes and red-eye ellipses are pointer-only; not tried with a real screen reader ([audit](ui-parity.md#accessibility-audit)) |
+ | LR-BEHAV-ACCESS | Accessibility | P2 | 🟑 | `crates/ui-egui/src/widgets.rs`, `crates/ui-egui/src/text_field.rs`, `crates/ui-egui/src/panels/grid.rs`, `crates/ui-egui/tests/it/accessibility.rs` | AccessKit (VoiceOver / Narrator / AT-SPI): sliders announce control, value, range and step and take Increment / Decrement, buttons / icon buttons / dropdowns / section headers / sources their labels and state, text fields their caption, grid thumbnails file name, rating, flag and label. `tests/it/accessibility.rs` fails on an unnamed control, a slider without range or an untitled dialog in every view, Develop tool and 13 dialogs, and checks that Crop and Remove sliders are reached with Tab and that Tab walks the right panels top to bottom. Canvas tools by keyboard (`crates/ui-egui/src/canvas_keys.rs`, `crates/ui-egui/src/tests_canvas_keys.rs`): crop corners, edges and box, spot targets and sources, a New spot point (Return adds), radial / linear gradient handles and mask pins take the focus, are announced with their position and move with the arrows (Shift: further). Brush strokes and red-eye ellipses are pointer-only; not tried with a real screen reader ([audit](ui-parity.md#accessibility-audit)) |
-| LR-BEHAV-LOCALE | Language options | P2 | βœ… | `cmd:app.language.english`, `cmd:app.language.simplifiedChinese`, `cmd:app.language.traditionalChinese`, `cmd:app.language.japanese`, `cmd:app.language.portuguese`, `cmd:app.language.french`, `cmd:app.language.spanish`, `cmd:app.language.german`, `cmd:app.language.russian`, `cmd:app.language.ukrainian`, `cmd:app.language.georgian` | Edit > Language lists every language in the table and the active one is checked; shared with Settings > General (docs/localization.md) |
-| LR-BEHAV-LOCALIZE | Localisation | P2 | 🟑 | `crates/ui-egui/src/i18n.rs`, `crates/ui-egui/locales/`, `docs/localization.md`, `docs/localization-zh-hans.md`, `docs/localization-zh-hant.md`, `docs/localization-ja.md`, `docs/localization-pt-br.md`, `docs/localization-es.md`, `docs/localization-de.md`, `docs/localization-ru.md`, `docs/localization-ka.md` | One table entry per language (code, endonym, ISO 15924 script, catalog): English, Simplified Chinese, Traditional Chinese (Taiwan), Japanese, Brazilian Portuguese, Spanish, German, Russian, Ukrainian and Georgian UI with a persisted language preference and craft-fonts regular/bold faces per script (a variable face, as for Arabic, is drawn heavier for bold from its one file); menus, edit, crop/masks, settings, import/export and primary progress messages. Adding a language registers the locale and its language command, plus two catalogs. Stock presets/profiles, history steps, library headings, date headings and capture times are localised (user-named items stay verbatim); the Ukrainian catalog covers every existing catalog key, command/control label and rule-editor label; the German catalog reports newly added gaps; the other catalogs fall back to English for messages they lack. Technical errors remain English; release notes are translated in German and Ukrainian; craft-fonts faces for other scripts (Thai, Arabic, …) are UI fallbacks in every language, for file, folder and album names (#736); Traditional Chinese borrows the Simplified Chinese face (no TC face in craft-fonts yet), and the web build embeds the Japanese, Thai and Georgian faces in WASM while loading the Simplified Chinese face from a separate font file. |
+| LR-BEHAV-LOCALE | Language options | P2 | βœ… | `cmd:app.language.english`, `cmd:app.language.simplifiedChinese`, `cmd:app.language.traditionalChinese`, `cmd:app.language.japanese`, `cmd:app.language.portuguese`, `cmd:app.language.french`, `cmd:app.language.spanish`, `cmd:app.language.german`, `cmd:app.language.russian`, `cmd:app.language.ukrainian`, `cmd:app.language.georgian`, `cmd:app.language.polish` | Edit > Language lists every language in the table and the active one is checked; shared with Settings > General (docs/localization.md) |
+| LR-BEHAV-LOCALIZE | Localisation | P2 | 🟑 | `crates/ui-egui/src/i18n.rs`, `crates/ui-egui/locales/`, `docs/localization.md`, `docs/localization-zh-hans.md`, `docs/localization-zh-hant.md`, `docs/localization-ja.md`, `docs/localization-pt-br.md`, `docs/localization-es.md`, `docs/localization-de.md`, `docs/localization-ru.md`, `docs/localization-ka.md`, `docs/localization-pl.md` | One table entry per language (code, endonym, ISO 15924 script, catalog): English, Simplified Chinese, Traditional Chinese (Taiwan), Japanese, Brazilian Portuguese, Spanish, German, Russian, Ukrainian and Georgian UI with a persisted language preference and craft-fonts regular/bold faces per script (a variable face, as for Arabic, is drawn heavier for bold from its one file); menus, edit, crop/masks, settings, import/export and primary progress messages. Adding a language registers the locale and its language command, plus two catalogs. Stock presets/profiles, history steps, library headings, date headings and capture times are localised (user-named items stay verbatim); the Ukrainian catalog covers every existing catalog key, command/control label and rule-editor label; the German catalog reports newly added gaps; the other catalogs fall back to English for messages they lack. Technical errors remain English; release notes are translated in German and Ukrainian; craft-fonts faces for other scripts (Thai, Arabic, …) are UI fallbacks in every language, for file, folder and album names (#736); Traditional Chinese borrows the Simplified Chinese face (no TC face in craft-fonts yet), and the web build embeds the Japanese, Thai and Georgian faces in WASM while loading the Simplified Chinese face from a separate font file. |
| LR-BEHAV-LEARN | Tutorials | OOS | 🚫 | | |
| LR-BEHAV-WHATSNEW | What's new | P2 | βœ… | `cmd:app.whatsNew`, `docs/whats-new.md` | Help β–Έ What's New: release highlights |
| LR-BEHAV-AI-EA | Early-access badges | P2 | ⬜ | | |
diff --cc xtask/src/main.rs
index fcda976a2,7ce3cb423..05ce3fd9c
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@@ -36,15 -34,13 +36,17 @@@ commands
web [--serve [port]] [--dev]
build the browser app (apps/lightcraft-web) into <target>/web-site/;
--serve serves it on http://127.0.0.1:<port> (default 8080)
- ci [--hardware] [--summary-md]
+ ci [--hardware] [--summary-md] [--quick [--base REF]]
fmt --check, clippy -D warnings, heif, test, GPU probe, parity refs, layers, assets, wasm
- (stops at first failure); writes target/ci/report.json (machine, GPU adapters, data,
+ (stops at first failure). Tests run under cargo test (cargo nextest with
+ LIGHTCRAFT_NEXTEST=1), without examples, then doctests with cargo test --doc. Writes
+ target/ci/report.json (machine, GPU adapters, data,
steps, skipped tests) and target/ci/summary.md; --hardware also runs the GPU tests on
- every backend with a hardware adapter; --summary-md prints the Markdown summary
+ every backend with a hardware adapter; --summary-md prints the Markdown summary.
+ --quick: only what the changes since the merge base with origin/main (or REF) can
+ break: clippy, the changed packages' tests, and heif / parity / wasm when they apply.
+ One ci runs at a time per machine; others wait (LIGHTCRAFT_CI_SLOTS=N for N at once,
+ LIGHTCRAFT_CI_LOCK=off to skip the lock)
corpus [--download]
show where test corpora live; --download fetches PngSuite and CC0 raw samples (raw.pixls.us) into corpus/ and checks their sha256
stats [--exact] count tests and lines per crate (--exact: ask the test harness via `-- --list`)
@@@ -190,60 -189,55 +195,109 @@@ fn total_ram_gb() -> Option<u64>
Some(bytes.saturating_add(1 << 29) >> 30)
}
+ /// The targets the test runs build: no examples (clippy `--all-targets` still checks them).
+ /// Doctests run on their own, [`doctests`]: nextest can't run them.
+ const TEST_TARGETS: [&str; 3] = ["--lib", "--bins", "--tests"];
+
+ /// `args` followed by [`TEST_TARGETS`].
+ fn with_test_targets<'a>(args: &[&'a str]) -> Vec<&'a str> {
+ args.iter().copied().chain(TEST_TARGETS).collect()
+ }
+
+ /// Whether the tests run under `cargo nextest`: only when `LIGHTCRAFT_NEXTEST=1` asks for it and
+ /// nextest is installed. `cargo test` is the default because the demo library's generated scenes
+ /// are cached per process: libtest runs a binary's tests in one process and generates each scene
+ /// once, while nextest's process per test regenerates them (measured: the ui-egui tests take about
+ /// 30 min under nextest, under 5 min under cargo test).
+ fn nextest() -> bool {
+ static FOUND: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
+ *FOUND.get_or_init(|| {
+ if std::env::var_os("LIGHTCRAFT_NEXTEST").is_none_or(|v| v != "1") {
+ return false;
+ }
+ let found = cargo()
+ .args(["nextest", "--version"])
+ .stdout(std::process::Stdio::null())
+ .stderr(std::process::Stdio::null())
+ .status()
+ .is_ok_and(|s| s.success());
+ if !found {
+ eprintln!("note: LIGHTCRAFT_NEXTEST=1 but cargo-nextest is not installed, so the tests run under cargo test (cargo install cargo-nextest --locked)");
+ }
+ found
+ })
+ }
+
+ /// A test run of `args` (packages, features, targets, filters): `cargo nextest run`, or `cargo
+ /// test`. The command and how to print it.
+ fn tests(args: &[&str]) -> (Command, String) {
+ let mut c = cargo();
+ let tool = if nextest() { "nextest run" } else { "test" };
+ c.args(tool.split(' ')).args(args);
+ (c, format!("cargo {tool} {}", args.join(" ")))
+ }
+
+ /// The workspace's doctests.
+ fn doctests() -> (Command, String) {
+ let mut c = cargo();
+ c.args(["test", "--workspace", "--doc"]);
+ (c, "cargo test --workspace --doc".to_owned())
+ }
+
+/// `ci --quick`'s tests: build every workspace test target, then run only the test binaries of
+/// `packages`. Building with `-p` instead would resolve features per selection: different
+/// artifacts from `ci`'s and a warm worktree's (`cargo xtask warm`) workspace builds, so it would
+/// recompile ~130 crates. Doc tests are left to the full `ci`.
+fn test_selected(root: &Path, packages: &std::collections::BTreeSet<String>, skip_log: &Path) -> Result<(), String> {
+ let manifests: std::collections::BTreeMap<String, String> = metadata()?["packages"]
+ .as_array()
+ .into_iter()
+ .flatten()
+ .filter_map(|p| Some((p["manifest_path"].as_str()?.to_owned(), p["name"].as_str()?.to_owned())))
+ .filter(|(_, name)| packages.contains(name))
+ .collect();
- let what = "cargo test --workspace --no-run";
++ let what = "cargo test --workspace --no-run --lib --bins --tests";
+ eprintln!("$ {what} (then the test binaries of {})", packages.iter().map(String::as_str).collect::<Vec<_>>().join(", "));
+ let out = cargo()
- .args(["test", "--workspace", "--no-run", "--message-format=json-render-diagnostics"])
++ .args(with_test_targets(&["test", "--workspace", "--no-run", "--message-format=json-render-diagnostics"]))
+ .stderr(std::process::Stdio::inherit())
+ .output()
+ .map_err(|e| format!("{what}: failed to spawn: {e}"))?;
+ if !out.status.success() {
+ return Err(format!("{what}: exited with {}", out.status));
+ }
+ let mut binaries = Vec::new();
+ for line in String::from_utf8_lossy(&out.stdout).lines() {
+ let Ok(msg) = serde_json::from_str::<serde_json::Value>(line) else { continue };
+ if msg["reason"] != "compiler-artifact" || msg["profile"]["test"] != true {
+ continue;
+ }
+ let (Some(exe), Some(manifest)) = (msg["executable"].as_str(), msg["manifest_path"].as_str()) else { continue };
+ if let Some(name) = manifests.get(manifest) {
+ binaries.push((name.clone(), manifest.to_owned(), exe.to_owned()));
+ }
+ }
+ if binaries.is_empty() {
+ println!("no test binaries in {}", packages.iter().map(String::as_str).collect::<Vec<_>>().join(", "));
+ return Ok(());
+ }
+ let mut failed = Vec::new();
+ for (name, manifest, exe) in &binaries {
+ let dir = Path::new(manifest).parent().unwrap_or(root);
+ let mut c = Command::new(exe);
+ c.current_dir(dir).env("CARGO_MANIFEST_DIR", dir).env("CARGO_PKG_NAME", name).env(ci_report::SKIP_LOG_ENV, skip_log);
+ if std::env::var_os("RUST_TEST_THREADS").is_none() {
+ // as the cargo runs of ci (`cargo()`): more threads make the frame-budget tests flaky
+ c.env("RUST_TEST_THREADS", std::thread::available_parallelism().map_or(4, |n| n.get()).min(4).to_string());
+ }
+ let file = Path::new(exe).file_name().map(|f| f.to_string_lossy().into_owned()).unwrap_or_default();
+ if run(c, &format!("{name}: {file}")).is_err() {
+ failed.push(format!("{name} ({file})"));
+ }
+ }
+ if failed.is_empty() { Ok(()) } else { Err(format!("tests failed in {}", failed.join(", "))) }
+}
+
pub fn run(mut cmd: Command, what: &str) -> Result<(), String> {
eprintln!("$ {what}");
let status = cmd.status().map_err(|e| format!("{what}: failed to spawn: {e}"))?;
@@@ -308,30 -302,15 +362,24 @@@ fn wasm_set() -> Result<Vec<String>, St
.collect())
}
+ /// One `cargo check` over the whole set; `--keep-going` reports every crate that fails.
fn cmd_wasm() -> Result<(), String> {
- let set = wasm_set()?;
+ cmd_wasm_for(None)
+}
+
+/// The wasm check of the wasm-safe crates, or only those of them in `only` (`ci --quick`).
+fn cmd_wasm_for(only: Option<&std::collections::BTreeSet<String>>) -> Result<(), String> {
+ let set: Vec<String> = wasm_set()?.into_iter().filter(|p| only.is_none_or(|o| o.contains(p))).collect();
+ if set.is_empty() {
+ println!("wasm32-unknown-unknown check: no changed crate builds for wasm32");
+ return Ok(());
+ }
- let mut results = Vec::new();
+ let mut c = cargo();
+ c.args(["check", "--target", "wasm32-unknown-unknown", "--keep-going"]);
for pkg in &set {
- let mut c = cargo();
- c.args(["check", "--target", "wasm32-unknown-unknown", "-p", pkg]);
- let ok = run(c, &format!("cargo check --target wasm32-unknown-unknown -p {pkg}")).is_ok();
- results.push((pkg.clone(), ok));
- }
- println!("\nwasm32-unknown-unknown check:");
- for (p, ok) in &results {
- println!(" {:<6} {p}", if *ok { "ok" } else { "FAIL" });
+ c.args(["-p", pkg]);
}
- let failed = results.iter().filter(|r| !r.1).count();
- if failed == 0 { Ok(()) } else { Err(format!("{failed} crate(s) failed the wasm check")) }
+ run(c, &format!("cargo check --target wasm32-unknown-unknown --keep-going -p {}", set.join(" -p ")))
}
fn cmd_ci(args: &[&str]) -> Result<(), String> {
@@@ -432,9 -378,9 +483,9 @@@
),
(
"test",
- Box::new(|| {
- test(tests(&with_test_targets(&["--workspace"])), "test")?;
- test(doctests(), "test")
+ Box::new(|| match &plan {
+ Some(p) if !p.workspace_wide => test_selected(&root, &p.packages, &ci_report::skip_log(&root, "test")),
- _ => test(&["test", "--workspace"], "test"),
++ _ => test(tests(&with_test_targets(&["--workspace"])), "test").and_then(|()| test(doctests(), "test")),
}),
),
];