PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(ci): run native Windows tests for format changes
denstu473c82674439f75
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex ba8243353..b933deb81 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -37,7 +37,8 @@ concurrency:jobs:# Which OSes the test job runs on. main, manual runs and PRs labelled `full-ci` get Linux and# Windows. Other PRs get Linux, plus Windows when they touch code whose behaviour differs by- # platform: the app shell, UI, text and fonts, GPU, pen input, build scripts or the lockfile.+ # platform: the app shell, UI, text and fonts, GPU, pen input, native saves, build scripts or+ # the lockfile. Format changes must exercise the Windows-only publication barriers (#8034).# macOS is tested only by release.yml.platforms:timeout-minutes: 10@@ -78,7 +79,7 @@ jobs:elseecho "web=false" >> "$GITHUB_OUTPUT"fi- if git diff --name-only "$BASE" HEAD | grep -Eq '^(apps/|crates/(ui-egui|text|gpu|tablet|heif)/|Cargo\.lock$|(.*/)?build\.rs$|\.github/workflows/ci\.yml$)'; then+ if git diff --name-only "$BASE" HEAD | grep -Eq '^(apps/|crates/(ui-egui|text|gpu|tablet|heif|format)/|Cargo\.lock$|(.*/)?build\.rs$|\.github/workflows/ci\.yml$)'; thenecho "legs=$all" >> "$GITHUB_OUTPUT"elseecho "legs=[$linux]" >> "$GITHUB_OUTPUT"diff --git a/crates/format/src/atomic.rs b/crates/format/src/atomic.rsindex 095ae3026..635bf924a 100644--- a/crates/format/src/atomic.rs+++ b/crates/format/src/atomic.rs@@ -101,6 +101,8 @@ impl AtomicFs for RealFs {fn remove(&self, path: &Path) -> io::Result<()> {std::fs::remove_file(path)}+ /// Flush directory publication using a directory handle on Unix and Windows.+ /// Windows requests only `FILE_ADD_FILE`; opening or flushing the handle can fail the save.fn sync_dir(&self, dir: &Path) -> io::Result<()> {#[cfg(unix)]{diff --git a/crates/format/src/atomic/tests.rs b/crates/format/src/atomic/tests.rsindex c2912803d..853a11293 100644--- a/crates/format/src/atomic/tests.rs+++ b/crates/format/src/atomic/tests.rs@@ -69,6 +69,7 @@ impl AtomicFs for Faulty {fn remove(&self, path: &Path) -> io::Result<()> {RealFs.remove(path)}+ /// Count publication barriers and optionally fail before the real directory flush.fn sync_dir(&self, dir: &Path) -> io::Result<()> {self.synced.set(self.synced.get() + 1);if self.fail_sync_dir {@@ -107,6 +108,7 @@ fn a_failed_publication_flush_is_reported_and_can_be_retried() {assert_no_temp(&d.0);}+/// A real Windows directory handle must flush successfully and preserve directory-open errors.#[cfg(windows)]#[test]fn windows_directory_flush_opens_a_directory_and_reports_open_errors() {@@ -152,6 +154,7 @@ fn creates_missing_parent_folders() {assert_eq!(std::fs::read(&p).unwrap(), b"x");}+/// A partial temporary write must preserve the original and never reach publication or its flush.#[test]fn write_failure_halfway_keeps_original() {let d = TempDir::new("write");@@ -167,6 +170,7 @@ fn write_failure_halfway_keeps_original() {assert_no_temp(&d.0);}+/// A failed replacement must preserve the original and skip the publication barrier.#[test]fn rename_failure_keeps_original() {let d = TempDir::new("rename");diff --git a/crates/format/src/store.rs b/crates/format/src/store.rsindex 564ab5156..40b7c45e7 100644--- a/crates/format/src/store.rs+++ b/crates/format/src/store.rs@@ -525,6 +525,8 @@ fn validate_bundle_file(root: &Path, path: &Path) -> Result<()> {plain_file_or_missing(path)}+/// Publish a validated bundle entry through a flushed temporary file and replacing rename.+/// On Windows, propagate a failed directory barrier even though the new entry is already visible.fn write_bundle_file(root: &Path, path: &Path, data: &[u8], fs: &dyn crate::atomic::AtomicFs) -> Result<()> {#[cfg(not(windows))]let _ = fs;diff --git a/crates/format/src/store/durability_tests.rs b/crates/format/src/store/durability_tests.rsindex 963524d3c..5f60db294 100644--- a/crates/format/src/store/durability_tests.rs+++ b/crates/format/src/store/durability_tests.rs@@ -6,6 +6,7 @@ use photocraft_doc::{Layer, Size};use std::cell::{Cell, RefCell};use std::io;+/// The object or manifest directory barrier at which to inject one publication failure.#[derive(Clone, Copy, Debug)]enum FailAt {Tiles,@@ -13,6 +14,7 @@ enum FailAt {Manifest,}+/// Real filesystem operations with recorded barriers and a single failure at the chosen stage.struct PublicationFault {root: PathBuf,old_manifest: Vec<u8>,@@ -22,18 +24,23 @@ struct PublicationFault {}impl AtomicFs for PublicationFault {+ /// Keep temporary-file writes and file flushes real; only directory barriers are injected.fn write_new(&self, path: &Path, bytes: &[u8]) -> io::Result<()> {RealFs.write_new(path, bytes)}+ /// Publish through the real rename so a barrier error occurs after replacement.fn rename(&self, from: &Path, to: &Path) -> io::Result<()> {RealFs.rename(from, to)}+ /// Use real cleanup so the test can detect premature removal of old objects.fn remove(&self, path: &Path) -> io::Result<()> {RealFs.remove(path)}+ /// Preserve normal replacement metadata behavior during failure injection.fn copy_metadata(&self, from: &Path, to: &Path) -> io::Result<()> {RealFs.copy_metadata(from, to)}+ /// Record every barrier and fail the selected stage once, allowing a same-writer retry.fn sync_dir(&self, dir: &Path) -> io::Result<()> {self.synced.borrow_mut().push(dir.to_path_buf());let fail = match self.stage {@@ -48,6 +55,8 @@ impl AtomicFs for PublicationFault {}}+/// Failed object or manifest publication retains old objects; a retry flushes reused objects+/// before the manifest and resumes garbage collection only after durable publication.#[test]fn failed_bundle_publication_retains_old_objects_and_same_writer_retry_is_durable() {static NEXT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);