Skip to content

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

Merged
firecow merged 2 commits into
firecow:masterfrom
Paul-Goulpie:fix/completion-script-name
Apr 16, 2026
Merged

fix: --completion outputs wrong script name when run via Bun#1826
firecow merged 2 commits into
firecow:masterfrom
Paul-Goulpie:fix/completion-script-name

Conversation

@Paul-Goulpie

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

Copy link
Copy Markdown
Contributor

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

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 3 files

@firecow
firecow merged commit ac02922 into firecow:master Apr 16, 2026
14 checks passed
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request May 7, 2026
This MR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Adoption](https://docs.renovatebot.com/merge-confidence/) | [Passing](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|---|---|
| [npm:gitlab-ci-local](https://github.com/firecow/gitlab-ci-local) | `4.70.1` → `4.71.0` | ![age](https://developer.mend.io/api/mc/badges/age/npm/gitlab-ci-local/4.71.0?slim=true) | ![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/gitlab-ci-local/4.71.0?slim=true) | ![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/gitlab-ci-local/4.70.1/4.71.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/gitlab-ci-local/4.70.1/4.71.0?slim=true) |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>firecow/gitlab-ci-local (npm:gitlab-ci-local)</summary>

### [`v4.71.0`](https://github.com/firecow/gitlab-ci-local/releases/tag/4.71.0)

[Compare Source](firecow/gitlab-ci-local@4.70.1...4.71.0)

#### What's Changed

- Fix remaining SonarCloud findings by [@&#8203;firecow](https://github.com/firecow) in [#&#8203;1823](firecow/gitlab-ci-local#1823)
- fix(windows): skip id -u on Windows to avoid confusing startup error by [@&#8203;bcouetil](https://github.com/bcouetil) in [#&#8203;1824](firecow/gitlab-ci-local#1824)
- fix: --completion outputs wrong script name when run via Bun by [@&#8203;Paul-Goulpie](https://github.com/Paul-Goulpie) in [#&#8203;1826](firecow/gitlab-ci-local#1826)
- feat: improve --list-csv and --list output by [@&#8203;bcouetil](https://github.com/bcouetil) in [#&#8203;1810](firecow/gitlab-ci-local#1810)
- chore(deps): update all non-major by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;1830](firecow/gitlab-ci-local#1830)
- chore(deps): lock file maintenance by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;1827](firecow/gitlab-ci-local#1827)
- fix(deps): update dependency re2js to v2 by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;1828](firecow/gitlab-ci-local#1828)

#### New Contributors

- [@&#8203;Paul-Goulpie](https://github.com/Paul-Goulpie) made their first contribution in [#&#8203;1826](firecow/gitlab-ci-local#1826)

**Full Changelog**: <firecow/gitlab-ci-local@4.70.1...4.71.0>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMzkuMSIsInVwZGF0ZWRJblZlciI6IjQzLjE0MC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6bWlub3IiXX0=-->
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.

2 participants