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 .env.test file #835

Merged
merged 2 commits into from
Feb 1, 2025
Merged

Remove .env.test file #835

merged 2 commits into from
Feb 1, 2025

Conversation

bradleyayers
Copy link
Member

@bradleyayers bradleyayers commented Jan 31, 2025

Replace it with the convention of gracefully handling missing environment variables by disabling functionality "just in time", and having a fail fast check when running outside dev or tests.

Summary by CodeRabbit

  • Environment Configuration

    • Removed Replicache license key from CI workflows and test environment
    • Introduced new environment variable checks for Postmark server token
    • Added utility functions to detect CI and test environments and handle missing environment variables
    • Removed references to .env.test from testing tasks
  • Code Refactoring

    • Simplified environment variable handling across multiple files
    • Improved error checking and validation for critical configuration settings
    • Cleaned up comments for clarity in various files
    • Removed support for NEON_DATABASE_URL in environment configuration

Copy link

coderabbitai bot commented Jan 31, 2025

Walkthrough

This pull request involves the removal of the EXPO_PUBLIC_REPLICACHE_LICENSE_KEY environment variable from multiple configuration files and workflow definitions. The changes span across GitHub Actions workflow files, test environment configuration, and source code files. Modifications include the deletion of environment variable declarations, updates to license key handling in the Replicache context, and the introduction of new utility functions for managing environment variables.

Changes

File Change Summary
.github/workflows/ci-daily.yml, .github/workflows/pr.yml Removed EXPO_PUBLIC_REPLICACHE_LICENSE_KEY environment variable from CI jobs
projects/app/.env.test Completely removed the file containing the Replicache license key
projects/app/src/client/ui/ReplicacheContext.tsx Added environment variable check and modified license key configuration
projects/app/src/env.ts Deleted file containing license key handling logic
projects/app/src/server/lib/inngest.ts Added environment variable check for POSTMARK_SERVER_TOKEN
projects/app/src/server/schemaUtil.ts Imported isRunningTests function for test context checking
projects/app/src/util/env.ts Added isRunningTests and isRunningCi constants; updated failFastIfMissingEnvVars logic
projects/app/moon.yml Removed references to .env.test from test and testWatch tasks
projects/app/src/client/ui/auth.ts, projects/app/src/client/ui/replicacheOptions.web.ts Minor comment corrections
projects/app/src/typings/node.d.ts Removed optional environment variable NEON_DATABASE_URL from ProcessEnv interface
projects/app/drizzle.config.ts Removed dbCredentials object from configuration

Possibly related PRs

  • Remove .env file #712: Removal of the EXPO_PUBLIC_REPLICACHE_LICENSE_KEY environment variable in the .github/workflows/ci-daily.yml file.
  • Fix Sentry.init() #715: Modifications to the EXPO_PUBLIC_REPLICACHE_LICENSE_KEY in the .github/workflows/pr.yml file.
  • Various fixes #707: Addition of the EXPO_PUBLIC_SENTRY_DSN environment variable in the .env file, reflecting changes in environment variable management.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.

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

🔭 Outside diff range comments (1)
projects/app/src/server/schemaUtil.ts (1)

Line range hint 56-56: Update environment check to use isRunningTests.

For consistency with the changes above, this check should also use the new isRunningTests constant.

Apply this diff:

-  if (`NODE_TEST_CONTEXT` in process.env || __DEV__) {
+  if (isRunningTests || __DEV__) {
🧹 Nitpick comments (1)
projects/app/src/server/lib/inngest.ts (1)

79-80: Consider removing redundant invariant check.

The token is already validated at the top level when failFastIfMissingEnvVars is true, making this check redundant in production. In development/test environments, the top-level check is skipped but we still want validation before usage.

Consider this pattern instead:

-    invariant(POSTMARK_SERVER_TOKEN != null);
+    if (!failFastIfMissingEnvVars) {
+      // Only validate in dev/test since production is already validated
+      invariant(POSTMARK_SERVER_TOKEN != null, "POSTMARK_SERVER_TOKEN is required");
+    }
     const client = new postmark.ServerClient(POSTMARK_SERVER_TOKEN);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e7c57c and 0be8c62.

📒 Files selected for processing (8)
  • .github/workflows/ci-daily.yml (0 hunks)
  • .github/workflows/pr.yml (0 hunks)
  • projects/app/.env.test (0 hunks)
  • projects/app/src/client/ui/ReplicacheContext.tsx (3 hunks)
  • projects/app/src/env.ts (0 hunks)
  • projects/app/src/server/lib/inngest.ts (2 hunks)
  • projects/app/src/server/schemaUtil.ts (2 hunks)
  • projects/app/src/util/env.ts (1 hunks)
💤 Files with no reviewable changes (4)
  • projects/app/src/env.ts
  • projects/app/.env.test
  • .github/workflows/pr.yml
  • .github/workflows/ci-daily.yml
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: moon-ci (1)
  • GitHub Check: moon-ci (0)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (7)
projects/app/src/client/ui/ReplicacheContext.tsx (3)

5-5: LGTM! Import changes align with PR objectives.

The addition of failFastIfMissingEnvVars and TEST_LICENSE_KEY imports supports the new approach for handling missing environment variables.

Also applies to: 20-25


32-34: LGTM! Robust environment variable validation.

The fail-fast check ensures that EXPO_PUBLIC_REPLICACHE_LICENSE_KEY is defined when required, aligning with the PR's objective of improving environment variable handling.


53-54: LGTM! Graceful fallback for license key.

The configuration gracefully handles missing environment variables by falling back to TEST_LICENSE_KEY, which aligns with the PR's objective of maintaining functionality in development/testing environments.

projects/app/src/util/env.ts (2)

1-1: LGTM! Clear and effective test environment detection.

The use of the in operator is a reliable way to check for environment variable presence. The comment clearly explains the purpose.


3-3: LGTM! Robust environment-aware validation strategy.

This implements a fail-fast approach for production while being more lenient in development and test environments, which aligns well with the PR objectives.

projects/app/src/server/lib/inngest.ts (1)

8-12: LGTM! Robust environment variable validation.

The implementation correctly follows the new pattern for handling missing environment variables:

  • Early destructuring improves readability
  • Fail-fast check only in production environments
  • Clear error message in the invariant
projects/app/src/server/schemaUtil.ts (1)

41-41: LGTM! Consistent use of the new environment detection utility.

The change correctly uses the new isRunningTests constant instead of directly checking process.env.

Replace it with the convention of gracefully handling missing environment
variables by disabling functionality "just in time", and having a fail fast
check when running outside dev or tests.
- remove non-null assertion
- fix english typos
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 (2)
projects/app/src/util/env.ts (2)

1-3: Clarity in Environment Variable Check for Test Context

The new constant isRunningTests is implemented correctly by checking if "NODE_TEST_CONTEXT" exists in process.env. Consider using single quotes instead of backticks for consistency and clarity, as template literals aren’t needed here.

-export const isRunningTests = `NODE_TEST_CONTEXT` in process.env;
+export const isRunningTests = 'NODE_TEST_CONTEXT' in process.env;

4-6: Consistent String Literal Usage for CI Check

The constant isRunningCi correctly determines the CI context by checking for "CI" in process.env. Similar to the previous comment, replacing the backticks with single quotes may improve readability.

-export const isRunningCi = `CI` in process.env;
+export const isRunningCi = 'CI' in process.env;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6c3b40 and eb5a3e0.

📒 Files selected for processing (13)
  • .github/workflows/ci-daily.yml (0 hunks)
  • .github/workflows/pr.yml (0 hunks)
  • projects/app/.env.test (0 hunks)
  • projects/app/drizzle.config.ts (0 hunks)
  • projects/app/moon.yml (0 hunks)
  • projects/app/src/client/ui/ReplicacheContext.tsx (3 hunks)
  • projects/app/src/client/ui/auth.ts (1 hunks)
  • projects/app/src/client/ui/replicacheOptions.web.ts (1 hunks)
  • projects/app/src/env.ts (0 hunks)
  • projects/app/src/server/lib/inngest.ts (2 hunks)
  • projects/app/src/server/schemaUtil.ts (2 hunks)
  • projects/app/src/typings/node.d.ts (0 hunks)
  • projects/app/src/util/env.ts (1 hunks)
💤 Files with no reviewable changes (7)
  • projects/app/.env.test
  • projects/app/drizzle.config.ts
  • projects/app/src/env.ts
  • .github/workflows/ci-daily.yml
  • .github/workflows/pr.yml
  • projects/app/moon.yml
  • projects/app/src/typings/node.d.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • projects/app/src/client/ui/replicacheOptions.web.ts
  • projects/app/src/client/ui/auth.ts
  • projects/app/src/server/schemaUtil.ts
  • projects/app/src/server/lib/inngest.ts
  • projects/app/src/client/ui/ReplicacheContext.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: moon-ci (1)
  • GitHub Check: moon-ci (0)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
projects/app/src/util/env.ts (1)

8-9: Robust failFastIfMissingEnvVars Flag

The failFastIfMissingEnvVars flag is defined to be true only when not running tests, not running in CI, and not in a development environment. This approach aligns well with the fail-fast philosophy outside specified environments. Ensure that the global variable __DEV__ is reliably defined in your environment.

@bradleyayers bradleyayers added this pull request to the merge queue Feb 1, 2025
Merged via the queue into main with commit 49af4e4 Feb 1, 2025
7 checks passed
@bradleyayers bradleyayers deleted the dev branch February 1, 2025 00:32
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