Skip to content

Commit a5a5db0

Browse files
test: fix vacuous assertions in src/fuzzy_schedule.rs (#737)
1 parent 8d0be09 commit a5a5db0

1 file changed

Lines changed: 32 additions & 33 deletions

File tree

src/fuzzy_schedule.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -836,16 +836,24 @@ mod tests {
836836
));
837837

838838
let schedule = parse_fuzzy_schedule("daily around 14:00").unwrap();
839-
assert!(matches!(
839+
assert_eq!(
840840
schedule,
841-
FuzzySchedule::Daily(TimeConstraint::Around(_))
842-
));
841+
FuzzySchedule::Daily(TimeConstraint::Around(TimeSpec {
842+
hour: 14,
843+
minute: 0
844+
})),
845+
"daily around 14:00 should capture 14:00 in the Around variant"
846+
);
843847

844848
let schedule = parse_fuzzy_schedule("daily between 9:00 and 17:00").unwrap();
845-
assert!(matches!(
849+
assert_eq!(
846850
schedule,
847-
FuzzySchedule::Daily(TimeConstraint::Between(_, _))
848-
));
851+
FuzzySchedule::Daily(TimeConstraint::Between(
852+
TimeSpec { hour: 9, minute: 0 },
853+
TimeSpec { hour: 17, minute: 0 }
854+
)),
855+
"daily between should capture both boundary times"
856+
);
849857
}
850858

851859
#[test]
@@ -946,41 +954,32 @@ mod tests {
946954

947955
#[test]
948956
fn test_between_equal_times_daily() {
949-
// Test edge case: daily between 14:00 and 14:00 (same time)
950-
// Should not panic and should generate valid cron
957+
// When start == end the range expands to the full 24-hour day, so the
958+
// scattered time must NOT be pinned to the specified hour (14).
959+
// The cron expression must be deterministic for a given workflow key.
951960
let schedule = parse_fuzzy_schedule("daily between 14:00 and 14:00").unwrap();
952961
let cron = generate_cron(&schedule, "test/agent");
953-
954-
// Verify it's a valid cron format
955-
let parts: Vec<&str> = cron.split_whitespace().collect();
956-
assert_eq!(parts.len(), 5, "Cron should have 5 fields");
957-
958-
let minute: u32 = parts[0].parse().expect("Minute should be a number");
959-
assert!(minute < 60, "Minute should be 0-59");
960-
961-
let hour: u32 = parts[1].parse().expect("Hour should be a number");
962-
assert!(hour < 24, "Hour should be 0-23");
962+
// FNV-1a("test/agent")=196813323; offset=196813323%1440=1323;
963+
// scattered=(840+1323)%1440=723 → hour=12, min=3
964+
assert_eq!(
965+
cron, "3 12 * * *",
966+
"Same start/end time should scatter across full 24-hour day deterministically"
967+
);
963968
}
964969

965970
#[test]
966971
fn test_between_equal_times_weekly() {
967-
// Test edge case: weekly on monday between 09:00 and 09:00 (same time)
968-
// Should not panic and should generate valid cron
972+
// When start == end the range expands to the full 24-hour day, so the
973+
// scattered time must NOT be pinned to the specified hour (09).
974+
// The cron expression must be deterministic for a given workflow key.
969975
let schedule = parse_fuzzy_schedule("weekly on monday between 09:00 and 09:00").unwrap();
970976
let cron = generate_cron(&schedule, "test/agent");
971-
972-
// Verify it's a valid cron format
973-
let parts: Vec<&str> = cron.split_whitespace().collect();
974-
assert_eq!(parts.len(), 5, "Cron should have 5 fields");
975-
976-
let minute: u32 = parts[0].parse().expect("Minute should be a number");
977-
assert!(minute < 60, "Minute should be 0-59");
978-
979-
let hour: u32 = parts[1].parse().expect("Hour should be a number");
980-
assert!(hour < 24, "Hour should be 0-23");
981-
982-
// Verify day of week is Monday (1)
983-
assert_eq!(parts[4], "1", "Day of week should be Monday (1)");
977+
// FNV-1a("test/agent")=196813323; offset=196813323%1440=1323;
978+
// scattered=(540+1323)%1440=423 → hour=7, min=3; day-of-week=1 (Monday)
979+
assert_eq!(
980+
cron, "3 7 * * 1",
981+
"Same start/end time on Monday should scatter across full day deterministically"
982+
);
984983
}
985984

986985
#[test]

0 commit comments

Comments
 (0)