Skip to content

让 Windows CI 实际运行 Rust-only 后端单测#374

Merged
H-Chris233 merged 5 commits into
Open-Less:betafrom
H-Chris233:fix/backend-rust-unit-tests
May 9, 2026
Merged

让 Windows CI 实际运行 Rust-only 后端单测#374
H-Chris233 merged 5 commits into
Open-Less:betafrom
H-Chris233:fix/backend-rust-unit-tests

Conversation

@H-Chris233
Copy link
Copy Markdown
Collaborator

@H-Chris233 H-Chris233 commented May 8, 2026

User description

背景

跟进 #295 的 Windows CI 可执行性问题。上一版尝试让 Windows 直接运行完整 cargo test --lib,但完整 Tauri lib test harness 会在桌面运行时/系统 DLL 路径里于 Rust 单测启动前退出,所以这次按“只做后端单侧、只做 Rust 到 Rust”收敛处理。

改动

  • 把 Coordinator 的纯 session 状态转移抽到 coordinator_state.rs,由生产 coordinator.rs 继续调用同一套 helper。
  • 新增 src-tauri/backend-tests 纯 Rust 测试 crate:按源码路径编入 coordinator_state / hotkey / recorder / insertion 等后端逻辑,不链接完整 Tauri app lib。
  • Windows CI 保留原 cargo test --lib --no-run 做 cfg/link 覆盖,并新增实际执行的 Rust-only 后端单测步骤。

验证

  • cargo test --manifest-path openless-all/app/src-tauri/backend-tests/Cargo.toml(33 passed)
  • cargo test --manifest-path openless-all/app/src-tauri/Cargo.toml --lib(169 passed)
  • cargo check --manifest-path openless-all/app/src-tauri/Cargo.toml
  • .github/workflows/ci.yml YAML parse OK
  • git diff --check

Refs #295


PR Type

Enhancement, Tests


Description

  • Extract coordinator session state machine into new coordinator_state.rs module

  • Add backend-tests crate to run Rust-only backend unit tests on Windows CI

  • Update CI workflow with dedicated Windows step for backend tests

  • Expand unit tests for hotkey modifier edges, recorder resampling/RMS, and insertion fallback

  • Fix shortcut binding test to respect Windows modifier normalization


Diagram Walkthrough

flowchart LR
  coordinator_rs["coordinator.rs"] --> coordinator_state["coordinator_state.rs"]
  backend_tests["backend-tests crate"] --> coordinator_state
  backend_tests --> hotkey["hotkey.rs (modifier tests)"]
  backend_tests --> recorder["recorder.rs (resample/RMS tests)"]
  backend_tests --> insertion["insertion.rs (clipboard tests)"]
  backend_tests --> shortcut_binding["shortcut_binding.rs"]
  ci["CI (Windows)"] --> backend_tests
Loading

File Walkthrough

Relevant files
Tests
4 files
backend_rust.rs
Add backend-only test harness entry point                               
+40/-0   
hotkey.rs
Add Windows/Linux modifier edge detection tests                   
+62/-0   
insertion.rs
Add empty insertion clipboard fallback test for non-macOS
+9/-2     
recorder.rs
Add recorder resampling and RMS unit tests                             
+93/-0   
Enhancement
2 files
coordinator.rs
Delegate session state transitions to coordinator_state module
+28/-164
coordinator_state.rs
Extract pure session state machine functions                         
+484/-0 
Miscellaneous
1 files
lib.rs
Register coordinator_state module                                               
+1/-0     
Bug fix
1 files
shortcut_binding.rs
Fix shortcut test for Windows modifier normalization         
+3/-0     
Configuration changes
2 files
ci.yml
Add Windows CI step for Rust-only backend tests                   
+7/-1     
Cargo.toml
Add Cargo manifest for backend-test crate                               
+32/-0   

Windows cannot reliably execute the full Tauri lib test harness in CI because the process exits before Rust tests start in the desktop runtime loader path. Split the coordinator session state transitions into a Tauri-free Rust module used by coordinator.rs, and add a small Rust-only backend test crate that path-includes coordinator/hotkey/recorder/insertion logic for real Windows execution.

Constraint: User scoped this follow-up to backend-only Rust-to-Rust tests, not app/runtime smoke tests.
Constraint: Existing Windows CI still keeps full lib --no-run cfg/link coverage.
Rejected: Keep trying to execute cargo test --lib on Windows | it starts the full Tauri-linked test binary and fails before unit tests run.
Rejected: Rework release/runtime DLL handling | outside the backend unit-test scope.
Confidence: high
Scope-risk: moderate
Directive: Keep Windows actual unit execution on the Rust-only backend-tests manifest unless the full Tauri lib harness is proven runnable on clean Windows CI.
Tested: cargo test --manifest-path openless-all/app/src-tauri/backend-tests/Cargo.toml
Tested: cargo test --manifest-path openless-all/app/src-tauri/Cargo.toml --lib
Tested: cargo check --manifest-path openless-all/app/src-tauri/Cargo.toml
Tested: python yaml parse for .github/workflows/ci.yml; git diff --check
Not-tested: Windows runner execution; intended to be verified by GitHub Actions.
Related: Open-Less#295
Co-authored-by: OmX <omx@oh-my-codex.dev>
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

PR Reviewer Guide 🔍

(Review updated until commit c63c69f)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

295 - PR Code Verified

Compliant requirements:

  • coordinator 会话状态机纯逻辑已抽出并补了转移测试。
  • hotkey.rs 已补 modifier 边沿相关测试。
  • recorder.rs 已补重采样与 RMS 相关测试。
  • insertion.rs 已补剪贴板恢复与失败回退相关测试。
  • Windows CI 已新增 Rust-only 后端单测执行步骤。

Requires further human verification:

  • Windows CI 新增的后端测试步骤在目标 runner 镜像上是否稳定通过。
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

Windows intentionally normalizes cmd/command shortcut modifiers to ctrl, while macOS and Linux keep the super bit. The Rust-only backend test crate now executes these source tests on Windows, so the assertion must follow the same platform contract as production parsing instead of assuming the non-Windows result.\n\nConstraint: Keep the fix inside Rust backend tests and avoid changing shortcut behavior.\nRejected: Change normalize_modifier_tag to keep cmd as super on Windows | would alter user-facing hotkey semantics.\nConfidence: high\nScope-risk: narrow\nTested: cargo test --manifest-path openless-all/app/src-tauri/backend-tests/Cargo.toml\nTested: cargo test --manifest-path openless-all/app/src-tauri/Cargo.toml --lib\nNot-tested: GitHub Windows runner rerun result pending after push.\n\nCo-authored-by: OmX <omx@oh-my-codex.dev>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

Persistent review updated to latest commit f339209

The backend-tests crate is intentionally an integration-test harness, but declaring the target explicitly makes Cargo discovery and review intent unambiguous. The harness comment also records that path-included modules run their own cfg(test) unit tests for hotkey, recorder, and insertion without linking the full Tauri library.\n\nConstraint: Stay within Rust-only backend tests; do not add a Tauri lib/runtime target.\nRejected: Add src/lib.rs just to satisfy target discovery | would introduce an unused crate surface instead of the actual test harness.\nConfidence: high\nScope-risk: narrow\nTested: cargo test --manifest-path openless-all/app/src-tauri/backend-tests/Cargo.toml -- --list | grep -E '^(hotkey|recorder|insertion)::'\nTested: cargo test --manifest-path openless-all/app/src-tauri/backend-tests/Cargo.toml\nTested: git diff --check\nNot-tested: GitHub Windows runner rerun result pending after push.\n\nCo-authored-by: OmX <omx@oh-my-codex.dev>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

Persistent review updated to latest commit 02ccac2

The Rust-only backend harness already ran existing hotkey, recorder, and insertion unit tests, but the review could not see target edge coverage directly in this diff. Add focused edge tests for modifier trigger filtering/re-emission, recorder callback no-op inputs, and insertion fallback status so the coverage is explicit in the changed files.\n\nConstraint: Keep scope to backend Rust unit tests and avoid app/runtime integration.\nRejected: Add UI or Tauri runtime tests | conflicts with the Rust-only backend boundary.\nConfidence: high\nScope-risk: narrow\nTested: cargo test --manifest-path openless-all/app/src-tauri/backend-tests/Cargo.toml\nTested: cargo test --manifest-path openless-all/app/src-tauri/Cargo.toml --lib\nTested: git diff --check\nNot-tested: GitHub Windows runner result after push.\n\nCo-authored-by: OmX <omx@oh-my-codex.dev>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

Persistent review updated to latest commit 044799e

The backend-only test PR needs to cover the concrete recorder paths named in the ticket, not just empty input handling. This adds focused Rust unit coverage for non-target sample-rate resampling, emitted PCM shape, scaled RMS levels, and peak tracking while keeping the production recorder unchanged.\n\nConstraint: Scope is Rust-only backend tests; do not launch or link extra Tauri runtime paths for Windows CI.\nConfidence: high\nScope-risk: narrow\nTested: cargo test --manifest-path openless-all/app/src-tauri/backend-tests/Cargo.toml recorder:: -- --nocapture\nTested: cargo test --manifest-path openless-all/app/src-tauri/backend-tests/Cargo.toml\nTested: cargo test --manifest-path openless-all/app/src-tauri/Cargo.toml --lib\nCo-authored-by: OmX <omx@oh-my-codex.dev>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

Persistent review updated to latest commit c63c69f

@H-Chris233 H-Chris233 merged commit 15442b5 into Open-Less:beta May 9, 2026
4 checks passed
@H-Chris233 H-Chris233 deleted the fix/backend-rust-unit-tests branch May 9, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant