Skip to content

Freestyle mock#814

Merged
BilalG1 merged 10 commits intoemail-sending-and-unsubscribesfrom
email-rendering-emulator
Aug 2, 2025
Merged

Freestyle mock#814
BilalG1 merged 10 commits intoemail-sending-and-unsubscribesfrom
email-rendering-emulator

Conversation

@BilalG1
Copy link
Contributor

@BilalG1 BilalG1 commented Jul 30, 2025


Important

Enhance email functionality by updating mock server setup, email templates, and tests, and switching Freestyle mock to Bun.

  • Behavior:
    • Removed mock API key handling in renderEmailWithTemplate() in email-rendering.tsx.
    • Updated Freestyle class in freestyle.tsx to set baseUrl for mock environments.
    • Changed port for Freestyle mock from 8119 to 8122 in docker.compose.yaml and index.html.
  • Docker:
    • Updated freestyle-mock/Dockerfile to use Bun instead of Deno.
    • Updated docker.compose.yaml to reflect new Freestyle mock setup.
  • Tests:
    • Updated email-related tests in send-email.test.ts, render-email.test.ts, and others to reflect changes in email handling.
    • Added tests for handling invalid user IDs and missing email content.
  • Misc:
    • Updated esbuild.tsx to use a new URL for esbuild.wasm.
    • Minor updates to server-app-impl.ts for email sending logic.

This description was created by Ellipsis for 4137933. You can customize this summary. It will automatically update as commits are pushed.

@vercel
Copy link

vercel bot commented Jul 30, 2025

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

Name Status Preview Comments Updated (UTC)
stack-backend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 2, 2025 1:16am
stack-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 2, 2025 1:16am
stack-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 2, 2025 1:16am
stack-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 2, 2025 1:16am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 30, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch email-rendering-emulator

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @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.

@recurseml
Copy link

recurseml bot commented Jul 30, 2025

😱 Found 2 issues. Time to roll up your sleeves! 😱

🗒️ View all ignored comments in this repo
  • The constraint 'TokenStoreType extends string' is too restrictive. It should likely be 'TokenStoreType extends string | object' to match the condition check in line 113 where TokenStoreType is checked against {}
  • Return type mismatch - the interface declares useUsers() returning ServerUser[] but the Team interface that this extends declares useUsers() returning TeamUser[]
  • There is a syntax error in the super constructor call due to the ellipsis operator used incorrectly. Objects aren't being merged correctly. This syntax usage can lead to runtime errors when trying to pass the merged object to 'super()'. Verify that the intended alterations to the object occur before or outside of the super() call if needed.
  • Throwing an error when no active span is found is too aggressive. The log function should gracefully fallback to console.log or another logging mechanism when there's no active span, since not all execution contexts will have an active span. This makes the code less resilient and could break functionality in non-traced environments.

📚 Relevant Docs

  • Function sets backendContext with a new configuration but doesn't pass 'defaultProjectKeys'. Since defaultProjectKeys is required in the type definition and cannot be updated (throws error if tried to set), this will cause a type error.
  • The schema is using array syntax for pick() which is incorrect for Yup schemas. The pick() method in Yup expects individual arguments, not an array. Should be changed to: emailConfigSchema.pick('type', 'host', 'port', 'username', 'sender_name', 'sender_email')

📚 Relevant Docs

  • Creating a refresh token with current timestamp as expiration means it expires immediately. Should set a future date for token expiration.
  • The 'tools' object is initialized as an empty object, even though 'tools' is presumably expected to contain tool definitions. This could cause the server capabilities to lack necessary tool configurations, thus potentially impacting functionalities that depend on certain tool setups.

📚 Relevant Docs

  • 'STACK_SECRET_SERVER_KEY' is potentially being included in every request header without checking its existence again here. Although it's checked during initialization, this could lead to security issues as it's exposed in all communications where the header is logged or captured.

📚 Relevant Docs

  • When adding 'use client' directive at the beginning, it doesn't check if file.text already contains the 'use client' directive. This could lead to duplicate 'use client' directives if the file already has one.

📚 Relevant Docs

⚠️ Only 5 files were analyzed due to processing limits.

Need help? Join our Discord for support!
https://discord.gg/qEjHQk64Z9

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR implements a comprehensive email rendering emulation system that transitions from mock email rendering to a production-like email processing pipeline. The core change introduces a "Freestyle mock" system that uses Bun-based sandboxes to actually execute React email templates and render proper HTML emails, rather than returning mock template strings.

The implementation includes several key components:

Freestyle Integration: The apps/backend/src/lib/freestyle.tsx file now detects development/test environments with the mock API key (mock_stack_freestyle_key) and redirects to a local mock server at localhost:8119. This allows offline development and testing without external API dependencies.

Docker Mock Service: A complete rewrite of the freestyle mock server from Deno to Bun (docker/dependencies/freestyle-mock/Dockerfile) provides a more sophisticated execution environment that supports React email components and proper Node.js ecosystem compatibility.

Email Rendering Pipeline: The apps/backend/src/lib/email-rendering.tsx file removes the previous mock functionality that returned simple debug strings. Now all email rendering goes through the full FreestyleSandboxes execution path, even in test environments, with React 19.1.1 explicitly configured.

Template Format Updates: Email templates now require specific formats with named exports (EmailTemplate function and variablesSchema using arktype), and themes must export named EmailTheme functions with proper TypeScript interfaces.

Enhanced Email Features: The default email themes now include unsubscribe functionality with proper Link component integration and ThemeProps interface support.

All test files have been updated to expect properly rendered email content (subjects like "Reset your password at Stack Dashboard") instead of raw template syntax, demonstrating that the email rendering pipeline now processes templates correctly with variable substitution and HTML generation.

Confidence score: 2/5

• This PR introduces significant complexity and potential reliability issues that could cause production problems
• The Docker service rewrite from Deno to Bun adds multiple layers of process spawning and JSON parsing that could fail unpredictably
• The docker/dependencies/freestyle-mock/Dockerfile needs more attention due to complex child process handling and potential race conditions in stdout/stderr parsing

17 files reviewed, 3 comments

Edit Code Review Bot Settings | Greptile

@BilalG1 BilalG1 assigned N2D4 and unassigned BilalG1 Jul 30, 2025
@N2D4 N2D4 assigned BilalG1 and unassigned N2D4 Aug 1, 2025
@BilalG1 BilalG1 merged commit 5fd9ab2 into email-sending-and-unsubscribes Aug 2, 2025
16 of 18 checks passed
@BilalG1 BilalG1 deleted the email-rendering-emulator branch August 2, 2025 01:21
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