Skip to content

Conversation

@derduher
Copy link
Collaborator

Summary

This PR addresses several bugs and code quality issues discovered during an audit of sitemap-item-stream.ts:

Critical Bugs Fixed

  • Null safety for video.tag iteration: Added check to prevent runtime crash when video.tag is null/undefined (previously would throw TypeError: Cannot read property Symbol(Symbol.iterator) of null)
  • Type-safe view_count handling: Changed from .toString() to String() for more robust type coercion that handles both number and string inputs

Code Quality Improvements

  • Consistent attribute handling: Changed gallery_loc to use attrBuilder() like all other video attributes, maintaining consistent pattern throughout the codebase
  • Fixed type signature: Changed attrBuilder return type from Record<string, string> to StringObj to accurately reflect that function can return non-string values
  • Added comprehensive JSDoc: Documented the attrBuilder function with params, returns, throws, and example for improved maintainability

Test Coverage

Added 5 new test cases covering:

  • Null/undefined video.tag edge cases
  • Empty video.tag arrays
  • Numeric field serialization (view_count, rating, duration)
  • Priority precision handling (full vs fixed)

Test Results

✅ All 177 tests pass
✅ TypeScript compilation successful (ESM + CJS)
✅ Linting passes with no errors
✅ Coverage increased for sitemap-item-stream.ts to 99.1%

Files Changed

  • lib/sitemap-item-stream.ts - Bug fixes and improvements
  • tests/sitemap-item-stream.test.ts - New edge case tests

🤖 Generated with Claude Code

This commit addresses several bugs and code quality issues in sitemap-item-stream.ts:

**Critical Bugs Fixed:**
- Add null safety check for video.tag iteration to prevent runtime crash
- Fix view_count type handling by using String() instead of .toString()

**Code Quality Improvements:**
- Make attribute handling consistent by using attrBuilder for gallery_loc
- Fix attrBuilder return type from Record<string, string> to StringObj
- Add comprehensive JSDoc documentation to attrBuilder function

**Test Coverage:**
- Add tests for null/undefined video.tag edge cases
- Add tests for empty video.tag arrays
- Add tests for numeric field serialization (view_count, rating, duration)
- Add tests for priority precision handling (full vs fixed)

All tests pass (177/177) with 99.1% coverage on sitemap-item-stream.ts.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@derduher derduher merged commit 82e5e66 into master Oct 12, 2025
6 checks passed
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