-
Notifications
You must be signed in to change notification settings - Fork 392
feat(nextjs): Add CI environment detection header for Next.js keyless app creation #6852
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
🦋 Changeset detectedLatest commit: 7b1060b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds CI environment detection to Next.js keyless metadata: introduces Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant App as Next.js App
participant Env as Process Env
participant Module as keyless-custom-headers.ts
participant API as Clerk Backend
App->>Module: collectKeylessMetadata()
Module->>Env: read CI env vars (CI_ENV_VARS)
Env-->>Module: boolean isCI
Module-->>App: MetadataHeaders { ..., isCI }
App->>Module: formatMetadataHeaders(metadata)
alt metadata.isCI == true
Module-->>App: Headers (incl. "Clerk-Is-CI: true")
else metadata.isCI == false
Module-->>App: Headers (no Clerk-Is-CI)
end
App->>API: POST accountless_applications with Headers
API-->>App: Response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests
Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/nextjs/src/server/keyless-custom-headers.ts
(3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep/ci
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
b99277d
to
2351ade
Compare
4b7b5a9
to
39e97b3
Compare
39e97b3
to
62c4697
Compare
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.
🚢
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.
Actionable comments posted: 2
🧹 Nitpick comments (2)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts (2)
477-506
: Consider extracting duplicated metadata scaffolding
metadataWithCI
andmetadataWithoutCI
only differ byisCI
. Extracting a helper (e.g.createMinimalMetadata({ isCI })
) keeps future changes to the common fields in one place and trims noise in the assertions.
566-621
: Prefer table-driven tests for CI detection scenariosThe two CI detection tests above already loop through value/provider matrices. You can collapse this final integration check into a parameterized test that reuses that data, further reducing duplication while keeping coverage intact.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
(11 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Unit tests should use Jest or Vitest as the test runner.
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/__tests__/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/__tests__/**/*.{ts,tsx}
: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
🧬 Code graph analysis (1)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts (1)
packages/nextjs/src/server/keyless-custom-headers.ts (2)
collectKeylessMetadata
(22-38)formatMetadataHeaders
(100-148)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
d9be68e
to
99e142b
Compare
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts (1)
579-638
: Minor: isolate CI state explicitly for clarityThis test will pass regardless due to CI=1, but adding clearAllCIEnvironmentVariables() at the start improves isolation and intent.
Apply this small tweak:
it('should format metadata with CI environment detected correctly', async () => { - // Reset mock to ensure clean state from previous test + // Reset mock to ensure clean state from previous test mockHeaders.mockReset(); + clearAllCIEnvironmentVariables(); // Setup environment with CI detection
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
(14 hunks)packages/nextjs/src/server/keyless-custom-headers.ts
(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/nextjs/src/server/keyless-custom-headers.ts
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Unit tests should use Jest or Vitest as the test runner.
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/__tests__/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/__tests__/**/*.{ts,tsx}
: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
🧬 Code graph analysis (1)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts (1)
packages/nextjs/src/server/keyless-custom-headers.ts (3)
CI_ENV_VARS
(41-67)collectKeylessMetadata
(22-38)formatMetadataHeaders
(102-150)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (11)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts (11)
5-5
: Importing CI_ENV_VARS keeps tests in sync with implementationGood call importing the allowlist from the source to avoid drift.
67-73
: Centralized CI env clearing helperSolid helper; this reduces flakiness across tests and reflects the actual allowlist.
144-161
: Verifies Clerk-Is-CI emissionAsserting exact casing and value for the CI header looks good.
163-191
: Asserts absence of Clerk-Is-CI when isCI=falseCorrect expectation; header is not set.
193-224
: Undefined optional fields and isCI=false behaviorCovers the “undefined” path and ensures the CI header is omitted.
226-255
: Empty string behavior is correctEmpty strings are treated as absent; CI header omitted as expected.
291-294
: Pre-test CI cleanupGood use of clearAllCIEnvironmentVariables() to ensure a clean slate.
342-356
: Explicitly expecting isCI=false in full metadata pathExpectation matches the cleared CI state.
478-486
: No-indicator path coveredGood: uses the centralized helper to guarantee no CI signals are present.
487-516
: Header emission togglingClear, focused test ensures Clerk-Is-CI is only present when intended.
520-577
: End-to-end formatting without CIGreat integration-style coverage; includes CI cleanup to prevent leakage.
4120c21
to
da348e4
Compare
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.
Actionable comments posted: 1
🧹 Nitpick comments (3)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts (1)
464-484
: Broaden falsy-value coverage in CI detection testsAdd 'no', 'off', and case/whitespace permutations to validate normalization.
Apply this diff to expand the falsy set:
- const falsyValues = ['0', 'false', '']; + const falsyValues = ['0', 'false', '', 'no', 'off', 'False', 'OFF', ' No ', ' Off '];packages/nextjs/src/server/keyless-custom-headers.ts (2)
40-67
: Make CI_ENV_VARS readonly and expand provider coverage
- Mark the list as readonly with
as const
.- Consider adding other common indicators (Render, Cloudflare Pages, AWS CodeBuild, Screwdriver, generic CI_* markers) to improve detection.
Apply this diff to the list and make it readonly:
-export const CI_ENV_VARS = [ +export const CI_ENV_VARS = [ 'CI', 'CONTINUOUS_INTEGRATION', 'BUILD_NUMBER', 'BUILD_ID', 'BUILDKITE', 'CIRCLECI', 'GITHUB_ACTIONS', 'GITLAB_CI', 'JENKINS_URL', 'TRAVIS', 'APPVEYOR', 'WERCKER', 'DRONE', 'CODESHIP', 'SEMAPHORE', 'SHIPPABLE', 'TEAMCITY_VERSION', 'BAMBOO_BUILDKEY', 'GO_PIPELINE_NAME', 'TF_BUILD', 'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI', 'BITBUCKET_BUILD_NUMBER', 'HEROKU_TEST_RUN_ID', 'VERCEL', 'NETLIFY', -]; + // Additional common indicators + 'RENDER', + 'CF_PAGES', + 'SCREWDRIVER', + 'CODEBUILD_BUILD_ARN', + 'CODEBUILD_BUILD_ID', + 'CI_NAME', + 'CI_SERVER', + 'CI_VENDOR', +] as const;Also export the narrow string union type for ergonomic use downstream:
export type CIEnvVar = (typeof CI_ENV_VARS)[number];
69-86
: Hoist falsy set and include additional false-like values ('off', 'disabled')Avoid re-allocating Set on every call and handle more negations.
Apply this diff:
-function detectCIEnvironment(): boolean { - const ciIndicators = CI_ENV_VARS; - - const falsyValues = new Set<string>(['', 'false', '0', 'no']); - - return ciIndicators.some(indicator => { - const value = process.env[indicator]; - if (value === undefined) { - return false; - } - - const normalizedValue = value.trim().toLowerCase(); - return !falsyValues.has(normalizedValue); - }); -} +const FALSY_CI_VALUES = new Set<string>(['', 'false', '0', 'no', 'off', 'disabled']); + +function detectCIEnvironment(): boolean { + return CI_ENV_VARS.some(indicator => { + const value = process.env[indicator]; + if (value == null) { + return false; + } + const normalized = value.trim().toLowerCase(); + return !FALSY_CI_VALUES.has(normalized); + }); +}
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
(14 hunks)packages/nextjs/src/server/keyless-custom-headers.ts
(3 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Unit tests should use Jest or Vitest as the test runner.
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/__tests__/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/__tests__/**/*.{ts,tsx}
: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
🧬 Code graph analysis (1)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts (1)
packages/nextjs/src/server/keyless-custom-headers.ts (3)
CI_ENV_VARS
(41-67)collectKeylessMetadata
(22-38)formatMetadataHeaders
(102-150)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (10)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts (9)
5-5
: Good call: import CI_ENV_VARS to avoid drift with implementationKeeps tests aligned with the production allowlist.
67-73
: Helper to clear CI envs looks goodIterating CI_ENV_VARS and stubbing to undefined prevents runner leakage when combined with vi.unstubAllEnvs() in tests.
144-161
: Header behavior assertions are correctClerk-Is-CI is only set when isCI is true; omitted otherwise. This matches formatMetadataHeaders.
Also applies to: 171-191, 205-224, 238-255
292-294
: Nice: clear CI envs before the “all fields present” metadata testPrevents flakiness from the runner and keeps isCI deterministic.
442-462
: Fix for previously noted flakiness looks solidPer‑iteration env clearing and fresh header mocks address the stale state concerns raised earlier.
486-493
: LGTM: baseline non-CI scenarioUsing clearAllCIEnvironmentVariables() ensures no indicators slip through.
495-524
: LGTM: header emitted only when isCI is trueAsserts both presence and absence cases clearly.
528-585
: End-to-end without CI: good coveragePipeline validates collection and formatting, and confirms Clerk-Is-CI is omitted.
587-646
: Good isolation between sequential integration testsResetting mockHeaders avoids leaked state from the previous test.
packages/nextjs/src/server/keyless-custom-headers.ts (1)
145-147
: Header emission only when true is correctOnly sets Clerk-Is-CI when metadata.isCI is true, as discussed in review.
da348e4
to
43b46d7
Compare
43b46d7
to
6e87cb9
Compare
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/nextjs/src/server/keyless-custom-headers.ts (3)
5-17
: Document the new public API surface (MetadataHeaders and isCI).Add JSDoc for the exported interface and the new field to meet the project's “All public APIs must be documented” guideline.
-export interface MetadataHeaders { +/** + * Keyless metadata forwarded as HTTP headers to Clerk. + * @public + */ +export interface MetadataHeaders { @@ - isCI: boolean; + /** + * True when running in a CI/build/test environment. Controls the `Clerk-Is-CI` header emission. + */ + isCI: boolean;
40-67
: Make CI_ENV_VARS readonly and document it.Prevent unintended mutation and improve type safety by using a const assertion, and add brief docs since this is exported.
-// Common CI environment variables -export const CI_ENV_VARS = [ +// Common CI environment variables used to detect CI environments. +// Exported for transparency and testing. +export const CI_ENV_VARS = [ @@ - 'NETLIFY', -]; + 'NETLIFY', +] as const;
69-86
: Optional: rely on ci-info to avoid maintaining provider lists.Consider using the well‑maintained ci-info package (isCI flag) to reduce maintenance and edge cases; keep your list as a fallback if adding a dep is undesirable.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/nextjs/src/server/keyless-custom-headers.ts
(4 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
🧬 Code graph analysis (1)
packages/nextjs/src/server/keyless-custom-headers.ts (1)
scripts/notify.mjs (1)
process
(6-6)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (26)
- GitHub Check: Integration Tests (custom, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (quickstart, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (tanstack-react-router, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Unit Tests (22, **)
- GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
- GitHub Check: Static analysis
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (3)
packages/nextjs/src/server/keyless-custom-headers.ts (3)
36-37
: LGTM: isCI is correctly included in collected metadata.
69-86
: Treat 'off' as falsy too (minor correctness).Some CI toggles use 'off'; currently it’s treated as truthy. Include it in the falsy set.
- const falsyValues = new Set<string>(['', 'false', '0', 'no']); + const falsyValues = new Set<string>(['', 'false', '0', 'no', 'off']);
145-147
: Approved: Clerk-Is-CI header is correctly forwarded to the accountless applications API.
6e87cb9
to
1adb4fd
Compare
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.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/nextjs/src/server/keyless-custom-headers.ts
(3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (28)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (custom, chrome)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (tanstack-react-router, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (quickstart, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Unit Tests (22, **)
- GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
- GitHub Check: Static analysis
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
1adb4fd
to
ea7298a
Compare
ea7298a
to
3830563
Compare
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/nextjs/src/server/keyless-custom-headers.ts (1)
40-67
: MakeCI_ENV_VARS
readonly and document itPrevent accidental mutation and aid type inference with
as const
; add a short JSDoc since this is exported.As per coding guidelines
-// Common CI environment variables -export const CI_ENV_VARS = [ +// Common CI environment variables +export const CI_ENV_VARS = [ 'CI', 'CONTINUOUS_INTEGRATION', 'BUILD_NUMBER', 'BUILD_ID', 'BUILDKITE', 'CIRCLECI', 'GITHUB_ACTIONS', 'GITLAB_CI', 'JENKINS_URL', 'TRAVIS', 'APPVEYOR', 'WERCKER', 'DRONE', 'CODESHIP', 'SEMAPHORE', 'SHIPPABLE', 'TEAMCITY_VERSION', 'BAMBOO_BUILDKEY', 'GO_PIPELINE_NAME', 'TF_BUILD', 'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI', 'BITBUCKET_BUILD_NUMBER', 'HEROKU_TEST_RUN_ID', 'VERCEL', 'NETLIFY', -]; + ] as const;
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
(7 hunks)packages/nextjs/src/server/keyless-custom-headers.ts
(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/nextjs/src/tests/keyless-custom-headers.test.ts
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/nextjs/src/server/keyless-custom-headers.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (27)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (custom, chrome)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (tanstack-react-router, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (quickstart, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Unit Tests (22, **)
- GitHub Check: Static analysis
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (4)
packages/nextjs/src/server/keyless-custom-headers.ts (4)
5-17
: ExportMetadataHeaders
(public API) and add JSDocThis type is part of the exported surface via
collectKeylessMetadata()
. Export it so downstreams can reference it; also add brief JSDoc.As per coding guidelines
-interface MetadataHeaders { +/** + * Public type describing metadata forwarded to Clerk for diagnostics/debugging. + */ +export interface MetadataHeaders { nodeVersion?: string; nextVersion?: string; npmConfigUserAgent?: string; userAgent: string; port?: string; host: string; xHost: string; xPort: string; xProtocol: string; xClerkAuthStatus: string; isCI: boolean; }#!/bin/bash # Verify if consumers expect to import MetadataHeaders (will fail if not exported). rg -nP -C2 '\bMetadataHeaders\b'
36-37
: LGTM:isCI
is correctly plumbed into metadata
145-147
: LGTM: Header added only when the signal is trueMatches the behavior agreed in the review thread and aligns with other Clerk headers.
Please confirm tests assert that the header is omitted when
isCI
is false and present when true.
72-86
: Treat 'off' as falsy to avoid misreporting CIValues like
CI=OFF
orVERCEL=off
are currently treated as true. Include'off'
in the falsy set.- const falsyValues = new Set<string>(['', 'false', '0', 'no']); + const falsyValues = new Set<string>(['', 'false', '0', 'no', 'off']);Optional: hoist the set to module scope to avoid re-allocations.
// outside the function const CI_FALSY_VALUES = new Set(['', 'false', '0', 'no', 'off']); // inside detectCIEnvironment() const normalizedValue = value.trim().toLowerCase(); return !CI_FALSY_VALUES.has(normalizedValue);#!/bin/bash # Ensure test coverage for the OFF case exists or add one. rg -nP -C2 "Clerk-Is-CI|isCI|detectCIEnvironment|CI_ENV_VARS|CI=OFF|VERCEL=off|NETLIFY=off" --type=ts --type=tsx --type=js --type=jsx
3830563
to
321c9b7
Compare
Co-authored-by: Tom Milewski <me@tm.codes>
321c9b7
to
7b1060b
Compare
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts (1)
1-39
: Import the CI allowlist from the sourceWe now define the CI variable allowlist twice (here and in
keyless-custom-headers.ts
). That duplication will drift the moment we tweak the source list, reintroducing the flakes we just cleaned up. Export the array from the implementation module and import it here so the tests always exercise the real allowlist.-import { collectKeylessMetadata, formatMetadataHeaders } from '../server/keyless-custom-headers'; - -const CI_ENV_VARS = [ - 'CI', - 'CONTINUOUS_INTEGRATION', - 'BUILD_NUMBER', - 'BUILD_ID', - 'BUILDKITE', - 'CIRCLECI', - 'GITHUB_ACTIONS', - 'GITLAB_CI', - 'JENKINS_URL', - 'TRAVIS', - 'APPVEYOR', - 'WERCKER', - 'DRONE', - 'CODESHIP', - 'SEMAPHORE', - 'SHIPPABLE', - 'TEAMCITY_VERSION', - 'BAMBOO_BUILDKEY', - 'GO_PIPELINE_NAME', - 'TF_BUILD', - 'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI', - 'BITBUCKET_BUILD_NUMBER', - 'HEROKU_TEST_RUN_ID', - 'VERCEL', - 'NETLIFY', -]; +import { CI_ENV_VARS, collectKeylessMetadata, formatMetadataHeaders } from '../server/keyless-custom-headers';
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
.changeset/wild-shoes-divide.md
(1 hunks)packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
(7 hunks)packages/nextjs/src/server/keyless-custom-headers.ts
(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- .changeset/wild-shoes-divide.md
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/nextjs/src/server/keyless-custom-headers.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/nextjs/src/server/keyless-custom-headers.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/nextjs/src/server/keyless-custom-headers.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/nextjs/src/server/keyless-custom-headers.ts
packages/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Unit tests should use Jest or Vitest as the test runner.
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
packages/nextjs/src/server/keyless-custom-headers.ts
**/__tests__/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/__tests__/**/*.{ts,tsx}
: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces
Files:
packages/nextjs/src/__tests__/keyless-custom-headers.test.ts
🧬 Code graph analysis (1)
packages/nextjs/src/server/keyless-custom-headers.ts (1)
scripts/notify.mjs (1)
process
(6-6)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (tanstack-react-router, chrome)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (custom, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (quickstart, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Unit Tests (22, **)
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
- GitHub Check: Static analysis
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/nextjs/src/server/keyless-custom-headers.ts (1)
75-85
: Treat'off'
values as CI falseWe regress on the earlier fix:
CI=OFF
(or any* = off
) now reports as CI because'off'
isn’t in the falsy set. That will emit theClerk-Is-CI
header in environments explicitly opting out, undermining the signal we’re adding. Please bring'off'
back into the falsy allowlist (and update the tests accordingly).- const falsyValues = new Set<string>(['', 'false', '0', 'no']); + const falsyValues = new Set<string>(['', 'false', '0', 'no', 'off']);
Description
To help us debug why keyless applications are failing to make certain API requests, this PR forwards a new header,
clerk-is-ci
) with requests toaccountless_applications
.Adds a new function,
detectCIEnvironment()
, that checks for 25+ common CI environment variables (GitHub Actions, GitLab CI, CircleCI, Jenkins, Vercel, Netlify, etc.)Linear task
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit
New Features
Behavior Changes
Tests
Chores