Skip to content

Add 55 tests for deps/_utils.py and view.py coverage#682

Open
Copilot wants to merge 3 commits intomainfrom
copilot/test-improver-monthly-activity-2026-04
Open

Add 55 tests for deps/_utils.py and view.py coverage#682
Copilot wants to merge 3 commits intomainfrom
copilot/test-improver-monthly-activity-2026-04

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

Description

Addresses backlog items #4 (commands/deps/_utils.py, 50% coverage) and #5 (commands/view.py, 66% coverage) from the Test Improver tracking issue.

tests/unit/test_deps_utils.py — 43 tests (new file)

  • _is_nested_under_package: nested/boundary/deep nesting cases
  • _count_primitives: all primitive types, root-level files, hooks in both dirs, combined counts
  • _count_package_files / _count_workflows: context dirs, workflow sources, combined
  • _get_detailed_context_counts: per-type counts, singular context/ dir mapping
  • _get_package_display_info: valid yml, empty version, missing yml, malformed yml
  • _get_detailed_package_info: full metadata, no-yml fallback, error path, defaults
  • _scan_installed_packages: ADO 3-level, hidden dirs, .apm/ detection, single-level exclusion

tests/unit/test_view_command.py — 12 new tests

  • _lookup_lockfile_ref: exact match, substring fallback, no match, exception swallowing, None lockfile
  • CLI paths: --global flag, context/workflow/hook display, lockfile ref+commit rendering

All 3,877 tests pass.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Copilot AI and others added 2 commits April 12, 2026 10:33
- 43 tests for commands/deps/_utils.py: _is_nested_under_package,
  _count_primitives, _count_package_files, _count_workflows,
  _get_detailed_context_counts, _get_package_display_info,
  _get_detailed_package_info, _scan_installed_packages
- 12 tests for commands/view.py: _lookup_lockfile_ref (6 tests),
  --global flag, context/workflow/hook display, lockfile ref display
- All 3877 tests pass

Agent-Logs-Url: https://github.com/microsoft/apm/sessions/1c34cfd0-85c8-4350-a475-0395a41f0707

Co-authored-by: sergio-sisternes-epam <207026618+sergio-sisternes-epam@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/apm/sessions/1c34cfd0-85c8-4350-a475-0395a41f0707

Co-authored-by: sergio-sisternes-epam <207026618+sergio-sisternes-epam@users.noreply.github.com>
Copilot AI changed the title [WIP] Review monthly activity for Test Improver in April 2026 Add 55 tests for deps/_utils.py and view.py coverage Apr 12, 2026
@sergio-sisternes-epam sergio-sisternes-epam marked this pull request as ready for review April 12, 2026 11:33
Copilot AI review requested due to automatic review settings April 12, 2026 11:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds targeted unit test coverage for dependency utility helpers and the apm view command to improve confidence in filesystem scanning/counting and lockfile-ref rendering.

Changes:

  • Added a new tests/unit/test_deps_utils.py suite covering apm_cli.commands.deps._utils helpers and edge cases.
  • Expanded tests/unit/test_view_command.py with additional CLI scenarios and direct unit tests for _lookup_lockfile_ref.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/unit/test_deps_utils.py New unit tests for deps utility helpers (scan/count/metadata error paths).
tests/unit/test_view_command.py Additional apm view CLI coverage + focused unit tests for lockfile ref lookup.

Comment on lines +365 to +378
fake_home = Path(tempfile.mkdtemp())
pkg_dir = fake_home / "apm_modules" / "gorg" / "grepo"
pkg_dir.mkdir(parents=True)
(pkg_dir / "apm.yml").write_text(
"name: grepo\nversion: 1.0.0\ndescription: global pkg\nauthor: X\n"
)
with patch(
"apm_cli.core.scope.get_apm_dir", return_value=fake_home,
), _force_rich_fallback():
result = self.runner.invoke(
cli, ["view", "gorg/grepo", "-g"]
)
assert result.exit_code == 0
assert "grepo" in result.output
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_view_global_flag uses tempfile.mkdtemp() to create fake_home but never cleans it up, which can leak temp directories across test runs. Prefer using tempfile.TemporaryDirectory() (or creating fake_home under the existing _chdir_tmp() path) so the directory is always removed.

Suggested change
fake_home = Path(tempfile.mkdtemp())
pkg_dir = fake_home / "apm_modules" / "gorg" / "grepo"
pkg_dir.mkdir(parents=True)
(pkg_dir / "apm.yml").write_text(
"name: grepo\nversion: 1.0.0\ndescription: global pkg\nauthor: X\n"
)
with patch(
"apm_cli.core.scope.get_apm_dir", return_value=fake_home,
), _force_rich_fallback():
result = self.runner.invoke(
cli, ["view", "gorg/grepo", "-g"]
)
assert result.exit_code == 0
assert "grepo" in result.output
with tempfile.TemporaryDirectory() as fake_home_dir:
fake_home = Path(fake_home_dir)
pkg_dir = fake_home / "apm_modules" / "gorg" / "grepo"
pkg_dir.mkdir(parents=True)
(pkg_dir / "apm.yml").write_text(
"name: grepo\nversion: 1.0.0\ndescription: global pkg\nauthor: X\n"
)
with patch(
"apm_cli.core.scope.get_apm_dir", return_value=fake_home,
), _force_rich_fallback():
result = self.runner.invoke(
cli, ["view", "gorg/grepo", "-g"]
)
assert result.exit_code == 0
assert "grepo" in result.output

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +8
import tempfile
from pathlib import Path
from unittest.mock import patch
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests/unit/test_deps_utils.py imports tempfile and patch but does not use them. Removing unused imports keeps the test module clean and avoids future lint/type-check noise.

Suggested change
import tempfile
from pathlib import Path
from unittest.mock import patch
from pathlib import Path

Copilot uses AI. Check for mistakes.
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.

[Test Improver] Monthly Activity 2026-04

3 participants