From 85c8e41be74939161ba662313cb0f1bc242cc3c2 Mon Sep 17 00:00:00 2001 From: oratis Date: Sat, 27 Jun 2026 16:29:40 +0800 Subject: [PATCH] ci: run Rust suite on Win/Linux + test paths_from_argv MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cross-platform CI job was compile-only. Add `cargo test` so platform- specific logic (argv file-open, the Linux token-file fallback) is exercised where it runs, not just compiled. Also adds a unit test for paths_from_argv (skips argv[0], keeps only existing Markdown files) — it's cfg(win/linux) so it runs in that CI job. Co-Authored-By: Claude Opus 4.8 --- .github/workflows/ci.yml | 14 +++++++++++--- src-tauri/src/lib.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 316c02c..f80bbcd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -175,12 +175,13 @@ jobs: run: cargo build --release cross-platform: - name: Cross-platform compile (${{ matrix.os }}) + name: Cross-platform compile + test (${{ matrix.os }}) runs-on: ${{ matrix.os }} timeout-minutes: 30 # Guards the cfg(target_os) gating so a macOS-only change can't silently - # break the Windows/Linux build (GTM §9 "提前搭 CI 矩阵"). Compile + link - # only (--debug --no-bundle); real installers are the on-demand + # break the Windows/Linux build (GTM §9 "提前搭 CI 矩阵"), and runs the Rust + # suite there so platform-specific logic is tested, not just compiled. + # Compile + link via --debug --no-bundle; real installers are the on-demand # cross-platform-bundle workflow. strategy: fail-fast: false @@ -224,3 +225,10 @@ jobs: - name: tauri build (compile + link only) run: pnpm tauri build --debug --no-bundle + + # Run the Rust suite on Win/Linux too, so platform-specific logic + # (argv file-open, the Linux token-file fallback) is tested where it + # actually runs — not just compiled. + - name: Cargo test + working-directory: src-tauri + run: cargo test diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 50c3a94..27cb09c 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -82,6 +82,33 @@ fn paths_from_argv(argv: &[String]) -> Vec { .collect() } +#[cfg(all(test, any(target_os = "windows", target_os = "linux")))] +mod argv_tests { + use super::paths_from_argv; + + #[test] + fn keeps_existing_markdown_only_and_skips_argv0() { + let dir = std::env::temp_dir().join(format!("markup-argv-{}", std::process::id())); + let _ = std::fs::create_dir_all(&dir); + let md = dir.join("note.md"); + std::fs::write(&md, b"# hi").unwrap(); + let txt = dir.join("note.txt"); + std::fs::write(&txt, b"nope").unwrap(); + let md_str = md.to_string_lossy().into_owned(); + + let argv = vec![ + md_str.clone(), // argv[0] — skipped even though real .md + md_str.clone(), // kept + txt.to_string_lossy().into_owned(), // not markdown — skipped + dir.join("missing.md").to_string_lossy().into_owned(), // doesn't exist — skipped + ]; + // Exactly one entry: argv[0] dropped by skip(1), only the existing .md kept. + assert_eq!(paths_from_argv(&argv), vec![md_str]); + + let _ = std::fs::remove_dir_all(&dir); + } +} + #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { let _ = tracing_subscriber::fmt()