-
Notifications
You must be signed in to change notification settings - Fork 0
Description
User Story #83: System Date Mocking
The Goal
Provide the agent with the ability to "time travel." In an F1 competition, logic often depends on the current time (e.g., locking selections when qualifying starts). Since the agent can't wait for a real Sunday to test these gates, it needs a way to override the system's perception of "Now" within the :test environment.
Acceptance Criteria
[ ] Abstraction Layer: Replace all direct calls to DateTime.Now or DateTime.UtcNow in the C# code with a custom IDateTimeProvider interface.
[ ] Header/Env Override: The provider must check for a specific HTTP Header (e.g., X-Mock-Date) or an Environment Variable before falling back to the real system clock.
[ ] Steward Console Integration: The Admin "Steward" Console (#51) includes a date-picker that sets this mock date for the current session or environment.
[ ] Selenium Compatibility: The Selenium suite (#82) can pass a mock date via headers or an API call to test that the UI correctly "locks" or "unlocks" selection inputs based on the race schedule.
Implementation Details
- The Interface (C#)
Injecting this into your services allows the agent to control time across the entire application stack.
C#
public interface IDateTimeProvider {
DateTime UtcNow { get; }
}
public class MachineDateTimeProvider : IDateTimeProvider {
public DateTime UtcNow => DateTime.UtcNow;
}
- The Mock Implementation (Agent-Ready)
This implementation allows the agent to pass a date string in the header of a request. If the header is present, the app "becomes" that date for the duration of that request.
C#
public class MockableDateTimeProvider : IDateTimeProvider {
private readonly IHttpContextAccessor _httpContextAccessor;
public MockableDateTimeProvider(IHttpContextAccessor httpContextAccessor) {
_httpContextAccessor = httpContextAccessor;
}
public DateTime UtcNow {
get {
var headers = _httpContextAccessor.HttpContext?.Request.Headers;
if (headers != null && headers.TryGetValue("X-Mock-Date", out var mockDate)) {
if (DateTime.TryParse(mockDate, out var parsedDate)) {
return parsedDate.ToUniversalTime();
}
}
return DateTime.UtcNow;
}
}
}
Why this is critical for the Agent
Deterministic Testing: The agent can verify that a "Late Submission" (after the race has started) correctly returns a 403 Forbidden error without having to wait for a real race weekend.
UI State Verification: Using Selenium, the agent can set the mock date to "Saturday 2:00 PM" and verify that the "Submit" button is visually disabled.
Technical Risks
Persistence: If the mock date is only in the Header, background tasks (like the Race Data Service #85) won't see it. You may need to store the "Global Mock Date" in a cache or a specific DB table for environment-wide mocking.
Timezone Confusion: Always use UtcNow for mocking to avoid the "Agent in one timezone, Server in another" headache.