Skip to content

fix(deps): align _count_package_files to use .apm/context/ (singular) dir#748

Merged
danielmeppiel merged 1 commit intomicrosoft:mainfrom
edenfunf:fix/count-package-files-context-dir
Apr 18, 2026
Merged

fix(deps): align _count_package_files to use .apm/context/ (singular) dir#748
danielmeppiel merged 1 commit intomicrosoft:mainfrom
edenfunf:fix/count-package-files-context-dir

Conversation

@edenfunf
Copy link
Copy Markdown
Contributor

@edenfunf edenfunf commented Apr 17, 2026

What

_count_package_files() in src/apm_cli/commands/deps/_utils.py scanned .apm/contexts/ (plural) for context files, but the canonical directory is .apm/context/ (singular). This caused apm deps list to always report 0 context files for every package, while apm view showed the correct count — a silent, persistent inconsistency.

Before:

context_dirs = ['instructions', 'chatmodes', 'contexts']

After:

context_dirs = ["instructions", "chatmodes", "context"]

Why

.apm/context/ (singular) is the established convention across the codebase:

  • _get_detailed_context_counts() in the same file already maps correctly, with an explicit comment:
    'contexts': 'context'  # Note: directory is 'context', not 'contexts'
  • Primitive discovery in primitives/discovery.py uses "**/.apm/context/*.context.md".

_count_package_files() was the only function using the wrong plural form, so it always traversed a directory that doesn't exist and returned 0.


How

One-character change: 'contexts''context' in _count_package_files(), aligning it with _get_detailed_context_counts() at src/apm_cli/commands/deps/_utils.py:149.

No public CLI interface is affected — apm --help output is unchanged.


Tests

pytest tests/unit/test_deps_utils.py    43/43   pass  (Python 3.13, Windows 11)
pytest tests/unit/                    3908/3908  pass  (no regression)

The test suite covers all public helpers in _utils.py across 8 test classes, adapted from the structure proposed in #682. One test was corrected in the process: test_contexts_dir_counted in #682 created .apm/contexts/ (plural) and expected a non-zero count, which validated the buggy behavior. This PR changes it to use .apm/context/ (singular), so it now correctly documents and pins the fix.

Fixes #704

Copy link
Copy Markdown
Collaborator

@sergio-sisternes-epam sergio-sisternes-epam left a comment

Choose a reason for hiding this comment

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

Good catch on the contexts -> context typo in _count_package_files()! The core fix is correct and the test coverage is solid.

However, this PR bundles several unrelated changes that should be split:

  1. The context dir fix (the actual bug fix for #704) -- great, keep this and its test
  2. Formatting cleanup across _utils.py and _helpers.py (single->double quotes, line wrapping) -- should be a separate PR
  3. start.prompt.md creation in _create_minimal_apm_yml() and init.py changes -- these overlap with #649 which already addresses this exact feature. Merging both would create conflicts.

Could you please scope this down to just the _count_package_files() fix in _utils.py and its corresponding test? The formatting and init changes create unnecessary merge conflicts with other in-flight PRs.

The new test_deps_utils.py test file is welcome -- but please submit it without the init/helpers changes mixed in.

@edenfunf edenfunf force-pushed the fix/count-package-files-context-dir branch from 7d271e6 to 6ab396c Compare April 17, 2026 14:03
@edenfunf
Copy link
Copy Markdown
Contributor Author

@sergio-sisternes-epam Thanks for the thorough review!

Scoped the PR down to just the _count_package_files() fix and the test file — removed the formatting changes from _utils.py / _helpers.py and the init.py changes (noted the overlap with #649). Now it's a single commit touching only src/apm_cli/commands/deps/_utils.py (1-line change) and tests/unit/test_deps_utils.py.

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

Fixes a mismatch in dependency package scanning so apm deps list correctly counts context files by using the canonical .apm/context/ (singular) directory, aligning it with the rest of the codebase and apm view.

Changes:

  • Update _count_package_files() to scan .apm/context/ (singular) instead of .apm/contexts/.
  • Add/adjust unit tests covering _utils.py helpers, including the corrected context directory expectation.
Show a summary per file
File Description
src/apm_cli/commands/deps/_utils.py Aligns context directory scanning to the canonical .apm/context/ to fix incorrect context counts in deps output.
tests/unit/test_deps_utils.py Adds comprehensive unit tests for deps utility helpers and pins the corrected context directory behavior.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread tests/unit/test_deps_utils.py Outdated
Comment thread src/apm_cli/commands/deps/_utils.py
_count_package_files() scanned .apm/contexts/ (plural), which does not
exist. The canonical directory is .apm/context/ (singular), consistent
with _get_detailed_context_counts() in the same file and the discovery
pattern in primitives/discovery.py.

Result: apm deps list always reported 0 context files even for packages
with many .context.md files in .apm/context/. apm view showed the
correct count via _get_detailed_context_counts, making the two commands
disagree.

Verified: pytest tests/unit/ — 3907 passed on Python 3.13, Windows 11

Fixes microsoft#704
@edenfunf edenfunf force-pushed the fix/count-package-files-context-dir branch from 0770011 to 92428b1 Compare April 18, 2026 04:12
@edenfunf
Copy link
Copy Markdown
Contributor Author

Rebased onto the latest main and resolved the conflict with #682's merged test file. Two changes applied on top of main's test_deps_utils.py:

1.Removed unused tempfile and patch imports as suggested.
2.Corrected test_contexts_dir_counted to use .apm/context/ (singular) — the version merged from #682 creates .apm/contexts/ (plural) and expects a non-zero count, which validates the bug this PR fixes. The test now reflects the correct behavior.

Regarding the docs finding — the references to contexts/ (plural) in docs/ and packages/apm-guide/ are pre-existing and outside this PR's scope. Happy to open a follow-up PR to update those if that's the preferred approach.

@danielmeppiel danielmeppiel merged commit 924c088 into microsoft:main Apr 18, 2026
6 checks passed
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.

[BUG] _count_package_files and _get_detailed_context_counts disagree on contexts directory name

4 participants