Skip to content

fix(bundle): keep a directory source package out of the bundle path - #3447

Closed
JohnnyXu (xubenqiang) wants to merge 6 commits into
microsoft:mainfrom
xubenqiang:fix/dir-source-package-not-bundle
Closed

JohnnyXu (xubenqiang) wants to merge 6 commits into
microsoft:mainfrom
xubenqiang:fix/dir-source-package-not-bundle

Conversation

@xubenqiang

Copy link
Copy Markdown
Contributor

Fixes #3443

Problem

apm install <dir> takes the local-bundle path whenever the argument is a directory with a plugin.json at its root:

    if path.is_dir():
        if not (path / "plugin.json").is_file():
            return None
        return _build_info(path, is_archive=False, temp_dir=None)

A normal APM source package that has an apm.yml (and no apm pack lockfile) also matches, so apm install ../demo-pkg warns that the bundle "was produced by an older APM version", copies the source tree under the target root instead of integrating it, and records no dependency. Passing the same directory twice resolves it as a normal local dependency — the outcome depends only on the argument count.

Fix

A directory with an apm.yml is a bundle only when its lockfile carries the pack manifest written by apm pack:

        if (path / "apm.yml").is_file() and not _has_pack_manifest(path):
            # An APM source package that happens to ship a plugin.json is a normal
            # local dependency, not a bundle: only packed bundles carry the pack
            # manifest in apm.lock.yaml.
            return None

_has_pack_manifest() reads apm.lock.yaml and checks the pack mapping. Directories without apm.yml keep the current behaviour (legacy bundles that lack a lockfile are still detected), and archives are unchanged.

Verification

I called detect_local_bundle() directly against two fixture directories (the CLI path is the only caller of this function for the reported case):

Before the change:

source package with apm.yml -> BUNDLE demo-pkg
packed bundle with apm.yml  -> BUNDLE packed

After:

source package with apm.yml -> None (dependency)
packed bundle with apm.yml  -> BUNDLE packed

Two regression tests are added to tests/unit/bundle/test_local_bundle.py:

  • test_detect_local_bundle_skips_source_package_with_apm_yml
  • test_detect_local_bundle_keeps_packed_bundle_with_apm_yml

ruff check and ruff format --check pass on both changed files.

Note on the full suite: this machine's sandbox cannot create pytest tmp_path directories (PermissionError on pytest-of-<user>), so the two new tests were verified through the direct call above rather than pytest tests/unit/bundle/test_local_bundle.py. The existing tests in that file are unchanged.

Notes

  • A packed bundle that also ships an apm.yml stays a bundle, which the second test pins.
  • The detection for plugin.json collections without apm.yml is intentionally untouched.

`apm install <dir>` sends every directory with a plugin.json at its root down
the local-bundle path, even when the directory is a normal APM source package
with an apm.yml and no pack manifest. That path warns about an older APM
version, copies the source tree verbatim and records no dependency.

Only treat a directory with an apm.yml as a bundle when its lockfile carries the
pack manifest written by `apm pack`; otherwise it stays a local dependency.

Fixes microsoft#3443

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@sergio-sisternes-epam

Copy link
Copy Markdown
Collaborator

Thank you for contributing this fix. APM starts with an issue, not an implementation (https://github.com/microsoft/apm/blob/main/CONTRIBUTING.md). Please ask a maintainer to review and accept the scope in #3443 before implementation proceeds. This PR is labelled status/deferred until then. Current review requests include Daniel Meppiel (@danielmeppiel) and Sergio Sisternes (@sergio-sisternes-epam).


Generated by autopilot-pr-triage-worker. This comment is AI-generated and may contain errors.

@sergio-sisternes-epam Sergio Sisternes (sergio-sisternes-epam) added status/deferred Not invited for implementation now; no release commitment. triage/recommended Automated advice completed; not human scope approval. type/bug Something does not work as documented. labels Nov 3, 2026
@danielmeppiel Daniel Meppiel (danielmeppiel) removed the status/deferred Not invited for implementation now; no release commitment. label Nov 10, 2026
The scope record on microsoft#3443 requires a regression showing that a single
argument apm install DIR records a source package with apm.yml,
plugin.json and .apm/skills as a local dependency identical to
apm install DIR DIR, while real apm pack output (directory and archive)
and legacy manifestless bundles keep the local-bundle path. The unit
tests only exercise detect_local_bundle; this drives the packaged CLI.
Mutation-break: disabling the apm.yml guard fails the single-arg test.

Addresses scope record 6772320901 Done-when on microsoft#3443.

Co-authored-by: xubenqiang <[email protected]>
Co-authored-by: Copilot <[email protected]>
Bundle detection for directories now requires the apm pack manifest when
apm.yml is present, so the deploy-a-bundle detect step, the fall-through
note and the apm-usage commands reference would otherwise overstate when
a plugin.json directory installs as a bundle. Adds the CHANGELOG entry.

Co-authored-by: xubenqiang <[email protected]>
Co-authored-by: Copilot <[email protected]>
A source package that has already run apm install carries an
apm.lock.yaml without a pack section. The existing unit test only pinned
the no-lockfile case, so a regression treating any lockfile as a pack
manifest would misroute such directories to the bundle path unnoticed.
Mutation-break: returning True for any lockfile fails the new variant.

Addresses CEO follow-up from test-coverage-expert (panel lean, PR microsoft#3447).

Co-authored-by: xubenqiang <[email protected]>
Co-authored-by: Copilot <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator

APM Review Panel: ship_now

Delta pass closes the sole prior gap: the lockfile-without-pack guard is now mutation-proven. Community PR is ready to ship pending CLA.

panel-mode=delta; personas=test-coverage-expert,apm-ceo (prior lean pass: devx-ux-expert, test-coverage-expert, python-architect [adhoc: diff touches a selector of the canonical owner Package format precedence])

cc JohnnyXu (@xubenqiang) Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

The lean panel on 939f811 surfaced exactly one recommended follow-up: the lockfile-without-pack edge lacked a test proving the source-package guard holds under mutation. It was folded at dbc001c with a parametrized unit variant whose mutation-break resistance the test-coverage-expert confirms. The delta panelist returns zero findings.

All nine targeted tests pass on the exact head (4 installed-CLI, 3 unit, 2 architecture-precedence), the lint mirror is silent, and the canonical-owner check (Package format precedence, owner-extension, boundary lint) is clean. The merge of current main touched none of the PR's files, so the prior devx-ux-expert (npm-aligned ./dir semantics) and python-architect (owner-extension correct, no split authority) signals still hold.

One prerequisite is outside the panel's remit: the contributor's CLA is unsigned (license/cla is still queued). The PR cannot merge until JohnnyXu (@xubenqiang) signs it. The issue's suggested rewording of the "older APM version" warning is outside the approved scope record and was left unchanged.

Aligned with: Portable by manifest -- local-directory install follows the same manifest-first resolution regardless of argument count. Pragmatic as npm -- apm install ./dir now matches npm's directory-as-dependency mental model. OSS community driven -- a community fix against a maintainer-scoped issue (#3443).

Panel summary

Persona B R N Takeaway
DevX UX Expert (lean) 0 0 0 Removes argument-count-dependent install behavior; aligns with npm ./dir semantics. No UX regressions.
Python Architect (lean) 0 0 0 Owner-extension correct; non-pack dirs route through the canonical NormalizationPlanner; no split authority.
Test Coverage Expert (delta) 0 0 0 Fold closes the prior finding; lockfile-without-pack variant is mutation-proven. No remaining gap.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Recommendation

All prior findings are resolved, coverage is mutation-proven, and the panel has zero open findings. Ship once the contributor signs the CLA.

Folded in this run

  • (panel) Installed-CLI regression (requires_apm_binary, tests/integration/test_install_dir_source_package_lifecycle.py): single-argument apm install DIR records the local dependency (apm.yml + lockfile source: local) and deploys identically to apm install DIR DIR; real apm pack directory and archive output still install as bundles; legacy manifestless bundles keep the warning and bundle path -- resolved in be1cf3b.
  • (panel) Doc drift: consumer/deploy-a-bundle.md detect step and fall-through note, apm-guide commands.md, CHANGELOG Fixed entry -- resolved in 939f811.
  • (panel) Unit variant: a source package whose apm.lock.yaml has no pack key is not a bundle -- resolved in dbc001c.

Copilot signals reviewed

  • review 5739656277 -- NOT-LEGIT: quota notice only ("unable to review ... insufficient remaining quota"); no review content.

Regression-trap evidence (mutation-break gate)

  • test_single_argument_dir_install_matches_two_argument_dependency_install -- deleted the apm.yml / _has_pack_manifest guard; test FAILED as expected; guard restored.
  • test_detect_local_bundle_skips_source_package_with_apm_yml[no-lockfile] -- deleted the same guard; test FAILED as expected; guard restored.
  • test_detect_local_bundle_skips_source_package_with_apm_yml[lockfile-without-pack] -- replaced the pack-mapping check with return lockfile is not None; test FAILED as expected; guard restored.

Lint contract

The full CI-mirror lint chain passed on dbc001c after merging current main: ruff check and ruff format --check reported nothing, pylint R0801 scored 10.00/10, lint-auth-signals was clean, and lint-architecture-boundaries exited 0.

CI

CI on dbc001c (fork runs approved): 23 SUCCESS, 2 NEUTRAL, 1 SKIPPED, including Lint, Build & Test Shards 1-2, PR Binary Smoke, Lifecycle Smoke, Spec conformance and Merge Gate. Only license/cla is QUEUED (contributor CLA unsigned; not CI). The new installed-CLI module runs in the merge-group integration lane; at the exact head it passed locally: 9 passed in 8.08s (after 0 CI fix iterations).

Mergeability status

PR head stance iterations folds deferrals copilot rounds CI mergeable merge state notes
#3447 dbc001c ship_now 2 3 0 2 green MERGEABLE BLOCKED CLA unsigned; pending required review
Full per-persona findings

DevX UX Expert

No findings.

Python Architect

No findings.

Test Coverage Expert

Lean pass (resolved in dbc001c):

  • [recommended] The source-package guard was untested for the apm.yml plus lockfile-without-pack-key edge, at tests/unit/bundle/test_local_bundle.py:120.
    A source package that already ran apm install carries an apm.lock.yaml without a pack section, and only the no-lockfile and pack-present states were pinned.
    Suggested: Parametrize the skips-source unit test with a lockfile-without-pack variant.

Delta pass: No findings.

This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.


Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors.

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Thank you for this fix, JohnnyXu (@xubenqiang) -- the change itself is in good shape and matches the approved scope on #3443.

We can only merge contributions once the Microsoft Contributor License Agreement (CLA) is signed, and this PR has been waiting on it for more than 7 days. Per our maintainer policy we are closing it for now so the queue reflects what can actually land.

This is not a rejection. As soon as the CLA is signed (follow the license/cla check link above), comment here and we will reopen and merge. Your branch and authorship are preserved.


Posted with AI assistance on behalf of Daniel Meppiel (@danielmeppiel) (APM maintainer backlog policy, 2026-11-11).

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 12, 2026
…3604)

* fix(bundle): keep a directory source package out of the bundle path (#3443)

A directory with apm.yml and a root plugin.json but no pack manifest in
apm.lock.yaml is an APM source package, so 'apm install DIR' now resolves
it as a local dependency, matching 'apm install DIR DIR'. Real apm pack
output, archives and legacy manifestless bundles keep the bundle path.

Credit: approach from #3447 by @xubenqiang.

Co-authored-by: xubenqiang <[email protected]>
Co-authored-by: Copilot App <[email protected]>

* docs(changelog): note single-arg source package install fix (#3604)

Co-authored-by: Copilot App <[email protected]>

---------

Co-authored-by: danielmeppiel <[email protected]>
Co-authored-by: xubenqiang <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage/recommended Automated advice completed; not human scope approval. type/bug Something does not work as documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] apm install <dir> installs a source package as a local bundle when the directory has a root plugin.json

4 participants