Skip to content

为 Rust 后端补充单元测试门禁#361

Merged
H-Chris233 merged 3 commits into
Open-Less:betafrom
H-Chris233:fix/issue-295-rust-unit-tests
May 8, 2026
Merged

为 Rust 后端补充单元测试门禁#361
H-Chris233 merged 3 commits into
Open-Less:betafrom
H-Chris233:fix/issue-295-rust-unit-tests

Conversation

@H-Chris233
Copy link
Copy Markdown
Collaborator

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

User description

变更说明

  • 为 Rust 后端轻量补上核心纯逻辑单测:
    • coordinator.rs:begin/startup 竞态与录音中止状态边界
    • hotkey.rs:binding / modifier shortcut 更新时 latch 重置边界
    • recorder.rs:下混、量化、RMS/电平、callback liveness 标记
    • insertion.rs:空文本不触发剪贴板/粘贴路径
  • 在 CI 轻量检查链路中新增 cargo test --manifest-path src-tauri/Cargo.toml --lib
  • 更新 AGENTS.md / CLAUDE.md 中 Rust 测试说明,避免继续写“无 cargo test”。

验证

  • npm run build
  • cargo test --manifest-path src-tauri/Cargo.toml --lib(149 passed)
  • cargo check --manifest-path src-tauri/Cargo.toml

Closes #295


PR Type

Tests, Enhancement, Documentation


Description

  • Add coordinator session edge tests

    • Start, stop, cancel, and race coverage
  • Cover hotkey latches on all platforms

    • Deduplicate modifier presses and releases
  • Test recorder and insertion helpers

    • Resampling, quantization, RMS, and fallback paths
  • Run Rust lib tests in CI

    • Windows compiles test binaries only
  • Update Rust testing guidance docs


Diagram Walkthrough

flowchart LR
  CI["CI workflow"] -- "runs" --> CargoTest["cargo test --lib"]
  CargoTest -- "covers" --> Coordinator["coordinator tests"]
  CargoTest -- "covers" --> Hotkey["hotkey tests"]
  CargoTest -- "covers" --> Recorder["recorder tests"]
  CargoTest -- "covers" --> Insertion["insertion tests"]
  Docs["AGENTS / CLAUDE docs"] -- "document" --> CargoTest
Loading

File Walkthrough

Relevant files
Tests
4 files
coordinator.rs
Add coordinator session edge tests                                             
+162/-0 
hotkey.rs
Test hotkey latch reset and dedupe                                             
+315/-5 
insertion.rs
Refactor paste status helpers and tests                                   
+83/-9   
recorder.rs
Add audio processing helper tests                                               
+77/-0   
Configuration changes
1 files
ci.yml
Gate Rust lib tests in CI                                                               
+11/-0   
Documentation
2 files
AGENTS.md
Document Rust lib test workflow                                                   
+1/-1     
CLAUDE.md
Document Rust lib test workflow                                                   
+1/-1     

Issue Open-Less#295 calls out that core Rust paths have been too dependent on manual app runs. Keep the change narrow by covering existing pure state/audio/clipboard helpers instead of refactoring coordinator or touching hardware-facing code, then wire the existing lib test suite into the lightweight CI lane.

Constraint: Global hotkey, recorder, and insertion integration still require real OS permissions and devices.

Rejected: Split coordinator before adding tests | broader refactor would raise review risk and is tracked separately.

Confidence: high

Scope-risk: narrow

Directive: Keep Rust CI on --lib unless integration tests get explicit OS fixtures.

Tested: npm run build

Tested: cargo test --manifest-path src-tauri/Cargo.toml --lib

Tested: cargo check --manifest-path src-tauri/Cargo.toml

Not-tested: Live microphone, global hotkey, clipboard, and insertion device paths.

Related: Open-Less#295
@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 ffeaa24)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

295 - Partially compliant

Compliant requirements:

  • coordinator.rs 状态机边界单测
  • hotkey.rs modifier / latch 单测
  • recorder.rs 数值与 callback 单测
  • insertion.rs 剪贴板与空文本路径单测
  • CI 中新增 cargo test --lib
  • 更新 AGENTS.md / CLAUDE.md 测试说明

Non-compliant requirements:

Requires further human verification:

  • Windows CI 仅编译测试二进制,不实际执行;需要人工确认这不会掩盖 Windows 专属回归。
  • 这些新增单测主要覆盖纯逻辑,macOS / Windows / Linux 的真实输入法、剪贴板和热键注入行为仍需在真机或对应环境中验证。
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

The first Open-Less#295 pass made cargo tests visible but still left the reviewer-requested state-machine, modifier-edge, and insertion fallback contracts too implicit. This adds narrow unit coverage around those contracts without refactoring runtime flow.\n\nConstraint: Address review compliance with minimal production changes.\nRejected: Split coordinator or hotkey adapters for testability | broader than the issue and riskier for the active PR.\nConfidence: high\nScope-risk: narrow\nTested: cargo test --manifest-path openless-all/app/src-tauri/Cargo.toml --lib; cargo check --manifest-path src-tauri/Cargo.toml; npm run build\nNot-tested: Live macOS/Windows native hotkey hooks and clipboard/AX behavior.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

Persistent review updated to latest commit b082805

The Open-Less#295 unit suite now runs in CI, but the Windows clean runner exits before the lib test harness starts with STATUS_ENTRYPOINT_NOT_FOUND when optional native runtime entrypoints are absent. Windows still needs cfg/link coverage, while macOS and Linux can execute the shared Rust unit suite.

Constraint: Preserve the new Rust test gate without making optional Windows native runtime installation a CI prerequisite.
Rejected: Install Foundry/Windows App Runtime into every CI run | broader, slower, and unrelated to backend unit-test coverage.
Confidence: high
Scope-risk: narrow
Directive: Do not switch Windows back to executing the lib test binary until the optional native runtime dependency is present on the runner.
Tested: cargo test --manifest-path openless-all/app/src-tauri/Cargo.toml --lib
Not-tested: Windows CI rerun before push.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

Persistent review updated to latest commit ffeaa24

@H-Chris233 H-Chris233 merged commit 7d77044 into Open-Less:beta May 8, 2026
4 checks passed
@H-Chris233 H-Chris233 deleted the fix/issue-295-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.

[refactor][P1] Rust 后端零单元测试覆盖 — 关键模块靠人工验证

1 participant