Skip to content

test(cli): unit tests for plugin command (#794) - #805

Merged
alfredo1996 merged 2 commits into
release/1.0from
fix/issue-794-cli-plugin-tests
May 16, 2026
Merged

test(cli): unit tests for plugin command (#794)#805
alfredo1996 merged 2 commits into
release/1.0from
fix/issue-794-cli-plugin-tests

Conversation

@alfredo1996

@alfredo1996 alfredo1996 commented May 16, 2026

Copy link
Copy Markdown
Owner

Closes #794.

Summary

  • Adds cli/src/__tests__/commands/plugin.test.ts (15 tests)
  • Mocks findProjectRoot, run, output, manifest, validatePluginExport, plus per-test dynamic-import mocks via vi.doMock

Coverage

runPluginAdd:

  • Happy paths: chart plugin, connector plugin (correct manifest + codegen script per type)
  • --overrideoverrides: true in manifest entry
  • --export <name> → export name in manifest entry
  • Already-registered package → warn + still success (idempotent)
  • npm install fails → rollback, no manifest write, exit 1
  • Dynamic import throws → "Failed to import" + rollback uninstall + exit 1
  • Missing named export → "no "X" export" + rollback + exit 1
  • Validator rejects → each error line printed + rollback + exit 1
  • Codegen failure → warn (not fatal)

runPluginList:

  • Built-in counts + external counts + (overrides) marker rendering

runPluginRemove:

  • Chart removal (plugins manifest + chart codegen + npm uninstall)
  • Connector fallback (when not in plugins manifest)
  • Not-registered → error + exit 1
  • npm uninstall failure after manifest update → warn, still success

Why

Plugin command is the public extension point for third-party charts/connectors. Shipping v1.0 with the install/validate/rollback pipeline untested was a reputational risk for the plugin ecosystem story.

Test plan

  • npm -w cli run test → 201 passing, 9 integration skipped
  • npm -w cli run build clean
  • CI green

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suite for plugin management commands, validating installation workflows, manifest registration and updates, listing with built-in and external categorization, removal operations with cleanup, package validation, and error handling with automatic rollback mechanisms.

Review Change Stack

Covers runPluginAdd happy paths (chart + connector), --export named,
--override flag, manifest-collision warning, validator-failure rollback,
npm-install rollback, missing --export rollback, broken-import rollback,
codegen-failure warning; runPluginList counts + overrides marker;
runPluginRemove for chart, connector fallback, not-registered error,
and npm-uninstall warning.

15 new tests. CLI unit suite: 201 passing, 9 integration skipped.

Closes #794.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ff51f6e6-a5c4-49a7-98d7-58321d11afb6

📥 Commits

Reviewing files that changed from the base of the PR and between 17ec7dd and f3f6c4e.

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

Walkthrough

This PR adds a complete test suite for the CLI plugin management commands, covering installation, listing, and removal of external plugins. Tests mock configuration, command execution, manifest operations, and validation—validating happy paths, multiple error/rollback scenarios, and proper output formatting.

Changes

Plugin command test coverage

Layer / File(s) Summary
Test setup and mock infrastructure
cli/src/__tests__/commands/plugin.test.ts (lines 1–86)
Vitest imports and top-level mocks for config, execution, logging, manifest, and validator. Shared package name constants and beforeEach hook that clears mocks, resets exit code, and registers dynamic plugin package mocks.
Plugin add command tests
cli/src/__tests__/commands/plugin.test.ts (lines 87–272)
runPluginAdd suite covering chart/connector installation and codegen; manifest entry with overrides and named exports; idempotent re-add warnings; rollback paths for npm install failure, import failure, missing exports, and validation rejection; non-fatal codegen errors.
Plugin list and remove command tests
cli/src/__tests__/commands/plugin.test.ts (lines 274–377)
runPluginList validates manifest reads, built-in/external counts, and override labels. runPluginRemove validates chart removal, connector fallback, not-registered errors, and warn-on-uninstall-failure behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • alfredo1996/neoboard#606: Tests the same plugin-management implementation from cli/src/commands/plugin.ts (manifest, validator, and import flows).
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title clearly and concisely describes the main change: adding unit tests for the plugin command.
Linked Issues check ✅ Passed All acceptance criteria from issue #794 are met: test file exists with 15 tests covering happy paths, rollback scenarios, --export handling, runPluginList, and runPluginRemove for chart/connector/not-registered cases.
Out of Scope Changes check ✅ Passed All changes are scoped to adding test coverage for plugin commands as specified in issue #794; no unrelated code modifications present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-794-cli-plugin-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.

…st mock cache

The --export test used CHART_PKG which was already dynamically imported in an
earlier test with the default-export mock shape. Vitest's module cache returned
the cached version, so the per-test vi.doMock re-registration with the
named-export shape was silently ignored on CI, causing addToManifest to never
be called and the assertion to fail with `undefined is not iterable`.

Using a distinct package name sidesteps the cache and matches the actual code
path tested (validator + manifest entry recording the --export name).

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@alfredo1996
alfredo1996 merged commit fc4efc0 into release/1.0 May 16, 2026
14 checks passed
@alfredo1996
alfredo1996 deleted the fix/issue-794-cli-plugin-tests branch May 16, 2026 23:57
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