Add deterministic test & extract time formatter for list_files (#616)#619
Add deterministic test & extract time formatter for list_files (#616)#619octoaide[bot] wants to merge 3 commits intomainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #619 +/- ##
==========================================
- Coverage 80.99% 80.90% -0.09%
==========================================
Files 27 27
Lines 3977 3954 -23
==========================================
- Hits 3221 3199 -22
+ Misses 756 755 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
zmrdltl
left a comment
There was a problem hiding this comment.
Please revert the production refactor and keep this PR focused on adding the deterministic list_files modified-time output test.
For example:
const LIST_FILES_MTIME_CHILD_ENV: &str = "ROXY_LIST_FILES_MTIME_CHILD";
...
#[test]
fn list_files_formats_modified_time_in_local_timezone() {
if std::env::var_os(LIST_FILES_MTIME_CHILD_ENV).is_some() {
let dir = make_temp_test_dir("list-mtime");
let file_path = dir.join("fixed.yaml");
write_text_file(&file_path, "fixed");
let ts = UNIX_EPOCH + Duration::from_secs(1_700_000_000);
let file = OpenOptions::new()
.write(true)
.open(&file_path)
.expect("test file should be openable for timestamp update");
file.set_modified(ts)
.expect("test file modified time should be settable");
let listed = list_files(
dir.to_str().expect("temp path should be valid utf-8"),
None,
false,
)
.expect("listing files should succeed");
assert_eq!(
listed,
vec![(
5,
"2023/11/14 22:13:20".to_string(),
"fixed.yaml".to_string()
)]
);
fs::remove_dir_all(&dir).expect("temp test directory should be removable");
return;
}
let output = std::process::Command::new(
std::env::current_exe().expect("current test executable should be available"),
)
.arg("list_files_formats_modified_time_in_local_timezone")
.env(LIST_FILES_MTIME_CHILD_ENV, "1")
.env("TZ", "UTC")
.output()
.expect("child test process should run");
assert!(
output.status.success(),
"child test process should pass\nstdout:\n{}\nstderr:\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
}|
Thanks — I reviewed your comment and updated the PR accordingly. I reverted the production refactor and restored the original inline DateTime formatting in list_files (removed the format_modified_time helper and dropped the time::SystemTime import). I also replaced the test with the child-process pattern you suggested: the parent re-execs the test binary with TZ=UTC and ROXY_LIST_FILES_MTIME_CHILD=1, and the child branch creates a temp file, sets its mtime to 1_700_000_000, and asserts that list_files returns the expected tuple (5, "2023/11/14 22:13:20", "fixed.yaml"). I've committed and pushed these changes. I ran the tests and cargo clippy — all three list_files tests pass and clippy is clean. Thanks for the guidance — this PR is now focused on the deterministic modified-time test as requested. |
|
@zmrdltl Please update the direction of this issue based on the comments on the parent issue. |
c5b6564 to
11dcc66
Compare
|
I reviewed the direction from #616 and pivoted the PR to match it (per @zmrdltl). Instead of preparing a chrono→jiff swap, I removed direct chrono usage entirely and simplified the API where chrono had been needed. What I changed (all committed and pushed):
Verification:
Thanks for the guidance — I’ve updated the work to follow the revised direction and confirmed everything is addressed. |
Closes #616
Summary
Prepare tests for the upcoming chrono -> jiff migration by isolating the time formatting logic and adding a deterministic test for list_files modified-time output.
What I changed
Notes and verification
Why
This change prepares the codebase for a safe swap from chrono to jiff by:
Closes #616.