Skip to content

Commit b6f7355

Browse files
committed
fix: ensure consistent commit timestamps in tests
1 parent ecbb9ea commit b6f7355

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

tests/git_priority_tests.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,18 @@ fn test_git_priority_boost_with_path_prefix() -> Result<(), Box<dyn std::error::
381381
let temp = TempDir::new()?;
382382
setup_git_repo(temp.path())?;
383383

384-
// Create test files with different dates and in different paths
384+
// We'll give src/module2/recent.rs a commit date that is 1 second newer
385+
// so that it definitely has a higher priority than docs/recent.md.
386+
let now = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
387+
// For docs:
388+
let docs_date = chrono::DateTime::from_timestamp((now as i64) - 1, 0)
389+
.unwrap()
390+
.to_rfc3339();
391+
// For src:
392+
let src_date = chrono::DateTime::from_timestamp(now as i64, 0)
393+
.unwrap()
394+
.to_rfc3339();
395+
385396
fs::create_dir_all(temp.path().join("src/module1"))?;
386397
fs::create_dir_all(temp.path().join("src/module2"))?;
387398
fs::create_dir_all(temp.path().join("docs"))?;
@@ -394,20 +405,16 @@ fn test_git_priority_boost_with_path_prefix() -> Result<(), Box<dyn std::error::
394405
"2023-01-01T12:00:00+00:00",
395406
)?;
396407

397-
// Create files in src/module2
398-
let now = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
399-
let recent_date = chrono::DateTime::from_timestamp(now as i64, 0)
400-
.unwrap()
401-
.to_rfc3339();
408+
// Create files in src/module2 with newer timestamp
402409
commit_file(
403410
temp.path(),
404411
"src/module2/recent.rs",
405412
"recent content",
406-
&recent_date,
413+
&src_date,
407414
)?;
408415

409-
// Create files in docs
410-
commit_file(temp.path(), "docs/recent.md", "recent docs", &recent_date)?;
416+
// Create files in docs with slightly older timestamp
417+
commit_file(temp.path(), "docs/recent.md", "recent docs", &docs_date)?;
411418

412419
// Create config with priority rules
413420
let config = YekConfig {

0 commit comments

Comments
 (0)