Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ cargo = { level = "deny", priority = -1 }
multiple_crate_versions = "allow"
# Forbid leftover `dbg!` debugging macros from reaching production
dbg_macro = "deny"
# Forbid leftover `todo!` placeholders from reaching production
todo = "deny"
4 changes: 1 addition & 3 deletions src/commands/open/hook_build_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ fn test_run_auto_prune_with_ttl_no_expired() {
let mut config = Config::default();
config.workspace.auto_prune = true;
// 1000-year TTL: no real registry entry can be this old, so nothing is pruned
config.workspace.ttl = Some(Ttl::new(std::time::Duration::from_secs(
1_000 * 365 * 24 * 3600,
)));
config.workspace.ttl = Some(Ttl::new(std::time::Duration::from_hours(1_000 * 365 * 24)));
run_auto_prune(&config);
}
3 changes: 1 addition & 2 deletions src/git/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,5 @@ pub fn branch_exists_remote(bare: &Path, branch: &str) -> bool {
&format!("refs/remotes/origin/{branch}"),
])
.output()
.map(|o| o.status.success())
.unwrap_or(false)
.is_ok_and(|o| o.status.success())
}
3 changes: 1 addition & 2 deletions src/git/local_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ pub fn branch_exists_local(repo: &Path, branch: &str) -> bool {
.arg(repo)
.args(["rev-parse", "--verify", &format!("refs/heads/{branch}")])
.output()
.map(|o| o.status.success())
.unwrap_or(false)
.is_ok_and(|o| o.status.success())
}
2 changes: 1 addition & 1 deletion src/issue/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl IssueRef {
/// Panics if the home directory cannot be determined.
#[must_use]
pub fn bare_clone_path(&self) -> PathBuf {
let temp = Config::load().map(|c| c.workspace.temp).unwrap_or(false);
let temp = Config::load().is_ok_and(|c| c.workspace.temp);
self.bare_clone_path_rooted(temp)
}

Expand Down
3 changes: 1 addition & 2 deletions src/ttl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ impl std::str::FromStr for Ttl {
#[must_use]
pub fn is_expired(record: &WorkspaceRecord, ttl: &Ttl, now: SystemTime) -> bool {
now.duration_since(record.created_at)
.map(|age| age >= ttl.0)
.unwrap_or(false)
.is_ok_and(|age| age >= ttl.0)
}

/// Returns workspaces that are both present on disk and have exceeded the TTL.
Expand Down
8 changes: 4 additions & 4 deletions src/ttl/prune_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn record(path: PathBuf, created_at: SystemTime) -> WorkspaceRecord {
#[test]
fn test_prune_returns_expired_with_existing_path() {
let dir = tempfile::tempdir().unwrap();
let ttl = Ttl::new(Duration::from_secs(60));
let ttl = Ttl::new(Duration::from_mins(1));
let records = vec![record(dir.path().to_path_buf(), past(120))];
let expired = prune(&records, &ttl, SystemTime::now());
assert_eq!(expired.len(), 1);
Expand All @@ -25,15 +25,15 @@ fn test_prune_returns_expired_with_existing_path() {

#[test]
fn test_prune_skips_missing_paths() {
let ttl = Ttl::new(Duration::from_secs(60));
let ttl = Ttl::new(Duration::from_mins(1));
let records = vec![record(PathBuf::from("/nonexistent/path/xyz"), past(120))];
assert!(prune(&records, &ttl, SystemTime::now()).is_empty());
}

#[test]
fn test_prune_skips_unexpired() {
let dir = tempfile::tempdir().unwrap();
let ttl = Ttl::new(Duration::from_secs(3600));
let ttl = Ttl::new(Duration::from_hours(1));
let records = vec![record(dir.path().to_path_buf(), past(60))];
assert!(prune(&records, &ttl, SystemTime::now()).is_empty());
}
Expand All @@ -42,7 +42,7 @@ fn test_prune_skips_unexpired() {
fn test_prune_mixed_records() {
let expired_dir = tempfile::tempdir().unwrap();
let fresh_dir = tempfile::tempdir().unwrap();
let ttl = Ttl::new(Duration::from_secs(600));
let ttl = Ttl::new(Duration::from_mins(10));
let records = vec![
record(expired_dir.path().to_path_buf(), past(1200)),
record(fresh_dir.path().to_path_buf(), past(60)),
Expand Down
4 changes: 2 additions & 2 deletions src/ttl/serde_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct RecordHelper {

#[test]
fn test_ttl_serde_round_trip() {
let original = Ttl::new(Duration::from_secs(7 * 24 * 3600));
let original = Ttl::new(Duration::from_hours(7 * 24));
let s = toml::to_string(&TtlHelper { ttl: original }).unwrap();
let parsed: TtlHelper = toml::from_str(&s).unwrap();
assert_eq!(parsed.ttl.duration(), original.duration());
Expand All @@ -44,7 +44,7 @@ fn test_workspace_registry_serde_with_entries() {
#[test]
fn test_workspace_record_serde_round_trip() {
let created_at = SystemTime::now()
.checked_sub(Duration::from_secs(3600))
.checked_sub(Duration::from_hours(1))
.unwrap();
let h = RecordHelper {
workspace: vec![WorkspaceRecord {
Expand Down
12 changes: 6 additions & 6 deletions src/ttl/ttl_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ fn future(secs: u64) -> SystemTime {

#[test]
fn test_ttl_new_and_duration() {
let d = Duration::from_secs(3600);
let d = Duration::from_hours(1);
assert_eq!(Ttl::new(d).duration(), d);
}

#[test]
fn test_ttl_display_round_trips() {
let ttl = Ttl::new(Duration::from_secs(7 * 24 * 3600));
let ttl = Ttl::new(Duration::from_hours(7 * 24));
let parsed: Ttl = ttl.to_string().parse().unwrap();
assert_eq!(parsed.duration(), ttl.duration());
}

#[test]
fn test_ttl_parse_valid() {
let ttl: Ttl = "1day".parse().unwrap();
assert_eq!(ttl.duration(), Duration::from_secs(86_400));
assert_eq!(ttl.duration(), Duration::from_hours(24));
}

#[test]
Expand All @@ -45,7 +45,7 @@ fn test_ttl_parse_invalid() {

#[test]
fn test_is_expired_when_age_exceeds_ttl() {
let ttl = Ttl::new(Duration::from_secs(60));
let ttl = Ttl::new(Duration::from_mins(1));
let r = WorkspaceRecord {
path: PathBuf::new(),
created_at: past(120),
Expand All @@ -55,7 +55,7 @@ fn test_is_expired_when_age_exceeds_ttl() {

#[test]
fn test_is_not_expired_when_young() {
let ttl = Ttl::new(Duration::from_secs(3600));
let ttl = Ttl::new(Duration::from_hours(1));
let r = WorkspaceRecord {
path: PathBuf::new(),
created_at: past(60),
Expand All @@ -65,7 +65,7 @@ fn test_is_not_expired_when_young() {

#[test]
fn test_is_not_expired_when_created_in_future() {
let ttl = Ttl::new(Duration::from_secs(60));
let ttl = Ttl::new(Duration::from_mins(1));
let r = WorkspaceRecord {
path: PathBuf::new(),
created_at: future(30),
Expand Down
Loading