use super::{World, ball};
use crate::binding::work_worktree_path;
use crate::opslog::{Origin, SYNTHETIC_EXIT, YOG_STEP};
use crate::projects::join::JoinState;
use crate::start::{Payload, StartError, on_mint, resolve_worktree};
use litany::mint::MintError;
use std::path::PathBuf;
#[test]
fn on_mint_passes_a_name_through() {
let w = World::new();
let name = on_mint(
Ok("cobalt-gecko".to_owned()),
w.state.path(),
"TS",
w.home.path(),
Origin::Conversation,
crate::registry::Client::default(),
)
.unwrap();
assert_eq!(name, "cobalt-gecko");
assert!(w.ops().is_empty(), "a clean mint logs nothing");
}
#[test]
fn on_mint_logs_an_exhausted_pool() {
let w = World::new();
let err = on_mint(
Err(MintError::Exhausted(6)),
w.state.path(),
"TS",
w.home.path(),
Origin::Conversation,
crate::registry::Client::default(),
)
.unwrap_err();
assert!(matches!(err, StartError::Mint(MintError::Exhausted(6))));
let e = &w.ops()[0];
assert_eq!(e.argv, [YOG_STEP, "mint"]);
assert_eq!(e.exit, SYNTHETIC_EXIT);
assert!(e.stderr.contains("pool exhausted"));
}
#[test]
fn resolve_worktree_prefers_the_claim_then_disk_then_canonical() {
let w = World::new();
let (balls, project, name) = (w.balls.path(), w.project.path(), "cobalt-gecko");
let existing = |id: &str| ball(project, id, JoinState::Bound);
assert_eq!(
resolve_worktree(&Payload::Bare, Some(project), balls, name, None),
None
);
let claimed = PathBuf::from("/claimed/wt-suffixed");
assert_eq!(
resolve_worktree(
&existing("bl-1"),
Some(project),
balls,
name,
Some(claimed.clone())
),
Some(claimed),
);
assert_eq!(
resolve_worktree(&existing("bl-2"), Some(project), balls, name, None),
Some(work_worktree_path(balls, project, "bl-2", None)),
);
let suffixed = work_worktree_path(balls, project, "bl-3", Some(name));
std::fs::create_dir_all(&suffixed).unwrap();
assert_eq!(
resolve_worktree(&existing("bl-3"), Some(project), balls, name, None),
Some(suffixed),
);
}