Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Continuous integration: run `cargo xtask ci` (the project's one quality gate, see AGENTS.md)
# on Linux and Windows x64, and on macOS arm64 from main and the weekly schedule. Only FreeBSD
# ran `cargo test` before this; these add the main platforms. The jobs are independent and run
# in parallel; none is `needs:`-gated on another.
name: CI

on:
push:
branches: [main]
pull_request:
paths:
- "**.rs"
- "**.toml"
- "**.lock"
# `cargo xtask ci` also runs the assets and parity gates, which read these:
- "assets/**"
- docs/parity-checklist.md
- .github/workflows/ci.yml
schedule:
- cron: "41 4 * * 1" # weekly, so drift in the runner images shows up
workflow_dispatch:

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: 1
RUST_TEST_THREADS: "4"

jobs:
linux-x64:
name: Linux x86_64 (build + test)
runs-on: ubuntu-22.04
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# Fonts (optional build input; required in CI): see craftrules standards/fonts.md.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: storytold/craft-fonts
ref: 8dcdacd5153e64560d109541a47d806f26f048c0
path: craft-fonts
# `cargo xtask ci` ends with the wasm32 check, so the target must be installed or the
# step fails with "can't find crate for `std`" (the same reason release.yml sets it).
- uses: dtolnay/rust-toolchain@686976e191b89faba57d3206551f0f330d8cb249 # stable
with:
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
key: ci-linux-x64-${{ hashFiles('Cargo.lock') }}
# Only what building and testing the workspace needs: the X11/Wayland/GL and
# fontconfig/freetype headers for egui/winit. The packaging tools release.yml needs
# (desktop-file-validate, appstreamcli, zsyncmake) are not run by `cargo xtask ci`.
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev \
pkg-config libfontconfig1-dev libfreetype6-dev
- name: Run cargo xtask ci
env:
CRAFT_FONTS_DIR: ${{ github.workspace }}/craft-fonts
CRAFT_FONTS_REQUIRED: "1"
CARGO_TARGET_DIR: ${{ runner.temp }}/target
run: cargo xtask ci

windows-x64:
name: Windows x86_64 (build + test)
runs-on: windows-2022
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# Fonts (optional build input; required in CI): see craftrules standards/fonts.md.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: storytold/craft-fonts
ref: 8dcdacd5153e64560d109541a47d806f26f048c0
path: craft-fonts
# `cargo xtask ci` ends with the wasm32 check, so the target must be installed or the
# step fails with "can't find crate for `std`" (the same reason release.yml sets it).
- uses: dtolnay/rust-toolchain@686976e191b89faba57d3206551f0f330d8cb249 # stable
with:
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
key: ci-windows-x64-${{ hashFiles('Cargo.lock') }}
# No system dependencies: the X11/Wayland/GL and fontconfig headers Linux needs have no
# Windows equivalent here, and the HEIF decoder is pure Rust (heic-rs), so unlike Linux
# there is nothing to install. MSVC, freetype and fontconfig are part of the toolchain.
- name: Run cargo xtask ci
env:
CRAFT_FONTS_DIR: ${{ github.workspace }}/craft-fonts
CRAFT_FONTS_REQUIRED: "1"
# Off the workspace by default: the runner's checkout path is already long and MSVC
# hits the 260-character limit, which cargo's deep target/ paths can exceed.
CARGO_TARGET_DIR: ${{ runner.temp }}/target
run: cargo xtask ci

macos-arm64:
name: macOS arm64 (build + test)
# Standard hosted runner, not macos-15-xlarge: the larger macOS runners are budget-capped
# and reserved for release.yml (see its comment). macOS minutes bill at roughly 10x Linux,
# so this skips pull_request and runs on pushes to main, the weekly schedule and dispatch.
# Deleting this one line is the whole "run on every PR" decision, if that is ever wanted.
if: github.event_name != 'pull_request'
runs-on: macos-14 # arm64 (M1), 3 vCPU
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# Fonts (optional build input; required in CI): see craftrules standards/fonts.md.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: storytold/craft-fonts
ref: 8dcdacd5153e64560d109541a47d806f26f048c0
path: craft-fonts
# `cargo xtask ci` ends with the wasm32 check, so the target must be installed or the
# step fails with "can't find crate for `std`" (the same reason release.yml sets it).
- uses: dtolnay/rust-toolchain@686976e191b89faba57d3206551f0f330d8cb249 # stable
with:
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
key: ci-macos-arm64-${{ hashFiles('Cargo.lock') }}
# No system dependencies: no X11/Wayland/GL or fontconfig headers (macOS uses CoreText),
# and the HEIF decoder is pure Rust, so like Windows there is nothing to install.
- name: Run cargo xtask ci
env:
CRAFT_FONTS_DIR: ${{ github.workspace }}/craft-fonts
CRAFT_FONTS_REQUIRED: "1"
# 3 vCPU, so do not oversubscribe the test harness the way the 4-core runners do.
RUST_TEST_THREADS: "3"
CARGO_TARGET_DIR: ${{ runner.temp }}/target
run: cargo xtask ci
3 changes: 3 additions & 0 deletions apps/lightcraft/src/editors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ mod tests {
assert_eq!(reg_value("ERROR: The system was unable to find the specified registry key or value."), None);
}

/// Freedesktop `.desktop` entries: only the Linux/FreeBSD branch of `locate` reaches this code,
/// and a POSIX path like `/home/...` is not `is_absolute()` on Windows, so the test is Unix only.
#[cfg(unix)]
#[test]
fn desktop_entries_give_their_program() {
let appimage = "[Desktop Entry]\nName=PhotoCraft\nExec=\"/home/simon/Apps/photocraft-1.2-linux-x86_64.AppImage\" %F\n";
Expand Down
6 changes: 4 additions & 2 deletions crates/catalog/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ impl LibraryLock {
}

/// Another descriptor on the locked file: what a process spawned by another thread holds
/// between fork and exec (a `dup` refers to the same open file description). Tests only.
#[cfg(test)]
/// between fork and exec (a `dup` refers to the same open file description). Tests only,
/// and Unix only — it exists solely for the flock test, so compiling it on Windows left it
/// unused and `cargo xtask ci`'s `-D warnings` failed there.
#[cfg(all(test, unix))]
pub(crate) fn descriptor_copy(&self) -> Option<File> {
self.file.as_ref().and_then(|f| f.try_clone().ok())
}
Expand Down
13 changes: 9 additions & 4 deletions crates/engine/src/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,8 @@ pub(crate) mod tests {

/// Compare the unfinished operation and every observed packet after partial progress.
/// Companion order is incidental; paths and recorded content versions are exact.
/// Only the `#[cfg(unix)]` sidecar-repair tests use it.
#[cfg(unix)]
pub(crate) fn assert_repair_packets(actual: &SidecarMove, unfinished: &SidecarMove, packets: &[(PathBuf, &[u8])]) {
let mut expected = unfinished.clone();
expected.companions =
Expand Down Expand Up @@ -1311,10 +1313,13 @@ pub(crate) mod tests {
assert_eq!(to.join(old_sidecar.file_name().unwrap()).exists(), copied);
for (step, current) in [("edit.undo", &from), ("edit.redo", &to)] {
s.execute(step, &serde_json::json!({})).unwrap();
assert_eq!(
s.catalog.photo(PhotoId(1)).unwrap().source,
Source::File { path: current.join("b.jpg").to_string_lossy().into_owned() }
);
// Compare as `Path`: the recorded source is the native path the move wrote
// (`\` on Windows), while `join` keeps the `/` of its argument, and only
// `Path`'s equality normalizes separators.
let Source::File { path } = &s.catalog.photo(PhotoId(1)).unwrap().source else {
panic!("the photo is still a file source");
};
assert_eq!(std::path::Path::new(path), current.join("b.jpg"), "{step}");
assert_eq!(std::fs::read(current.join(sidecar.file_name().unwrap())).unwrap(), b"Retained edits");
assert_eq!(current.join(old_sidecar.file_name().unwrap()).exists(), copied);
}
Expand Down
7 changes: 5 additions & 2 deletions crates/engine/src/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,14 +748,17 @@ mod tests {
}
}

#[cfg(test)]
// Sidecar save/repair round trips: they build sidecars that differ only in case, which is the
// same file twice on a case-insensitive volume (Windows), so they are Unix-only.
#[cfg(all(test, unix))]
#[path = "sidecar/tests_repair_saves.rs"]
mod tests_repair_saves;

#[cfg(test)]
#[path = "sidecar/tests_repair_companions.rs"]
mod tests_repair_companions;

#[cfg(test)]
// Companion provenance likewise, like tests_repair_saves.
#[cfg(all(test, unix))]
#[path = "sidecar/tests_repair_provenance.rs"]
mod tests_repair_provenance;
3 changes: 3 additions & 0 deletions crates/engine/src/sidecar/tests_repair_companions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ fn assert_fresh(path: &Path) {
assert!(data.keywords.unwrap().contains(&"café".to_string()));
}

#[cfg(unix)]
#[test]
fn partial_move_companions_allow_save_and_autowrite_without_weakening_collisions() {
for upper_stem in [false, true] {
Expand Down Expand Up @@ -151,6 +152,7 @@ fn partial_move_companions_allow_save_and_autowrite_without_weakening_collisions
}
}

#[cfg(unix)]
#[test]
fn rollback_repair_and_shared_copy_keep_known_companions() {
for rollback in [false, true] {
Expand Down Expand Up @@ -226,6 +228,7 @@ fn a_later_save_recognizes_companions_after_an_earlier_repair_retires() {
std::fs::remove_dir_all(dir).unwrap();
}

#[cfg(unix)]
#[test]
fn queued_stem_retry_preserves_shared_packet_after_batch_rollback() {
let dir = crate::tests_xmp::temp_dir("queued-stem-batch-rollback");
Expand Down
16 changes: 15 additions & 1 deletion crates/engine/src/tests_filesystem_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use lightcraft_catalog::{Op, Photo, PhotoId, Source};
use serde_json::json;

use crate::{Selection, Session};
use crate::Session;
// Only the case-sensitive-fs sidecar history tests below reach for `Selection`.
#[cfg(unix)]
use crate::Selection;

fn select(s: &mut Session, ids: &[u64], active: u64) {
s.execute("library.select", &json!({"ids": ids, "active": active})).unwrap();
Expand Down Expand Up @@ -42,6 +45,9 @@ fn assert_file_catalog_and_journal(s: &Session, fs: &crate::rename::tests::FakeF
assert_eq!(replayed.catalog.to_snapshot(), s.catalog.to_snapshot());
}

/// Only used by the `#[cfg(unix)]` sidecar-history tests, which need two sidecars that differ
/// only in case (one file on Windows).
#[cfg(unix)]
fn sidecar_history_fixture(redo: bool) -> (Session, crate::rename::tests::FakeFs, lightcraft_catalog::MemStore) {
let store = lightcraft_catalog::MemStore::new();
let mut s = memory_library(&store);
Expand Down Expand Up @@ -73,10 +79,12 @@ fn sidecar_history_fixture(redo: bool) -> (Session, crate::rename::tests::FakeFs
(s, fs, store)
}

#[cfg(unix)]
fn sidecar_history_entry(s: &Session, redo: bool) -> &crate::UndoEntry {
if redo { s.redo.last().unwrap() } else { s.undo.last().unwrap() }
}

#[cfg(unix)]
#[test]
fn merged_renames_coalesce_physical_moves_and_keep_retry_inverses_and_journal() {
use crate::rename::tests::FakeFs;
Expand Down Expand Up @@ -131,6 +139,7 @@ fn merged_renames_coalesce_physical_moves_and_keep_retry_inverses_and_journal()
}
}

#[cfg(unix)]
#[test]
fn partial_file_history_failures_retry_without_losing_either_inverse_or_journal() {
use crate::rename::tests::FakeFs;
Expand Down Expand Up @@ -214,6 +223,7 @@ fn partial_file_history_failures_retry_without_losing_either_inverse_or_journal(
}
}

#[cfg(unix)]
#[test]
fn history_retries_both_sidecar_styles_after_following_a_photo_with_failed_rollback() {
use crate::rename::MoveFs;
Expand Down Expand Up @@ -289,6 +299,7 @@ fn history_retries_both_sidecar_styles_after_following_a_photo_with_failed_rollb
}
}

#[cfg(unix)]
#[test]
fn history_repairs_a_sidecar_whose_rollback_failed_before_retrying_the_photo() {
use crate::sidecar::{SidecarNaming, sidecar_path};
Expand Down Expand Up @@ -328,6 +339,7 @@ fn history_repairs_a_sidecar_whose_rollback_failed_before_retrying_the_photo() {
}
}

#[cfg(unix)]
#[test]
fn initial_partial_rename_keeps_sidecar_repairs_for_noop_retry_and_history() {
use crate::rename::tests::FakeFs;
Expand Down Expand Up @@ -404,6 +416,7 @@ fn initial_sidecar_rollback_failure_keeps_a_repair_only_history_step() {
assert_file_catalog_and_journal(&s, &fs, &store);
}

#[cfg(unix)]
#[test]
fn discarded_file_history_keeps_sidecar_repairs_without_stale_catalog_inverses() {
use crate::rename::MoveFs;
Expand Down Expand Up @@ -484,6 +497,7 @@ fn discarded_file_history_keeps_sidecar_repairs_without_stale_catalog_inverses()
}
}

#[cfg(unix)]
#[test]
fn merged_rename_failure_keeps_rolled_back_photo_identity() {
use crate::rename::tests::FakeFs;
Expand Down
16 changes: 10 additions & 6 deletions crates/engine/src/tests_folders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,10 @@ fn a_folder_is_created_on_disk_and_undo_removes_it() {
#[test]
fn photos_move_to_another_folder_with_their_sidecars_and_back_on_undo() {
let dir = Scratch::new("move-photos");
// Compare as `PathBuf`, not as text: the catalog stores the native path the move wrote
// (`\` on Windows) while `Scratch::path` keeps the literal `/` from its argument, and
// `PathBuf` equality normalizes separators so the same file compares equal either way.
let at = |s: String| std::path::PathBuf::from(s);
std::fs::create_dir_all(dir.0.join("in")).unwrap();
std::fs::create_dir_all(dir.0.join("out")).unwrap();
let mut s = Session::new();
Expand All @@ -621,17 +625,17 @@ fn photos_move_to_another_folder_with_their_sidecars_and_back_on_undo() {
assert_eq!(std::fs::read_to_string(dir.path("out/a.jpg")).unwrap(), "A");
assert!(dir.0.join("out/a.xmp").is_file(), "the sidecar goes along");
assert!(!dir.0.join("in/a.jpg").exists() && !dir.0.join("in/a.xmp").exists());
assert_eq!(file_of(&s, a), dir.path("out/a.jpg"));
assert_eq!(file_of(&s, b), dir.path("out/b.jpg"));
assert_eq!(file_of(&s, vc), dir.path("out/a.jpg"), "the virtual copy follows");
assert_eq!(at(file_of(&s, a)), at(dir.path("out/a.jpg")));
assert_eq!(at(file_of(&s, b)), at(dir.path("out/b.jpg")));
assert_eq!(at(file_of(&s, vc)), at(dir.path("out/a.jpg")), "the virtual copy follows");
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(file_of(&s, a), dir.path("in/a.jpg"));
assert_eq!(file_of(&s, vc), dir.path("in/a.jpg"));
assert_eq!(at(file_of(&s, a)), at(dir.path("in/a.jpg")));
assert_eq!(at(file_of(&s, vc)), at(dir.path("in/a.jpg")));
assert!(dir.0.join("in/a.jpg").is_file() && dir.0.join("in/a.xmp").is_file() && dir.0.join("in/b.jpg").is_file());
assert!(!dir.0.join("out/a.jpg").exists());
s.execute("edit.redo", &json!({})).unwrap();
assert!(dir.0.join("out/b.jpg").is_file());
assert_eq!(file_of(&s, b), dir.path("out/b.jpg"));
assert_eq!(at(file_of(&s, b)), at(dir.path("out/b.jpg")));
}

#[test]
Expand Down
10 changes: 10 additions & 0 deletions crates/gpu/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,16 @@ mod tests {
let seen = with_init_marker(Backends::DX12, || m.exists());
set_init_marker(None);
assert!(seen, "the marker exists while the device is created");
// `disarm` removes the marker best-effort and deliberately discards the error, so on
// Windows a scanner or indexer that holds the file open just long enough makes
// `remove_file` fail with a sharing violation. Poll briefly: this still checks that the
// marker really goes away when the scope ends, without making it a coin flip.
for _ in 0..100 {
if !m.exists() {
break;
}
std::thread::sleep(std::time::Duration::from_millis(20));
}
assert!(!m.exists(), "and is removed afterwards");
// a marker left behind by a crashed process is reported once; reading it leaves it in place
std::fs::write(&m, "GPU device and kernel creation started (backends DX12)").unwrap();
Expand Down
6 changes: 4 additions & 2 deletions crates/pipeline/src/spots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,10 @@ fn fill_box(src: &mut [[f32; 3]], tgt: &[[f32; 3]], alpha: &[f32], bw: usize, bh
let flat: Vec<f32> = tgt.iter().flatten().copied().collect();
let out = lightcraft_inpaint::complete(bw, bh, 3, &flat, &hole, &lightcraft_inpaint::CompleteParams::default())
.unwrap_or_else(|| lightcraft_inpaint::membrane_fill(bw, bh, 3, &flat, &hole));
for (d, v) in src.iter_mut().zip(out.chunks_exact(3)) {
*d = [v[0], v[1], v[2]];
// `as_chunks` instead of `chunks_exact(3)`: same remainder-dropping behaviour, and it hands
// back `&[f32; 3]` so the copy needs no indexing.
for (d, v) in src.iter_mut().zip(out.as_chunks::<3>().0) {
*d = *v;
}
}

Expand Down
Loading