Summary of What Needs to be Done:
Add unit tests for WorkflowScheduler._should_run in backend/secuscan/workflows.py. This method is a pure datetime-comparison function that determines whether a scheduled workflow should run based on the elapsed time since its last execution. It currently has no test coverage.
The method handles three cases:
last_run_at is None (never run) → return True
last_run_at is a naive datetime (SQLite returns no timezone suffix) → treat as UTC
last_run_at is an aware datetime → compare with current UTC time
elapsed >= schedule_seconds → return True, else False
Changes that Need to be Made:
Create testing/backend/unit/test_workflows_scheduler_should_run.py with the following test cases:
test_no_last_run_at_returns_true: when last_run_at=None, _should_run returns True regardless of schedule_seconds
test_elapsed_exceeds_schedule_returns_true: when enough time has passed, returns True
test_elapsed_less_than_schedule_returns_false: when not enough time has passed, returns False
test_naive_datetime_treated_as_utc: SQLite datetime format (no Z, no +00:00) is treated as UTC — a naive datetime 30s ago with schedule_seconds=60 should return False
test_aware_datetime_comparison_correct: an aware datetime 120s ago with schedule_seconds=60 returns True
test_zero_schedule_seconds: schedule_seconds=0 always returns True
test_exactly_at_boundary: elapsed == schedule_seconds returns True
Import the real WorkflowScheduler from backend.secuscan.workflows. Instantiate it directly (WorkflowScheduler()) — the _should_run method does not require a running scheduler or database.
Impact that it would Provide:
- Reliability: ensures the scheduler respects timing constraints correctly
- Regression safety: prevents silent scheduler overruns if datetime handling changes
- Documentation: the test cases document the expected behavior for naive vs aware datetimes
Note: This task is being handled by tmdeveloper007 — please assign to that account when picking it up.
Summary of What Needs to be Done:
Add unit tests for
WorkflowScheduler._should_runinbackend/secuscan/workflows.py. This method is a pure datetime-comparison function that determines whether a scheduled workflow should run based on the elapsed time since its last execution. It currently has no test coverage.The method handles three cases:
last_run_atisNone(never run) → returnTruelast_run_atis a naive datetime (SQLite returns no timezone suffix) → treat as UTClast_run_atis an aware datetime → compare with current UTC timeelapsed >= schedule_seconds→ returnTrue, elseFalseChanges that Need to be Made:
Create
testing/backend/unit/test_workflows_scheduler_should_run.pywith the following test cases:test_no_last_run_at_returns_true: whenlast_run_at=None,_should_runreturnsTrueregardless of schedule_secondstest_elapsed_exceeds_schedule_returns_true: when enough time has passed, returnsTruetest_elapsed_less_than_schedule_returns_false: when not enough time has passed, returnsFalsetest_naive_datetime_treated_as_utc: SQLite datetime format (no Z, no +00:00) is treated as UTC — a naive datetime 30s ago with schedule_seconds=60 should returnFalsetest_aware_datetime_comparison_correct: an aware datetime 120s ago with schedule_seconds=60 returnsTruetest_zero_schedule_seconds: schedule_seconds=0 always returnsTruetest_exactly_at_boundary: elapsed == schedule_seconds returnsTrueImport the real
WorkflowSchedulerfrombackend.secuscan.workflows. Instantiate it directly (WorkflowScheduler()) — the_should_runmethod does not require a running scheduler or database.Impact that it would Provide:
Note: This task is being handled by tmdeveloper007 — please assign to that account when picking it up.