-
-
Notifications
You must be signed in to change notification settings - Fork 88
refactor(relay): implement factory pattern with Mastodon and LitePub relay support #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- add actor and state
This commit addresses all 6 unresolved review comments from @dahlia on PR fedify-dev#484: 1. Add type safety to createRelay parameter by introducing RelayType union type 2. Create common Relay interface and use it as return type for createRelay factory function 3. Add missing await keyword in litepub.ts for kv.delete operation 4. Fix poorly named variable in Move handler (mastodon.ts): deleteActivity → move 5. Fix poorly named variable in Update handler (mastodon.ts): deleteActivity → update 6. Extract duplicate code in followers/following dispatchers into shared getFollowerActors function Changes: - Add RelayType = "mastodon" | "litepub" type alias - Add Relay interface with fetch method - Update MastodonRelay and LitePubRelay to implement Relay interface - Change createRelay return type from union to abstract Relay interface - Remove unnecessary default case in createRelay switch (exhaustive with RelayType) - Extract getFollowerActors helper to eliminate duplicate dispatcher logic - Fix missing await in litepub.ts:182 - Rename handler parameters to match their actual activity types 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Summary of ChangesHello @sij411, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the ActivityPub relay module by introducing separate, specialized implementations for Mastodon and LitePub protocols. It enhances modularity, improves testability with dedicated test suites for each relay type, and streamlines relay creation through a new factory function. The inclusion of a temporal polyfill ensures robust date and time handling across the system. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a major new feature: ActivityPub relays. It adds two types of relays, Mastodon-compatible and LitePub-compatible, by refactoring the existing code into a more modular structure. The core logic is split into mastodon.ts and litepub.ts, with common functionality in relay.ts. New comprehensive test suites are added for both relay types.
My review focuses on the new litepub.ts implementation. I've found a high-severity bug where forwarded activities are not announced correctly according to the LitePub protocol. I've also pointed out some medium-severity issues related to code consistency, clarity, and potential bugs with non-unique IDs. The overall structure and refactoring are well-done.
Codecov Report❌ Patch coverage is
... and 4 files with indirect coverage changes 🚀 New features to boost your workflow:
|
- add actor and state
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- Add relayBuilder with actor, key pairs dispatchers - Add shared followers/following dispatchers - Extract getFollowerActors and dispatchRelayActors helpers
- Add validateFollowActivity for common validation - Add sendFollowResponse for Accept/Reject responses - Add handleUndoFollow for unsubscription handling - These functions are shared by both relay types
- Provides common fetch() method and federation setup - Defines abstract setupInboxListeners() for protocol-specific logic - Base for both Mastodon and LitePub relay implementations
- MastodonRelay: Use forwardActivity for direct forwarding - LitePubRelay: Use Announce wrapping and reciprocal follows - Both now extend BaseRelay and implement setupInboxListeners()
- Add createRelay() factory for instantiating relay types - Update mod.ts to export new structure - Remove old relay.ts interface
|
Apparently the deno.lock file seems broken. Try to remove it and run |
|
Merry Christmas 🎅 I refactored Relay classes and the package's structure as @dahlia reviewed previously. Relay Package Refactoring (80858b6 → ac2ada3)Major refactoring to eliminate code duplication between MastodonRelay and LitePubRelay implementations using Template Method pattern. Stats: 15 commits, 12 files changed, 541 insertions(+), 489 deletions(-) Key Changes
Review Checklist Must verify:
Key files to review:
p.s.
|
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request is a great refactoring of the @fedify/relay package. The introduction of the factory pattern for Mastodon and LitePub relays significantly improves the code's structure, maintainability, and extensibility. The separation of concerns into different files (base.ts, builder.ts, follow.ts, etc.) and the comprehensive new test suites are excellent.
I've found a critical correctness issue related to potential race conditions when updating the list of followers in both MastodonRelay and LitePubRelay implementations. These race conditions could lead to data loss (followers not being added or removed correctly) under concurrent requests. I've left detailed comments with suggestions on how to resolve this using atomic operations provided by the KvStore.
dahlia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good now.
|
Alright, since those race condition problems seem bit out of this PR scope, I'll be handling in another PR. I'll keep those in mind and resolve conversations for now. |
dahlia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, @sij411!
Summary
This PR refactors the
@fedify/relaypackage to introduce a factory pattern that supports multiple relay implementations, specifically Mastodon and LitePub relay protocols. The changes improve code organization, maintainability, and extensibility for future relay implementations.Key Changes
createRelay()factory function that instantiates relay implementations based on type ("mastodon"or"litepub")MastodonRelay: Implements Mastodon's relay protocol with immediate follower acceptanceLitePubRelay: Implements LitePub's relay protocol with reciprocal follow pattern (pending → accepted states)relay.tswith shared:mastodon.test.ts: 896 lines of tests covering Mastodon relay behaviorlitepub.test.ts: 896 lines of tests covering LitePub relay behavior with reciprocal followsrelay.test.tsProtocol Differences
Mastodon Relay:
LitePub Relay:
pending→acceptedArchitecture Improvements
relay.tsandrelayBuilderRelayOptions,LitePubFollower)Migration Guide
Before:
After:
Files Changed
packages/relay/src/relay.ts: Refactored to shared infrastructure (771 → 161 lines)packages/relay/src/mastodon.ts: New Mastodon relay implementation (191 lines)packages/relay/src/litepub.ts: New LitePub relay implementation (297 lines)packages/relay/src/mastodon.test.ts: New comprehensive test suite (784 lines)packages/relay/src/litepub.test.ts: New comprehensive test suite (896 lines)packages/relay/src/relay.test.ts: Removed old monolithic tests (1128 lines deleted)packages/relay/src/mod.ts: Updated exports to include new relay classesTest Plan
Breaking Changes
This is a breaking change that requires updates to existing relay usage code:
Relayclass constructor is replaced withcreateRelay()factory function"mastodon"or"litepub"Related Commits
🤖 Generated with Claude Code