Skip to content

feat(plugin-completion): support Bun runtimes#556

Merged
kazupon merged 4 commits into
kazupon:mainfrom
ReoHakase:feat/completion-for-bun
May 17, 2026
Merged

feat(plugin-completion): support Bun runtimes#556
kazupon merged 4 commits into
kazupon:mainfrom
ReoHakase:feat/completion-for-bun

Conversation

@ReoHakase

@ReoHakase ReoHakase commented May 14, 2026

Copy link
Copy Markdown
Contributor

Description

Resolve completion script executables for Bun source execution and likely Bun single-file binaries while keeping Deno as an unsupported runtime path.

This PR splits executable resolution into testable helpers, quotes shell command parts consistently, and documents the Bun compile heuristic with upstream references. It also escapes executable commands for the @bomb.sh/tab generated shell assignment before eval to avoid command substitution while preserving token quoting.

Implementation references:

Test coverage added:

  • Runtime detection priority: Bun, then Deno, then Node.
  • Node executable resolution.
  • Bun source executable resolution.
  • Bun source executable resolution with process.execArgv.
  • Bun single-file executable resolution on Unix and Windows.
  • Bun virtual entry detection for /$bunfs/, B:\~BUN\, and B:/~BUN/.
  • Shell quoting for spaces, single quotes, command substitution, backticks, double quotes, and Windows backslashes.
  • Bun E2E smoke tests for source execution and bun build --compile binaries:
    • complete zsh
    • complete -- --config vite.config

Linked Issues

Closes #557

Additional context

Reviewer focus:

  • Bun source execution replays the Bun launcher, runtime args, and source entry.
  • Likely Bun single-file executables re-enter the compiled executable itself.
  • The Bun virtual path heuristic is intentionally internal and based on current Bun standalone executable paths.
  • Deno remains explicitly unsupported for completion script generation in this PR.

Validation:

  • pnpm fix:oxfmt
  • pnpm test:plugin-completion
  • pnpm --filter @gunshi/plugin-completion typecheck:deno
  • pnpm exec vitest run --config vitest.e2e.config.ts e2e/bun.spec.ts
  • pnpm lint

Summary by CodeRabbit

  • New Features

    • Added Bun support for completion script generation (source execution and single-file executables) alongside Node.js; improved runtime detection for multiple JS runtimes.
  • Tests

    • Added e2e tests for Bun completions (fixture and compiled binary) and unit tests for runtime-detection and command-generation utilities.
  • Documentation

    • README and docs updated to document Bun support, clarify prerequisites, and refine API/docs anchors and type representations.

Review Change Stack

Resolve completion script executables for Bun source execution and likely Bun single-file binaries while keeping Deno as an unsupported runtime path.

Split executable resolution into testable helpers, quote shell command parts consistently, and document the Bun compile heuristic with upstream references. Escape executable commands for the @bomb.sh/tab generated shell assignment before eval to avoid command substitution while preserving token quoting.
@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@ReoHakase has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 44 minutes and 23 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e9d572e3-4808-493c-81d2-7c3ea06b6a08

📥 Commits

Reviewing files that changed from the base of the PR and between 36d0b5e and 0597abc.

📒 Files selected for processing (2)
  • packages/plugin-completion/src/utils.test.ts
  • packages/plugin-completion/src/utils.ts
📝 Walkthrough

Walkthrough

Refactors completion tooling to detect runtimes (Bun/Deno/Node), produce completion-safe shell command strings, add Bun single-binary heuristics, and validate behavior with unit and e2e tests; also updates documentation and generated docs anchors.

Changes

Bun Runtime Support and Command Composition Refactoring

Layer / File(s) Summary
Runtime detection types and infrastructure
packages/plugin-completion/src/utils.ts
Introduces Runtime, ProcessLike, and RuntimeGlobals; exports detectRuntime()/detectRuntimeFromGlobals() with Bun > Deno > Node precedence.
Shell escaping and Bun heuristics
packages/plugin-completion/src/utils.ts
Adds shellQuote() and internal escaping for double-quoted contexts; implements Bun single-binary and virtual-entry detection heuristics.
Runtime-specific command resolution
packages/plugin-completion/src/utils.ts
Adds resolveNodeExecParts() and resolveBunExecParts() producing token arrays; joinExecParts() composes a single shell-escaped command string.
Public quoteExec refactoring
packages/plugin-completion/src/utils.ts
Rewrites quoteExec() to detect runtime and select appropriate resolver; throws explicit errors for unsupported/unknown runtimes.
Unit tests for runtime utilities
packages/plugin-completion/src/utils.test.ts
Adds tests for runtime detection precedence, Node/Bun exec-part resolution (including single-binary and virtual entry cases), and shell quoting/joining behavior.
End-to-end Bun completion tests
e2e/bun.spec.ts
Adds tests validating completion output for Bun source execution and compiled single-file binaries, with temp-dir build cleanup.
Documentation and generated docs updates
packages/plugin-completion/README.md, packages/plugin-completion/docs/*
README updated to mention Node.js and Bun support; generated docs anchors adjusted and default() options shown as optional in docs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

improvement

Poem

🐰 A rabbit hops through runtimes swift,
From Node to Bun, a graceful shift!
Shell tokens quoted, safe and neat,
Completion sings on every beat. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(plugin-completion): support Bun runtimes' clearly and specifically describes the main change: adding Bun runtime support to the completion plugin.
Linked Issues check ✅ Passed The PR successfully implements all coding objectives from issue #557: Bun source execution and compiled-binary completion script resolution [#557], improved runtime detection prioritizing Bun over Deno [#557], shell command quoting for safe eval embedding [#557], and comprehensive test coverage for both Node/Bun resolvers and E2E scenarios [#557].
Out of Scope Changes check ✅ Passed All changes are directly scoped to Bun runtime support: runtime detection refactoring, executable resolution helpers for Node/Bun, shell quoting/escaping utilities, comprehensive test coverage, documentation updates reflecting Bun support, and e2e tests validating the implementation.

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

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

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

❤️ Share

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

@ReoHakase ReoHakase marked this pull request as ready for review May 14, 2026 18:40
@ReoHakase ReoHakase marked this pull request as draft May 14, 2026 18:42
@ReoHakase ReoHakase marked this pull request as ready for review May 14, 2026 18:43

@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 (1)
e2e/bun.spec.ts (1)

9-11: ⚡ Quick win

Note: POSIX quoting works on current CI but consider centralizing if Windows support is added.

shellQuote uses POSIX single-quote escaping, and runCommand executes commands via shell (exec). This is not a current risk since E2E CI runs only on ubuntu-latest, but would become relevant if Windows CI is ever introduced. Consider moving this helper to a shared utilities file or documenting the Unix-only assumption.

🤖 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 `@e2e/bun.spec.ts` around lines 9 - 11, shellQuote currently implements POSIX
single-quote escaping and is used by runCommand which invokes a shell;
centralize or document this Unix-only assumption to avoid surprises if Windows
CI is added: move the shellQuote function into a shared utilities module (e.g.,
a test-utils or e2e-utils file), update callers (runCommand) to import it, and
either (a) add clear inline comments and README/test docs stating it is
POSIX-only and CI runs on ubuntu-latest, or (b) replace/guard it with a
cross-platform implementation when detecting Windows; reference the shellQuote
function and runCommand so the helper is relocated and consumers updated
accordingly.
🤖 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/plugin-completion/README.md`:
- Line 16: Update the user-facing sentence in
packages/plugin-completion/README.md to use correct grammar: change "This
package support Node.js and Bun runtime only. Deno support is not available
yet." to use "supports" (e.g., "This package supports Node.js and Bun runtimes
only; Deno support is not available yet.") so the verb agrees with the singular
subject and the wording is clearer.

In `@packages/plugin-completion/src/utils.ts`:
- Line 230: The error message thrown in packages/plugin-completion/src/utils.ts
is grammatically incorrect; update the thrown Error's message (the throw new
Error(...) in the completion script generation path) to a clear, correct phrase
such as "Unsupported JavaScript runtime for completion script generation." so
diagnostics are readable and consistent.

---

Nitpick comments:
In `@e2e/bun.spec.ts`:
- Around line 9-11: shellQuote currently implements POSIX single-quote escaping
and is used by runCommand which invokes a shell; centralize or document this
Unix-only assumption to avoid surprises if Windows CI is added: move the
shellQuote function into a shared utilities module (e.g., a test-utils or
e2e-utils file), update callers (runCommand) to import it, and either (a) add
clear inline comments and README/test docs stating it is POSIX-only and CI runs
on ubuntu-latest, or (b) replace/guard it with a cross-platform implementation
when detecting Windows; reference the shellQuote function and runCommand so the
helper is relocated and consumers updated accordingly.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 55b699ea-6258-4e84-ac24-6bbc004af862

📥 Commits

Reviewing files that changed from the base of the PR and between 9aaf8a7 and 31bcf27.

📒 Files selected for processing (9)
  • e2e/bun.spec.ts
  • packages/plugin-completion/README.md
  • packages/plugin-completion/docs/functions/default.md
  • packages/plugin-completion/docs/interfaces/CompletionConfig.md
  • packages/plugin-completion/docs/interfaces/CompletionOptions.md
  • packages/plugin-completion/docs/interfaces/CompletionParams.md
  • packages/plugin-completion/docs/type-aliases/CompletionHandler.md
  • packages/plugin-completion/src/utils.test.ts
  • packages/plugin-completion/src/utils.ts

Comment thread packages/plugin-completion/README.md Outdated
Comment thread packages/plugin-completion/src/utils.ts Outdated
@kazupon kazupon added the feature Includes new features label May 17, 2026
@pkg-pr-new

pkg-pr-new Bot commented May 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

@gunshi/bone

npm i https://pkg.pr.new/@gunshi/bone@556

@gunshi/combinators

npm i https://pkg.pr.new/@gunshi/combinators@556

@gunshi/definition

npm i https://pkg.pr.new/@gunshi/definition@556

@gunshi/docs

npm i https://pkg.pr.new/@gunshi/docs@556

gunshi

npm i https://pkg.pr.new/gunshi@556

@gunshi/plugin

npm i https://pkg.pr.new/@gunshi/plugin@556

@gunshi/plugin-completion

npm i https://pkg.pr.new/@gunshi/plugin-completion@556

@gunshi/plugin-dryrun

npm i https://pkg.pr.new/@gunshi/plugin-dryrun@556

@gunshi/plugin-global

npm i https://pkg.pr.new/@gunshi/plugin-global@556

@gunshi/plugin-i18n

npm i https://pkg.pr.new/@gunshi/plugin-i18n@556

@gunshi/plugin-renderer

npm i https://pkg.pr.new/@gunshi/plugin-renderer@556

@gunshi/resources

npm i https://pkg.pr.new/@gunshi/resources@556

@gunshi/shared

npm i https://pkg.pr.new/@gunshi/shared@556

commit: 0597abc

@kazupon kazupon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you for your contribution!
I've just reviewed your PR!

Please check it!

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think we can keep the README simpler here.

Instead of adding a dedicated Runtime Support section with Bun-specific implementation details, it may be enough to update the existing warning and the Shell Completion Setup prerequisites so users know that Node.js and Bun are supported while Deno is not supported yet.

The current Bun-specific text explains internal details such as the compiled-executable detection heuristic, which feels more appropriate for code comments, tests, or the PR description than for end-user documentation.

For the README, I think it is clearer to keep the focus on what users need to do to set up shell completions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in ea008a9. I removed the dedicated Runtime Support section and kept the README focused on the warning and setup prerequisites.

Comment thread packages/plugin-completion/src/utils.ts Outdated
* @param globals - Runtime globals to inspect
* @returns The detected runtime name
*/
export function detectRuntime(globals: RuntimeGlobals = getRuntimeGlobals()): Runtime {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Do we need globals in the public signature here?

For actual runtime detection, the natural usage seems to be detectRuntime() with the current environment. Passing custom globals looks useful mainly for tests, but I do not see a production use case for callers to provide them intentionally.

If the goal is testability, would it be clearer to keep detectRuntime() as the environment-facing function and extract a separate pure helper such as detectRuntimeFromGlobals(globals) for the injected case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 36d0b5e. detectRuntime() now reads the current environment, and tests use detectRuntimeFromGlobals(globals) for injected globals.

ReoHakase added 2 commits May 18, 2026 03:31
Keep the README focused on supported runtimes and setup prerequisites while moving Bun heuristic details out of the user-facing docs.
Expose detectRuntime() as the environment-facing path and move injected global detection into detectRuntimeFromGlobals() for tests.

Update quoteExec() to use the environment detector, clean up the unsupported runtime message, and document the POSIX-only E2E shell quoting assumption.

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

🧹 Nitpick comments (1)
packages/plugin-completion/src/utils.test.ts (1)

117-138: ⚡ Quick win

Add coverage for the B:/~BUN/ virtual-entry branch.

isBunVirtualEntry() accepts both Windows spellings, but this suite only exercises the backslash variant. That leaves one branch of the compiled-binary heuristic unguarded, so a regression in the forward-slash path would slip through.

🧪 Proposed test addition
   test('resolves Bun Windows virtual compiled entry', () => {
     expect(
       resolveBunExecParts(
         createProcess({
           argv: ['C:\\tools\\bun.exe', 'B:\\~BUN\\root.js'],
           execPath: 'C:\\tools\\bun.exe'
         })
       )
     ).toEqual(['C:\\tools\\bun.exe'])
   })
+
+  test('resolves Bun Windows virtual compiled entry with forward slashes', () => {
+    expect(
+      resolveBunExecParts(
+        createProcess({
+          argv: ['C:\\tools\\bun.exe', 'B:/~BUN/root.js'],
+          execPath: 'C:\\tools\\bun.exe'
+        })
+      )
+    ).toEqual(['C:\\tools\\bun.exe'])
+  })
 })
🤖 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/plugin-completion/src/utils.test.ts` around lines 117 - 138, Add a
test exercising the forward-slash Windows virtual-entry path so the branch in
isBunVirtualEntry that matches "B:/~BUN/" is covered: update the tests that call
resolveBunExecParts (and use createProcess) to include a case where argv
contains 'B:/~BUN/root.js' with execPath set to the bun executable (e.g.,
'/usr/local/bin/bun' or 'C:\\tools\\bun.exe' as appropriate) and assert the same
expected output as the backslash variant; this ensures the forward-slash branch
of isBunVirtualEntry and the compiled-binary heuristic in resolveBunExecParts
are exercised.
🤖 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.

Nitpick comments:
In `@packages/plugin-completion/src/utils.test.ts`:
- Around line 117-138: Add a test exercising the forward-slash Windows
virtual-entry path so the branch in isBunVirtualEntry that matches "B:/~BUN/" is
covered: update the tests that call resolveBunExecParts (and use createProcess)
to include a case where argv contains 'B:/~BUN/root.js' with execPath set to the
bun executable (e.g., '/usr/local/bin/bun' or 'C:\\tools\\bun.exe' as
appropriate) and assert the same expected output as the backslash variant; this
ensures the forward-slash branch of isBunVirtualEntry and the compiled-binary
heuristic in resolveBunExecParts are exercised.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: df0a763b-9c49-4a73-a5fd-c430e020f2ec

📥 Commits

Reviewing files that changed from the base of the PR and between 31bcf27 and 36d0b5e.

📒 Files selected for processing (4)
  • e2e/bun.spec.ts
  • packages/plugin-completion/README.md
  • packages/plugin-completion/src/utils.test.ts
  • packages/plugin-completion/src/utils.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/plugin-completion/README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/bun.spec.ts

@ReoHakase ReoHakase requested a review from kazupon May 17, 2026 18:59
Remove the current-environment runtime assertion from the unit tests and keep detectRuntime() as an internal quoteExec() helper.

@kazupon kazupon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you so much!
LGTM!

@kazupon kazupon merged commit 3511b42 into kazupon:main May 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Includes new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Bun runtime completion generation

2 participants