Skip to content

feat(cli): add "testsprite completion" for bash/zsh/fish#184

Open
Andy00L wants to merge 1 commit into
TestSprite:mainfrom
Andy00L:feat/completion
Open

feat(cli): add "testsprite completion" for bash/zsh/fish#184
Andy00L wants to merge 1 commit into
TestSprite:mainfrom
Andy00L:feat/completion

Conversation

@Andy00L

@Andy00L Andy00L commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Adds testsprite completion [bash|zsh|fish]: prints a shell completion script.

Command names, per-group subcommands, and global flags are NOT hardcoded: index.ts walks the fully-assembled Commander program (buildCompletionSpec) and passes a CompletionSpec in, so the generated script can never drift from the real command tree. renderCompletion is a pure function of the spec (unit-testable without a live program). The shell auto-detects from $SHELL when omitted.

Enable it:
eval "$(testsprite completion bash)" # bash
testsprite completion zsh > ~/.zsh/_testsprite
testsprite completion fish | source # fish

  • New command: src/commands/completion.ts (pure renderers + $SHELL detect)
  • 11 unit tests, fully offline

Fixes #74

Summary by CodeRabbit

  • New Features

    • Added a completion command to generate shell completion scripts.
    • Supports bash, zsh, and fish, with automatic shell detection when available (or erroring on unsupported/unknown shells).
    • Completion output is generated from the current CLI command tree, including global flags and appropriate command/subcommand entries.
  • Tests

    • Added a Vitest suite covering shell detection, completion script rendering for bash/zsh/fish, and command behavior for explicit shells vs auto-detect and validation failures.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 569004bc-9c0a-4b7a-b0cc-afbab82ba0da

📥 Commits

Reviewing files that changed from the base of the PR and between fe68ec0 and df8b676.

⛔ Files ignored due to path filters (1)
  • test/__snapshots__/help.snapshot.test.ts.snap is excluded by !**/*.snap, !**/*.snap
📒 Files selected for processing (3)
  • src/commands/completion.test.ts
  • src/commands/completion.ts
  • src/index.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/commands/completion.test.ts
  • src/commands/completion.ts
  • src/index.ts

Walkthrough

Adds shell completion support for bash, zsh, and fish. The new command detects or accepts a shell, builds completion output from the live Commander tree, and prints a generated script. Tests cover helper behavior, rendering, and command execution.

Changes

Shell completion feature

Layer / File(s) Summary
Completion types, shell detection, and renderers
src/commands/completion.ts
Defines shell and completion-spec types, shell detection helpers, and shell-specific completion rendering for bash, zsh, and fish.
Completion command wiring
src/commands/completion.ts, src/index.ts
Adds the completion subcommand, shell validation and auto-detection, stdout writing, and runtime spec construction from the Commander program tree.
Completion unit tests
src/commands/completion.test.ts
Adds tests for shell detection helpers, shell-specific rendering output, and command execution through parseAsync.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CompletionCommand
  participant Index
  participant Renderer
  User->>CompletionCommand: testsprite completion [shell]
  CompletionCommand->>CompletionCommand: isShell(shell) / detectShell($SHELL)
  CompletionCommand->>Index: buildCompletionSpec()
  Index-->>CompletionCommand: CompletionSpec
  CompletionCommand->>Renderer: renderCompletion(shell, spec)
  Renderer-->>CompletionCommand: completion script text
  CompletionCommand-->>User: stdout(script)
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR appears to meet #74, but the required help snapshot update lives in excluded test/snapshots/help.snapshot.test.ts.snap, so full compliance can't be verified. Please include the regenerated help snapshot diff or confirm test/snapshots/help.snapshot.test.ts.snap was updated after rebasing; it was filtered out by the !**/*.snap rule.
✅ 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 is concise and accurately summarizes the main change: adding shell completion for bash, zsh, and fish.
Out of Scope Changes check ✅ Passed The changes stay focused on shell completion wiring, rendering, tests, and command registration, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

🧹 Nitpick comments (1)
src/commands/completion.test.ts (1)

57-91: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider covering stdout/stderr separation.

Per path instructions, machine output must go to stdout while human chatter/hints go to stderr. The tests only assert on injected stdout capture; there's no coverage ensuring validation error messages or hints for an unsupported/undetected shell are routed to stderr rather than stdout.

As per path instructions, "human chatter, hints, and advisories go to stderr" for src/** files.

🤖 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 `@src/commands/completion.test.ts` around lines 57 - 91, The completion command
tests only verify stdout output, but they should also cover that validation
errors and hints are emitted to stderr for unsupported or undetected shells.
Update createCompletionCommand test coverage in createCompletionCommand and its
parseAsync cases by injecting a stderr sink alongside stdout, then assert that
normal completion script output stays on stdout while error/advisory messaging
is routed to stderr for the failing scenarios.

Source: Path instructions

🤖 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 `@src/commands/completion.test.ts`:
- Around line 57-91: The completion command tests only verify stdout output, but
they should also cover that validation errors and hints are emitted to stderr
for unsupported or undetected shells. Update createCompletionCommand test
coverage in createCompletionCommand and its parseAsync cases by injecting a
stderr sink alongside stdout, then assert that normal completion script output
stays on stdout while error/advisory messaging is routed to stderr for the
failing scenarios.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3017b8d1-d345-4207-906d-86b4c843bd19

📥 Commits

Reviewing files that changed from the base of the PR and between b9e9601 and fe68ec0.

⛔ Files ignored due to path filters (1)
  • test/__snapshots__/help.snapshot.test.ts.snap is excluded by !**/*.snap, !**/*.snap
📒 Files selected for processing (3)
  • src/commands/completion.test.ts
  • src/commands/completion.ts
  • src/index.ts

@zeshi-du

zeshi-du commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Approved on content — doctor (#183) landed first and both PRs add a line to the same top-level Commands block in the help snapshot, hence the conflict. Rebase on latest main, regenerate the snapshot (npx vitest run test/help.snapshot.test.ts -u), and it merges on green.

Emit a shell completion script for bash, zsh, or fish. Command names,
subcommands, and global flags are derived from the fully-assembled Commander
tree at call time (buildCompletionSpec walks program.commands), so the script
can never drift from the real command surface. The shell auto-detects from
$SHELL when the argument is omitted.

Fixes TestSprite#74
@Andy00L Andy00L force-pushed the feat/completion branch from fe68ec0 to df8b676 Compare July 6, 2026 23:27
@Andy00L

Andy00L commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main. Ready to merge.

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.

[Hackathon] Add shell completion (bash/zsh/fish)

2 participants