Skip to content

Require max duration in trigger.config. Validate TRIGGER_ACCESS_TOKEN is a PAT. #1620

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

Merged
merged 6 commits into from
Jan 17, 2025

Conversation

matt-aitken
Copy link
Member

@matt-aitken matt-aitken commented Jan 16, 2025

Require max duration

We now require a maxDuration to be set in your trigger.config file.

The maximum duration in compute-time seconds that a task run is allowed to run. If the task run exceeds this duration, it will be stopped.
Minimum value is 5 seconds
Setting this value will effect all tasks in the project.
https://trigger.dev/docs/tasks/overview#maxduration-option

  • If you try and run any command that uses the trigger.config file, like dev or deploy, we will throw a useful error.
  • It's a required property in TypeScriot
  • The init command templates now include a 1hr max duration by default, with better comments explaining it.

Validate TRIGGER_ACCESS_TOKEN

When deploying using GitHub Actions (or some other CI system) you need to set the TRIGGER_ACCESS_TOKEN env var to a Personal Access Token.

Sometimes users put a secret key in here instead, which doesn't work… Now we detect that it's not a token (starts with tr_pat_) and link you to the page to create one.

Summary by CodeRabbit

  • New Features

    • Added a required maxDuration configuration parameter to control maximum task execution time.
    • Introduced personal access token validation during the login process.
  • Bug Fixes

    • Enhanced error handling for invalid CI tokens.
  • Documentation

    • Updated configuration templates with clearer explanations about the maxDuration setting.
  • Chores

    • Updated multiple configuration files to include maxDuration set to 3600 seconds.
    • Modified type definitions to make maxDuration a mandatory configuration option.
    • Changed package manager from Yarn to PNPM in several package configurations.
    • Updated dependency versions to reflect pre-release status.

Copy link

changeset-bot bot commented Jan 16, 2025

🦋 Changeset detected

Latest commit: b806c18

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
trigger.dev Patch
@trigger.dev/core Patch
@trigger.dev/build Patch
@trigger.dev/sdk Patch
@internal/redis-worker Patch
@internal/zod-worker Patch
@trigger.dev/react-hooks Patch
@trigger.dev/rsc Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
references-nextjs-realtime Patch
@internal/testcontainers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Jan 16, 2025

Walkthrough

This pull request introduces a new maxDuration configuration parameter across multiple project files, standardizing a maximum duration setting of 3600 seconds (1 hour) for task execution. The modification includes updates to configuration templates, validation enhancements in the core configuration, and the implementation of personal access token validation in the login process. Additionally, error handling for invalid CI tokens is improved to provide clearer feedback.

Changes

File Path Change Summary
packages/core/src/v3/config.ts Made maxDuration a required property in TriggerConfig type
packages/cli-v3/src/config.ts Added validation to ensure maxDuration is present and at least 5 seconds
packages/cli-v3/src/commands/login.ts Added personal access token validation
packages/cli-v3/src/utilities/isPersonalAccessToken.ts Created utility function and error class for token validation
packages/cli-v3/templates/* Updated maxDuration from 300 to 3600 seconds in configuration templates
references/*/trigger.config.ts & packages/cli-v3/e2e/fixtures/*/trigger.config.ts Added maxDuration: 3600 to multiple configuration files
packages/cli-v3/e2e/fixtures/*/package.json Updated packageManager to pnpm and @trigger.dev/sdk to prerelease version

Possibly related PRs

Poem

🐰 Hop, hop, config's got a new beat!
Max duration now complete
Tokens checked with rabbit's might
Seconds ticking, setting things right
Configuration dancing with glee 🕒


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2626eb2 and b806c18.

⛔ Files ignored due to path filters (14)
  • packages/cli-v3/e2e/fixtures/emit-decorator-metadata/package-lock.json is excluded by !**/package-lock.json
  • packages/cli-v3/e2e/fixtures/emit-decorator-metadata/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • packages/cli-v3/e2e/fixtures/emit-decorator-metadata/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • packages/cli-v3/e2e/fixtures/esm-only-external/package-lock.json is excluded by !**/package-lock.json
  • packages/cli-v3/e2e/fixtures/esm-only-external/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • packages/cli-v3/e2e/fixtures/esm-only-external/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • packages/cli-v3/e2e/fixtures/hello-world/package-lock.json is excluded by !**/package-lock.json
  • packages/cli-v3/e2e/fixtures/hello-world/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • packages/cli-v3/e2e/fixtures/hello-world/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • packages/cli-v3/e2e/fixtures/monorepo-react-email/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • packages/cli-v3/e2e/fixtures/monorepo-react-email/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • packages/cli-v3/e2e/fixtures/otel-telemetry-loader/package-lock.json is excluded by !**/package-lock.json
  • packages/cli-v3/e2e/fixtures/otel-telemetry-loader/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • packages/cli-v3/e2e/fixtures/otel-telemetry-loader/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (6)
  • packages/cli-v3/e2e/fixtures/emit-decorator-metadata/package.json (1 hunks)
  • packages/cli-v3/e2e/fixtures/esm-only-external/package.json (2 hunks)
  • packages/cli-v3/e2e/fixtures/hello-world/package.json (2 hunks)
  • packages/cli-v3/e2e/fixtures/monorepo-react-email/package.json (1 hunks)
  • packages/cli-v3/e2e/fixtures/monorepo-react-email/packages/trigger/package.json (1 hunks)
  • packages/cli-v3/e2e/fixtures/otel-telemetry-loader/package.json (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (buildjet-8vcpu-ubuntu-2204 - pnpm)
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: e2e / 🧪 CLI v3 tests (buildjet-8vcpu-ubuntu-2204 - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
packages/cli-v3/e2e/fixtures/monorepo-react-email/packages/trigger/package.json (1)

6-6: Verify compatibility with new SDK features.

The SDK version update to prerelease suggests significant changes. Ensure this version includes support for the new maxDuration configuration and token validation features.

✅ Verification successful

SDK version compatibility verified

The prerelease version includes both maxDuration configuration and token validation features, with comprehensive implementation across core, schema validation, and CLI components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check SDK version for maxDuration and token validation features

# Search for maxDuration validation in SDK
rg -l "maxDuration" "packages/cli-v3/node_modules/@trigger.dev/sdk"

# Search for token validation in SDK
rg -l "tr_pat_" "packages/cli-v3/node_modules/@trigger.dev/sdk"

Length of output: 299


Script:

#!/bin/bash
# Search for maxDuration and token validation in source files
echo "=== Searching for maxDuration ==="
rg -l "maxDuration" --type-add 'code:*.{js,jsx,ts,tsx}' -t code

echo -e "\n=== Searching for token validation ==="
rg -l "tr_pat_" --type-add 'code:*.{js,jsx,ts,tsx}' -t code

echo -e "\n=== Checking SDK package contents ==="
fd "package.json" | xargs rg "0.0.0-prerelease-20250116195421"

Length of output: 3242

packages/cli-v3/e2e/fixtures/monorepo-react-email/package.json (1)

4-4: Verify CI/CD compatibility with pnpm.

The switch to pnpm as the package manager while maintaining yarn in engines suggests a transition period. Ensure CI/CD pipelines and deployment processes are updated accordingly.

✅ Verification successful

CI/CD is properly configured for pnpm usage

All workflows are correctly set up with pnpm@8.15.5, including proper workspace handling, dependency management, and build processes. The E2E testing matrix ensures compatibility across both npm and pnpm package managers.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for pnpm-specific configuration in CI files

# Search for pnpm-related CI configuration
rg -l "pnpm" ".github/"

Length of output: 204


Script:

#!/bin/bash
# Check pnpm setup and usage in CI workflows
rg -A 5 "pnpm" .github/workflows/

Length of output: 7820

packages/cli-v3/e2e/fixtures/hello-world/package.json (1)

4-4: LGTM! Changes consistent with other packages.

The updates to package manager and SDK version align with changes in other packages.

Also applies to: 13-13

packages/cli-v3/e2e/fixtures/esm-only-external/package.json (1)

14-14: Verify ESM compatibility with prerelease SDK.

The change from stable version 3.0.6 to prerelease version is significant. Ensure the prerelease SDK maintains ESM compatibility and validate the regression from stable version.

✅ Verification successful

ESM compatibility verified in prerelease SDK

The prerelease SDK and its dependencies maintain proper ESM support with appropriate module configurations and export definitions. The version change from stable to prerelease is safe from an ESM compatibility perspective.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check SDK package.json for ESM compatibility

# Check SDK package type
jq .type "packages/cli-v3/node_modules/@trigger.dev/sdk/package.json"

# Check for ESM-specific exports
jq .exports "packages/cli-v3/node_modules/@trigger.dev/sdk/package.json"

Length of output: 376


Script:

#!/bin/bash
# Find SDK package.json location
fd -t f "package.json" -E "**/node_modules/**"

# Once found, check contents of all package.json files for ESM compatibility
fd -t f "package.json" -E "**/node_modules/**" -x cat {} \; | grep -A 5 '"type":\|"exports":'

Length of output: 6024

packages/cli-v3/e2e/fixtures/otel-telemetry-loader/package.json (1)

13-13: Verify OpenTelemetry compatibility with prerelease SDK.

Ensure the prerelease SDK version maintains compatibility with OpenTelemetry instrumentation.

✅ Verification successful

OpenTelemetry compatibility is maintained in prerelease SDK

The prerelease SDK includes all necessary OpenTelemetry dependencies and maintains compatibility through proper version constraints. The presence of dedicated OpenTelemetry test fixtures further confirms active support for telemetry instrumentation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check SDK for OpenTelemetry integration

# Search for OpenTelemetry-related code in SDK
rg -l "opentelemetry" "packages/cli-v3/node_modules/@trigger.dev/sdk"

Length of output: 153


Script:

#!/bin/bash
# Search for OpenTelemetry-related code in the repository
echo "=== OpenTelemetry References ==="
rg -i "opentelemetry|otel" -l

echo -e "\n=== OpenTelemetry Imports ==="
ast-grep --pattern 'import { $$ } from "@opentelemetry/$_"'

echo -e "\n=== OpenTelemetry Integration Code ==="
rg -i "opentelemetry|otel" -A 5

Length of output: 71330

packages/cli-v3/e2e/fixtures/emit-decorator-metadata/package.json (1)

13-13: LGTM! Consistent version updates across @trigger.dev packages.

Both @trigger.dev packages have been updated to the same prerelease version, maintaining consistency.

Let's verify these versions exist in the registry:

Also applies to: 17-17

✅ Verification successful

✅ Version verification successful

Both @trigger.dev packages are available in the npm registry with the specified prerelease version, maintaining version consistency.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the prerelease versions exist in the npm registry
for pkg in "@trigger.dev/sdk" "@trigger.dev/build"; do
  echo "Checking $pkg..."
  curl -s "https://registry.npmjs.org/$pkg" | jq '.versions | has("0.0.0-prerelease-20250116195421")'
done

Length of output: 479


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.

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
Contributor

@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: 1

🧹 Nitpick comments (7)
packages/cli-v3/e2e/fixtures/hello-world/trigger.config.ts (1)

6-6: Consider a shorter duration for the hello-world example.

While the 1-hour duration maintains consistency across configurations, consider using a shorter duration (e.g., 300 seconds) for this hello-world example to demonstrate best practices in setting appropriate limits.

-  maxDuration: 3600,
+  maxDuration: 300, // 5 minutes should be sufficient for hello-world example
packages/cli-v3/e2e/fixtures/esm-only-external/trigger.config.ts (1)

9-9: Consider grouping related configuration properties.

While the addition of maxDuration is correct, consider grouping it with other execution-related properties, separate from build configuration, to improve readability.

export default defineConfig({
  project: "<fixture project>",
  dirs: ["./src/trigger"],
+  maxDuration: 3600,
  build: {
    external: ["mupdf"],
  },
-  maxDuration: 3600,
});
packages/cli-v3/e2e/fixtures/otel-telemetry-loader/trigger.config.ts (1)

8-8: Document duration considerations for OpenAI operations.

The 1-hour maxDuration is added correctly. However, consider adding a comment to document duration considerations specific to OpenAI operations, as they might have varying completion times based on the model and task complexity.

-  maxDuration: 3600,
+  maxDuration: 3600, // Adjusted for potential long-running AI operations. Modify based on your specific OpenAI usage patterns.
packages/cli-v3/src/utilities/isPersonalAccessToken.ts (2)

1-1: Consider making the token prefix readonly.

To prevent accidental modification, consider making the token prefix constant readonly:

-const tokenPrefix = "tr_pat_";
+const TOKEN_PREFIX = "tr_pat_" as const;

7-12: Consider enhancing error type safety.

The custom error implementation is good, but could benefit from better type safety:

-export class NotPersonalAccessTokenError extends Error {
+export class NotPersonalAccessTokenError extends Error {
   constructor(message: string) {
     super(message);
     this.name = "NotPersonalAccessTokenError";
+    Object.setPrototypeOf(this, NotPersonalAccessTokenError.prototype);
   }
 }
references/nextjs-realtime/trigger.config.ts (1)

14-14: Consider grouping related configuration properties.

While the addition of maxDuration is correct, consider grouping it with other execution-related settings for better organization:

export default defineConfig({
  project: "proj_bzhdaqhlymtuhlrcgbqy",
  dirs: ["./src/trigger"],
+  maxDuration: 3600,
  telemetry: {
    exporters: [new AISDKExporter()],
  },
  build: {
    extensions: [rscExtension({ reactDomEnvironment: "worker" })],
  },
-  maxDuration: 3600,
});
packages/cli-v3/templates/trigger.config.mjs.template (1)

7-10: Add minimum duration to the configuration comments.

The comments are clear and informative, but consider adding a note about the minimum allowed duration (5 seconds) to prevent configuration errors.

 // The max compute seconds a task is allowed to run. If the task run exceeds this duration, it will be stopped.
 // You can override this on an individual task.
+// Note: The minimum allowed duration is 5 seconds.
 // See https://trigger.dev/docs/runs/max-duration
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 11f2832 and ba565be.

📒 Files selected for processing (15)
  • .changeset/tiny-seals-appear.md (1 hunks)
  • packages/cli-v3/e2e/fixtures/emit-decorator-metadata/trigger.config.ts (1 hunks)
  • packages/cli-v3/e2e/fixtures/esm-only-external/trigger.config.ts (1 hunks)
  • packages/cli-v3/e2e/fixtures/hello-world/trigger.config.ts (1 hunks)
  • packages/cli-v3/e2e/fixtures/monorepo-react-email/packages/trigger/trigger.config.ts (1 hunks)
  • packages/cli-v3/e2e/fixtures/otel-telemetry-loader/trigger.config.ts (1 hunks)
  • packages/cli-v3/src/commands/login.ts (3 hunks)
  • packages/cli-v3/src/config.ts (1 hunks)
  • packages/cli-v3/src/utilities/isPersonalAccessToken.ts (1 hunks)
  • packages/cli-v3/templates/trigger.config.mjs.template (1 hunks)
  • packages/cli-v3/templates/trigger.config.ts.template (1 hunks)
  • packages/core/src/v3/config.ts (1 hunks)
  • references/bun-catalog/trigger.config.ts (1 hunks)
  • references/nextjs-realtime/trigger.config.ts (1 hunks)
  • references/v3-catalog/trigger.config.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (buildjet-8vcpu-ubuntu-2204 - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (buildjet-8vcpu-ubuntu-2204 - npm)
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (11)
packages/cli-v3/e2e/fixtures/monorepo-react-email/packages/trigger/trigger.config.ts (1)

6-6: LGTM! Verify if 1 hour is sufficient for email-related tasks.

The addition of maxDuration: 3600 aligns with the PR objectives and maintains consistency across configurations.

Consider reviewing typical email task durations in your monitoring system to confirm that 1 hour is an appropriate limit for this specific use case.

packages/cli-v3/e2e/fixtures/emit-decorator-metadata/trigger.config.ts (1)

10-10: LGTM! Verify consistency across all test fixtures.

The addition of maxDuration: 3600 aligns with the PR objective and matches the default 1-hour duration.

Let's verify this value is consistent across all test fixtures:

✅ Verification successful

✅ Verified: maxDuration is consistent across all test fixtures

All test fixtures consistently use maxDuration: 3600, aligning with the 1-hour default duration requirement.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check maxDuration value across all test fixtures
rg -U "maxDuration:.*(\d+)" "packages/cli-v3/e2e/fixtures/**/trigger.config.ts"

Length of output: 171


Script:

#!/bin/bash
# First find all trigger.config.ts files
fd "trigger.config.ts" packages/cli-v3/e2e/fixtures/ --type f --exec rg -U "maxDuration:\s*\d+" {}

Length of output: 205

packages/cli-v3/src/utilities/isPersonalAccessToken.ts (1)

3-5: LGTM! Simple and focused validation.

The validation function is well-implemented with a clear single responsibility.

references/bun-catalog/trigger.config.ts (1)

6-6: Verify interaction between maxDuration and retry settings.

The maxDuration (3600s) looks good, but please verify its interaction with the retry configuration:

  • With max 4 attempts and 10s timeouts that double each retry
  • Will tasks have enough time to complete all retries within the maxDuration?

Let's check for any retry-related documentation or tests:

✅ Verification successful

Retry configuration is compatible with maxDuration

The retry settings (4 attempts with exponential backoff) would use at most 150 seconds for retries, leaving plenty of room within the 3600-second maxDuration for task execution.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for retry-related documentation and tests
rg -l "retry.*maxDuration|maxDuration.*retry" \
  --type md \
  --type ts \
  --type test

Length of output: 108


Script:

#!/bin/bash
# Get the retry configuration from the trigger file
cat references/bun-catalog/trigger.config.ts

# Search for retry and maxDuration documentation
rg -i "retry.*duration|duration.*retry" \
  --type ts \
  --type md \
  -A 3 -B 3

# Find similar configurations
fd -e ts -e js "config" -x rg -l "maxDuration.*retry|retry.*maxDuration|retries.*timeout"

Length of output: 5520

references/v3-catalog/trigger.config.ts (1)

20-20: LGTM! The maxDuration setting is appropriate.

The 1-hour (3600 seconds) maximum duration is a reasonable default that should accommodate most task execution times while preventing runaway processes.

packages/core/src/v3/config.ts (1)

119-119: LGTM! The maxDuration property is now required with clear documentation.

The type definition change enforces the requirement for maxDuration while maintaining comprehensive documentation that clearly explains its purpose, constraints, and minimum value.

packages/cli-v3/src/commands/login.ts (3)

26-29: LGTM! Clean import organization.

The imports are well-organized and clearly indicate the new token validation functionality.


91-95: LGTM! Proper validation of environment-based tokens.

The validation ensures that environment-based tokens are personal access tokens and provides a helpful error message with guidance on how to obtain a valid token.


305-308: LGTM! Appropriate error handling in embedded mode.

The error handling correctly propagates token validation errors in embedded mode while maintaining the existing error handling behavior.

.changeset/tiny-seals-appear.md (1)

1-6: LGTM! Changeset correctly describes the changes.

The patch version bumps are appropriate for these non-breaking enhancements.

packages/cli-v3/templates/trigger.config.ts.template (1)

7-10: Configuration is consistent with MJS template.

The TypeScript template maintains consistency with the JavaScript template, which is good. Please apply the same documentation improvement suggested in the MJS template review.

Comment on lines +292 to +296
if (!config.maxDuration) {
throw new Error(
`The "maxDuration" trigger.config option is now required, and must be at least 5 seconds.`
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for the minimum maxDuration value.

While the validation ensures maxDuration is present, it should also verify that the value is at least 5 seconds as mentioned in the error message and documentation.

 if (!config.maxDuration) {
   throw new Error(
     `The "maxDuration" trigger.config option is now required, and must be at least 5 seconds.`
   );
 }
+if (config.maxDuration < 5) {
+  throw new Error(
+    `The "maxDuration" trigger.config option must be at least 5 seconds, got ${config.maxDuration}.`
+  );
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!config.maxDuration) {
throw new Error(
`The "maxDuration" trigger.config option is now required, and must be at least 5 seconds.`
);
}
if (!config.maxDuration) {
throw new Error(
`The "maxDuration" trigger.config option is now required, and must be at least 5 seconds.`
);
}
if (config.maxDuration < 5) {
throw new Error(
`The "maxDuration" trigger.config option must be at least 5 seconds, got ${config.maxDuration}.`
);
}

@ericallam ericallam force-pushed the require-max-duration branch from ba565be to 2626eb2 Compare January 17, 2025 10:14
Copy link
Contributor

@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)
packages/cli-v3/src/commands/login.ts (3)

91-95: Improve error message readability.

While the validation logic is well-placed, the error message could be more concise and readable.

Consider using template literals for better readability:

-          throw new NotPersonalAccessTokenError(
-            "Your TRIGGER_ACCESS_TOKEN is not a Personal Access Token, they start with 'tr_pat_'. You can generate one here: https://cloud.trigger.dev/account/tokens"
-          );
+          throw new NotPersonalAccessTokenError(
+            `Invalid TRIGGER_ACCESS_TOKEN format. Expected a Personal Access Token starting with 'tr_pat_'.
+             Generate a new token at: https://cloud.trigger.dev/account/tokens`
+          );

305-308: Consider consistent error handling across modes.

While the specific handling of NotPersonalAccessTokenError in embedded mode is good, consider applying similar specific handling in non-embedded mode for consistency.

Consider handling the error specifically in both modes:

       if (options?.embedded) {
         if (e instanceof NotPersonalAccessTokenError) {
           throw e;
         }
         return {
           ok: false as const,
           error: e instanceof Error ? e.message : String(e),
         };
+      } else if (e instanceof NotPersonalAccessTokenError) {
+        outro(e.message);
+        throw new SkipLoggingError(e.message);
       }

       throw e;

Line range hint 91-308: Overall implementation effectively validates PAT format.

The changes successfully implement the validation of Personal Access Tokens with appropriate error handling and user guidance. The implementation is solid, with only minor suggestions for improvement in error message formatting and handling consistency.

Consider documenting the PAT format requirements in the project's API documentation to help users understand the token requirements before they encounter validation errors.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ba565be and 2626eb2.

📒 Files selected for processing (15)
  • .changeset/tiny-seals-appear.md (1 hunks)
  • packages/cli-v3/e2e/fixtures/emit-decorator-metadata/trigger.config.ts (1 hunks)
  • packages/cli-v3/e2e/fixtures/esm-only-external/trigger.config.ts (1 hunks)
  • packages/cli-v3/e2e/fixtures/hello-world/trigger.config.ts (1 hunks)
  • packages/cli-v3/e2e/fixtures/monorepo-react-email/packages/trigger/trigger.config.ts (1 hunks)
  • packages/cli-v3/e2e/fixtures/otel-telemetry-loader/trigger.config.ts (1 hunks)
  • packages/cli-v3/src/commands/login.ts (3 hunks)
  • packages/cli-v3/src/config.ts (1 hunks)
  • packages/cli-v3/src/utilities/isPersonalAccessToken.ts (1 hunks)
  • packages/cli-v3/templates/trigger.config.mjs.template (1 hunks)
  • packages/cli-v3/templates/trigger.config.ts.template (1 hunks)
  • packages/core/src/v3/config.ts (1 hunks)
  • references/bun-catalog/trigger.config.ts (1 hunks)
  • references/nextjs-realtime/trigger.config.ts (1 hunks)
  • references/v3-catalog/trigger.config.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (14)
  • .changeset/tiny-seals-appear.md
  • packages/cli-v3/e2e/fixtures/monorepo-react-email/packages/trigger/trigger.config.ts
  • references/nextjs-realtime/trigger.config.ts
  • packages/cli-v3/e2e/fixtures/otel-telemetry-loader/trigger.config.ts
  • packages/cli-v3/e2e/fixtures/esm-only-external/trigger.config.ts
  • references/bun-catalog/trigger.config.ts
  • packages/cli-v3/src/config.ts
  • packages/cli-v3/templates/trigger.config.mjs.template
  • packages/cli-v3/e2e/fixtures/hello-world/trigger.config.ts
  • packages/cli-v3/templates/trigger.config.ts.template
  • packages/cli-v3/src/utilities/isPersonalAccessToken.ts
  • references/v3-catalog/trigger.config.ts
  • packages/core/src/v3/config.ts
  • packages/cli-v3/e2e/fixtures/emit-decorator-metadata/trigger.config.ts
🔇 Additional comments (1)
packages/cli-v3/src/commands/login.ts (1)

26-29: LGTM! Clean import organization.

The new imports for token validation are well-organized and properly grouped with related functionality.

Copy link

pkg-pr-new bot commented Jan 17, 2025

@trigger.dev/core

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/core@1620

@trigger.dev/build

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/build@1620

@trigger.dev/rsc

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/rsc@1620

@trigger.dev/sdk

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/sdk@1620

trigger.dev

npm i https://pkg.pr.new/triggerdotdev/trigger.dev@1620

@trigger.dev/react-hooks

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/react-hooks@1620

commit: b806c18

@ericallam ericallam merged commit 5798024 into main Jan 17, 2025
13 checks passed
@ericallam ericallam deleted the require-max-duration branch January 17, 2025 11: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.

2 participants