Skip to content

test: add shared CLI test helpers#30

Merged
chenjiahan merged 2 commits into
mainfrom
chenjiahan/feat-test-helpers
Jul 11, 2026
Merged

test: add shared CLI test helpers#30
chenjiahan merged 2 commits into
mainfrom
chenjiahan/feat-test-helpers

Conversation

@chenjiahan

@chenjiahan chenjiahan commented Jul 11, 2026

Copy link
Copy Markdown
Member

Rstack's e2e tests need reusable process and polling utilities for long-running CLI scenarios. This PR adds Rsbuild-aligned async command, random port, and file polling helpers while retaining the explicit types required by isolated declarations. The process cleanup and port-allocation behavior includes the fixes already landed in Rsbuild.

Related Links

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 93aa102c0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rstack/test/helpers/cliTest.ts Outdated
Comment thread packages/rstack/test/helpers/cliTest.ts Outdated
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Expanded rstack test helpers to export the CLI binary path, execute raw child processes, and provide asynchronous CLI execution with inherited environment and working-directory options. Process output is forwarded to logging and processes are cleaned up during teardown. Added utilities for selecting unused TCP ports, polling for file existence, standardizing expect.poll settings, and exporting POSIX path normalization.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly matches the change set: shared CLI test helpers for Rstack.
Description check ✅ Passed The description is directly related to the added CLI execution, port, and polling helpers.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chenjiahan/feat-test-helpers

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
packages/rstack/test/helpers/cliTest.ts (1)

102-107: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Quote RSTACK_BIN_PATH to handle paths with spaces.

If the project directory contains spaces, the shell will misparse node /path with spaces/bin/rs.js as multiple arguments. A simple fix is to quote the path; for full robustness, consider spawn('node', [RSTACK_BIN_PATH, ...args]) with an argument array.

♻️ Proposed fix: quote the binary path
     const execCliAsync: Exec = (command, options = {}) => {
-      return exec(`node ${RSTACK_BIN_PATH} ${command}`, options);
+      return exec(`node "${RSTACK_BIN_PATH}" ${command}`, options);
     };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/rstack/test/helpers/cliTest.ts` around lines 102 - 107, Update
execCliAsync to quote RSTACK_BIN_PATH when constructing the node command,
ensuring project paths containing spaces remain a single shell argument while
preserving the existing command and options behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/rstack/test/helpers/cliTest.ts`:
- Around line 77-101: Update the exec fixture around the Exec function to track
every spawned child process cleanup handler rather than overwriting a single
close callback. Store each process’s stdout/stderr listener removal and kill
logic in a collection, then run all handlers during teardown after await
use(exec).

In `@packages/rstack/test/helpers/utils.ts`:
- Around line 32-43: Update getRandomPort to enforce the valid TCP port upper
bound while scanning candidates. Stop the loop when port exceeds 65535 and
return or propagate a clear failure instead of continuing indefinitely; preserve
the existing portMap reservation and availability checks for valid ports.
- Around line 7-22: Update isPortAvailable to resolve true only from the
server.close callback, ensuring the port is fully released before callers
proceed. Make the catch path return a resolved Promise<boolean> as well, keeping
the function’s return type consistently Promise<boolean>.

---

Nitpick comments:
In `@packages/rstack/test/helpers/cliTest.ts`:
- Around line 102-107: Update execCliAsync to quote RSTACK_BIN_PATH when
constructing the node command, ensuring project paths containing spaces remain a
single shell argument while preserving the existing command and options
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 871a3d19-5c19-42a7-9e47-4ba60e6c094a

📥 Commits

Reviewing files that changed from the base of the PR and between 08e65ab and 93aa102.

📒 Files selected for processing (3)
  • packages/rstack/test/helpers/cli.ts
  • packages/rstack/test/helpers/cliTest.ts
  • packages/rstack/test/helpers/utils.ts

Comment thread packages/rstack/test/helpers/cliTest.ts
Comment thread packages/rstack/test/helpers/utils.ts
Comment thread packages/rstack/test/helpers/utils.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/rstack/test/helpers/cliTest.ts`:
- Line 81: Update the CLI process cleanup around childProcess in the test helper
to terminate the entire process tree cross-platform rather than only the shell,
then await the child process close event before the finally block completes.
Preserve existing teardown behavior while ensuring no spawned CLI descendants
outlive the fixture.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3296e190-426a-4059-96c2-d2f8365f06b0

📥 Commits

Reviewing files that changed from the base of the PR and between 93aa102 and 9777e6f.

📒 Files selected for processing (2)
  • packages/rstack/test/helpers/cliTest.ts
  • packages/rstack/test/helpers/utils.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/rstack/test/helpers/utils.ts

Comment thread packages/rstack/test/helpers/cliTest.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9777e6f37a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rstack/test/helpers/utils.ts
@chenjiahan chenjiahan merged commit 511c326 into main Jul 11, 2026
4 checks passed
@chenjiahan chenjiahan deleted the chenjiahan/feat-test-helpers branch July 11, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant