Skip to content
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

Remove duplicate config and fix tests #37

Merged
merged 2 commits into from
Feb 5, 2025
Merged

Conversation

elliotBraem
Copy link
Collaborator

@elliotBraem elliotBraem commented Feb 5, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved processing of social interactions to ensure submissions and acknowledgments are handled accurately and smoothly.
  • Chores
    • Streamlined configuration loading and system initialization for a more reliable startup experience.
    • Removed unused dependencies to optimize overall system performance.

These updates enhance the system’s reliability and efficiency, resulting in a smoother operational flow and improved handling of social interactions.

Copy link

vercel bot commented Feb 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
curatedotfun-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 5, 2025 4:32am
curatedotfun-docs 🔄 Building (Inspect) Visit Preview Feb 5, 2025 4:32am
curatedotfun-landing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 5, 2025 4:32am

Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

This pull request updates several key areas of the codebase. The submission service and its related mock service now use a submission object—with tweet identification extracted from a property—rather than a direct ID string. The configuration logic has been refactored by removing the custom dotenv call and validation functions, replacing them with a centralized ConfigService. The Twitter client now validates that required credentials exist and uses non-null assertions for tweet IDs. Finally, two dependencies have been removed from the package.json file.

Changes

File(s) Change Summary
backend/src/config/config.ts & backend/src/index.ts Removed custom dotenv configuration and environment validation. Deleted config.ts functions (validateEnv, getConfig) and default export; index.ts now uses ConfigService.getInstance() with loadConfig() and updated messaging.
backend/src/__tests__/mocks/distribution-service.mock.ts, backend/src/services/submissions/submission.service.ts & backend/src/services/twitter/client.ts Updated tweet submission handling and type safety: the processStreamOutput method now accepts a submission object (extracting tweetId), the submission service conditionally uses an existing submission, and tweet IDs are now accessed with non-null assertions. The Twitter client additionally validates required credentials.
package.json Removed dependencies: @curatedotfun/supabase: "^0.0.5" and elysia-rate-limit: "^4.1.0".

Sequence Diagram(s)

sequenceDiagram
  participant App as Application
  participant CS as ConfigService
  App->>CS: getInstance()
  App->>CS: loadConfig()
  CS-->>App: return config data
  App->>App: Initialize with config
Loading
sequenceDiagram
  participant SS as SubmissionService
  participant DS as DistributionService
  SS->>SS: Receive submission event
  SS->>SS: Select submission (existing or new)
  SS->>DS: processStreamOutput(feedId, submission)
  DS-->>DS: Extract tweetId from submission.tweetId
  DS-->>SS: Processed submission acknowledged
Loading

Poem

I'm a hopping rabbit on a code spree,
Configs now load so swiftly and free.
Tweet IDs are clear with a gentle "!" command,
And submissions march as planned.
CodeRabbit cheers for changes so grand!
🐇✨

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
backend/src/__tests__/mocks/distribution-service.mock.ts (1)

7-11: Consider using a proper type for the submission parameter.

While the mock implementation works, using any type bypasses TypeScript's type checking. Consider using the TwitterSubmission type for better type safety.

Apply this diff to improve type safety:

-  async processStreamOutput(feedId: string, submission: any): Promise<void> {
+  async processStreamOutput(feedId: string, submission: TwitterSubmission): Promise<void> {
backend/src/services/twitter/client.ts (1)

207-224: Consider a more defensive approach to handling potentially null tweet IDs.

While non-null assertions work, a more defensive approach would be safer. Consider adding explicit null checks or using optional chaining.

Apply this diff to make the code more defensive:

-        const tweetId = BigInt(tweet.id!);
+        if (!tweet.id) continue;
+        const tweetId = BigInt(tweet.id);
         if (!lastCheckedId || tweetId > lastCheckedId) {
           allNewTweets.push(tweet);
         }

       // Sort chronologically (oldest to newest)
       allNewTweets.sort((a, b) => {
-        const aId = BigInt(a.id!);
-        const bId = BigInt(b.id!);
+        if (!a.id || !b.id) return 0;
+        const aId = BigInt(a.id);
+        const bId = BigInt(b.id);
         return aId > bId ? 1 : aId < bId ? -1 : 0;
       });

       // Only update last checked ID if we found new tweets
       if (allNewTweets.length > 0) {
         // Use the first tweet from the batch since it's the newest (batch comes in newest first)
         const highestId = batch[0].id;
-        await this.setLastCheckedTweetId(highestId!);
+        if (highestId) {
+          await this.setLastCheckedTweetId(highestId);
+        }
       }
backend/src/services/submissions/submission.service.ts (1)

351-354: Consider adding a null check for tweet ID.

The function uses a non-null assertion without first checking if the tweet ID exists. Consider adding a defensive check.

Apply this diff to make the code more defensive:

 private async handleAcknowledgement(tweet: Tweet): Promise<void> {
+    if (!tweet.id) return;
     // Like the tweet
-    await this.twitterService.likeTweet(tweet.id!);
+    await this.twitterService.likeTweet(tweet.id);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c1b68a and 8c8d2a3.

⛔ Files ignored due to path filters (1)
  • bun.lockb is excluded by !**/bun.lockb
📒 Files selected for processing (6)
  • backend/src/__tests__/mocks/distribution-service.mock.ts (1 hunks)
  • backend/src/config/config.ts (0 hunks)
  • backend/src/index.ts (3 hunks)
  • backend/src/services/submissions/submission.service.ts (3 hunks)
  • backend/src/services/twitter/client.ts (2 hunks)
  • package.json (0 hunks)
💤 Files with no reviewable changes (2)
  • package.json
  • backend/src/config/config.ts
🔇 Additional comments (3)
backend/src/services/twitter/client.ts (1)

112-122: LGTM! Good addition of credential validation.

The validation ensures all required Twitter credentials are present before proceeding with initialization. The error message is descriptive and helpful.

backend/src/index.ts (1)

4-4: LGTM! Good refactor of configuration management.

The changes successfully centralize configuration management through ConfigService, aligning with the PR objective to remove duplicate config.

Also applies to: 40-45

backend/src/services/submissions/submission.service.ts (1)

296-296: LGTM! Good handling of submission objects.

The changes ensure the correct submission object is passed to processStreamOutput. The non-null assertion is safe as the submission is guaranteed to exist at this point.

Also applies to: 334-334

@elliotBraem elliotBraem merged commit 38c059a into main Feb 5, 2025
6 checks passed
@elliotBraem elliotBraem deleted the fix/remove-dup-config branch February 5, 2025 04:36
This was referenced Feb 5, 2025
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.

1 participant