Skip to content

fix: --completion outputs wrong script name when run via Bun#1826

Open
Paul-Goulpie wants to merge 2 commits intofirecow:masterfrom
Paul-Goulpie:fix/completion-script-name
Open

fix: --completion outputs wrong script name when run via Bun#1826
Paul-Goulpie wants to merge 2 commits intofirecow:masterfrom
Paul-Goulpie:fix/completion-script-name

Conversation

@Paul-Goulpie
Copy link
Copy Markdown

@Paul-Goulpie Paul-Goulpie commented Apr 5, 2026

fix: --completion outputs wrong script name when run via Bun

Problem

Running gitlab-ci-local --completion generated a bash completion
script referencing bun instead of gitlab-ci-local:

###-begin-bun-completions-###
...
mapfile -t type_list < <(bun --get-yargs-completions "${args[@]}")
...
complete -o bashdefault -o default -F _bun_yargs_completions bun
###-end-bun-completions-###

When run via bun run src/index.ts, yargs derives $0 from
process.argv[0], which resolves to the bun binary instead of
the command name. The handler.ts completion branch was creating
a fresh yargs instance without overriding this value.

Fix

Call .scriptName("gitlab-ci-local") on the yargs instance before
showCompletionScript() to explicitly set $0.

Test

Added a subprocess-based regression test. vi.spyOn(console, "log")
cannot intercept the output because Bun implements console.log
natively — the test runs the CLI via execSync and asserts the
generated script references gitlab-ci-local throughout.
The test is registered in the forks vitest pool and excluded from
threads to avoid worker initialisation failures.


Summary by cubic

Fixes --completion so the generated bash script uses gitlab-ci-local instead of bun when run via bun. Ensures the markers, function name, and complete directive reference the correct command.

  • Bug Fixes
    • Set yargs.scriptName("gitlab-ci-local") before .showCompletionScript() to override $0 (which yargs derived from process.argv[0] as bun).
    • Added a subprocess regression test that runs the CLI via execSync and asserts all references use gitlab-ci-local; test runs in the forks pool and is excluded from threads.

Written for commit 1eb7b49. Summary will update on new commits.

- yargs derives $0 from process.argv[0] which resolves to "bun"
  when running via `bun run src/index.ts`
- call .scriptName("gitlab-ci-local") on the yargs instance
  before showCompletionScript() to override $0
- completion script now correctly references gitlab-ci-local
  in markers, function name, and complete directive
- Add test case that runs the CLI as a subprocess via execSync
  to capture console.log output, which Bun implements natively
  and cannot be intercepted with vi.spyOn
- Assert completion output references gitlab-ci-local, not bun
- Register test in the forks pool (isolated process per file)
  since it spawns subprocesses
- Exclude from the threads pool to prevent worker init failure
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

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