fix(test): make timeline day-grouping test deterministic
Timeline_groups_by_day_newest_first seeded two "same day" events as DateTime.Now.AddDays(-3) and DateTime.Now.AddDays(-3).AddHours(2). When the wall clock was within two hours of midnight the second timestamp crossed into the next calendar day, so the service grouped them into two days instead of one and the test failed (expected 2 day-groups, got 3). The service is correct -- it groups by e.At.Date, which is the intended behaviour and what the test name asserts. The test was nondeterministic, failing roughly two hours out of every twenty-four, including in CI whenever CI ran late in the day. Anchor the two older events to DateTime.Today plus fixed hours (9 and 11) so they always land on the same calendar day regardless of wall-clock time. The "today" event stays DateTime.Now so the "Today" label assertion still exercises the real path. Verified: 420 tests pass at 22:35 local (the failing window) and on Linux with full ICU and under DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -115,8 +115,11 @@ public sealed class ApplicationIntelligenceTests
|
|||||||
var (db, _, timeline) = New("user-1");
|
var (db, _, timeline) = New("user-1");
|
||||||
await using var _d = db;
|
await using var _d = db;
|
||||||
var job = await SeedJobAsync(db, "user-1");
|
var job = await SeedJobAsync(db, "user-1");
|
||||||
db.JobEvents.Add(new JobEvent { JobApplicationId = job.Id, Type = "Created", At = DateTime.Now.AddDays(-3) });
|
// Anchor the two older events to a fixed time-of-day so they always land on the same
|
||||||
db.JobEvents.Add(new JobEvent { JobApplicationId = job.Id, Type = "AiRefreshed", At = DateTime.Now.AddDays(-3).AddHours(2) });
|
// calendar day. Using DateTime.Now.AddDays(-3).AddHours(2) straddled midnight whenever the
|
||||||
|
// wall clock was within two hours of it, splitting one day into two and failing the test.
|
||||||
|
db.JobEvents.Add(new JobEvent { JobApplicationId = job.Id, Type = "Created", At = DateTime.Today.AddDays(-3).AddHours(9) });
|
||||||
|
db.JobEvents.Add(new JobEvent { JobApplicationId = job.Id, Type = "AiRefreshed", At = DateTime.Today.AddDays(-3).AddHours(11) });
|
||||||
db.JobEvents.Add(new JobEvent { JobApplicationId = job.Id, Type = "ReplyReceived", At = DateTime.Now });
|
db.JobEvents.Add(new JobEvent { JobApplicationId = job.Id, Type = "ReplyReceived", At = DateTime.Now });
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user