#4137: [AI-assisted] test(cli): add missing test cases for parseDurationMs
cli
Cluster:
Backoff and Duration Tests
# PR Description
## Summary
Add missing test cases for the `parseDurationMs` function to improve test coverage and document expected error handling behavior.
## Changes
Added 4 new test cases to `src/cli/parse-duration.test.ts`:
1. **Empty string validation** - Verifies that empty or whitespace-only strings throw "invalid duration (empty)"
2. **Invalid format handling** - Tests that malformed inputs (like "abc", "10x", "not-a-number") throw appropriate errors
3. **Negative value rejection** - Ensures negative durations are rejected with proper error messages
4. **Custom defaultUnit option** - Validates that the `defaultUnit` parameter works correctly for all supported units (ms, s, m, h, d)
## Testing Status
✅ **Fully tested**
- All 10 tests in `src/cli/parse-duration.test.ts` pass (6 existing + 4 new)
- Lint checks pass (`pnpm lint`)
- Build completes successfully (`pnpm build`)
- No production code changes, test-only improvement
## AI Involvement
🤖 **AI-assisted contribution** - This PR was created with Claude Code assistance.
I understand what the code does:
- The `parseDurationMs` function parses human-readable duration strings (like "5s", "2h", "100ms") into milliseconds
- It validates input format, handles various time units, and includes safeguards against invalid/negative values
- The new tests ensure these validation paths are properly covered and documented
## Why This Matters
- Improves test coverage for edge cases and error paths
- Documents expected behavior for future contributors
- Makes the validation rules more discoverable
- No risk to production code (test-only changes)
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [x] Test improvement
- [ ] Documentation
- [ ] Refactoring
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds additional Vitest coverage for `parseDurationMs` by asserting behavior for empty/whitespace input, malformed duration strings, negative values, and the `defaultUnit` option.
These tests live alongside the existing duration parsing cases in `src/cli/parse-duration.test.ts`, and effectively document the expected error messages and option handling without changing production logic.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge; it only adds test cases and doesn’t modify production code.
- The diff is confined to a single test file and adds straightforward assertions that match the documented intent (error cases and defaultUnit behavior). No behavioral changes outside tests, and no signs of brittle environmental dependencies were introduced.
- No files require special attention
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#11421: Tests: add unit tests for infra/format-duration
by PythonUser42 · 2026-02-07
87.2%
#4095: Test/add format duration tests
by TechWizard9999 · 2026-01-29
83.9%
#12684: Test: add missing unit tests for src/utils modules
by shaynhornik · 2026-02-09
82.5%
#20496: test(utils): add comprehensive unit tests for utility functions
by masifislamm · 2026-02-19
81.7%
#15569: test: comprehensive test coverage expansion (57 new test files)
by tangcruz · 2026-02-13
78.8%
#9333: Tests: add test coverage for security/audit-fs.ts
by M00N7682 · 2026-02-05
78.6%
#6111: fix: detect float underflow in duration parsing
by T1mn · 2026-02-01
76.6%
#15784: fix: timestamp parsing should convert seconds to milliseconds
by murasame-desu-ai · 2026-02-13
76.6%
#8964: test(msteams): add comprehensive tests for graph-upload module
by RajdeepKushwaha5 · 2026-02-04
76.4%
#4086: Test/add backoff tests
by TechWizard9999 · 2026-01-29
75.2%