Skip to content

test: Use compile serverpod_cli to speed up e2e cli tests - #4475

Merged
nielsenko merged 9 commits into
serverpod:mainfrom
nielsenko:test-util-run-serverpod
Dec 19, 2025
Merged

nielsenko merged 9 commits into
serverpod:mainfrom
nielsenko:test-util-run-serverpod

Conversation

@nielsenko

@nielsenko nielsenko commented Dec 18, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Refactors CLI e2e tests to use shared test utilities for running serverpod commands:

  • Add sharedTestDir - a temp directory shared across all test files in a single dart test run (based on PID), with automatic cleanup of stale directories older than 1 day
  • Add runServerpod() and startServerpod() utilities that handle CLI execution with proper SERVERPOD_HOME setup
  • Compile CLI once per test run and share the executable across all test files via sharedTestDir
  • Remove duplicate CLI activation/compilation code from individual test files
  • Simplify test setup by removing boilerplate Process.start/Process.run calls

Benefits:

  • Faster test execution (CLI compiled once, not per test file)
  • Less boilerplate in test files
  • Consistent CLI invocation across all tests
  • Automatic temp directory cleanup

Fixes #4438

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

None.

Summary by CodeRabbit

Release Notes

  • New Features

    • Improved Dart SDK discovery in the analyzer with automatic detection via multiple fallback strategies.
  • Refactor

    • Consolidated test infrastructure with improved test execution helpers and shared utilities.
  • Chores

    • Removed unused dev dependencies from project configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

@nielsenko nielsenko self-assigned this Dec 18, 2025
@nielsenko
nielsenko force-pushed the test-util-run-serverpod branch 3 times, most recently from 6688dba to 13b8951 Compare December 18, 2025 15:55
@nielsenko
nielsenko force-pushed the test-util-run-serverpod branch from 13b8951 to c9f1427 Compare December 19, 2025 12:49
@nielsenko

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 19, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Dec 19, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR centralizes serverpod CLI invocation in e2e tests by introducing helper functions (runServerpod, startServerpod) and a shared test directory utility. Seven test files are refactored to use the new helpers. Dart SDK discovery is added to endpoints_analyzer. Test configuration and dependencies are updated accordingly.

Changes

Cohort / File(s) Summary
Test Infrastructure
tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart
New test helper module providing centralized CLI execution with support for multiple run modes (dartRun, activated, compiled). Implements compilation with single-instance locking, activation, command resolution, and execution primitives (runServerpod, startServerpod). Injects SERVERPOD_HOME for environment isolation.
Shared Test Utilities
tests/serverpod_cli_e2e_test/lib/src/shared_test_dir.dart
New utility for shared test directory management across isolates with per-invocation temp directories and cleanup of stale test directories older than one day. Exports public sharedTestDir getter.
Test Configuration
tests/serverpod_cli_e2e_test/dart_test.yaml, tests/serverpod_cli_e2e_test/pubspec.yaml, templates/pubspecs/tests/serverpod_cli_e2e_test/pubspec.yaml
Adds timeout: 3x to dart_test.yaml with explanatory comments. Removes path and test dev_dependencies from both pubspec.yaml files.
Test Refactoring
tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart, create_migration_from_anywhere_test.dart, generate_from_anywhere_test.dart, generate_interactive_flag_test.dart, generate_watch_test.dart, generate_with_directory_test.dart, run_command_test.dart
Replaces direct Process invocations with runServerpod and startServerpod helpers. Removes manual setup/teardown logic, CLI activation, and process lifecycle management. Consolidates output handling via helper-provided result objects (exitCode, stdout, stderr). Updates path constructions to use sandbox approach. Signature change in generate_watch_test.dart: createRandomProjectName() now returns String instead of (String, String) tuple.
Production Code
tools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.dart
Introduces dynamic Dart SDK discovery via _findDartSdk() helper, wiring sdkPath into AnalysisContextCollection. Searches for SDK via resolved dart executable, DART_SDK env var, FLUTTER_ROOT, and system PATH. Adds _sdkPathFromDartExe and _isValidSdk validators. All new logic is private; no public API changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • run_serverpod.dart: Verify lock mechanism correctness for concurrent compilation, error handling paths (StateError on dependency/compilation failures), and all RunType branch implementations, especially the unimplemented RunType.installed
  • Test refactoring consistency: Spot-check 2-3 refactored test files to confirm patterns are correctly applied (result.exitCode/stdout/stderr usage, working directory setup)
  • endpoints_analyzer.dart: Validate Dart SDK discovery precedence order and _isValidSdk checks across typical host environments
  • shared_test_dir.dart: Verify process ID-based directory isolation and stale directory cleanup logic for edge cases (permission issues, symlinks)

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: using compiled serverpod_cli to speed up e2e tests, which aligns with the primary objective of the PR.
Description check ✅ Passed The description follows the template structure, explains the changes, lists the fixed issue (#4438), and includes a completed pre-launch checklist. All required sections are present.
Linked Issues check ✅ Passed The PR successfully addresses issue #4438 by introducing shared test utilities (runServerpod, startServerpod, sharedTestDir) and refactoring all specified test files to use these centralized helpers instead of manual CLI setup.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #4438 objectives. The addition of SDK discovery logic in endpoints_analyzer.dart and dependency removals from pubspec.yaml files support the main test refactoring goal.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart (1)

47-80: The test doesn't actually set the CI environment variable despite claiming to test CI mode behavior.

The test name "then code generation succeeds in CI environment (CI=true)" and the comment "For this test we need to use startServerpod to set custom environment" indicate intent to test CI mode, but the startServerpod helper function doesn't support passing custom environment variables—it only sets SERVERPOD_HOME. To properly test CI mode behavior, either enhance startServerpod to accept an environment parameter (similar to how runServerpod does), or use a different approach to set the CI=true environment variable before running the test.

🧹 Nitpick comments (5)
tests/serverpod_cli_e2e_test/lib/src/shared_test_dir.dart (1)

28-45: Consider edge cases in cleanup logic.

While the cleanup logic is generally sound, consider these edge cases:

  • listSync() could fail if systemTemp is inaccessible
  • statSync() at line 34 could throw if a directory is deleted between listSync() and statSync() by another process
  • Permission errors during deletion (line 37) are caught, which is good

The current implementation handles the most common case (line 38-40: ignoring deletion errors), but statSync() could propagate exceptions. Consider wrapping the entire loop body in a try-catch for robustness.

🔎 Proposed enhancement
   for (final entity in Directory.systemTemp.listSync()) {
     if (entity is Directory) {
       final name = entity.uri.pathSegments.last;
       if (name.startsWith(prefix)) {
-        final dirPid = int.tryParse(name.substring(prefix.length));
-        if (dirPid != null && dirPid != pid) {
-          final age = now.difference(entity.statSync().modified);
-          if (age.inDays >= 1) {
-            try {
-              entity.deleteSync(recursive: true);
-            } catch (_) {
-              // Ignore - might be in use
+        try {
+          final dirPid = int.tryParse(name.substring(prefix.length));
+          if (dirPid != null && dirPid != pid) {
+            final age = now.difference(entity.statSync().modified);
+            if (age.inDays >= 1) {
+              try {
+                entity.deleteSync(recursive: true);
+              } catch (_) {
+                // Ignore - might be in use or already deleted
+              }
             }
           }
+        } catch (_) {
+          // Directory might have been deleted by another process
         }
       }
     }
   }
tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart (4)

43-45: Busy-waiting is inefficient for lock acquisition.

The current implementation uses a tight polling loop with 100ms delays, which can add unnecessary latency and CPU usage if multiple isolates are waiting. Consider using a file watcher or exponential backoff to improve efficiency.

🔎 Proposed enhancement with exponential backoff
     // Another isolate is compiling, wait for lock to be released
+    var delay = const Duration(milliseconds: 50);
     while (lockFile.existsSync()) {
-      await Future<void>.delayed(const Duration(milliseconds: 100));
+      await Future<void>.delayed(delay);
+      delay = delay * 2;
+      if (delay > const Duration(seconds: 5)) {
+        delay = const Duration(seconds: 5);
+      }
     }

50-64: Add timeouts to Process.run calls to prevent hanging.

The dart pub get and dart compile exe commands lack timeouts. If these processes hang, tests will stall indefinitely. Consider adding explicit timeouts to fail fast.

🔎 Proposed fix
     var result = await Process.run(
       'dart',
       ['pub', 'get', '--directory', _cliRoot],
-    );
+    ).timeout(
+      const Duration(minutes: 2),
+      onTimeout: () => throw TimeoutException('dart pub get timed out'),
+    );
     if (result.exitCode != 0) {
       throw StateError('Failed to resolve dependencies:\n${result.stderr}');
     }

     result = await Process.run(
       'dart',
       ['compile', 'exe', _cliPath, '-o', exePath],
-    );
+    ).timeout(
+      const Duration(minutes: 5),
+      onTimeout: () => throw TimeoutException('dart compile exe timed out'),
+    );
     if (result.exitCode != 0) {
       throw StateError('Failed to compile serverpod_cli:\n${result.stderr}');
     }

Note: Import dart:async for TimeoutException.


74-80: Add timeout to activation command.

The dart pub global activate command lacks a timeout and could hang indefinitely. Consider adding an explicit timeout.

🔎 Proposed fix
   final result = await Process.run(
     'dart',
     ['pub', 'global', 'activate', '--overwrite', '--source', 'path', _cliRoot],
-  );
+  ).timeout(
+    const Duration(minutes: 2),
+    onTimeout: () => throw TimeoutException('dart pub global activate timed out'),
+  );
   if (result.exitCode != 0) {
     throw StateError('Failed to activate serverpod_cli:\n${result.stderr}');
   }

26-70: Lock file may persist if compilation crashes.

If the process crashes between lock creation and the finally block (e.g., out-of-memory, killed), the lock file will persist and block subsequent test runs. Consider adding a timestamp check when encountering an existing lock to detect stale locks.

🔎 Proposed enhancement
   // Try to create lock file exclusively - only one isolate succeeds
   try {
     lockFile.createSync(exclusive: true);
   } on FileSystemException {
     // Another isolate is compiling, wait for lock to be released
+    final lockCreated = lockFile.statSync().modified;
+    final lockAge = DateTime.now().difference(lockCreated);
+    if (lockAge > const Duration(minutes: 10)) {
+      // Stale lock from crashed process, remove it
+      try {
+        lockFile.deleteSync();
+        // Retry creating lock
+        lockFile.createSync(exclusive: true);
+      } catch (_) {
+        // Another isolate beat us to it, continue waiting
+      }
+    }
     while (lockFile.existsSync()) {
       await Future<void>.delayed(const Duration(milliseconds: 100));
     }

Note: This adds resilience against stale locks from crashed processes.

📜 Review details

Configuration used: Organization UI

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.

📥 Commits

Reviewing files that changed from the base of the PR and between dd6b58c and c9f1427.

📒 Files selected for processing (13)
  • templates/pubspecs/tests/serverpod_cli_e2e_test/pubspec.yaml (0 hunks)
  • tests/serverpod_cli_e2e_test/dart_test.yaml (1 hunks)
  • tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart (1 hunks)
  • tests/serverpod_cli_e2e_test/lib/src/shared_test_dir.dart (1 hunks)
  • tests/serverpod_cli_e2e_test/pubspec.yaml (0 hunks)
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart (6 hunks)
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart (7 hunks)
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart (7 hunks)
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart (8 hunks)
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart (23 hunks)
  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart (8 hunks)
  • tests/serverpod_cli_e2e_test/test/run_command_test.dart (2 hunks)
  • tools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.dart (2 hunks)
💤 Files with no reviewable changes (2)
  • tests/serverpod_cli_e2e_test/pubspec.yaml
  • templates/pubspecs/tests/serverpod_cli_e2e_test/pubspec.yaml
🧰 Additional context used
📓 Path-based instructions (2)
**/*.dart

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.dart: Follow Dart formatting conventions with dart format command
Run 'dart format .' to format all code before committing
Run 'melos lint_strict' or 'util/run_tests_analyze' to check code quality before committing, ensuring compliance with CI strict mode

Files:

  • tests/serverpod_cli_e2e_test/lib/src/shared_test_dir.dart
  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart
  • tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart
  • tests/serverpod_cli_e2e_test/test/run_command_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
**/*test.dart

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*test.dart: When using group() with test(), ensure each statement ('Given', 'When', 'Then') appears only once in the combined description to avoid duplication
Place passing/success test cases at the top of test files before error test cases for the same functionality
Group related test cases using group() where appropriate

Files:

  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart
  • tests/serverpod_cli_e2e_test/test/run_command_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
🧠 Learnings (16)
📓 Common learnings
Learnt from: tp
Repo: serverpod/serverpod PR: 3917
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/analysis_options.yaml:3-6
Timestamp: 2025-08-25T19:46:58.073Z
Learning: In Serverpod, test tool paths like `test/integration/test_tools/serverpod_test_tools.dart` are configured per project in the "generator.yaml" file and managed by a generator system, so they don't need to be updated manually across all files at once.
Learnt from: tp
Repo: serverpod/serverpod PR: 3651
File: modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts.dart:35-39
Timestamp: 2025-06-16T12:07:26.018Z
Learning: The `withServerpod` test helper runs tests within a transaction, which may require adapting database queries to accept transaction parameters for proper snapshot consistency during testing.
Learnt from: tp
Repo: serverpod/serverpod PR: 3747
File: tests/serverpod_new_auth_test/serverpod_new_auth_test_server/pubspec.yaml:37-38
Timestamp: 2025-07-02T16:09:27.702Z
Learning: In Serverpod migration testing, it's appropriate for test servers like serverpod_new_auth_test_server to include dependencies on both legacy packages (e.g., serverpod_auth_server) and new modular packages to enable comprehensive testing of migration paths from old to new authentication systems.
Learnt from: SandPod
Repo: serverpod/serverpod PR: 4144
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart:0-0
Timestamp: 2025-11-03T15:40:41.827Z
Learning: In Serverpod authentication IDP endpoint files (modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server), endpoint base classes should import `serverpod_auth_idp_server/core.dart` to access the Session type, rather than importing `package:serverpod_auth_core_server/session.dart` directly. This pattern is consistently used in Apple, Email, and Google endpoint files.
Learnt from: tp
Repo: serverpod/serverpod PR: 3747
File: modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/lib/src/business/migrating_email_endpoint_base.dart:4-4
Timestamp: 2025-07-02T16:07:50.947Z
Learning: In Serverpod, tp prefers importing the full package (e.g., 'package:serverpod_auth_migration_server/serverpod_auth_migration_server.dart') as a baseline rather than using smaller local imports, even within the same package where it might be considered a "self-import".
Learnt from: tp
Repo: serverpod/serverpod PR: 3651
File: tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart:1-1
Timestamp: 2025-06-19T11:00:17.085Z
Learning: In Serverpod applications, methods that rely on public asset storage (like setUserImage/removeUserImage) should be tested in E2E tests rather than withServerpod integration tests, as they require a full server environment with asset storage infrastructure to properly test image upload/download functionality.
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-11T03:56:54.151Z
Learning: Verify example projects still work before submitting PR by running example servers with 'dart bin/main.dart --apply-migrations'
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-11T03:56:54.151Z
Learning: Activate serverpod_cli from source using 'dart pub global activate --source path tools/serverpod_cli' after installation for development
Learnt from: SandPod
Repo: serverpod/serverpod PR: 4131
File: tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart:67-70
Timestamp: 2025-11-02T17:36:02.137Z
Learning: In Serverpod test files, use `assert` for setup preconditions in `setUp()` or `setUpAll()` blocks (e.g., verifying project creation succeeded) to distinguish setup failures from test assertion failures. Reserve `expect` for actual test assertions within test cases.
Learnt from: SandPod
Repo: serverpod/serverpod PR: 3904
File: modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/test/jwt/integration/authentication_tokens_test.dart:141-143
Timestamp: 2025-08-20T13:29:38.181Z
Learning: In Serverpod test files, SandPod prefers to avoid redundant null-checks in tests when the preconditions guarantee non-null values. They consider such defensive assertions as "redundant bloat" when the test environment is controlled and the implementation guarantees the presence of values like refreshToken.
📚 Learning: 2025-08-25T19:46:58.073Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3917
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/analysis_options.yaml:3-6
Timestamp: 2025-08-25T19:46:58.073Z
Learning: In Serverpod, test tool paths like `test/integration/test_tools/serverpod_test_tools.dart` are configured per project in the "generator.yaml" file and managed by a generator system, so they don't need to be updated manually across all files at once.

Applied to files:

  • tests/serverpod_cli_e2e_test/dart_test.yaml
  • tests/serverpod_cli_e2e_test/lib/src/shared_test_dir.dart
  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart
  • tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart
  • tests/serverpod_cli_e2e_test/test/run_command_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
📚 Learning: 2025-09-17T16:23:58.795Z
Learnt from: nielsenko
Repo: serverpod/serverpod PR: 3980
File: tests/serverpod_test_server/test_integration/static_files_test.dart:1-2
Timestamp: 2025-09-17T16:23:58.795Z
Learning: In Dart, annotations like `Timeout.none` can be applied to library declarations. The syntax `Timeout.none library;` is valid, where `library;` creates an unnamed library and `Timeout.none` applies the timeout annotation to the entire library. This is commonly used in test files to prevent timeouts during debugging.

Applied to files:

  • tests/serverpod_cli_e2e_test/dart_test.yaml
📚 Learning: 2025-06-16T12:07:26.018Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3651
File: modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts.dart:35-39
Timestamp: 2025-06-16T12:07:26.018Z
Learning: The `withServerpod` test helper runs tests within a transaction, which may require adapting database queries to accept transaction parameters for proper snapshot consistency during testing.

Applied to files:

  • tests/serverpod_cli_e2e_test/dart_test.yaml
  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart
  • tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart
  • tests/serverpod_cli_e2e_test/test/run_command_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
📚 Learning: 2025-07-02T16:09:27.702Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3747
File: tests/serverpod_new_auth_test/serverpod_new_auth_test_server/pubspec.yaml:37-38
Timestamp: 2025-07-02T16:09:27.702Z
Learning: In Serverpod migration testing, it's appropriate for test servers like serverpod_new_auth_test_server to include dependencies on both legacy packages (e.g., serverpod_auth_server) and new modular packages to enable comprehensive testing of migration paths from old to new authentication systems.

Applied to files:

  • tests/serverpod_cli_e2e_test/dart_test.yaml
  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart
  • tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart
  • tests/serverpod_cli_e2e_test/test/run_command_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
📚 Learning: 2025-12-11T03:56:54.151Z
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-11T03:56:54.151Z
Learning: Applies to **/*test.dart : Group related test cases using group() where appropriate

Applied to files:

  • tests/serverpod_cli_e2e_test/lib/src/shared_test_dir.dart
  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart
  • tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
📚 Learning: 2025-07-02T16:07:50.947Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3747
File: modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/lib/src/business/migrating_email_endpoint_base.dart:4-4
Timestamp: 2025-07-02T16:07:50.947Z
Learning: In Serverpod, tp prefers importing the full package (e.g., 'package:serverpod_auth_migration_server/serverpod_auth_migration_server.dart') as a baseline rather than using smaller local imports, even within the same package where it might be considered a "self-import".

Applied to files:

  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart
  • tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart
  • tests/serverpod_cli_e2e_test/test/run_command_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
📚 Learning: 2025-12-11T03:56:54.151Z
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-11T03:56:54.151Z
Learning: Activate serverpod_cli from source using 'dart pub global activate --source path tools/serverpod_cli' after installation for development

Applied to files:

  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart
  • tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart
  • tests/serverpod_cli_e2e_test/test/run_command_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
📚 Learning: 2025-12-11T03:56:54.151Z
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-11T03:56:54.151Z
Learning: Verify example projects still work before submitting PR by running example servers with 'dart bin/main.dart --apply-migrations'

Applied to files:

  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart
  • tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart
  • tests/serverpod_cli_e2e_test/test/run_command_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
📚 Learning: 2025-11-03T15:40:41.827Z
Learnt from: SandPod
Repo: serverpod/serverpod PR: 4144
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart:0-0
Timestamp: 2025-11-03T15:40:41.827Z
Learning: In Serverpod authentication IDP endpoint files (modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server), endpoint base classes should import `serverpod_auth_idp_server/core.dart` to access the Session type, rather than importing `package:serverpod_auth_core_server/session.dart` directly. This pattern is consistently used in Apple, Email, and Google endpoint files.

Applied to files:

  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart
  • tests/serverpod_cli_e2e_test/test/run_command_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
📚 Learning: 2025-06-19T11:00:17.085Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3651
File: tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart:1-1
Timestamp: 2025-06-19T11:00:17.085Z
Learning: In Serverpod applications, methods that rely on public asset storage (like setUserImage/removeUserImage) should be tested in E2E tests rather than withServerpod integration tests, as they require a full server environment with asset storage infrastructure to properly test image upload/download functionality.

Applied to files:

  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
📚 Learning: 2025-06-27T08:39:36.440Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3721
File: util/pub_get_all:0-0
Timestamp: 2025-06-27T08:39:36.440Z
Learning: In the Serverpod project, `dart pub get` commands work fine on Flutter packages both locally and in CI environments, even when the package has `flutter: sdk: flutter` dependencies in pubspec.yaml. The technical constraint of Flutter SDK dependencies causing `dart pub` failures may not apply in all environments or recent Dart versions.

Applied to files:

  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart
  • tests/serverpod_cli_e2e_test/lib/src/run_serverpod.dart
  • tests/serverpod_cli_e2e_test/test/run_command_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
📚 Learning: 2025-11-04T12:09:52.649Z
Learnt from: marcelomendoncasoares
Repo: serverpod/serverpod PR: 4150
File: examples/auth/auth_flutter/lib/widgets/profile_info.dart:23-30
Timestamp: 2025-11-04T12:09:52.649Z
Learning: In Serverpod example and testing projects (e.g., examples/auth/auth_flutter), prefer letting errors bubble up naturally rather than handling them gracefully with catchError or try-catch blocks. This helps developers see what went wrong during development and testing.

Applied to files:

  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart
  • tests/serverpod_cli_e2e_test/test/run_command_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
📚 Learning: 2025-12-11T03:56:54.151Z
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-11T03:56:54.151Z
Learning: Applies to **/*test.dart : When using group() with test(), ensure each statement ('Given', 'When', 'Then') appears only once in the combined description to avoid duplication

Applied to files:

  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
📚 Learning: 2025-11-02T17:36:02.137Z
Learnt from: SandPod
Repo: serverpod/serverpod PR: 4131
File: tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart:67-70
Timestamp: 2025-11-02T17:36:02.137Z
Learning: In Serverpod test files, use `assert` for setup preconditions in `setUp()` or `setUpAll()` blocks (e.g., verifying project creation succeeded) to distinguish setup failures from test assertion failures. Reserve `expect` for actual test assertions within test cases.

Applied to files:

  • tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_watch_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
  • tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart
  • tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart
📚 Learning: 2025-08-20T13:29:38.181Z
Learnt from: SandPod
Repo: serverpod/serverpod PR: 3904
File: modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/test/jwt/integration/authentication_tokens_test.dart:141-143
Timestamp: 2025-08-20T13:29:38.181Z
Learning: In Serverpod test files, SandPod prefers to avoid redundant null-checks in tests when the preconditions guarantee non-null values. They consider such defensive assertions as "redundant bloat" when the test environment is controlled and the implementation guarantees the presence of values like refreshToken.

Applied to files:

  • tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart
⏰ 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). (31)
  • GitHub Check: Module integration tests in modules/serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server with Flutter 3.38.4
  • GitHub Check: Module integration tests in modules/serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server with Flutter 3.32.0
  • GitHub Check: Serverpod integration tests (server) (3.38.4)
  • GitHub Check: Bootstrap tests (3.38.4, ubuntu-latest, tests/bootstrap_project)
  • GitHub Check: CLI e2e tests (3.32.0, ubuntu-latest, tests/serverpod_cli_e2e_test)
  • GitHub Check: Bootstrap tests (3.38.4, windows-latest, tests/bootstrap_project)
  • GitHub Check: Bootstrap tests (3.32.0, ubuntu-latest, tests/bootstrap_project)
  • GitHub Check: Serverpod concurrent integration tests (server) (3.38.4)
  • GitHub Check: Migration e2e tests (3.38.4)
  • GitHub Check: Migration e2e tests (3.32.0)
  • GitHub Check: Bootstrap tests (3.32.0, windows-latest, tests/bootstrap_project)
  • GitHub Check: dart analyze (3.32.0, windows-latest)
  • GitHub Check: CLI e2e tests (3.38.4, ubuntu-latest, tests/serverpod_cli_e2e_test)
  • GitHub Check: Serverpod concurrent integration tests (server) (3.32.0)
  • GitHub Check: Serverpod integration tests (server) (3.32.0)
  • GitHub Check: dart analyze (3.32.0, ubuntu-latest)
  • GitHub Check: dart analyze downgrade (3.32.0, ubuntu-latest)
  • GitHub Check: dart analyze latest (3.38.4, windows-latest)
  • GitHub Check: dart analyze downgrade (3.32.0, windows-latest)
  • GitHub Check: dart analyze downgrade (3.38.4, windows-latest)
  • GitHub Check: Unit tests IO (3.32.0, windows-latest)
  • GitHub Check: Unit tests IO (3.38.4, ubuntu-latest)
  • GitHub Check: Unit tests IO (3.38.4, windows-latest)
  • GitHub Check: Unit tests IO (3.32.0, ubuntu-latest)
  • GitHub Check: dart analyze downgrade (3.38.4, ubuntu-latest)
  • GitHub Check: serverpod generate (3.32.0)
  • GitHub Check: Serverpod E2E IO tests (3.38.4)
  • GitHub Check: Serverpod E2E web tests (3.38.4)
  • GitHub Check: serverpod generate (3.38.4)
  • GitHub Check: Serverpod E2E IO tests (3.32.0)
  • GitHub Check: Serverpod E2E web tests (3.32.0)
🔇 Additional comments (20)
tools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.dart (3)

369-381: LGTM!

The SDK path derivation logic correctly handles both Flutter and standalone Dart installations, and properly validates each candidate path.


383-383: LGTM!

The SDK validation using the presence of a version file is a standard and reliable approach.


32-32: The SDK path approach correctly addresses dart-lang/sdk#48002.

The issue occurs when Platform.resolvedExecutable returns incorrect paths in certain environments, causing SDK detection to fail. The analyzer package added sdkPath to AnalysisContextCollection as the recommended solution, with implementations updated to use the current SDK when sdkPath is not provided. Your implementation at line 32 properly leverages this parameter, and the _findDartSdk() function implements a robust multi-fallback discovery strategy that handles Platform.resolvedExecutable, environment variables, Flutter installations, and PATH lookup—appropriately addressing the edge cases that cause the original issue.

tests/serverpod_cli_e2e_test/dart_test.yaml (1)

1-3: LGTM! Timeout configuration is appropriate.

The 3x timeout multiplier is reasonable given that the first test will compile the CLI. The comments clearly explain the rationale for the increased timeout.

tests/serverpod_cli_e2e_test/test/run_command_test.dart (1)

8-150: LGTM! Test refactoring is clean and consistent.

The migration to runServerpod and startServerpod helpers simplifies the test code while maintaining all original functionality. The SIGINT forwarding test correctly uses startServerpod for interactive process control.

tests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.dart (1)

2-164: LGTM! Test refactoring follows best practices.

The migration to runServerpod is clean and consistent. Good use of assert in setUp() to verify project creation (per Serverpod test conventions), and proper output validation using combined stdout/stderr.

tests/serverpod_cli_e2e_test/test/create_migration_exit_code_test.dart (1)

5-159: LGTM! Exit code testing is comprehensive.

The test refactoring is clean and maintains thorough coverage of exit code scenarios. Good use of assert for setup preconditions and clear separation between setup and test assertions.

tests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.dart (1)

4-153: LGTM! Test refactoring is clean and consistent.

The migration to runServerpod and test_descriptor sandbox is well-executed. All path references are consistent, and file verification checks are properly maintained.

tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart (1)

5-162: LGTM! Comprehensive testing of directory options.

The test refactoring maintains excellent coverage of the -d option with absolute paths, relative paths, and error cases. Sandbox usage is consistent throughout.

tests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.dart (6)

7-9: LGTM! Imports correctly support the new test harness.

The imports for run_serverpod.dart and test_descriptor enable the centralized CLI execution and sandbox directory management as intended by this refactoring.


20-29: LGTM! Setup correctly refactored with proper assertions.

The use of assert in setUp() to verify project creation is correct per project conventions, and the migration to runServerpod with d.sandbox aligns with the PR objectives.


31-45: LGTM! Test correctly migrated to new harness.

The test properly uses runServerpod with d.sandbox, checks result.exitCode, and validates output from result.stdout and result.stderr.


82-101: LGTM! Interactive flag test correctly implemented.

The test properly validates that --interactive flag overrides CI environment detection, using the new runServerpod helper consistently.


110-142: LGTM! Multiple servers error handling correctly tested.

The test properly validates that ambiguous server detection fails in non-interactive mode, using d.sandbox for paths and checking both exit code and error message content.


144-194: LGTM! Interactive prompt detection test well implemented.

The test correctly uses startServerpod for managing an interactive process, properly detects the selection prompt, and safely terminates the process with kill() followed by await exitCode.

tests/serverpod_cli_e2e_test/test/generate_watch_test.dart (5)

9-11: LGTM! Imports align with new test harness.

Consistent with the refactoring in other test files, properly enabling the centralized CLI runner and sandbox management.


903-907: LGTM! Function signature simplified appropriately.

The change from returning a tuple to returning just the project name String is a good refactoring. Callers now derive paths separately using createProjectFolderPaths(), which better separates concerns.


28-37: LGTM! Setup follows project conventions.

Correct use of assert for setup precondition verification and proper migration to runServerpod with d.sandbox.


917-1008: LGTM! Path helpers consistently refactored for sandbox support.

All path helper functions now properly accept and use the tmpFolder parameter, enabling sandbox isolation. The consistent use of path.join and path.joinAll ensures correct cross-platform path construction.


45-48: LGTM! Watch mode tests consistently refactored.

All startServerpod calls for generate --watch tests follow the same pattern with proper d.sandbox usage and correct working directory specification. Process lifecycle management in tearDown blocks is appropriate.

Also applies to: 195-198, 343-346, 501-504, 694-697, 815-818

@nielsenko
nielsenko force-pushed the test-util-run-serverpod branch from c9f1427 to 5dd8e62 Compare December 19, 2025 12:58
@nielsenko
nielsenko marked this pull request as ready for review December 19, 2025 13:03
@nielsenko
nielsenko requested a review from a team December 19, 2025 13:04

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🪽

@nielsenko
nielsenko force-pushed the test-util-run-serverpod branch from 42b8ede to 1b93624 Compare December 19, 2025 15:56
@nielsenko
nielsenko merged commit 75321bd into serverpod:main Dec 19, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor serverpod_cli_e2e_test tests to use runServerpod helper function

2 participants