refactor: move inline cfg-gated platform imports to top-level use statements#1564
Conversation
…tements Move inline statements behind and guards to the top of their respective files, following Rust convention of top-level imports. Changes: - src/core/auth.rs: Move to top with #[cfg(unix)] - src/openhuman/update/core.rs: Move to top with #[cfg(unix)] - src/openhuman/service/windows.rs: Move to top (file is windows-only) - src/openhuman/service/common.rs: Move to top with #[cfg(windows)] Closes tinyhumansai#684
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughConsolidates platform-only extension-trait imports to module-level ChangesImport consolidation and Windows no-window flag
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/core/auth.rs (1)
240-250:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winMissing
PermissionsExtimport causes test compilation failure.Line 247 calls
.mode()onstd::fs::Permissions, which requires thestd::os::unix::fs::PermissionsExttrait. This import is missing from the file, preventing compilation of the test.Add the missing import with the existing Unix-specific imports:
#[cfg(unix)] use std::os::unix::fs::OpenOptionsExt as _; +#[cfg(unix)] +use std::os::unix::fs::PermissionsExt as _;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/core/auth.rs` around lines 240 - 250, The test token_file_has_owner_only_permissions calls .mode() on std::fs::Permissions but is missing the Unix-specific trait; add use std::os::unix::fs::PermissionsExt to the Unix-only imports in this file (near the #[cfg(unix)] tests) so the .mode() method on Permissions resolves and the test compiles. Ensure the import is gated by #[cfg(unix)] alongside the token_file_has_owner_only_permissions test and related Unix-only imports.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/core/auth.rs`:
- Around line 240-250: The test token_file_has_owner_only_permissions calls
.mode() on std::fs::Permissions but is missing the Unix-specific trait; add use
std::os::unix::fs::PermissionsExt to the Unix-only imports in this file (near
the #[cfg(unix)] tests) so the .mode() method on Permissions resolves and the
test compiles. Ensure the import is gated by #[cfg(unix)] alongside the
token_file_has_owner_only_permissions test and related Unix-only imports.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 18ff9b70-047d-48a3-b8ea-3607c533cb33
📒 Files selected for processing (4)
src/core/auth.rssrc/openhuman/service/common.rssrc/openhuman/service/windows.rssrc/openhuman/update/core.rs
graycyrus
left a comment
There was a problem hiding this comment.
Review Summary
Mechanical refactor hoisting 4 inline use statements to file-level — 3 of 4 are correct. The fourth breaks Unix test compilation. Two minor style nits below.
| @@ -32,6 +32,9 @@ use std::io::Write as _; | |||
| use std::path::Path; | |||
| use std::sync::OnceLock; | |||
|
|
|||
There was a problem hiding this comment.
[critical] PermissionsExt import removed from the test at line 243 but never added here. This breaks token_file_has_owner_only_permissions compilation on Unix — .mode() on std::fs::Permissions requires the trait.
Suggested fix — merge both Unix trait imports into a single brace group:
#[cfg(unix)]
use std::os::unix::fs::{OpenOptionsExt as _, PermissionsExt as _};| use std::io::Write; | ||
| use std::path::PathBuf; | ||
|
|
||
| #[cfg(unix)] |
There was a problem hiding this comment.
[minor] The project consistently uses as _ for extension traits imported only for their methods (Write as _ on line 4, OpenOptionsExt as _ in auth.rs). This should match:
| #[cfg(unix)] | |
| #[cfg(unix)] | |
| use std::os::unix::fs::PermissionsExt as _; |
| use crate::openhuman::config::Config; | ||
| use anyhow::Result; | ||
| use std::fs; | ||
| use std::os::windows::process::CommandExt; |
There was a problem hiding this comment.
[nitpick] This compiles fine because the whole file is gated via #[cfg(windows)] mod windows; in mod.rs. A one-line comment would prevent a future maintainer from wondering whether this cross-compiles:
// File is `#[cfg(windows)]`-gated at the module level — no per-item guard needed.
use std::os::windows::process::CommandExt;…tements (tinyhumansai#1564) Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
Summary
Move inline
usestatements behind platform cfg guards (#[cfg(unix)],#[cfg(windows)]) to the top of their respective files, following the Rust convention of top-level imports.Changes
src/core/auth.rsstd::os::unix::fs::OpenOptionsExtwrite_token_file()behind#[cfg(unix)]src/openhuman/update/core.rsstd::os::unix::fs::PermissionsExtstage_update()behind#[cfg(unix)]src/openhuman/service/windows.rsstd::os::windows::process::CommandExtis_task_exists_windows()(file is already windows-only)src/openhuman/service/common.rsstd::os::windows::process::CommandExtno_window()behind#[cfg(windows)]Closes #684
Summary by CodeRabbit