From c3d602af5ae97c3f93f59504ba786aa02a67155c Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Thu, 18 Dec 2025 03:09:27 -0800 Subject: [PATCH] Refactor CI workflow and update test configurations - Removed the setup step for native dependencies in the CI workflow to streamline the build process. - Updated the `copy_action_test` to include conflict resolution options for better handling of file conflicts. - Enhanced metadata handling in `entry_move_integrity_test` to include job policies. - Added metadata to event handling in `file_structure_test` for improved context during file operations. - Updated service configuration in `file_sync_simple_test` and `file_sync_test` to use `fs_watcher_enabled` and included default logging settings. - Deleted the outdated README.md from the tests directory to reduce clutter and improve documentation focus. --- .github/workflows/core_tests.yml | 3 - core/tests/README.md | 94 ------------------------- core/tests/copy_action_test.rs | 1 + core/tests/entry_move_integrity_test.rs | 2 + core/tests/file_structure_test.rs | 1 + core/tests/file_sync_simple_test.rs | 3 +- core/tests/file_sync_test.rs | 3 +- core/tests/helpers/README.md | 21 ++++-- 8 files changed, 23 insertions(+), 105 deletions(-) delete mode 100644 core/tests/README.md diff --git a/.github/workflows/core_tests.yml b/.github/workflows/core_tests.yml index 33b4118a2..599be76ff 100644 --- a/.github/workflows/core_tests.yml +++ b/.github/workflows/core_tests.yml @@ -40,9 +40,6 @@ jobs: path: target key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} - - name: Setup native dependencies - run: cargo run -p xtask -- setup - - name: Build core run: cargo build -p sd-core --verbose diff --git a/core/tests/README.md b/core/tests/README.md deleted file mode 100644 index 5a90e91e6..000000000 --- a/core/tests/README.md +++ /dev/null @@ -1,94 +0,0 @@ -# Sync Integration Tests - -This directory contains integration tests for Spacedrive's sync system. - -## Quick Links - -- **[SYNC_TESTS.md](./SYNC_TESTS.md)** - Complete documentation of all sync test files -- **[SYNC_HARNESS_USAGE.md](./SYNC_HARNESS_USAGE.md)** - How to use shared test utilities -- **[REFACTORING_SUMMARY.md](./REFACTORING_SUMMARY.md)** - Refactoring impact summary -- **[helpers/README.md](./helpers/README.md)** - Helper module documentation - -## Writing New Tests - -Use the shared test harness for two-device sync tests: - -```rust -use helpers::TwoDeviceHarnessBuilder; - -#[tokio::test] -async fn test_my_scenario() -> anyhow::Result<()> { - let harness = TwoDeviceHarnessBuilder::new("my_scenario") - .await? - .build() - .await?; - - // Alice indexes a location - harness.add_and_index_location_alice("/path", "Name").await?; - - // Wait for sync to complete - harness.wait_for_sync(Duration::from_secs(60)).await?; - - // Capture snapshot - harness.capture_snapshot("final").await?; - - Ok(()) -} -``` - -## Running Tests - -```bash -# Run all sync tests -cargo test -p sd-core --test 'sync_*' -- --test-threads=1 --nocapture - -# Run specific test file -cargo test -p sd-core --test sync_realtime_test -- --test-threads=1 --nocapture - -# Run specific test -cargo test -p sd-core --test sync_realtime_test test_realtime_sync_alice_to_bob -- --nocapture -``` - -**Important:** Use `--test-threads=1` to prevent tests from interfering with each other. - -## Test Snapshots - -All tests capture comprehensive snapshots to: -``` -~/Library/Application Support/spacedrive/sync_tests/snapshots/{test_name}_{timestamp}/ -``` - -Each snapshot includes: -- `test.log` - Complete trace output -- `alice/database.db` - Alice's database -- `alice/sync.db` - Alice's sync database -- `alice/logs/` - Alice's library logs -- `bob/database.db` - Bob's database -- `bob/sync.db` - Bob's sync database -- `bob/logs/` - Bob's library logs -- `summary.md` - Test results summary - -## Current Test Files - -### Core Sync Tests -- `sync_realtime_test.rs` - Real-time sync between pre-paired devices -- `sync_backfill_test.rs` - Initial backfill when devices first connect -- `sync_backfill_race_test.rs` - Race condition between backfill and live events -- `sync_metrics_test.rs` - Metrics tracking validation -- `sync_event_log_test.rs` - Event logging system tests -- `sync_setup_test.rs` - Sync setup with subprocess framework - -### Helper Infrastructure -- `helpers/sync_harness.rs` - Shared test utilities -- `helpers/sync_transport.rs` - Mock network transport -- `helpers/test_volumes.rs` - Volume testing utilities -- `helpers/mod.rs` - Module exports - -## Refactoring Stats - -**55% code reduction** across refactored tests: -- Eliminated **2046 lines** of duplicated code -- Added **600 lines** of shared infrastructure -- Net savings: **~1446 lines** - -See [REFACTORING_SUMMARY.md](./REFACTORING_SUMMARY.md) for details. diff --git a/core/tests/copy_action_test.rs b/core/tests/copy_action_test.rs index efaa367c6..b3ab0e5ab 100644 --- a/core/tests/copy_action_test.rs +++ b/core/tests/copy_action_test.rs @@ -55,6 +55,7 @@ async fn test_copy_action_construction() { ]), destination: SdPath::local(dest_dir.clone()), options: CopyOptions { + conflict_resolution: ConflictResolution::Overwrite, overwrite: false, copy_method: CopyMethod::Auto, verify_checksum: true, diff --git a/core/tests/entry_move_integrity_test.rs b/core/tests/entry_move_integrity_test.rs index 2024cf294..16c0f7ac4 100644 --- a/core/tests/entry_move_integrity_test.rs +++ b/core/tests/entry_move_integrity_test.rs @@ -107,6 +107,7 @@ async fn test_entry_metadata_preservation_on_move() { path: SdPath::local(source_dir.clone()), name: Some("Source".to_string()), mode: IndexMode::Deep, + job_policies: None, }) .unwrap(), ) @@ -416,6 +417,7 @@ async fn test_child_entry_metadata_preservation_on_parent_move() { path: SdPath::local(source_dir.clone()), name: Some("Source".to_string()), mode: IndexMode::Deep, + job_policies: None, }; let add_loc_action = LocationAddAction::from_input(add_loc_input).unwrap(); let _add_output = action_manager diff --git a/core/tests/file_structure_test.rs b/core/tests/file_structure_test.rs index 8f37f429c..1a5ab5b43 100644 --- a/core/tests/file_structure_test.rs +++ b/core/tests/file_structure_test.rs @@ -98,6 +98,7 @@ async fn map_file_structure_per_phase() -> Result<(), Box if let Event::ResourceChangedBatch { resource_type, resources, + metadata, } = event { if resource_type == "file" { diff --git a/core/tests/file_sync_simple_test.rs b/core/tests/file_sync_simple_test.rs index d0360bdf2..2a7014e5a 100644 --- a/core/tests/file_sync_simple_test.rs +++ b/core/tests/file_sync_simple_test.rs @@ -34,8 +34,9 @@ impl FileSyncTestSetup { services: sd_core::config::ServiceConfig { networking_enabled: false, volume_monitoring_enabled: false, - location_watcher_enabled: false, + fs_watcher_enabled: false, }, + logging: sd_core::config::LoggingConfig::default(), }; config.save()?; diff --git a/core/tests/file_sync_test.rs b/core/tests/file_sync_test.rs index cd8260c1b..84b3a3614 100644 --- a/core/tests/file_sync_test.rs +++ b/core/tests/file_sync_test.rs @@ -60,8 +60,9 @@ impl FileSyncTestSetup { services: sd_core::config::ServiceConfig { networking_enabled: false, volume_monitoring_enabled: false, - location_watcher_enabled: false, + fs_watcher_enabled: false, }, + logging: sd_core::config::LoggingConfig::default(), }; config.save()?; diff --git a/core/tests/helpers/README.md b/core/tests/helpers/README.md index 2aca13888..51af8c004 100644 --- a/core/tests/helpers/README.md +++ b/core/tests/helpers/README.md @@ -2,12 +2,6 @@ Shared utilities for integration tests to reduce duplication and improve maintainability. -## Quick Links - -- **[Sync Harness Usage Guide](../SYNC_HARNESS_USAGE.md)** - How to use the shared sync test utilities -- **[Refactoring Example](../REFACTORING_EXAMPLE.md)** - Before/after comparison showing benefits -- **[Sync Tests Documentation](../SYNC_TESTS.md)** - Complete sync test suite documentation - ## Modules ### `sync_harness.rs` - Two-Device Sync Test Utilities @@ -17,6 +11,7 @@ Provides a comprehensive test harness for sync integration tests that eliminates **Key Components:** #### `TwoDeviceHarnessBuilder` + Builder for creating pre-configured two-device test environments. ```rust @@ -30,6 +25,7 @@ let harness = TwoDeviceHarnessBuilder::new("my_test") ``` Automatically handles: + - Creating test directories - Initializing tracing to files - Setting up cores and libraries @@ -39,6 +35,7 @@ Automatically handles: - Setting sync state #### `TwoDeviceHarness` + The resulting test harness with convenient methods: ```rust @@ -61,21 +58,26 @@ harness.transport_alice; #### Helper Functions **Configuration:** + - `TestConfigBuilder` - Build test configs with custom filters - `init_test_tracing()` - Standard tracing setup **Device Setup:** + - `register_device()` - Register a device in a library - `set_all_devices_synced()` - Mark devices as synced (prevent auto-backfill) **Waiting:** + - `wait_for_indexing()` - Wait for indexing job completion - `wait_for_sync()` - Sophisticated sync completion detection **Operations:** + - `add_and_index_location()` - Create and index a location **Snapshots:** + - `create_snapshot_dir()` - Create timestamped snapshot directory - `SnapshotCapture` - Utilities for capturing databases, logs, events @@ -84,6 +86,7 @@ harness.transport_alice; Mock implementation of `NetworkTransport` for testing sync without real networking. **Key Features:** + - Immediate message delivery (like production) - Request/response handling for backfill - Device blocking/unblocking (simulate offline) @@ -91,6 +94,7 @@ Mock implementation of `NetworkTransport` for testing sync without real networki - Queue inspection **Usage:** + ```rust // Single device let transport = MockTransport::new_single(device_id); @@ -114,11 +118,13 @@ Helper functions for creating mock volumes in tests (used by `sync_backfill_test ## Benefits of Using Shared Utilities ### Code Reduction + - **~200 lines** of boilerplate eliminated per test - **~2887 lines** saved across 6 sync tests (65% reduction) - **One source of truth** for test patterns ### Consistency + - Same tracing setup everywhere - Same config creation - Same device registration @@ -126,12 +132,14 @@ Helper functions for creating mock volumes in tests (used by `sync_backfill_test - Same waiting algorithms ### Maintainability + - Fix bugs in one place - Add features once, benefit everywhere - Clear upgrade path for tests - Easier code reviews ### Reliability + - Battle-tested algorithms - Sophisticated sync detection - Comprehensive snapshot capture @@ -193,6 +201,7 @@ When adding new shared utilities: 5. **Export from `mod.rs`** Keep utilities: + - **Generic** - Useful for multiple tests - **Well-documented** - Clear purpose and usage - **Battle-tested** - Used by actual tests