Skip to content

feat: Add serverpod run command for running scripts - #4416

Merged
nielsenko merged 8 commits into
serverpod:mainfrom
nielsenko:feat-run-command
Dec 15, 2025
Merged

nielsenko merged 8 commits into
serverpod:mainfrom
nielsenko:feat-run-command

Conversation

@nielsenko

@nielsenko nielsenko commented Dec 10, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Adds serverpod run command to execute scripts defined in serverpod_scripts section of pubspec.yaml.

  • New RunCommand with --list flag to show available scripts
  • Scripts class parses serverpod_scripts from pubspec.yaml with source span error messages
  • Uses ServerDirectoryFinder to locate the server project's pubspec
  • Extends UnmodifiableMapBase for readonly map semantics

Fixes #4402

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

  • New Features
    • Added a run command to the CLI for executing custom scripts defined in your project configuration
    • Users can list all available scripts or execute a specific script directly from the command line
    • Provides comprehensive error handling for missing scripts, invalid script definitions, and configuration issues with helpful error messages

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

@nielsenko

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 10, 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 10, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request introduces a new serverpod run CLI command that enables execution of scripts defined in the serverpod_scripts section of pubspec.yaml. The implementation includes script parsing with validation, listing capabilities, and subprocess execution with error handling.

Changes

Cohort / File(s) Summary
CLI Registration
tools/serverpod_cli/bin/serverpod_cli.dart
Added import and registered RunCommand in the command runner's addCommands list.
Run Command Implementation
tools/serverpod_cli/lib/src/commands/run.dart
Implemented RunCommand class extending ServerpodCommand with logic to parse pubspec.yaml, list available scripts, and execute selected scripts in child processes. Includes RunOption enum for scriptName and list flag options, plus helper methods for script listing and execution with stdout/stderr streaming.
Script Data Model
tools/serverpod_cli/lib/src/scripts/script.dart
Introduced Script class representing a named script with command, including value-based equality and toString override.
Script Parsing Utility
tools/serverpod_cli/lib/src/scripts/scripts.dart
Implemented Scripts class extending UnmodifiableMapBase for read-only access to parsed scripts. Provides factory constructors for YAML, pubspec files, and PubspecPlus objects with validation and error reporting. Includes ScriptsParseException for malformed script data and findPubspecFile static method for locating pubspec.yaml.
Test Suite
tools/serverpod_cli/test/scripts/scripts_test.dart
Comprehensive test coverage for Script creation, Scripts.fromYaml parsing, pubspec file loading, and pubspec discovery logic with validation of error messages and source spans.

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as RunCommand
    participant Finder as ServerDirectoryFinder
    participant Parser as Scripts
    participant Process as Child Process
    participant Terminal

    User->>CLI: serverpod run [--list] [script_name]
    CLI->>Finder: findPubspecFile(directory)
    Finder-->>CLI: pubspec.yaml File
    
    CLI->>Parser: Scripts.fromPubspecFile(pubspecFile)
    Parser-->>CLI: Scripts (parsed from YAML)
    
    alt --list flag
        CLI->>CLI: _listScripts(scripts)
        CLI->>Terminal: print script names
    else execute script
        CLI->>CLI: locate script by name
        CLI->>Process: spawn shell process
        Process->>Process: execute command
        Process-->>Terminal: stream stdout/stderr
        Process-->>CLI: exit code
        CLI->>Terminal: return exit code
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

  • Scripts.fromYaml and parsing logic: Validate YAML structure handling, null checks, type validation (strings for names and commands), and ScriptsParseException error reporting with source spans
  • RunCommand execution flow: Verify subprocess creation, shell invocation, working directory management, stdout/stderr streaming, and exit code handling
  • Error handling coverage: Confirm missing pubspec.yaml, empty scripts, unknown script names, and malformed YAML structures are handled correctly
  • Test coverage gaps: Ensure test assertions adequately cover edge cases in parsing, error messages, and execution behavior

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The PR description covers the feature, includes a reference to issue #4402, follows the template structure, and marks all required pre-launch checklist items as complete.
Linked Issues check ✅ Passed The code changes implement all primary objectives from issue #4402: new RunCommand with --list flag, Scripts class parsing serverpod_scripts with error handling, ServerDirectoryFinder integration, and UnmodifiableMapBase for readonly semantics.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the serverpod run command feature: RunCommand registration, Scripts parsing infrastructure, Script data model, and comprehensive tests—no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a new 'serverpod run' command for executing scripts from pubspec.yaml.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 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: 2

🧹 Nitpick comments (4)
tools/serverpod_cli/lib/src/scripts/script.dart (1)

1-28: Well-structured immutable data model.

The Script class is clean and follows Dart best practices with final fields, a const constructor, and proper equality/hashCode implementations.

One minor optional improvement: consider using Object.hash(name, command) instead of XOR for hashCode, as it provides better distribution and reduces collision risk:

  @override
- int get hashCode => name.hashCode ^ command.hashCode;
+ int get hashCode => Object.hash(name, command);
tools/serverpod_cli/lib/src/commands/run.dart (1)

1-1: Unused import.

The dart:async import appears unused. Future and Stream are available from dart:core.

-import 'dart:async';
tools/serverpod_cli/lib/src/scripts/scripts.dart (2)

13-16: Redundant implements Exception.

YamlException already implements Exception, so the explicit implements Exception is unnecessary.

-class ScriptsParseException extends YamlException implements Exception {
+class ScriptsParseException extends YamlException {
   ScriptsParseException(super.message, [super.span]);
 }

110-114: Consider using path.join for cross-platform path construction.

String interpolation with / may produce inconsistent path separators on Windows. Using path.join from package:path ensures consistent platform-appropriate separators.

+import 'package:path/path.dart' as path;
+
 ...
 
   static File? findPubspecFile(Directory directory) {
     final serverDir = ServerDirectoryFinder.search(directory);
     if (serverDir == null) return null;
-    return File('${serverDir.path}/pubspec.yaml');
+    return File(path.join(serverDir.path, 'pubspec.yaml'));
   }
#!/bin/bash
# Verify if path package is already used elsewhere in the codebase for consistency
rg -l "import 'package:path/path.dart'" tools/serverpod_cli/lib/
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 214ba09 and 01f3eea.

📒 Files selected for processing (5)
  • tools/serverpod_cli/bin/serverpod_cli.dart (2 hunks)
  • tools/serverpod_cli/lib/src/commands/run.dart (1 hunks)
  • tools/serverpod_cli/lib/src/scripts/script.dart (1 hunks)
  • tools/serverpod_cli/lib/src/scripts/scripts.dart (1 hunks)
  • tools/serverpod_cli/test/scripts/scripts_test.dart (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.dart

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

**/*.dart: Use the 'Given, When, Then' pattern for test descriptions to maintain consistency, appearing only once in the combined group and test description
Follow Dart formatting conventions using dart format .
Remove unnecessary comments from production code
Use descriptive variable and function names following Dart naming conventions
Run dart format . before committing code to maintain consistent formatting across the repository
Run code analysis with util/run_tests_analyze or melos lint_strict to match CI strict mode before committing

Files:

  • tools/serverpod_cli/bin/serverpod_cli.dart
  • tools/serverpod_cli/lib/src/scripts/script.dart
  • tools/serverpod_cli/test/scripts/scripts_test.dart
  • tools/serverpod_cli/lib/src/scripts/scripts.dart
  • tools/serverpod_cli/lib/src/commands/run.dart
tools/serverpod_cli/**/*.dart

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

Reactivate the Serverpod CLI after making changes by running dart pub global activate --source path . from the tools/serverpod_cli directory

Files:

  • tools/serverpod_cli/bin/serverpod_cli.dart
  • tools/serverpod_cli/lib/src/scripts/script.dart
  • tools/serverpod_cli/test/scripts/scripts_test.dart
  • tools/serverpod_cli/lib/src/scripts/scripts.dart
  • tools/serverpod_cli/lib/src/commands/run.dart
**/*_test.dart

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

Place passing/success test cases at the top of test files, followed by error test cases for the same functionality, grouping related test cases using group()

Files:

  • tools/serverpod_cli/test/scripts/scripts_test.dart
🧠 Learnings (7)
📓 Common learnings
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-09T11:50:11.951Z
Learning: Applies to tools/serverpod_cli/**/*.dart : Reactivate the Serverpod CLI after making changes by running `dart pub global activate --source path .` from the tools/serverpod_cli directory
📚 Learning: 2025-12-09T11:50:11.951Z
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-09T11:50:11.951Z
Learning: Applies to tools/serverpod_cli/**/*.dart : Reactivate the Serverpod CLI after making changes by running `dart pub global activate --source path .` from the tools/serverpod_cli directory

Applied to files:

  • tools/serverpod_cli/bin/serverpod_cli.dart
  • tools/serverpod_cli/lib/src/scripts/script.dart
  • tools/serverpod_cli/test/scripts/scripts_test.dart
  • tools/serverpod_cli/lib/src/scripts/scripts.dart
  • tools/serverpod_cli/lib/src/commands/run.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:

  • tools/serverpod_cli/bin/serverpod_cli.dart
  • tools/serverpod_cli/lib/src/scripts/scripts.dart
📚 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:

  • tools/serverpod_cli/bin/serverpod_cli.dart
  • tools/serverpod_cli/lib/src/scripts/script.dart
  • tools/serverpod_cli/test/scripts/scripts_test.dart
  • tools/serverpod_cli/lib/src/scripts/scripts.dart
  • tools/serverpod_cli/lib/src/commands/run.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:

  • tools/serverpod_cli/bin/serverpod_cli.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:

  • tools/serverpod_cli/bin/serverpod_cli.dart
📚 Learning: 2025-12-09T11:50:11.951Z
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-09T11:50:11.951Z
Learning: Applies to **/*_test.dart : Place passing/success test cases at the top of test files, followed by error test cases for the same functionality, grouping related test cases using `group()`

Applied to files:

  • tools/serverpod_cli/test/scripts/scripts_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). (42)
  • GitHub Check: Unit tests IO (3.32.0, ubuntu-latest)
  • GitHub Check: Unit tests IO (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: Module integration tests in modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server with Flutter 3.32.0
  • GitHub Check: Module integration tests in tests/serverpod_new_auth_test/serverpod_new_auth_test_server with Flutter 3.38.4
  • GitHub Check: Module integration tests in tests/serverpod_new_auth_test/serverpod_new_auth_test_server with Flutter 3.32.0
  • GitHub Check: Module integration tests in tests/serverpod_test_nonvector/serverpod_test_nonvector_server with Flutter 3.38.4
  • GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server with Flutter 3.38.4
  • GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server with Flutter 3.32.0
  • GitHub Check: Module integration tests in tests/serverpod_test_nonvector/serverpod_test_nonvector_server with Flutter 3.32.0
  • GitHub Check: Version change test
  • GitHub Check: CLI e2e tests (3.38.4, ubuntu-latest, tests/serverpod_cli_e2e_test)
  • GitHub Check: Bootstrap tests (3.38.4, windows-latest, tests/bootstrap_project)
  • GitHub Check: Serverpod E2E web tests (3.38.4)
  • GitHub Check: Flutter unit tests (3.32.0, windows-latest, packages/serverpod_flutter)
  • GitHub Check: dart analyze (3.32.0, ubuntu-latest)
  • GitHub Check: Serverpod E2E web tests (3.32.0)
  • GitHub Check: Flutter unit tests (3.38.4, windows-latest, packages/serverpod_flutter)
  • GitHub Check: Bootstrap tests (3.32.0, ubuntu-latest, tests/bootstrap_project)
  • GitHub Check: Serverpod integration tests (flutter)
  • GitHub Check: Bootstrap tests (3.38.4, ubuntu-latest, tests/bootstrap_project)
  • GitHub Check: Unit tests Web (3.38.4, windows-latest)
  • GitHub Check: Bootstrap tests (3.32.0, windows-latest, tests/bootstrap_project)
  • GitHub Check: CLI e2e tests (3.32.0, ubuntu-latest, tests/serverpod_cli_e2e_test)
  • GitHub Check: Migration e2e tests (3.32.0)
  • GitHub Check: Serverpod concurrent integration tests (server) (3.32.0)
  • GitHub Check: Serverpod E2E IO tests (3.38.4)
  • GitHub Check: Serverpod concurrent integration tests (server) (3.38.4)
  • GitHub Check: Serverpod E2E IO tests (3.32.0)
  • GitHub Check: Serverpod integration tests (server) (3.38.4)
  • GitHub Check: Serverpod integration tests (server) (3.32.0)
  • GitHub Check: Migration e2e tests (3.38.4)
  • GitHub Check: dart analyze latest (3.38.4, windows-latest)
  • GitHub Check: serverpod generate (3.32.0)
  • GitHub Check: serverpod generate (3.38.4)
  • GitHub Check: dart analyze downgrade (3.38.4, ubuntu-latest)
  • GitHub Check: dart analyze downgrade (3.32.0, windows-latest)
  • GitHub Check: dart analyze downgrade (3.38.4, windows-latest)
  • GitHub Check: dart analyze (3.32.0, windows-latest)
  • GitHub Check: dart analyze downgrade (3.32.0, ubuntu-latest)
  • GitHub Check: dart analyze latest (3.38.4, ubuntu-latest)
🔇 Additional comments (5)
tools/serverpod_cli/bin/serverpod_cli.dart (1)

14-14: LGTM!

The RunCommand import and registration follow the existing patterns for other CLI commands. The command is correctly added to the command list.

Also applies to: 82-82

tools/serverpod_cli/test/scripts/scripts_test.dart (1)

12-392: Comprehensive test coverage following coding guidelines.

The test file:

  • Uses the "Given, When, Then" pattern consistently as per coding guidelines
  • Places success test cases before error test cases within each group
  • Covers edge cases including null YAML, non-existent files, invalid structures, and directory traversal scenarios
  • Uses appropriate matchers (isA, having, allOf) for detailed exception verification
tools/serverpod_cli/lib/src/commands/run.dart (1)

51-103: Well-structured command flow with proper error handling.

The runWithConfig method handles all expected scenarios:

  • Missing pubspec file
  • Parse errors with informative messages
  • Empty scripts section
  • Unknown script names with helpful listing
  • Script execution with exit code propagation
tools/serverpod_cli/lib/src/scripts/scripts.dart (2)

31-61: LGTM!

The fromYaml factory properly:

  • Handles null input gracefully
  • Uses yaml.nodes.entries to preserve source spans for detailed error messages
  • Validates both keys and values with informative error messages

116-120: LGTM!

The UnmodifiableMapBase implementation correctly provides read-only map semantics by only implementing the required operator[] and keys accessors.

@nielsenko
nielsenko force-pushed the feat-run-command branch 2 times, most recently from 3d81379 to 52621b8 Compare December 11, 2025 00:30
@nielsenko nielsenko self-assigned this Dec 11, 2025
@nielsenko
nielsenko marked this pull request as ready for review December 11, 2025 00:32
@nielsenko
nielsenko requested a review from a team December 11, 2025 00:32

@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.

Nice quick work!

A couple of comments and suggestions.

Two additional things:

  1. Can we add an e2e test that validates this works as expected? We have our e2e cli tests we can use.
  2. Is it a big addition to allow additional arguments to be passed down to the script? This is scope creep and could be added later on upon request.

@nielsenko

Copy link
Copy Markdown
Collaborator Author

Nice quick work!

A couple of comments and suggestions.

Two additional things:

  1. Can we add an e2e test that validates this works as expected? We have our e2e cli tests we can use.
  2. Is it a big addition to allow additional arguments to be passed down to the script? This is scope creep and could be added later on upon request.

Due to some conflict between args and cli_tools (or my lagging knowledge) I'm having trouble getting rest args (those after --) to work with the run command. I will return to this later, as to not waste more time now.

@coderabbitai Will you create a follow-up issue for this?

@coderabbitai

coderabbitai Bot commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# Create a follow-up issue for passing additional arguments to scripts in serverpod run command
gh issue create \
  --title "Support passing additional arguments to scripts in serverpod run command" \
  --body "## Description

Add support for passing additional arguments to scripts executed by the \`serverpod run\` command. This would allow users to pass arguments after \`--\` that get forwarded to the underlying script.

## Context

This feature was identified during the implementation of the \`serverpod run\` command in PR #4416. Due to conflicts between the \`args\` and \`cli_tools\` packages, implementing rest args (those after \`--\`) proved challenging and was deferred to avoid blocking the initial implementation.

## References

- Original PR: https://github.com/serverpod/serverpod/pull/4416
- Requested by: @nielsenko

## Example Use Case

\`\`\`bash
serverpod run my-script -- --additional-arg value
\`\`\`

The arguments after \`--\` should be passed to the script being executed." \
  --assignee nielsenko

Length of output: 50


@nielsenko I've created a follow-up issue for supporting additional arguments to be passed to scripts: #4421

The issue captures the context about the conflicts between args and cli_tools packages and includes a reference back to this PR. This will allow you to revisit the rest args functionality when time permits.

@nielsenko nielsenko changed the title feat: Add serverpod run command for running scripts feat(cli_tools): Add serverpod run command for running scripts Dec 12, 2025
@nielsenko nielsenko changed the title feat(cli_tools): Add serverpod run command for running scripts feat: Add serverpod run command for running scripts Dec 12, 2025
@nielsenko

Copy link
Copy Markdown
Collaborator Author
  • Can we add an e2e test that validates this works as expected? We have our e2e cli tests we can use.

Added (/moved) in 80beac5

@nielsenko
nielsenko requested a review from SandPod December 12, 2025 16:14
@nielsenko

Copy link
Copy Markdown
Collaborator Author

@coderabbitai Create issue for using the runServerpod function from run_command_test.dart in all serverpod_cli_e2e_test tests.

@coderabbitai

coderabbitai Bot commented Dec 12, 2025

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find and read the run_command_test.dart file
fd -t f "run_command_test.dart" --exec cat {}

Length of output: 5557


🏁 Script executed:

#!/bin/bash
# Get an overview of the serverpod_cli_e2e_test directory structure
fd -t f ".*_test\.dart$" tests/serverpod_cli_e2e_test/test --exec basename {}

Length of output: 186


🏁 Script executed:

#!/bin/bash
# Sample a few e2e tests to understand their current structure
cat tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart | head -100

Length of output: 2942


🏁 Script executed:

#!/bin/bash
# Create a follow-up issue for using runServerpod function across all e2e tests
gh issue create \
  --title "Refactor serverpod_cli_e2e_test tests to use runServerpod helper function" \
  --body "## Description

Refactor all e2e tests in \`serverpod_cli_e2e_test\` to use the \`runServerpod\` function from \`run_command_test.dart\` instead of manually setting up and running the CLI.

## Context

The \`runServerpod\` function in \`tests/serverpod_cli_e2e_test/test/run_command_test.dart\` provides a centralized, standardized way to execute serverpod commands with:
- Support for different run types (dartRun, activated, compiled)
- Proper environment setup (SERVERPOD_HOME)
- Consistent path management
- Reusable activation logic

Currently, other e2e tests manually:
- Set up CLI paths and root paths
- Activate the CLI with \`dart pub global activate\`
- Use \`Process.start\` or \`Process.run\` directly
- Duplicate environment and path setup code

## Tests to Refactor

- \`generate_with_directory_test.dart\`
- \`generate_from_anywhere_test.dart\`
- \`generate_interactive_flag_test.dart\`
- \`generate_watch_test.dart\`
- \`create_migration_exit_code_test.dart\`

## Benefits

- Reduces code duplication
- Improves test maintainability
- Provides consistent CLI execution across all e2e tests
- Makes tests easier to read and understand

## References

- Original PR: https://github.com/serverpod/serverpod/pull/4416
- Requested by: @nielsenko" \
  --assignee nielsenko

Length of output: 88


🏁 Script executed:

#!/bin/bash
# Create a follow-up issue for using runServerpod function across all e2e tests
gh issue create \
  --title "Refactor serverpod_cli_e2e_test tests to use runServerpod helper function" \
  --body "## Description

Refactor all e2e tests in \`serverpod_cli_e2e_test\` to use the \`runServerpod\` function from \`run_command_test.dart\` instead of manually setting up and running the CLI.

## Context

The \`runServerpod\` function in \`tests/serverpod_cli_e2e_test/test/run_command_test.dart\` provides a centralized, standardized way to execute serverpod commands with:
- Support for different run types (dartRun, activated, compiled)
- Proper environment setup (SERVERPOD_HOME)
- Consistent path management
- Reusable activation logic

Currently, other e2e tests manually:
- Set up CLI paths and root paths
- Activate the CLI with \`dart pub global activate\`
- Use \`Process.start\` or \`Process.run\` directly
- Duplicate environment and path setup code

## Tests to Refactor

- \`generate_with_directory_test.dart\`
- \`generate_from_anywhere_test.dart\`
- \`generate_interactive_flag_test.dart\`
- \`generate_watch_test.dart\`
- \`create_migration_exit_code_test.dart\`

## Benefits

- Reduces code duplication
- Improves test maintainability
- Provides consistent CLI execution across all e2e tests
- Makes tests easier to read and understand

## References

- Original PR: https://github.com/serverpod/serverpod/pull/4416
- Requested by: @nielsenko" \
  --assignee nielsenko

Length of output: 50


@nielsenko I've created a follow-up issue for refactoring the e2e tests to use the runServerpod helper function: #4438

The issue documents the benefits of using the centralized runServerpod function (consistent environment setup, support for different run types, reduced code duplication) and lists all five e2e test files that should be refactored:

  • generate_with_directory_test.dart
  • generate_from_anywhere_test.dart
  • generate_interactive_flag_test.dart
  • generate_watch_test.dart
  • create_migration_exit_code_test.dart

🧠 Learnings used
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: 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: 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: 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: 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: 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: 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: 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.

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.

@nielsenko

Copy link
Copy Markdown
Collaborator Author

@coderabbitai Create issue to use execute from serverpod/cli_tools#96 instead of RunCommand._executeScript.

@coderabbitai

coderabbitai Bot commented Dec 12, 2025

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the RunCommand implementation to understand _executeScript
cat tools/serverpod_cli/lib/src/commands/run.dart

Length of output: 4832


🏁 Script executed:

#!/bin/bash
# Fetch information about the cli_tools PR #96
gh pr view 96 --repo serverpod/cli_tools --json title,body,url

Length of output: 1095


🏁 Script executed:

#!/bin/bash
# Create a follow-up issue for refactoring to use execute helper from cli_tools
gh issue create \
  --title "Refactor RunCommand to use execute helper from cli_tools" \
  --body "## Description

Refactor \`RunCommand._executeScript\` to use the new \`execute\` helper function from cli_tools instead of manually managing process execution, signal forwarding, and stdin/stdout/stderr streaming.

## Context

The \`RunCommand._executeScript\` method in \`tools/serverpod_cli/lib/src/commands/run.dart\` currently implements shell command execution with:
- Shell invocation (bash/cmd)
- Signal forwarding (SIGINT, SIGTERM)
- stdin passthrough to child process
- Real-time stdout/stderr streaming
- Exit code handling

The cli_tools package now provides an \`execute\` helper function (see https://github.com/serverpod/cli_tools/pull/96) that encapsulates all this functionality with proper signal propagation, stdin/stdout/stderr forwarding, and optional working directory support.

## Benefits

- Reduces code duplication by using shared utility
- Simplifies RunCommand implementation
- Centralizes shell execution logic in cli_tools
- Improves maintainability - fixes and improvements to execute benefit all consumers

## Implementation

Replace the custom \`_executeScript\` implementation with a call to the \`execute\` function from cli_tools:

\`\`\`dart
Future<int> _executeScript(Script script, String workingDirectory) async {
  log.info('Running \"\${script.name}\": \${script.command}');
  return execute(script.command, workingDirectory: workingDirectory);
}
\`\`\`

## Prerequisites

- Wait for cli_tools PR #96 to be merged and released
- Update cli_tools dependency version in serverpod_cli

## References

- cli_tools PR: https://github.com/serverpod/cli_tools/pull/96
- Original implementation PR: https://github.com/serverpod/serverpod/pull/4416
- Requested by: @nielsenko" \
  --assignee nielsenko

Length of output: 88


🏁 Script executed:

#!/bin/bash
# Create a follow-up issue for refactoring to use execute helper from cli_tools
gh issue create \
  --repo serverpod/serverpod \
  --title "Refactor RunCommand to use execute helper from cli_tools" \
  --body "## Description

Refactor \`RunCommand._executeScript\` to use the new \`execute\` helper function from cli_tools instead of manually managing process execution, signal forwarding, and stdin/stdout/stderr streaming.

## Context

The \`RunCommand._executeScript\` method in \`tools/serverpod_cli/lib/src/commands/run.dart\` currently implements shell command execution with:
- Shell invocation (bash/cmd)
- Signal forwarding (SIGINT, SIGTERM)
- stdin passthrough to child process
- Real-time stdout/stderr streaming
- Exit code handling

The cli_tools package now provides an \`execute\` helper function (see https://github.com/serverpod/cli_tools/pull/96) that encapsulates all this functionality with proper signal propagation, stdin/stdout/stderr forwarding, and optional working directory support.

## Benefits

- Reduces code duplication by using shared utility
- Simplifies RunCommand implementation
- Centralizes shell execution logic in cli_tools
- Improves maintainability - fixes and improvements to execute benefit all consumers

## Implementation

Replace the custom \`_executeScript\` implementation with a call to the \`execute\` function from cli_tools:

\`\`\`dart
Future<int> _executeScript(Script script, String workingDirectory) async {
  log.info('Running \"\${script.name}\": \${script.command}');
  return execute(script.command, workingDirectory: workingDirectory);
}
\`\`\`

## Prerequisites

- Wait for cli_tools PR #96 to be merged and released
- Update cli_tools dependency version in serverpod_cli

## References

- cli_tools PR: https://github.com/serverpod/cli_tools/pull/96
- Original implementation PR: https://github.com/serverpod/serverpod/pull/4416
- Requested by: @nielsenko" \
  --assignee nielsenko

Length of output: 50


@nielsenko I've created a follow-up issue for refactoring RunCommand._executeScript to use the execute helper from cli_tools: #4439

The issue documents the current implementation (shell invocation, signal forwarding, stdin/stdout/stderr streaming), explains the benefits of using the shared execute utility from cli_tools PR #96, and includes a simple implementation example. It also notes the prerequisite of waiting for the cli_tools PR to be merged and released before proceeding with this refactoring.


🧠 Learnings used
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.

- Add `RunType` enum (`dartRun`,`compiled`,`activated`,`installed`).
- `runServerpod` now takes a `RunType` to determine how to run.

@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.

Last couple of comments then we are good to go! 👍

@nielsenko
nielsenko merged commit 6146a60 into serverpod:main Dec 15, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 15, 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.

feat(cli): Add serverpod run command to execute scripts from pubspec.yaml

3 participants