Skip to content

Conversation

@derduher
Copy link
Collaborator

Summary

This PR enhances the robustness of sitemap-index-stream.ts with improved error handling, input validation, and race condition protection, along with comprehensive test coverage.

Changes

Code Improvements (lib/sitemap-index-stream.ts)

  • Race condition protection: Implemented isCreatingSitemap flag to prevent concurrent sitemap creation
  • Input validation: Added URL and date validation for SitemapIndexStream with proper ErrorLevel handling
  • Error handling: Improved promise chains with proper event listener cleanup to prevent memory leaks
  • Callback validation: Added comprehensive validation of getSitemapStream return values
  • Documentation: Enhanced JSDoc comments and added inline explanations

Test Coverage (tests/sitemap-index.test.ts)

  • Added 16 new test cases covering:
    • URL validation (invalid, empty, null) across all ErrorLevel modes
    • Date validation (invalid lastmod) across all ErrorLevel modes
    • getSitemapStream callback validation (wrong types, array length, exceptions)
    • Limit boundary validation

Coverage Impact

  • sitemap-index-stream.ts: 73% → 91% (+18%)
  • Overall project:
    • Statements: 87% → 90% ✅
    • Branches: 79% → 81% ✅
    • Lines: 88% → 91% ✅

Test Results

  • ✅ All 172 tests passing (16 new tests added)
  • ✅ Zero linting errors
  • ✅ All coverage thresholds exceeded

Backward Compatibility

All changes are fully backward compatible. New validations only catch previously uncaught errors, and existing valid code continues to work identically.

🤖 Generated with Claude Code

- Add race condition protection with isCreatingSitemap flag
- Add comprehensive input validation for URLs and dates
- Improve error handling with proper event listener cleanup
- Add validation for getSitemapStream callback return values
- Enhance documentation with JSDoc and inline comments
- Add 16 new test cases covering all validation scenarios
- Increase sitemap-index-stream.ts coverage from 73% to 91%
- Bring overall project coverage above all thresholds (90%+ statements, 81%+ branches)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@derduher derduher merged commit 7ef852d into master Oct 12, 2025
6 checks passed
@derduher derduher deleted the fix/sitemap-index-stream-improvements branch October 12, 2025 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants