use super::*;
use crate::session_manager::worktree_git_fixture::GitWorktreeFixture;
use crate::session_manager::worktree_safety::git_stdout;
fn origin_main(dir: &std::path::Path) -> String {
git_stdout(dir, &["rev-parse", "refs/remotes/origin/main"])
.expect("origin/main must exist in the fixture")
.trim()
.to_string()
}
#[test]
fn a_refresh_updates_the_stale_landing_ref() {
let fx = GitWorktreeFixture::new();
let wt = fx.add_worktree("agent-refresh");
let before = origin_main(&wt);
fx.land_on_the_remote_only(&wt, "landed.txt");
assert_eq!(
origin_main(&wt),
before,
"the fixture must leave this checkout's landing ref STALE, or the test \
proves nothing"
);
refresh_landing_refs(&wt).expect("a reachable origin must fetch");
assert_ne!(
origin_main(&wt),
before,
"the refresh must advance refs/remotes/origin/main"
);
}
#[test]
fn a_refresh_against_a_missing_remote_fails_without_touching_the_refs() {
let fx = GitWorktreeFixture::new();
let wt = fx.add_worktree("agent-broken-remote");
let before = origin_main(&wt);
let missing = fx.repos_root.join("no-such-remote.git");
git_stdout(
&wt,
&[
"remote",
"set-url",
"origin",
missing.to_str().expect("utf8 path"),
],
)
.expect("set-url must succeed");
let err = refresh_landing_refs(&wt).expect_err("an unreachable origin must fail");
assert!(
err.contains("git fetch --prune origin"),
"the error names the command that failed: {err}"
);
assert_eq!(
origin_main(&wt),
before,
"a failed fetch must advance no ref"
);
}