huskies: merge 645_bug_agent_runtime_panics_with_output_write_bytes_is_ok_assertion_marking_stories_falsely_blocked
This commit is contained in:
@@ -41,6 +41,26 @@ pub(crate) fn worktree_has_committed_work(wt_path: &Path) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// Run `cargo check` in the given worktree directory to verify committed code compiles.
|
||||
///
|
||||
/// Resets any dirty (uncommitted) files first via `git checkout .` so that only
|
||||
/// the committed state is evaluated. Used as part of the "work survived" check
|
||||
/// when an agent crashes mid-output (bug 645).
|
||||
pub(crate) fn cargo_check_in_worktree(wt_path: &Path) -> bool {
|
||||
// Reset uncommitted changes so cargo check evaluates only committed code.
|
||||
let _ = Command::new("git")
|
||||
.args(["checkout", "."])
|
||||
.current_dir(wt_path)
|
||||
.output();
|
||||
|
||||
Command::new("cargo")
|
||||
.args(["check"])
|
||||
.current_dir(wt_path)
|
||||
.output()
|
||||
.map(|o| o.status.success())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Check whether the given directory has any uncommitted git changes.
|
||||
/// Returns `Err` with a descriptive message if there are any.
|
||||
pub(crate) fn check_uncommitted_changes(path: &Path) -> Result<(), String> {
|
||||
@@ -434,4 +454,87 @@ mod tests {
|
||||
// Now the feature branch is ahead of the base branch.
|
||||
assert!(worktree_has_committed_work(&wt_path));
|
||||
}
|
||||
|
||||
// ── cargo_check_in_worktree tests ────────────────────────────────────────
|
||||
|
||||
/// Bug 645: cargo_check_in_worktree resets dirty files before checking.
|
||||
#[test]
|
||||
fn cargo_check_in_worktree_resets_dirty_files() {
|
||||
use std::fs;
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let project_root = tmp.path().join("project");
|
||||
fs::create_dir_all(&project_root).unwrap();
|
||||
init_git_repo(&project_root);
|
||||
|
||||
// Create a minimal Cargo project so cargo check works.
|
||||
fs::write(
|
||||
project_root.join("Cargo.toml"),
|
||||
"[package]\nname = \"test_proj\"\nversion = \"0.1.0\"\nedition = \"2021\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::create_dir_all(project_root.join("src")).unwrap();
|
||||
fs::write(project_root.join("src/lib.rs"), "// empty lib\n").unwrap();
|
||||
Command::new("git")
|
||||
.args(["add", "."])
|
||||
.current_dir(&project_root)
|
||||
.output()
|
||||
.unwrap();
|
||||
Command::new("git")
|
||||
.args([
|
||||
"-c",
|
||||
"user.email=test@test.com",
|
||||
"-c",
|
||||
"user.name=Test",
|
||||
"commit",
|
||||
"-m",
|
||||
"add cargo project",
|
||||
])
|
||||
.current_dir(&project_root)
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
// Create a worktree on a feature branch.
|
||||
let wt_path = tmp.path().join("wt");
|
||||
Command::new("git")
|
||||
.args([
|
||||
"worktree",
|
||||
"add",
|
||||
&wt_path.to_string_lossy(),
|
||||
"-b",
|
||||
"feature/story-645_test",
|
||||
])
|
||||
.current_dir(&project_root)
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
// Commit valid code.
|
||||
fs::write(wt_path.join("src/lib.rs"), "pub fn hello() {}\n").unwrap();
|
||||
Command::new("git")
|
||||
.args(["add", "."])
|
||||
.current_dir(&wt_path)
|
||||
.output()
|
||||
.unwrap();
|
||||
Command::new("git")
|
||||
.args([
|
||||
"-c",
|
||||
"user.email=test@test.com",
|
||||
"-c",
|
||||
"user.name=Test",
|
||||
"commit",
|
||||
"-m",
|
||||
"add hello fn",
|
||||
])
|
||||
.current_dir(&wt_path)
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
// Now simulate a crash leaving dirty files (broken syntax).
|
||||
fs::write(wt_path.join("src/lib.rs"), "THIS IS BROKEN SYNTAX!!!\n").unwrap();
|
||||
|
||||
// cargo_check_in_worktree should reset dirty files and check committed code.
|
||||
assert!(
|
||||
cargo_check_in_worktree(&wt_path),
|
||||
"cargo check should pass on committed code after resetting dirty files"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user