You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[0.38] fix(pack): honour a package's own targets: exclusion when its cache is missing (#4850) - #4858
Since #4824, apm pack in a Claude+Copilot project refuses when a dependency's apm_modules/<dep> copy is missing unless the lock records the dependency edge excluding Claude. A package that excludes Claude through its own targets: (for example an instruction-only package with targets: [copilot]) was refused too, although it has no Claude guidance to lose.
src/apm_cli/install/target_filter.py (owner of package target authorization) gains two functions. recorded_package_targets(package) returns the package's own restriction: canonical targets:, or empty when absent or all, the same rule resolve_effective_package_targets applies. recorded_targets_exclude(target, recorded) judges a recorded restriction with package_allows_target, the same function install uses.
Install records the restriction at each acquire site (source_helpers.record_package_targets, next to the declared-licence recorder) and attaches it to the lock row as package_targets, like package_type.
_lock_proves_claude_excluded (pack) now accepts either the edge's target subset or the recorded package_targets.
Old lockfiles load unchanged. An absent package_targets proves nothing, so pack still fails closed and apm install records the field. OpenAPM Section 5.2 requires consumers to preserve unknown entry fields, and the lockfile schema admits additional entry properties.
_copy_subset_pairings moves verbatim to models/dependency/subsets.copy_subset_pairings so lockfile.py stays under its 2100-line cap.
Human scope-approval comment: the accepted record on #4850 (status/accepted, milestone 0.38.0).
This PR completes the issue.
Type of change
Bug fix
New feature
Documentation
Maintenance / refactor
Testing
Tested locally
All existing tests pass
Added tests for new functionality (if applicable)
Local pytest is suspended for this team (rule 17); the evidence is PR CI and ci-integration. Failing-before is shown by reasoning: before this change install wrote no package_targets, so the new cell's lock assertion fails, and pack refused with "apm_modules/guard-kit is missing" because the edge declares no targets:.
promise: P-OWN-claude-agents-md-instruction-routing -- pack refuses only a dependency whose Claude guidance could be lost; a package excluding Claude by its own targets: has none (source: #4850 record)
cell: OP=pack SRC=git PRIM=instruction CACHE=missing TGT=claude+copilot PKG-TARGETS=[copilot] EDGE-TARGETS=none owner: install/target_filter.py
instrument: today test -> tests/integration/test_claude_agents_md_pack_lifecycle.py::test_pack_keeps_packing_a_package_whose_own_targets_exclude_claude (extends the #4755 module)
oracles: [lock row records package_targets: [copilot], both pack formats exit 0 with no missing-cache refusal, no Claude rule shipped]
control: test_pack_refuses_a_claude_dependency_whose_cache_directory_is_missing and test_pack_refuses_when_only_a_prompt_was_deployed_without_its_cache (non-excluding packages still refuse, both formats)
owner table: tests/unit/integration/test_pack_claude_exclusion_proof.py (edge / own / includes-claude / all / precedence; old rows load and round-trip)
ledger: tests/fixtures/lifecycle_bug_ledger/bugs/4850.json
One fragment per section, changelog.d/<pr>.<section>.md, holding
one line: user-visible effect first, 25 words or fewer, ending with (#PR); breaking changes only under upgrade notes; no Highlights; no
new lines under ## [Unreleased]. See changelog.d/README.md and .github/instructions/changelog.instructions.md.
…s missing (#4850)
Since #4824, pack refused a missing apm_modules/<dep> unless the lock
recorded the edge excluding Claude, so a package excluding Claude through
its own targets: was over-refused. Install now records that restriction on
the lock row (package_targets, decided by target_filter.recorded_package_targets),
and pack consults it through target_filter.recorded_targets_exclude. Old
lockfiles load unchanged (an absent field proves nothing, so pack still
fails closed). _copy_subset_pairings moves to models/dependency/subsets.py
to keep lockfile.py under its size cap.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical target-metadata validation and stale-manifest issues can falsely establish Claude exclusion, allowing pack to omit guidance rather than refuse when dependency caches are missing.
This PR addresses #4850 by recording a package's own target restrictions during install, allowing apm pack to recognize Claude exclusions when the dependency cache is missing.
Changes:
Persist package target restrictions in lock entries and consult them during pack.
Add regression coverage for both pack formats and older lock entries.
Relocate the subset-pairing copy helper without changing its behavior.
The consumer round-trip fixture and the property generator now cover the
new LockedDependency field.
apm-spec-waiver: package_targets is an APM implementation lock-entry field that OpenAPM Section 5.2 requires consumers to preserve as unknown; no req governs per-entry implementation fields and no normative behaviour changes
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Stale manifest target recording and malformed lockfile target values can falsely exclude Claude, allowing dependencies to be packed without required Claude guidance when their cache is missing.
…ialized manifest (#4850)
A scalar package_targets decoded into single letters and falsely proved
Claude excluded; only a list of strings is a recorded restriction now.
record_package_targets drops the parse-cache entry first, so a manifest
rewritten in this run is re-read.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved findings expose a missing-guidance safeguard bypass through blank target restrictions, quadratic cache scanning during install, and a plugin exclusion test that checks the wrong output path.
Reject blank package targets as proof of Claude exclusion
src/apm_cli/deps/lockfile.py:439
The decoder accepts package_targets: [""] or [" "] as a non-empty restriction, which recorded_targets_exclude() treats as proof that Claude is excluded. With an attested dependency's cache missing and no edge exclusion, pack then skips the missing-guidance refusal despite the malformed restriction. Reject blank elements as no proof and add blank-list cases alongside the scalar controls.
For the plugin-format iteration, this assertion checks the wrong location: Claude rules are exported to instructions/guard.md, not .claude/rules/guard.md (src/apm_cli/bundle/plugin_exporter.py:663-706). The assertion therefore passes even if the plugin incorrectly ships the Claude rule. Check the format-specific output path so both iterations protect the no-Claude-rule requirement.
…ache invalidation (#4850)
invalidate_apm_yml_cache_entry scans the whole parse cache, so calling it per
dependency made install O(N^2). Parse the manifest fresh with from_mapping
instead; behaviour is unchanged.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because an unpublished critical finding shows malformed exclusion evidence can bypass refusal safeguards and omit an attested dependency’s Claude guidance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Since #4824,
apm packin a Claude+Copilot project refuses when a dependency'sapm_modules/<dep>copy is missing unless the lock records the dependency edge excluding Claude. A package that excludes Claude through its owntargets:(for example an instruction-only package withtargets: [copilot]) was refused too, although it has no Claude guidance to lose.src/apm_cli/install/target_filter.py(owner of package target authorization) gains two functions.recorded_package_targets(package)returns the package's own restriction: canonicaltargets:, or empty when absent orall, the same ruleresolve_effective_package_targetsapplies.recorded_targets_exclude(target, recorded)judges a recorded restriction withpackage_allows_target, the same function install uses.source_helpers.record_package_targets, next to the declared-licence recorder) and attaches it to the lock row aspackage_targets, likepackage_type._lock_proves_claude_excluded(pack) now accepts either the edge's target subset or the recordedpackage_targets.package_targetsproves nothing, so pack still fails closed andapm installrecords the field. OpenAPM Section 5.2 requires consumers to preserve unknown entry fields, and the lockfile schema admits additional entry properties._copy_subset_pairingsmoves verbatim tomodels/dependency/subsets.copy_subset_pairingssolockfile.pystays under its 2100-line cap.Issue and approved scope
Issue: Fixes #4850
Human scope-approval comment: the accepted record on #4850 (status/accepted, milestone 0.38.0).
This PR completes the issue.
Type of change
Testing
Local pytest is suspended for this team (rule 17); the evidence is PR CI and ci-integration. Failing-before is shown by reasoning: before this change install wrote no
package_targets, so the new cell's lock assertion fails, and pack refused with "apm_modules/guard-kit is missing" because the edge declares notargets:.Lint mirror clean locally: ruff check/format (0.15.12), pylint R0801, lint-auth-signals, complexity ratchet, assertion-quality ratchet, tm006, architecture boundaries, Mode B (no critical-path diff).
Changelog
changelog.d/<pr>.<section>.md, holdingone line: user-visible effect first, 25 words or fewer, ending with
(#PR); breaking changes only under upgrade notes; no Highlights; nonew lines under
## [Unreleased]. Seechangelog.d/README.mdand.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regenerated