Repository navigation
test: Use compile serverpod_cli to speed up e2e cli tests - #4475
Conversation
6688dba to
13b8951
Compare
13b8951 to
c9f1427
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughThis 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
startServerpodhelper function doesn't support passing custom environment variables—it only setsSERVERPOD_HOME. To properly test CI mode behavior, either enhancestartServerpodto accept anenvironmentparameter (similar to howrunServerpoddoes), 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 ifsystemTempis inaccessiblestatSync()at line 34 could throw if a directory is deleted betweenlistSync()andstatSync()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 getanddart compile execommands 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:asyncforTimeoutException.
74-80: Add timeout to activation command.The
dart pub global activatecommand 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.
📒 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.darttests/serverpod_cli_e2e_test/test/generate_with_directory_test.darttests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.darttests/serverpod_cli_e2e_test/lib/src/run_serverpod.darttests/serverpod_cli_e2e_test/test/run_command_test.darttests/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.darttests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.darttests/serverpod_cli_e2e_test/test/run_command_test.darttests/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.yamltests/serverpod_cli_e2e_test/lib/src/shared_test_dir.darttests/serverpod_cli_e2e_test/test/generate_with_directory_test.darttests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.darttests/serverpod_cli_e2e_test/lib/src/run_serverpod.darttests/serverpod_cli_e2e_test/test/run_command_test.darttests/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.yamltests/serverpod_cli_e2e_test/test/generate_with_directory_test.darttests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.darttests/serverpod_cli_e2e_test/lib/src/run_serverpod.darttests/serverpod_cli_e2e_test/test/run_command_test.darttests/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.yamltests/serverpod_cli_e2e_test/test/generate_with_directory_test.darttests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.darttests/serverpod_cli_e2e_test/lib/src/run_serverpod.darttests/serverpod_cli_e2e_test/test/run_command_test.darttests/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.darttests/serverpod_cli_e2e_test/test/generate_with_directory_test.darttests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.darttests/serverpod_cli_e2e_test/lib/src/run_serverpod.darttests/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.darttests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.darttests/serverpod_cli_e2e_test/lib/src/run_serverpod.darttests/serverpod_cli_e2e_test/test/run_command_test.darttests/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.darttests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.darttests/serverpod_cli_e2e_test/lib/src/run_serverpod.darttests/serverpod_cli_e2e_test/test/run_command_test.darttests/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.darttests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.darttests/serverpod_cli_e2e_test/lib/src/run_serverpod.darttests/serverpod_cli_e2e_test/test/run_command_test.darttests/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.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/lib/src/run_serverpod.darttests/serverpod_cli_e2e_test/test/run_command_test.darttests/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.darttests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.darttests/serverpod_cli_e2e_test/lib/src/run_serverpod.darttests/serverpod_cli_e2e_test/test/run_command_test.darttests/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.darttests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.darttests/serverpod_cli_e2e_test/test/run_command_test.darttests/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.darttests/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.darttests/serverpod_cli_e2e_test/test/create_migration_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_watch_test.darttests/serverpod_cli_e2e_test/test/generate_from_anywhere_test.darttests/serverpod_cli_e2e_test/test/generate_interactive_flag_test.darttests/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
versionfile 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
runServerpodandstartServerpodhelpers simplifies the test code while maintaining all original functionality. The SIGINT forwarding test correctly usesstartServerpodfor 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
runServerpodis clean and consistent. Good use ofassertinsetUp()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
assertfor 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
runServerpodandtest_descriptorsandbox 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
-doption 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.dartandtest_descriptorenable 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
assertinsetUp()to verify project creation is correct per project conventions, and the migration torunServerpodwithd.sandboxaligns with the PR objectives.
31-45: LGTM! Test correctly migrated to new harness.The test properly uses
runServerpodwithd.sandbox, checksresult.exitCode, and validates output fromresult.stdoutandresult.stderr.
82-101: LGTM! Interactive flag test correctly implemented.The test properly validates that
--interactiveflag overrides CI environment detection, using the newrunServerpodhelper 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.sandboxfor paths and checking both exit code and error message content.
144-194: LGTM! Interactive prompt detection test well implemented.The test correctly uses
startServerpodfor managing an interactive process, properly detects the selection prompt, and safely terminates the process withkill()followed byawait 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
assertfor setup precondition verification and proper migration torunServerpodwithd.sandbox.
917-1008: LGTM! Path helpers consistently refactored for sandbox support.All path helper functions now properly accept and use the
tmpFolderparameter, enabling sandbox isolation. The consistent use ofpath.joinandpath.joinAllensures correct cross-platform path construction.
45-48: LGTM! Watch mode tests consistently refactored.All
startServerpodcalls forgenerate --watchtests follow the same pattern with properd.sandboxusage and correct working directory specification. Process lifecycle management intearDownblocks is appropriate.Also applies to: 195-198, 343-346, 501-504, 694-697, 815-818
c9f1427 to
5dd8e62
Compare
…es for a given `dart test` run.
…to runServerpod (can be overriden)
42b8ede to
1b93624
Compare
Description
Refactors CLI e2e tests to use shared test utilities for running serverpod commands:
sharedTestDir- a temp directory shared across all test files in a singledart testrun (based on PID), with automatic cleanup of stale directories older than 1 dayrunServerpod()andstartServerpod()utilities that handle CLI execution with properSERVERPOD_HOMEsetupsharedTestDirProcess.start/Process.runcallsBenefits:
Fixes #4438
Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes
None.
Summary by CodeRabbit
Release Notes
New Features
Refactor
Chores
✏️ Tip: You can customize this high-level summary in your review settings.