-
Notifications
You must be signed in to change notification settings - Fork 1
Add date range filtering and fix test infrastructure #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -301,6 +301,38 @@ export class LocalRepositoryDataSource implements IAdvisoryDataSource { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Parse date filter string and return start/end dates | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Supports: "2026-01-27" (single day) or "2026-01-01..2026-01-31" (range) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private parseDateFilter(dateStr: string): { start: string; end: string } { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Defense-in-depth: ensure dateStr is a string (HTTP query params can be arrays) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const str = Array.isArray(dateStr) ? String(dateStr[0]) : String(dateStr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (str.includes('..')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [start, end] = str.split('..'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [start, end] = str.split('..'); | |
| const parts = str.split('..'); | |
| if (parts.length !== 2 || !parts[0] || !parts[1]) { | |
| throw new Error('Invalid date range format. Expected "YYYY-MM-DD..YYYY-MM-DD".'); | |
| } | |
| const [start, end] = parts; |
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parseDateFilter method doesn't validate that the start date comes before the end date in a range filter. If a user provides "2026-12-31..2026-01-01", the filter will produce an empty result set without any error message, which could confuse users.
Add validation to ensure start is less than or equal to end when parsing a date range, and throw a descriptive error if the range is invalid.
| const [start, end] = str.split('..'); | |
| // End date: include full day by using next day midnight | |
| const endDate = new Date(end + 'T00:00:00Z'); | |
| endDate.setUTCDate(endDate.getUTCDate() + 1); | |
| return { start: start + 'T00:00:00Z', end: endDate.toISOString() }; | |
| const [startRaw, endRaw] = str.split('..'); | |
| const startDate = new Date(startRaw + 'T00:00:00Z'); | |
| const endDate = new Date(endRaw + 'T00:00:00Z'); | |
| if (startDate > endDate) { | |
| throw new Error( | |
| `Invalid date range "${str}": start date must be less than or equal to end date.`, | |
| ); | |
| } | |
| // End date: include full day by using next day midnight (end is exclusive) | |
| endDate.setUTCDate(endDate.getUTCDate() + 1); | |
| return { start: startDate.toISOString(), end: endDate.toISOString() }; |
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parseDateFilter method lacks input validation for invalid dates. When an invalid date string is provided (e.g., "2026-13-45", "invalid-date", or "2026-02-30"), new Date() will create an Invalid Date object. The code will still proceed and call toISOString() on this Invalid Date, which will throw an error at runtime.
Add validation to check if the parsed dates are valid before proceeding. For example, after creating a Date object, check if date.getTime() returns NaN to detect invalid dates, and throw a descriptive error message.
| // End date: include full day by using next day midnight | |
| const endDate = new Date(end + 'T00:00:00Z'); | |
| endDate.setUTCDate(endDate.getUTCDate() + 1); | |
| return { start: start + 'T00:00:00Z', end: endDate.toISOString() }; | |
| } | |
| // Single date: filter for that specific day | |
| const startDate = new Date(str + 'T00:00:00Z'); | |
| const endDate = new Date(str + 'T00:00:00Z'); | |
| // Validate start and end dates | |
| const startDate = new Date(start + 'T00:00:00Z'); | |
| const endDate = new Date(end + 'T00:00:00Z'); | |
| if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) { | |
| throw new Error(`Invalid date filter: "${str}"`); | |
| } | |
| // End date: include full day by using next day midnight | |
| endDate.setUTCDate(endDate.getUTCDate() + 1); | |
| // Preserve original behavior for the start bound string | |
| return { start: start + 'T00:00:00Z', end: endDate.toISOString() }; | |
| } | |
| // Single date: filter for that specific day | |
| const startDate = new Date(str + 'T00:00:00Z'); | |
| const endDate = new Date(str + 'T00:00:00Z'); | |
| if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) { | |
| throw new Error(`Invalid date filter: "${str}"`); | |
| } |
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new parseDateFilter and filterByDateRange methods lack unit test coverage. While there are E2E tests that exercise these methods indirectly, there are no unit tests that validate edge cases such as invalid dates, reversed date ranges, malformed input, or boundary conditions.
Consider adding unit tests for the LocalRepositoryDataSource class to cover these critical date parsing scenarios, following the pattern established in test/unit/refresh-database.test.ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description lists incorrect dependency version updates. The description claims updates to @opentelemetry/api (1.9.0 → 2.0.0), @opentelemetry/sdk-node (0.57.2 → 0.200.0), @opentelemetry/auto-instrumentations-node (0.57.2 → 0.200.0), @ai-sdk/azure (1.3.22 → 2.0.6), and ai (4.3.15 → 4.3.16).
However, the actual changes are:
The PR description should be updated to reflect the actual dependency changes made.