Skip to content

tests: add unit tests for observal_cli/cmd_scan.py#1369

Open
AnupamKumar-1 wants to merge 1 commit into
BlazeUp-AI:mainfrom
AnupamKumar-1:add-test-cmd-scan
Open

tests: add unit tests for observal_cli/cmd_scan.py#1369
AnupamKumar-1 wants to merge 1 commit into
BlazeUp-AI:mainfrom
AnupamKumar-1:add-test-cmd-scan

Conversation

@AnupamKumar-1

@AnupamKumar-1 AnupamKumar-1 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Closes #1363

Purpose / Description

cmd_scan.py is the entry point for observal scan but had no dedicated unit tests. This PR adds tests/test_cmd_scan.py covering the core scan logic — IDE discovery, MCP table output, --ide filtering, and MCP deduplication.

Fixes

Approach

Created tests/test_cmd_scan.py with 6 test cases organised into 4 classes:

  • TestScanNoIdes — verifies that when no IDE home directories exist, the command exits with code 1 and prints a message.
  • TestScanOneMcp — verifies that a single discovered MCP server appears in the output table and the component count is correct.
  • TestScanIdeFilter — verifies that --ide with an unknown IDE name exits with code 1 and prints an error, and that a valid --ide flag only invokes that adapter.
  • TestScanDeduplication — verifies that an MCP with the same name found in both home and project directories is counted only once.

All external dependencies (get_all_adapters, spinner, Path.is_dir, _is_already_shimmed) are mocked so no Docker or real filesystem is needed.

How Has This Been Tested?

Run the tests locally with:

uv run pytest tests/test_cmd_scan.py -v

Output:

collected 6 items

tests/test_cmd_scan.py::TestScanNoIdes::test_no_ides_found_prints_message_and_exits_1 PASSED
tests/test_cmd_scan.py::TestScanOneMcp::test_single_ide_single_mcp_appears_in_output PASSED
tests/test_cmd_scan.py::TestScanOneMcp::test_single_ide_shows_component_count PASSED
tests/test_cmd_scan.py::TestScanIdeFilter::test_unknown_ide_exits_1_with_error PASSED
tests/test_cmd_scan.py::TestScanIdeFilter::test_known_ide_filter_only_calls_that_adapter PASSED
tests/test_cmd_scan.py::TestScanDeduplication::test_same_mcp_name_from_home_and_project_counted_once PASSED

6 passed in 0.19s

Ruff lint also passes:

uv run ruff check tests/test_cmd_scan.py
# All checks passed!

No Docker required — all external services are mocked.

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)

@CLAassistant

CLAassistant commented Jun 6, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added tests Pull request adds or modifies tests new contributor Pull request from a first-time contributor labels Jun 6, 2026

@Haz3-jolt Haz3-jolt 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.

Well-structured test suite for cmd_scan. Good use of mocking, proper SPDX header, and covers the key paths (no IDEs, single MCP, IDE filter, deduplication). LGTM.

@AnupamKumar-1

Copy link
Copy Markdown
Contributor Author

Thanks for the review and approval. Could someone approve the pending workflows when convenient? Let me know if anything is needed from my side. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new contributor Pull request from a first-time contributor tests Pull request adds or modifies tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for observal_cli/cmd_scan.py

3 participants