apm icon indicating copy to clipboard operation
apm copied to clipboard

[FEATURE] Per-dependency tag pattern so git semver ranges resolve against `@scope/name@version` release tags

Open Leon4ever2802 opened this issue 1 week ago • 2 comments

Proposals are welcome before implementation. For substantive changes, wait for a responsible human maintainer to approve the scope and identify a review contact. An automated recommendation, label alone, or silence is not approval. See Contributing.

Is your feature request related to a problem? Please describe.

Monorepos that release with changesets or similar npm-style tooling tag each package as <package-name>@<version>, usually with an npm scope:

@acme/[email protected]
@acme/[email protected]
@acme/[email protected]

These tags work as exact literal refs:

dependencies:
  apm:
    - git: https://example.com/example-org/catalog.git
      path: skills/foo
      ref: '@acme/[email protected]'

They cannot be used with a semver range. With ref: '^1.2.0', the install fails even though matching tags exist:

No tags on example-org/catalog satisfy '^1.2.0'.
Tags considered: @acme/[email protected], @acme/[email protected], ... (and more).

What I found reading the source (v0.36.1 / main):

  • GitSemverResolver only matches tags against DEFAULT_TAG_PATTERNS (v{version}, {name}--v{version}, {name}-v{version}) plus the bare {version} fallback (src/apm_cli/deps/git_semver_resolver.py).
  • For virtual-subdirectory dependencies, {name} is the last segment of path (git_semver_package_name in src/apm_cli/install/helpers/ref_reuse.py), for example foo. It is never the published package name @acme/skill-foo.
  • The git-dependency call site does not pass tag_patterns. Neither a consumer nor a producer can declare a different pattern for a git dependency. The tag_pattern support from #2366 covers marketplace dependencies only.

Who runs into this. Authors of monorepos with independently versioned packages that depend on sibling packages in the same repository. A typical case is a catalog where two plugins both depend on a shared skill:

[email protected] (released at commit A) -> skills/foo
[email protected] (released at commit B) -> skills/foo

If the plugins reference the shared skill by exact tag or by relative path, each plugin pins it to its own release commit. Installing both plugins then fails with incompatible immutable requirements. A semver range (ref: '^1.2.0') would avoid this: range edges are not part of the immutable-commit check, and the resolver picks one matching tag. With changesets-style tags, though, the range cannot resolve at all.

Today the remaining options are adding a second, APM-specific tag family to every release, or asking every consumer to add root replace rules.

Describe the solution you'd like

An optional tag_pattern field on git dependencies in object form. The git semver resolver uses it instead of the built-in patterns when it resolves a range:

- git: https://example.com/example-org/catalog.git
  path: skills/foo
  ref: '^1.2.0'
  tag_pattern: '@acme/skill-foo@{version}'

This is mostly a manifest field plus passing it through. GitSemverResolver.resolve() already accepts tag_patterns, and build_tag_regex already builds the regex for a pattern.

For monorepos this also works centrally. The producer generates the field into its packages' own apm.yml files, on the edges between sibling packages. Consumers keep installing top-level packages by exact tag and never see or write tag_pattern.

How I would know it works:

  • ref: '^1.2.0' with tag_pattern: '@acme/skill-foo@{version}' resolves to the highest @acme/[email protected] tag that satisfies the range.
  • Tags of other packages in the same repository (@acme/plugin-bar@...) are never candidates.
  • It also works for transitive edges declared in a dependency's apm.yml, not only at the consumer root.
  • The lockfile records the constraint, the resolved tag and the commit, as it does for existing git semver resolutions. apm install replays the locked tag, and apm update / apm outdated use the declared pattern.
  • The pinned-constraint policy check treats these as pinned ranges (see #3731 / #3775 for the literal-tag case).

Boundaries:

  • Opt-in only. Without tag_pattern, the default patterns and fallback behave exactly as today. Exact-tag, branch and SHA refs are unchanged.
  • The pattern must contain {version}. {name} keeps its current meaning. All other text is literal and regex-escaped, so @ and / in scoped names are safe.
  • Pre-release handling follows the existing semver range rules.
  • Out of scope: how multiple requirements for the same dependency are merged. Today the shallowest/first-declared edge wins and ranges are not intersected. Non-overlapping ranges from two parents (e.g. ^0.2.0 and ^0.3.0) therefore resolve silently to one side. That may deserve its own issue, but this request does not depend on it.

Describe alternatives you've considered

  • Producer-declared pattern in the dependency's own apm.yml (e.g. a release-tag pattern next to version). Range consumers would not need to know the tag layout, so this would be nicer. It raises a design question, though: apm would have to read the dependency's manifest before it knows which tag to fetch, e.g. from the parent's commit for same-repository dependencies or from the default branch otherwise. I would be equally happy with this if maintainers prefer it, possibly together with the per-dependency field as an explicit override.
  • Reusing the marketplace build.tagPattern for git dependencies. A single repo-wide pattern does not fit repositories where the tag prefix differs per package (@acme/skill-foo@... vs @acme/plugin-bar@...). apm cannot derive the full package name from the path basename or the manifest name. Primitives that are not marketplace entries would also have no pattern to inherit.
  • Exact literal tags (ref: '@acme/[email protected]'). Reproducible, but they cannot express compatible updates. They cause incompatible immutable requirements as soon as two parents from different release commits share a dependency.
  • A second tag family in a supported format (e.g. foo-v1.2.0 next to @acme/[email protected]). This works with {name}-v{version} today. It doubles the tagging work, though. Because {name} is only the path basename, packages with the same basename in different directories (e.g. skills/foo and agents/foo) would also collide in one tag family.
  • Same-repository relative path: / git: parent. Good while developing on a branch because the child inherits the parent's ref. Two parents from different releases still pin the shared child to two different commits.
  • Consumer-side replace. It can force one source for the shared dependency. It is still a candidate feature, though, and every consumer would have to maintain rules for something the producer could declare once.

Leon4ever2802 avatar Nov 19 '26 08:11 Leon4ever2802

Thanks for the well-researched proposal. The source reading checks out against v0.37.0: GitSemverResolver.resolve() accepts tag_patterns, but git dependencies only use the built-in v{version}, {name}--v{version} and {name}-v{version} patterns. The tag_pattern support from #2366 covers marketplace entries only.

Triage suggestion (advisory, not a maintainer decision): needs-design. The direction is sound, but this adds a manifest field, so a few points need agreement before code:

  • Where the pattern lives: a consumer-side tag_pattern on the git dependency, a producer-declared pattern in the dependency's own apm.yml, or both with a clear precedence. You already named the fetch-order question for the producer option.
  • Lockfile and replay: which fields record the pattern, constraint, tag and commit, so that install, update and outdated agree, including on transitive edges.
  • Policy: confirm that require_pinned_constraint treats these as pinned ranges.
  • Validation: reuse the existing marketplace pattern builder, so one owner validates {version} and escapes literal text.
  • Spec and docs: the OpenAPM manifest text and the dependencies reference would need updating.

Related: #3648 (range grammar for registry ranges). Your acceptance criteria are a good basis for the done-when once the design is settled. Please wait for a maintainer to record scope and a review contact before implementing.


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

danielmeppiel avatar Nov 21 '26 08:11 danielmeppiel

Thanks for the triage.

  1. Where the pattern lives: I'd start with the consumer-side tag_pattern on the git dependency. It is the smallest change, since GitSemverResolver.resolve() already accepts tag_patterns. A producer-declared pattern in the dependency's own apm.yml could follow later, but it needs a decision on fetch order, so I'd keep it out of the first step.

  2. Lockfile and replay: From reading main, the lockfile already records constraint and resolved_tag, and replay_locked_git_semver reuses the locked tag without needing a pattern. So the pattern may not need to be stored. One edge case needs a decision: if only tag_pattern changes and ref stays the same, the constraint still matches the lock and the old tag would be replayed. Should a changed pattern invalidate the locked resolution?

  3. Policy: _constraint_pinning.py classifies the declared constraint only (#3224), so a range such as ^1.2.0 already counts as pinned whatever pattern resolves it. I think a test would be enough here, no behavior change. I haven't run it.

  4. Validation: Happy to reuse validate_tag_pattern / build_tag_regex from marketplace/tag_pattern.py, so one owner validates {version} and escapes literal text.

Leon4ever2802 avatar Nov 23 '26 15:11 Leon4ever2802