feat(ci) - ci pre check#300
Merged
Merged
Conversation
The test suite for the completion service failed on Windows because the standard library's `dirs::home_dir()` ignores the `HOME` environment variable and prefers `USERPROFILE`, `HOMEDRIVE` and `HOMEPATH`. This commit introduces a small test‑only helper (`EnvGuard`) that sets up a consistent home directory environment across platforms and restores the original values after each test. Key changes: - Added `EnvGuard` struct with fields for `HOME`, `WORKFLOW_DISABLE_ICLOUD` and Windows‑specific variables. - Implemented `EnvGuard::new` to set `HOME`, disable iCloud sync, and on Windows configure `USERPROFILE`, `HOMEDRIVE`, and `HOMEPATH` based on the temporary directory. - Implemented `Drop` for `EnvGuard` to cleanly revert all environment modifications. - Updated `test_check_status_when_no_scripts_exist` to use the guard and verify that the completion directory stays inside the temporary home. This ensures reliable, platform‑agnostic test execution without affecting production code.
The path service previously relied on `dirs::home_dir()` which, on Windows, ignores the `HOME` environment variable and always falls back to `USERPROFILE`/`HOMEDRIVE`+`HOMEPATH`. This caused tests that temporarily set `HOME` to a temporary directory to fail because the service resolved to the actual user profile instead of the intended temporary location.
**What changed**
- Added an explicit check for the `HOME` environment variable before calling `dirs::home_dir()`.
- If `HOME` is set, its value is used as the base directory; otherwise the original fallback logic is retained.
- Introduced a new unit test `try_local_base_dir_respects_home_env` that verifies the service respects `HOME` on both Unix and Windows platforms.
**How it was implemented**
- Utilized `std::env::var("HOME")` to read the variable and construct a `PathBuf` when present.
- Kept the existing error handling for the case where neither `HOME` nor `dirs::home_dir()` can determine a path.
- Added platform‑specific environment variable handling in the test to mimic Windows behaviour.
This fix restores expected behaviour across all platforms and ensures test reliability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Ready
Types of changes
Summary
在 CI 流水线中提前生成并公开预发布版本信息,使后续步骤能够依据是否需要递增版本进行判断。
Key Changes
Changes
Features
Refactors
Configuration
Tests
Impact Analysis
Affected Modules
Risk Assessment
Overall risk: medium
Risk factors:
Mitigation:
Testing Suggestions
Statistics
Review Info