Skip to content

feat: make seed-performance-testing script configurable from CLI#29006

Open
SinghaAnirban005 wants to merge 2 commits intocalcom:mainfrom
SinghaAnirban005:feat/cli
Open

feat: make seed-performance-testing script configurable from CLI#29006
SinghaAnirban005 wants to merge 2 commits intocalcom:mainfrom
SinghaAnirban005:feat/cli

Conversation

@SinghaAnirban005
Copy link
Copy Markdown
Contributor

@SinghaAnirban005 SinghaAnirban005 commented Apr 26, 2026

What does this PR do?

Resolves the TODO: Make it more structured and configurable from CLI in seed-performance-testing.ts.

Video Demo (if applicable):

Screencast.from.2026-04-26.19-30-14.webm

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs if this PR makes changes that would require a documentation change. N/A
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

Note for reviewers: The steps below require a locally reachable Postgres instance. The project's docker-compose.yml runs the database inside Docker , to connect from the host you will need to temporarily expose port 5432. This is a local only change and is not part of this PR.

In your local docker-compose.yml, add the following under the database service, run docker compose up -d database, then follow the steps below. Remove the port mapping when done.

database:
  ports:
    - "5432:5432"
  1. In .env
   DATABASE_URL=postgresql://unicorn_user:magical_password@localhost:5432/calendso
   DATABASE_DIRECT_URL=postgresql://unicorn_user:magical_password@localhost:5432/calendso
  1. Run docker-compose up -d database

  2. cd into /scripts

  3. Three modes are available

  • --bookings <n> — number of bookings per event type (default: 100)
  • --start-from <n> — start user index for many-users mode (default: 0), enables resuming an interrupted run
  • --till-user <n> — end user index for many-users mode (default: 20)
  • --mode many-bookings | many-users — replaces the previously commented-out createManyDifferentUsers call

Examples

  • npx ts-node --transpile-only ./scripts/seed-performance-testing.ts
  • npx ts-node --transpile-only ./scripts/seed-performance-testing.ts --bookings 50
  • npx ts-node --transpile-only ./scripts/seed-performance-testing.ts --mode many-users --till-user 100
  • npx ts-node --transpile-only ./scripts/seed-performance-testing.ts --mode many-users --start-from 500 --till-user 1000

@github-actions
Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @SinghaAnirban005! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 26, 2026

📝 Walkthrough

Walkthrough

The scripts/seed-performance-testing.ts file has been refactored to support multiple performance testing modes. Environment variables are now loaded at initialization. CLI arguments have been added to configure the seeding behavior, including mode selection (many-bookings or many-users), booking count, and user range parameters with validation. The booking generation logic has been optimized by replacing explicit object lists with generated arrays. The execution flow has been restructured to dispatch between different seeding strategies based on the selected mode rather than always running a single path.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: making the seed-performance-testing script configurable from CLI, which directly addresses the TODO resolved in the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description clearly explains what the PR does (resolves a TODO to make the script configurable from CLI), provides testing instructions, documents new CLI options, and includes examples of usage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/seed-performance-testing.ts`:
- Around line 212-223: main() is invoked without error handling or a clean
shutdown, so rejections become unhandled and the Prisma DB connection opened by
functions like createUserAndEventType (via seed-utils) can keep the process
hanging; wrap the main logic in a try/catch/finally (or add a top-level promise
chain) that catches errors from parseArgs(),
createManyDifferentUsersWithDifferentEventTypesAndBookings, and
createAUserWithManyBookings, logs the error and exits with a non-zero code on
failure, and in the finally block call the Prisma disconnect function provided
by your seed utilities (e.g., await prisma.$disconnect() or the seed-utils
disconnection helper) to ensure connections are closed and in-flight writes are
flushed before exiting.
- Around line 29-36: The parsed CLI integers bookingsPerEventType, startFrom and
tillUser (from get()) must be validated because parseInt can produce NaN; update
the block that defines bookingsPerEventType, startFrom and tillUser to check
each parsed value (e.g., Number.isInteger(...) && value >= 0 or
!Number.isNaN(...)) and if any is invalid, print a clear console.error including
the flag name and invalid value and call process.exit(1); keep the existing mode
validation but add this numeric-arg guard around the variables referenced later
(bookingsPerEventType, startFrom, tillUser) so loops and _numBookings never
receive NaN.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a8af9b9e-15bf-4bfa-b378-721dbd7f7614

📥 Commits

Reviewing files that changed from the base of the PR and between a69c176 and 441f72d.

📒 Files selected for processing (1)
  • scripts/seed-performance-testing.ts

Comment thread scripts/seed-performance-testing.ts Outdated
Comment thread scripts/seed-performance-testing.ts
Copy link
Copy Markdown
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.

🧹 Nitpick comments (2)
scripts/seed-performance-testing.ts (2)

19-32: Optional: derive Mode from a single source of truth to keep the type and runtime check in sync.

The as Mode cast on line 28 is immediately validated by the literal comparison on line 29, so it's safe today. However, the union type on line 19 and the runtime check on line 29 can drift independently if a new mode is added. Minor refactor:

♻️ Proposed refactor
-type Mode = "many-bookings" | "many-users";
+const MODES = ["many-bookings", "many-users"] as const;
+type Mode = (typeof MODES)[number];
@@
-  const mode = (get("--mode") ?? "many-bookings") as Mode;
-  if (mode !== "many-bookings" && mode !== "many-users") {
-    console.error(`Invalid --mode "${mode}". Must be many-bookings or many-users.`);
+  const modeRaw = get("--mode") ?? "many-bookings";
+  if (!MODES.includes(modeRaw as Mode)) {
+    console.error(`Invalid --mode "${modeRaw}". Must be one of: ${MODES.join(", ")}.`);
     process.exit(1);
   }
+  const mode = modeRaw as Mode;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/seed-performance-testing.ts` around lines 19 - 32, Replace the
separate manual union type and runtime check with a single source-of-truth
constant array and derive Mode from it: create a const (e.g., MODES) with the
allowed mode strings (as const), change the type alias Mode to type Mode =
typeof MODES[number], use MODES[0] as the default instead of the hardcoded
"many-bookings", and validate by checking MODES.includes(mode) inside parseArgs;
update parseArgs to remove the unsafe as Mode cast and rely on the derived type
and includes-based runtime check to keep compile-time and runtime lists in sync.

4-7: Add a comment explaining CommonJS dependency of the dotenv-before-imports pattern.

The dotenv.config() call at the top of the file relies on CommonJS sequential import execution, which is guaranteed here because ts-node is configured with "module": "CommonJS" in packages/tsconfig/base.json. However, if this script is ever migrated to ESM (e.g., by changing the ts-node configuration), the import hoisting would silently break env-dependent imports like seed-utils. A brief inline comment clarifying this dependency would prevent regressions during future refactors.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/seed-performance-testing.ts` around lines 4 - 7, Add a brief inline
comment above the dotenv.config({ path: ... }) call explaining that this
placement relies on CommonJS sequential import execution (ts-node configured
with "module": "CommonJS") so environment variables are available to subsequent
imports (e.g., seed-utils), and warn that migrating to ESM or changing ts-node
module settings will hoist imports and break env-dependent modules unless dotenv
is initialized earlier or an alternative pattern is used.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@scripts/seed-performance-testing.ts`:
- Around line 19-32: Replace the separate manual union type and runtime check
with a single source-of-truth constant array and derive Mode from it: create a
const (e.g., MODES) with the allowed mode strings (as const), change the type
alias Mode to type Mode = typeof MODES[number], use MODES[0] as the default
instead of the hardcoded "many-bookings", and validate by checking
MODES.includes(mode) inside parseArgs; update parseArgs to remove the unsafe as
Mode cast and rely on the derived type and includes-based runtime check to keep
compile-time and runtime lists in sync.
- Around line 4-7: Add a brief inline comment above the dotenv.config({ path:
... }) call explaining that this placement relies on CommonJS sequential import
execution (ts-node configured with "module": "CommonJS") so environment
variables are available to subsequent imports (e.g., seed-utils), and warn that
migrating to ESM or changing ts-node module settings will hoist imports and
break env-dependent modules unless dotenv is initialized earlier or an
alternative pattern is used.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3e831401-cef6-4101-a5bd-8c1511a7dc4b

📥 Commits

Reviewing files that changed from the base of the PR and between 441f72d and cb0a4e6.

📒 Files selected for processing (1)
  • scripts/seed-performance-testing.ts

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

This PR has been marked as stale due to inactivity. If you're still working on it or need any help, please let us know or update the PR to keep it active.

@github-actions github-actions Bot added the Stale label May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant