fix: calendar-accurate date validation in parseSessionFilename, add 22 tests

- Fix parseSessionFilename to reject impossible dates (Feb 31, Apr 31,
  Feb 29 non-leap) using Date constructor month/day roundtrip check
- Add 6 session-manager tests for calendar date validation edge cases
- Add 3 session-manager tests for code blocks/special chars in getSessionStats
- Add 10 package-manager tests for PM-specific command formats (getRunCommand
  and getExecCommand for pnpm, yarn, bun, npm)
- Add 3 integration tests for session-end transcript parsing (mixed JSONL
  formats, malformed lines, nested user messages)
This commit is contained in:
Affaan Mustafa
2026-02-13 01:42:56 -08:00
parent 34edb59e19
commit e96b522af0
4 changed files with 302 additions and 1 deletions

View File

@@ -32,9 +32,13 @@ function parseSessionFilename(filename) {
const dateStr = match[1];
// Validate date components are in valid ranges (not just format)
// Validate date components are calendar-accurate (not just format)
const [year, month, day] = dateStr.split('-').map(Number);
if (month < 1 || month > 12 || day < 1 || day > 31) return null;
// Reject impossible dates like Feb 31, Apr 31 — Date constructor rolls
// over invalid days (e.g., Feb 31 → Mar 3), so check month roundtrips
const d = new Date(year, month - 1, day);
if (d.getMonth() !== month - 1 || d.getDate() !== day) return null;
// match[2] is undefined for old format (no ID)
const shortId = match[2] || 'no-id';