Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- A dependency whose `apm.yml` declares `targets: [vscode]` now deploys its instructions, agents and skills into `copilot` projects, like `target: vscode`; it used to be skipped with "Package targets [vscode] do not overlap", so a package rewritten by `apm manifest migrate` silently stopped reaching its consumers. MCP configuration for `vscode` still goes to `.vscode/mcp.json`. (#3864)
- `require_pinned_constraint` accepts exact package release tags such as `shadcn@4.12.0` and `@upstash/context7-mcp@4.4.4` (npm workspaces and Changesets monorepos) as pinned; dist-tags, ranges and partial versions after `@` still fail. -- by @MohammedAlkindi (#3775)
- `apm install` no longer prints a `.github-private` warning when your org has no policy (or keeps it in `.github`); the private-repo hint now appears only with `--verbose`, in `apm policy status`, and in the error under `policy.fetch_failure_default: block`. (#3783)
- With `PROXY_REGISTRY_ONLY=1`, the semver-range error and the registry proxy guide no longer claim the proxy has no listing; they explain that APM fetches exact versions only and name the two supported routes: exact pins with lockfile replay, or a registry implementing the APM Registry HTTP API. (#3777)
Expand Down
19 changes: 9 additions & 10 deletions src/apm_cli/models/apm_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import yaml

from ..core.target_catalog import normalize_target_name
from .dependency import (
DependencyReference,
GitReferenceType,
Expand All @@ -30,6 +29,7 @@
_LEGACY_ALL_TARGET,
_MANIFEST_TARGET_KEYS,
ManifestTargetDeclaration,
canonical_target_names,
)
from .validation import (
InvalidVirtualPackageExtensionError,
Expand Down Expand Up @@ -533,9 +533,7 @@ def __post_init__(self) -> None:
raw_targets.extend(self.target)
elif isinstance(self.target, str):
raw_targets.append(self.target)
self.canonical_targets = tuple(
name if name == "all" else normalize_target_name(name) for name in raw_targets
)
self.canonical_targets = canonical_target_names(raw_targets)

@classmethod
def _parse_dependency_dict(cls, raw_deps: dict, label: str = "") -> dict:
Expand Down Expand Up @@ -966,19 +964,20 @@ def canonical_package_targets(package: object) -> tuple[str, ...]:
return tuple(canonical)
plural = getattr(package, "targets", None)
if isinstance(plural, list) and plural:
return tuple(name if name == "all" else normalize_target_name(name) for name in plural)
return canonical_target_names(plural)
singular = getattr(package, "target", None)
values = singular if isinstance(singular, list) else [singular]
return tuple(
name if name == "all" else normalize_target_name(name)
for name in values
if isinstance(name, str) and name
)
return canonical_target_names(name for name in values if isinstance(name, str) and name)


def canonical_package_target_config(package: object) -> dict[str, object]:
"""Project canonical targets into the compatibility config shape.

The projection is canonical and lossy: ``vscode`` becomes ``copilot``.
MCP destination fidelity (``.vscode/mcp.json``) comes from the
spelling-preserving ``selection`` that builds the effective target
decision, which MCP and LSP installs consult before this config.

Conflicting singular and plural fields remain present so the canonical
parser can reject the authoring error before any MCP write.
"""
Expand Down
21 changes: 16 additions & 5 deletions src/apm_cli/models/manifest_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from __future__ import annotations

from collections.abc import Mapping
from collections.abc import Iterable, Mapping
from dataclasses import dataclass
from functools import cached_property
from pathlib import Path
Expand Down Expand Up @@ -101,6 +101,17 @@ def _warn_deprecated_manifest_keys(data: Mapping[str, Any], manifest_path: Path)
_rich_warning(message, symbol="warning", err=True)


def canonical_target_names(names: Iterable[str]) -> tuple[str, ...]:
"""Resolve declared target names to canonical ones, keeping legacy ``all``.

The single alias rule for both ``target:`` and ``targets:``: ``vscode``
and ``agents`` become ``copilot``.
"""
return tuple(
name if name == _LEGACY_ALL_TARGET else normalize_target_name(name) for name in names
)


def _authored_target_tokens(value: Any) -> list[str]:
if isinstance(value, str):
return [token.strip().lower() for token in value.split(",") if token.strip()]
Expand Down Expand Up @@ -177,12 +188,12 @@ def _validated(self) -> tuple[str | list[str] | None, tuple[str, ...]]:
if "targets" in data:
# Also rejects a manifest that declares both keys.
parsed = parse_targets_field(data)
return (list(parsed) or None), tuple(parsed)
# ``selection`` keeps ``vscode`` for its MCP destination; the
# canonical view resolves it to ``copilot`` for both spellings.
return (list(parsed) or None), canonical_target_names(parsed)
value = parse_target_field(data.get("target"), source_path=self.source_path)
values = value if isinstance(value, list) else [value] if isinstance(value, str) else []
return value, tuple(
name if name == _LEGACY_ALL_TARGET else normalize_target_name(name) for name in values
)
return value, canonical_target_names(values)

@property
def selection(self) -> str | list[str] | None:
Expand Down
40 changes: 40 additions & 0 deletions tests/integration/test_manifest_target_migrate_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,43 @@ def test_dependency_manifest_with_target_does_not_warn(
assert "deprecated 'target:' key" not in result.stdout + result.stderr
assert "compilation.target" not in result.stdout + result.stderr
assert (scenario.project / ".claude" / "rules" / "style.md").is_file()


def test_migrated_dependency_manifest_keeps_its_consumers_deploys(
tmp_path: Path, apm_binary_path: Path
) -> None:
scenario = _Scenario(tmp_path, apm_binary_path, "targets: [copilot]")
package = scenario.project / "packages" / "fixture"
(package / "apm.yml").write_text(
"name: fixture\nversion: 1.0.0\ntarget: vscode\n", encoding="utf-8"
)
scenario.install()
legacy = scenario.deployed()
assert any(name.startswith("project/.github/instructions/") for name in legacy)
scenario.reset_deployment()

migrate = scenario.runner.run(("manifest", "migrate", "--yes"), cwd=package, env=scenario.env)
assert migrate.returncode == 0, migrate.stdout + migrate.stderr
assert "targets: [vscode]" in (package / "apm.yml").read_text(encoding="utf-8").splitlines()
migrated_install = scenario.install()

assert "do not overlap" not in migrated_install.stdout + migrated_install.stderr
# The lock and the vendored copy carry the dependency's migrated manifest;
# every file deployed for the consumer must stay byte-identical.
source_owned = {"project/apm.lock.yaml", "project/apm_modules/_local/fixture/apm.yml"}
migrated = scenario.deployed()
assert {k: v for k, v in migrated.items() if k not in source_owned} == {
k: v for k, v in legacy.items() if k not in source_owned
}

deployed_by_dependency = [
name for name in legacy if name.startswith("project/.github/") and "mcp.json" not in name
]
assert deployed_by_dependency
sentinel = scenario.project / ".github" / "user-notes.md"
sentinel.write_text("mine\n", encoding="utf-8")
uninstall = scenario.apm("uninstall", "./packages/fixture")
assert uninstall.returncode == 0, uninstall.stdout + uninstall.stderr
remaining = scenario.deployed()
assert not any(name in remaining for name in deployed_by_dependency)
assert sentinel.read_text(encoding="utf-8") == "mine\n"
18 changes: 18 additions & 0 deletions tests/unit/models/test_manifest_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from apm_cli.models.apm_package import (
APMPackage,
canonical_package_target_config,
canonical_package_targets,
package_target_declaration,
package_target_selection,
)
Expand Down Expand Up @@ -200,3 +201,20 @@ def test_reinit_prefill_expands_singular_all_with_install_spellings():
assert "vscode" in names
assert "copilot" not in names
assert _declaration(targets=["all"]).prefill_names() == ["all"]


@pytest.mark.parametrize(
"fields",
[{"target": "claude,vscode"}, {"targets": ["claude", "vscode"]}],
ids=["target", "targets"],
)
def test_both_spellings_resolve_vscode_to_copilot_for_dependency_intersection(tmp_path, fields):
"""A package migrated to ``targets: [vscode]`` still deploys to copilot (#3762)."""
manifest = tmp_path / "apm.yml"
dump_yaml({"name": "p", "version": "1.0.0", **fields}, manifest)

assert ManifestTargetDeclaration.from_mapping(fields).canonical == ("claude", "copilot")
assert canonical_package_targets(APMPackage.from_apm_yml(manifest)) == ("claude", "copilot")
assert canonical_package_target_config(APMPackage.from_apm_yml(manifest)) == {
"targets": ["claude", "copilot"]
}
Loading