Skip to content

Comments

[AI-assisted] test(cli): add missing test cases for parseDurationMs#4137

Open
sind00 wants to merge 1 commit intoopenclaw:mainfrom
sind00:test/parse-duration-edge-cases
Open

[AI-assisted] test(cli): add missing test cases for parseDurationMs#4137
sind00 wants to merge 1 commit intoopenclaw:mainfrom
sind00:test/parse-duration-edge-cases

Conversation

@sind00
Copy link

@sind00 sind00 commented Jan 29, 2026

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
  • Test improvement
  • Documentation
  • Refactoring

Greptile Overview

Greptile Summary

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.

Confidence Score: 5/5

  • 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

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Add test coverage for error handling and edge cases:
- Empty string validation
- Invalid format handling
- Negative value rejection
- Custom defaultUnit option

These tests document expected behavior without changing production code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant