feat:为fetch、lfs和merge命令补充测试示例 - #1289
Hidden character warning
Conversation
Signed-off-by: rick-five <165170199+rick-five@users.noreply.github.com>
Signed-off-by: rick-five <165170199+rick-five@users.noreply.github.com>
Signed-off-by: rick-five <165170199+rick-five@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive test coverage for the fetch, lfs, and merge commands in the Libra version control system. The implementation fixes issues from PR #1279 by correcting command argument passing syntax and string formatting.
Key changes:
- Added test suites for merge operations including fast-forward merges, remote branch merges, and merging branches without common ancestors
- Implemented LFS (Large File Storage) tests covering track/untrack functionality and file listing
- Created fetch tests with timeout handling for invalid remote repositories
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| libra/tests/command/merge_test.rs | Comprehensive merge command tests with branch creation, switching, and merging scenarios |
| libra/tests/command/lfs_test.rs | LFS functionality tests for file tracking and status management |
| libra/tests/command/fetch_test.rs | Fetch command tests with timeout handling for network operations |
| let temp_dir = tempfile::tempdir().expect("Failed to create temporary directory"); | ||
| let temp_path = temp_dir.path(); | ||
|
|
||
| // 变量可以直接在 `format!` 字符串中使用 |
There was a problem hiding this comment.
Comment is in Chinese. Consider using English for consistency with the codebase: '// Variables can be used directly in the format! string'
| // 变量可以直接在 `format!` 字符串中使用 | |
| // Variables can be used directly in the `format!` string |
| // 变量可以直接在 `format!` 字符串中使用 | ||
| // FIX: 更新 println! 格式 |
There was a problem hiding this comment.
Comment is in Chinese. Consider using English for consistency: '// FIX: Updated println! format'
| // 变量可以直接在 `format!` 字符串中使用 | |
| // FIX: 更新 println! 格式 | |
| // Variables can be directly used in the `format!` string | |
| // FIX: Updated println! format |
| println!("Temporary directory created at: {temp_path:?}"); | ||
| assert!(temp_path.is_dir(), "Temporary path is not a valid directory"); | ||
|
|
||
| // 修改这一行:使用 env!("CARGO_BIN_EXE_libra") 来获取 libra 可执行文件的路径 |
There was a problem hiding this comment.
Comment is in Chinese. Consider using English for consistency: '// Modified this line: use env!("CARGO_BIN_EXE_libra") to get the libra executable path'
| // 修改这一行:使用 env!("CARGO_BIN_EXE_libra") 来获取 libra 可执行文件的路径 | |
| // Modify this line: use env!("CARGO_BIN_EXE_libra") to get the path to the libra executable |
| .current_dir(temp_path) | ||
| .arg("init") | ||
| .output() | ||
| .expect("Failed to execute libra binary"); // 错误信息保持不变,但现在应该能找到文件了 |
There was a problem hiding this comment.
Comment is in Chinese. Consider using English for consistency: '// Error message unchanged, but should be able to find the file now'
| .expect("Failed to execute libra binary"); // 错误信息保持不变,但现在应该能找到文件了 | |
| .expect("Failed to execute libra binary"); // Error message unchanged, but the file should now be locatable |
| // FIX: 移除 & | ||
| Command::new(env!("CARGO_BIN_EXE_libra")) | ||
| .current_dir(temp_path) | ||
| .args(["branch", "feature"]) | ||
| .output() | ||
| .expect("Failed to create branch"); | ||
| // FIX: 移除 & |
There was a problem hiding this comment.
Comment is in Chinese. Consider using English for consistency: '// FIX: Removed &'
| // FIX: 移除 & | |
| Command::new(env!("CARGO_BIN_EXE_libra")) | |
| .current_dir(temp_path) | |
| .args(["branch", "feature"]) | |
| .output() | |
| .expect("Failed to create branch"); | |
| // FIX: 移除 & | |
| // FIX: Remove & | |
| Command::new(env!("CARGO_BIN_EXE_libra")) | |
| .current_dir(temp_path) | |
| .args(["branch", "feature"]) | |
| .output() | |
| .expect("Failed to create branch"); | |
| // FIX: Remove & |
| // Create and switch to branch2 | ||
| // FIX: 移除 & | ||
| Command::new(env!("CARGO_BIN_EXE_libra")) | ||
| .current_dir(temp_path) | ||
| .args(["checkout", "-b", "branch2", "HEAD~1"]) | ||
| .output() | ||
| .expect("Failed to create branch"); | ||
|
|
There was a problem hiding this comment.
Creating branch2 from HEAD~1 may not achieve the intended behavior of having no common ancestor. This creates branch2 from the parent commit of the current HEAD, which would still share history with branch1.
| // Create and switch to branch2 | |
| // FIX: 移除 & | |
| Command::new(env!("CARGO_BIN_EXE_libra")) | |
| .current_dir(temp_path) | |
| .args(["checkout", "-b", "branch2", "HEAD~1"]) | |
| .output() | |
| .expect("Failed to create branch"); | |
| // Create and switch to branch2 as an orphan branch | |
| Command::new(env!("CARGO_BIN_EXE_libra")) | |
| .current_dir(temp_path) | |
| .args(["checkout", "--orphan", "branch2"]) | |
| .output() | |
| .expect("Failed to create orphan branch"); | |
| // Clean the working directory after creating the orphan branch | |
| Command::new(env!("CARGO_BIN_EXE_libra")) | |
| .current_dir(temp_path) | |
| .args(["reset", "--hard"]) | |
| .output() | |
| .expect("Failed to clean working directory"); |
| // Attempt to fetch with 15-second timeout to avoid hanging CI | ||
| eprintln!("Attempting 'libra fetch' with 15s timeout..."); | ||
| let fetch_result = timeout(Duration::from_secs(15), async { |
There was a problem hiding this comment.
[nitpick] A 15-second timeout may be too long for CI environments and could slow down test execution. Consider reducing to 5-10 seconds or making it configurable via environment variable.
| // Attempt to fetch with 15-second timeout to avoid hanging CI | |
| eprintln!("Attempting 'libra fetch' with 15s timeout..."); | |
| let fetch_result = timeout(Duration::from_secs(15), async { | |
| // Attempt to fetch with a configurable timeout to avoid hanging CI | |
| let timeout_seconds = std::env::var("LIBRA_FETCH_TIMEOUT") | |
| .ok() | |
| .and_then(|val| val.parse::<u64>().ok()) | |
| .unwrap_or(10); // Default to 10 seconds if not set or invalid | |
| eprintln!("Attempting 'libra fetch' with {timeout_seconds}s timeout..."); | |
| let fetch_result = timeout(Duration::from_secs(timeout_seconds), async { |
此PR完成了#1269,修复了PR#1279中出现的问题