code
Clone this repository
https://tangled.org/bretton.dev/coves
git@knot.bretton.dev:bretton.dev/coves
For self-hosted knots, clone URLs may differ based on your setup.
- Update SELECT clauses to include c.handle as community_handle
- Update scanFeedPost to scan and populate handle field
- Changes apply to:
- Community feed (feed_repo.go)
- Timeline feed (timeline_repo.go)
- Discover feed (discover_repo.go)
- Shared base scanner (feed_repo_base.go)
All feed endpoints now return community handles in responses
- Update communityRef lexicon definition to include handle field
- Add Handle field to CommunityRef struct
- Follows atProto pattern of including both DID and handle
- Consistent with authorView which requires both fields
Fixes: Backend missing community handle in feed responses
Applied gofumpt strict formatting across entire codebase for consistency.
Changes:
- Import statement formatting (stdlib, external, internal order)
- Blank line grouping in imports
- Fix errcheck issue in user_repo.go (properly check rows.Close() error)
- Add log import for error logging
All tests pass after formatting changes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Addresses P0 PR review test coverage requirements:
Unit Tests (comment_service_test.go):
- Fix mockUserRepo to implement GetByDIDs method (compilation blocker)
- Update all buildCommentView calls to 4-parameter signature
- Add 5 tests for GetByDIDs mock (empty, single, multiple, missing, fields)
- Add 5 tests for JSON deserialization (facets, embeds, labels, malformed, nil/empty)
- Total: 10 new unit tests covering Phase 2C functionality
Integration Tests (user_test.go):
- Add TestUserRepository_GetByDIDs with 7 comprehensive test cases
- Test empty array, single/multiple DIDs, missing users, field preservation
- Test validation: batch size limit (>1000), invalid DID format
- All tests use real PostgreSQL database with migrations
Test Fixes (comment_query_test.go):
- Fix TestCommentQuery_InvalidInputs failing tests
- Create real test post/community for validation tests
- Tests now verify normalization works (negative depth, excessive limits)
- All 6 test cases now pass
Test Results:
- Unit tests: 43 total (33 existing + 10 new) - ALL PASS
- Integration tests: 26 total (19 comment + 7 user) - ALL PASS
- Zero compilation errors, zero test failures
Coverage validates:
- Batch user loading prevents N+1 queries
- Input validation rejects oversized/malformed inputs
- JSON deserialization handles errors gracefully
- Security validation prevents injection attacks
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Addresses critical P0 PR review issues for Phase 2C metadata hydration:
Input Validation (user_repo.go):
- Add MaxBatchSize constant (1000 DIDs) to prevent excessive queries
- Validate batch size before database operations
- Validate DID format (must start with "did:")
- Prevents SQL injection and malformed queries
Security Hardening (comment_service.go):
- Add HTTPS validation for community avatar URLs
- Validate CID format (must start with "baf" for IPFS CIDv1)
- Add URL escaping with url.QueryEscape() for DID and CID parameters
- Import "net/url" for proper URL handling
- Prevents mixed content warnings, MitM attacks, and injection attacks
API Documentation (interfaces.go):
- Add comprehensive godoc for GetByDIDs method
- Document parameters, return values, and behavior
- Include usage examples for developers
All changes maintain backward compatibility while adding critical
security and validation layers.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Update COMMENT_SYSTEM_IMPLEMENTATION.md to reflect completion of Phase 2C
metadata hydration work.
Changes:
- Updated overview status: Phase 1, 2A, 2B & 2C Complete
- Updated last updated date with Phase 2C details
- Added comprehensive Phase 2C implementation section (165+ lines)
- Updated conclusion with Phase 2C achievements
- Added Phase 2C features to key features list:
- Full author metadata (handles from users table)
- Community metadata (names, avatars with blob URLs)
- Rich text facets (mentions, links, formatting)
- Embedded content (images, quoted posts)
- Content labels (NSFW, spoilers)
- Updated scalability section with user batch loading stats
- Added Rich Content checkmark to production readiness
Documentation includes:
- Batch user loading implementation details
- Community name/avatar hydration with priority selection
- Rich text deserialization patterns
- Error handling strategies
- Performance impact analysis
- Lexicon compliance validation
All Phase 2C work is now fully documented with technical details,
implementation patterns, and production considerations.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add full user, community, and record metadata to comment query API responses.
Completes lexicon compliance for rich comment content including facets, embeds, and labels.
Changes to comment service:
1. **Batch User Hydration**
- Integrate GetByDIDs() for efficient author loading
- Collect all unique author DIDs from comment tree
- Single batch query prevents N+1 problem
- Populate AuthorView.Handle from users table
2. **Community Metadata Hydration**
- Fetch community for each post in response
- Populate community name with priority: DisplayName > Name > Handle > DID
- Construct avatar blob URL: {pds}/xrpc/com.atproto.sync.getBlob?did={did}&cid={cid}
- Graceful fallback if community not found
3. **Rich Text Deserialization**
- Deserialize contentFacets from JSONB (mentions, links, formatting)
- Deserialize embed from JSONB (images, quoted posts)
- Deserialize labels from JSONB (NSFW, spoilers, warnings)
- Populate both CommentView fields and complete record
- Graceful error handling (log warnings, don't fail requests)
4. **Complete Record Population**
- buildCommentRecord() now fully populates all fields
- Record includes: facets, embed, labels per lexicon
- Verbatim atProto record for full compatibility
API Response Enhancements:
- CommentView.ContentFacets: Rich text annotations
- CommentView.Embed: Embedded images or quoted posts
- CommentView.Record: Complete atProto record with all nested fields
- CommunityRef.Name: User-friendly community name
- CommunityRef.Avatar: Full blob URL for avatar image
- AuthorView.Handle: Correct handle from users table
Error Handling:
- All JSON parsing errors logged as warnings
- Requests succeed even if rich content parsing fails
- Missing users/communities handled gracefully
- Maintains API reliability with graceful degradation
Performance:
- Batch user loading prevents N+1 queries
- Single community query per response (acceptable for alpha)
- JSON deserialization happens in-memory (fast)
- No additional database queries for rich content
Lexicon Compliance:
- ✅ social.coves.community.comment.defs#commentView
- ✅ social.coves.community.post.get#authorView
- ✅ social.coves.community.post.get#communityRef
- ✅ All required fields populated, optional fields handled correctly
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>