Skip to content

test(cli): add runPick unit tests#2336

Open
Harshithk951 wants to merge 1 commit into
Karanjot786:mainfrom
Harshithk951:test-cli-pick
Open

test(cli): add runPick unit tests#2336
Harshithk951 wants to merge 1 commit into
Karanjot786:mainfrom
Harshithk951:test-cli-pick

Conversation

@Harshithk951

@Harshithk951 Harshithk951 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds comprehensive unit tests for the interactive picker CLI helper runPick inside packages/cli/src/commands/pick.ts.

Related Issue

Closes #2333

Which package(s)?

@termuijs/cli

Type of Change

  • 🐛 Bug fix (type:bug)
  • ✨ Feature (type:feature)
  • 📝 Docs (type:docs)
  • 🧪 Tests (type:testing)
  • ♻️ Refactor (type:refactor)
  • 🎨 Design / UX (type:design)
  • ♿ Accessibility (type:accessibility)
  • ⚡ Performance (type:performance)
  • 🔧 DevOps / CI (type:devops)
  • 🔒 Security (type:security)

Checklist

  • ⭐ You starred the repo. The needs-star check blocks your merge otherwise.
  • Tests pass locally: bun vitest run
  • Build passes: bun run build
  • Typecheck passes: bun run typecheck
  • You read CONTRIBUTING.md.
  • Your PR title follows type: short description.
  • Widget state mutators call markDirty() (if your change affects rendering).
  • No new any types without an inline comment explaining why.
  • No unrelated refactors bundled into this PR.

GSSoC 2026 Participation

  • You are a GSSoC 2026 contributor.
  • Your GSSoC profile: https://gssoc.girlscript.org/profile/Harshithk951

Screenshots / Recordings (UI changes)

N/A

Notes for the Reviewer

None

Summary by CodeRabbit

  • Tests
    • Added coverage for interactive component selection.
    • Verified appropriate handling when interactive input is unavailable.
    • Confirmed selected components are added correctly, including dry-run behavior.
    • Confirmed cancellation exits cleanly without adding a component.

@github-actions github-actions Bot added the type:testing +10 pts. Tests. label Jul 10, 2026
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a Vitest suite for runPick, covering non-TTY rejection, interactive component selection with runAdd, and escape-key cancellation.

Changes

runPick test coverage

Layer / File(s) Summary
Interactive runPick validation
packages/cli/src/commands/pick.test.ts
Mocks registry, add-command, and UI dependencies, then verifies TTY validation, selection handling, dry-run propagation, cancellation logging, and mock lifecycle cleanup.

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

Suggested reviewers: Karanjot786

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: adding unit tests for runPick.
Description check ✅ Passed The PR description matches the template and includes the required issue, package, type, checklist, and reviewer notes sections.
Linked Issues check ✅ Passed The tests cover the linked issue's required behaviors: TTY error, picker invocation, selection handling, and add operation triggering.
Out of Scope Changes check ✅ Passed The changes stay within the stated testing scope and only add the requested runPick test file.
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

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: 1

🧹 Nitpick comments (1)
packages/cli/src/commands/pick.test.ts (1)

21-128: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add inline comments for all any usages and type assertions.

The coding guidelines for **/*.{ts,tsx} require an inline comment explaining every any usage and every type assertion. This file uses any extensively (lines 21, 34, 57, 67, 69, 71, 85, 91, 106, 114, 121, 128) and type assertions via as any (lines 57, 67, 91, 128) without any inline justification.

For mock factory functions, a single comment at the top of each factory (e.g., // any: mock constructor uses dynamic this assignment) would satisfy the guideline. For as any on runPick args, a comment like // as any: test only passes partial CliArgs would suffice.

🤖 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/cli/src/commands/pick.test.ts` around lines 21 - 128, Add inline
comments explaining every any usage and type assertion in the runPick tests.
Place a single justification at the top of each mock factory using dynamic this,
and add targeted comments immediately before each as any assertion, including
partial runPick arguments and mocked component data; ensure all usages in the
test block are covered.

Source: Coding guidelines

🤖 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/cli/src/commands/pick.test.ts`:
- Line 126: Restore the console.log spy created in the cancellation test by
calling consoleSpy.mockRestore() at the test’s end or from its afterEach
cleanup, alongside the existing vi.clearAllMocks() handling; use the consoleSpy
variable to ensure the original console.log implementation is reinstated.

---

Nitpick comments:
In `@packages/cli/src/commands/pick.test.ts`:
- Around line 21-128: Add inline comments explaining every any usage and type
assertion in the runPick tests. Place a single justification at the top of each
mock factory using dynamic this, and add targeted comments immediately before
each as any assertion, including partial runPick arguments and mocked component
data; ensure all usages in the test block are covered.
🪄 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 Plus

Run ID: ac9b54a6-a99e-4fb4-851c-d9dd28ee703f

📥 Commits

Reviewing files that changed from the base of the PR and between 695d11d and 32ee05f.

📒 Files selected for processing (1)
  • packages/cli/src/commands/pick.test.ts

Comment thread packages/cli/src/commands/pick.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Unit Tests for runPick in packages/cli/src/commands/pick.ts

1 participant