Skip to content

fix: 0.36.0 red-team regression sweep (export-patch, view --file, lockfile symlink, audit replay, targeted install, MCP cleanup) - #3672

Merged
Daniel Meppiel (danielmeppiel) merged 56 commits into
mainfrom
danielmeppiel-redteam-0-36-regression-hunt
Nov 13, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 56 commits into
mainfrom
danielmeppiel-redteam-0-36-regression-hunt

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fixes from the 0.36.0 pre-release regression sweep. Six parallel red-team charters built APMLifecycle scenarios that drive the real apm binary over hermetic local Git fixtures. They cover install, install --frozen, update, audit --ci, prune, uninstall, pack, marketplace, export-patch, view --file, policy and user scope. Each scenario asserts the files on disk, apm.lock.yaml, receipts and the exit code after every step, including hand edits, a cold cache, missing receipts and a policy tightened after install.

This PR fixes every confirmed regression and broken promise in a feature merged since v0.35.0. It also adds those scenarios as permanent lifecycle tests.

Regressions fixed

# Regression Introduced by Guarding scenario
1 apm export-patch writes subdirectory package patches with subdirectory-relative paths, so git apply fails from the package repository root #2162 test_export_patch_installed_packages_lifecycle.py::test_export_patch_subdirectory_package_applies_from_repo_root
2 apm export-patch skips every skill and agent edit in Claude plugin packages as "ambiguous source" (the install-generated .apm/ mirror) #2162 test_export_patch_installed_packages_lifecycle.py::test_export_patch_claude_plugin_package_exports_upstream_files
3 apm view --file rejects an absolute path given through a symlinked working directory (macOS /tmp) as outside the project #3608 test_view_file_provenance_symlinked_cwd_lifecycle.py::test_view_file_accepts_logical_absolute_path_through_symlinked_cwd
4 With a symlinked apm.lock.yaml, apm update, apm install --update and apm uninstall apply their changes, fail at the lockfile write, and report "No install transaction changes were committed" #3532 test_lockfile_symlink_update_uninstall_lifecycle.py
5 apm audit --ci reports false unintegrated drift for a local apm.yml package that also ships plugin.json (now routed by apm install DIR) #3604 test_install_dir_plugin_audit_lifecycle.py
6 A targeted apm install PKG removes a transitive dependency that an unselected local package still needs after its apm.yml was edited #3528 x #3571 test_targeted_install_shared_transitive_lifecycle.py
7 Removing a slashed self-defined MCP server deletes a user-authored server entry (or a still-declared short-name server) from VS Code, Cursor, Copilot and OpenCode configs #3493 test_mcp_slashed_server_cleanup_lifecycle.py

Each guard fails on main's src/ (11 failed, 4 controls passed) and passes with this PR (15 passed).

Permanent lifecycle coverage added

32 new tests/integration/*_lifecycle.py modules (79 tests), with shared kits in tests/integration/_*_kit.py. The six fix-guard modules carry lifecycle_smoke. The others run in the merge-group integration shards. They protect the 0.36 flows: cold restore and update without receipts, upgrades from a 0.35.1 lockfile, multi-target edit, audit and narrow, pre-compile trust, Cursor user scope, MCP secrets and user entries across six targets, user hook $HOME migration, marketplace pack to consumer chains, pack bundle round trips, policy tightened after install, lifecycle deny_all, Claude profiles, user-scope agreement, init flags, Git-semver pre-releases, registry-only mode, TLS hints, monorepo switches, SSH cache transport and local graph reconciliation.

Broken promises fixed in the same sweep (fix wave)

Every finding that broke a documented promise was fixed here as well, through the canonical owner for that decision. Each fix has a lifecycle guard that fails on the pre-fix src/ and passes with it, and a python-architect review (all APPROVE, no blocking findings).

Issue Promise restored Owner routed through Guard
#3655 compile never overwrites hand-authored context files compilation/root_context_protection.py (any depth) test_compile_nested_context_protection_lifecycle.py
#3656 a refused uninstall leaves a truthful lockfile install/manifest_reconcile.py target contraction + install/selected_cleanup.py test_uninstall_refusal_lockfile_truth_lifecycle.py
#3657 PROXY_REGISTRY_ONLY locks replay under --frozen ArtifactoryRouter.routing_target / routes_to_locked_proxy test_registry_only_chain_lifecycle.py
#3658 audit applies the deny list to transitives like install policy_checks.resolved_policy_dependencies (shared seam) test_policy_cache_transitive_lifecycle.py
#3659 audit --no-cache fetches fresh policy single discovery call in commands/audit.py test_policy_cache_transitive_lifecycle.py
#3661 profile uninstall touches only the selected profile commands/uninstall/profile_scope.py test_profile_uninstall_runtime_scope_lifecycle.py
#3663 stale cleanup deletes only on a matching recorded hash integration/cleanup.py gate 3 test_stale_cleanup_hash_authority_lifecycle.py
#3664 uninstall removes recorded MCP servers after the runtime dir is pruned install/mcp/ownership.project_mcp_cleanup_reachable test_mcp_pruned_runtime_dir_cleanup_lifecycle.py
#3665 removed hook files retire their merged events hook_ownership.drop_source_entries (extracted from Cursor) test_hook_removed_file_event_retirement_lifecycle.py
#3666 apm mcp install exits like apm install --mcp install/outcome.py via standalone Click test_mcp_edit_policy_chain_lifecycle.py
#3667 audit replays local packages as install materializes them install/phases/local_content.materialize_local_package test_local_link_audit_replay_lifecycle.py
#3668 prune keeps dependencies still reachable deps/reachability.retained_lock_keys test_dropped_direct_dependency_transitive_lifecycle.py
#3669 uninstall writes the lockfile install would write; frozen never reports a write compute_forward_reachable_keys(dev_refs=...), LockFile.write result test_update_dev_reachability_lifecycle.py
#3670 pack and marketplace producer hints, refs and bundles marketplace/ref_resolver, hook_source_selection, local_bundle_paths test_marketplace_pack_producer_refs_lifecycle.py
#3671 deps list keys work with uninstall host_providers.classify_host_provider, shared display key test_deps_list_uninstall_key_lifecycle.py

Architecture hygiene in this PR: three private helpers were promoted to public owner APIs (MCPClientAdapter.determine_config_key, ArtifactoryRouter.routing_target, resolve_relative_hook_script), duplicated preflights were collapsed into owner functions (refuse_lockfile_before_mutation, plan_inputs.confirm_update_plan), and new or extended static guards each have a sorted MutationCase. Install modules stay within their LOC budgets.

Maintainer decisions implemented

  • #3662 (option C): apm install --frozen keeps the files, checkout and lockfile rows of a dependency removed from apm.yml, deletes nothing, writes no lockfile, and names the kept packages. A normal apm install removes them. Guard: test_frozen_undeclared_package_retention_lifecycle.py.
  • #3660 (option A): the policy docs state that org policy governs project installs only, and that apm install -g is not governed today. Docs only.
  • #3654 (option B, BREAKING): apm install --frozen re-verifies every deployed file against deployed_file_hashes through the verifier apm audit --ci uses, and exits 1 naming each path with its expected and observed hash, at project and user scope. Guards: test_frozen_deployed_hash_lifecycle.py and the CLI conformance test for req-lk-017. The CHANGELOG has a migration line.

Review folds

The panel advisory (lean: supply-chain-security, test-coverage, python-architect, CEO) found no blocking items. Its follow-ups are folded: a user-scope frozen hash guard, direct tests for the case-equivalent lookup, and an owner record for MCP config-key derivation. All six Copilot review threads are fixed and resolved:

  • per-package profile scoping in batched uninstalls;
  • unconditional symlinked-lockfile refusal on update;
  • lexical symlink validation for packed hook scripts;
  • ${CLAUDE_PLUGIN_ROOT} anchoring of packed scripts;
  • path-specific mirror evidence for export-patch;
  • legacy marker retirement for hooks.

Follow-ups filed

#3700 (register plugin hooks from local bundles), #3701 (cleanup evidence beyond lockfile hashes). Variants are noted on #1894 and #3525.

Issue and approved scope

Issue: Fixes #3649

Also fixes #3655, fixes #3656, fixes #3657, fixes #3658, fixes #3659, fixes #3661, fixes #3663, fixes #3664, fixes #3665, fixes #3666, fixes #3667, fixes #3668, fixes #3669, fixes #3670, fixes #3671, fixes #3660, fixes #3662

Human scope-approval comment: #3649 (comment)

Does this PR complete the issue, or what remains? It completes #3649: every confirmed regression and broken promise has a scenario that fails without its fix and passes with it. The three findings that needed a product decision (#3654, #3660, #3662) were decided by the maintainer and are implemented here, and the follow-ups are filed (#3700, #3701).

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Validation evidence (local, -p no:xdist):

  • Fix guards against main src/: APM_BINARY_PATH=.venv/bin/apm pytest <6 guard modules>: 11 failed, 4 passed (controls).
  • Fix guards with this PR: 15 passed.
  • All 32 new lifecycle modules, run one at a time: 79 passed, 1 skipped (opt-in baseline-binary test).
  • Related unit tests (export-patch, uninstall, lockfile, drift, package selection, pipeline, MCP integrator, view provenance, update): 745 passed. MCP stale cleanup and config key suites: 1345 passed.
  • Existing integration: test_export_patch_e2e.py test_lockfile_symlink_write_e2e.py test_targeted_install_dropped_dependency_lifecycle.py test_uninstall_multi_e2e.py test_install_dir_source_package_lifecycle.py: 22 passed, 2 skipped.
  • Lint contract: ruff check and ruff format --check clean; pylint R0801 10.00/10; scripts/lint-auth-signals.sh clean; scripts/lint-architecture-boundaries.sh clean; file length and relative_to guards clean.

Spec conformance (OpenAPM v0.1)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

apm-spec-waiver: restores promised behavior of features merged since v0.35.0; no OpenAPM requirement changes

@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-redteam-0-36-regression-hunt branch from bd2135f to 6fe9adf Compare November 12, 2026 22:13
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 12, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 12, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…epo root (#3649)

A git: + path: (or marketplace git-subdir) dependency is cached as just
its subdirectory, so exported diff paths were relative to that
subdirectory while the patch header says to apply from the package
repository root; git apply failed with 'No such file or directory'.
Prefix the locked virtual_path for subdirectory packages.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Install normalizes a Claude plugin (no apm.yml) by mirroring skills/,
agents/ and commands/ into .apm/ inside the cache. export-patch indexed
both copies, so every skill or agent edit in a marketplace plugin was
skipped as 'ambiguous source'. When the cache carries the parser-owned
normalization receipt, prefer the upstream candidate over the .apm/
mirror.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
apm view --file "$PWD/<file>" exited 2 ('outside the project deploy
root') whenever the working directory was reached through a symlink
(macOS /tmp and /var, symlinked workspaces): the deploy root comes from
the physical getcwd() while the query kept its logical parents. When
the lexical query is not under the deploy root, resolve only its parent
directory so the queried leaf stays exact.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ins (#3649)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… writes (#3649)

apm update, apm install --update and apm uninstall detected a symlinked
apm.lock.yaml (#3532) only when writing the lockfile, after deploying new
files, cleaning stale ones and editing apm.yml. The command then exited 1
with the lockfile still describing the old state, and update reported that
no transaction changes were committed. ensure_lockfile_writable() is now
the single owner of the rule; LockFile.write uses it, and update (when the
plan changes the graph) and uninstall (when it removes a locked package)
call it before any other write, so the transaction rolls back cleanly.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…kage (#3649)

apm install DIR (routed by #3604) and manifest-declared local deps classify
a directory with apm.yml and a root plugin.json as apm_package and deploy
only its .apm/ primitives. The audit --ci replay normalized any local dir
with a plugin.json as a legacy plugin, integrating root agents/ and failing
drift on a fresh install. Route the replay through detect_package_type,
the same classifier install uses.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ry may need (#3649)

apm install PKG drops the selected package's former descendants that this
run's graph no longer contains (#3528). With #3571 the graph is rebuilt from
the current apm.yml of every local package, so an unselected sibling edited
since it was locked makes the graph omit retained entries it still locks.
A shared dependency of such an entry was then removed while the entry stayed
locked, leaving apm.lock.yaml without that entry's dependency while audit
and prune passed. When the graph omits any retained entry it cannot prove the
candidate unneeded, so drop nothing; the next full install reconciles.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ed (#3649)

Stale MCP cleanup expanded every stale name to its last path segment, so
removing self-defined com.example/server deleted a user-authored or
still-declared 'server' entry from VS Code, Cursor, Copilot and OpenCode.
Self-defined servers keep their declared key (#3493) and older truncated
keys are reconciled only under ownership proof at install time, so derive
the alias from the adapter key owner with self-defined context.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
)

Permanent APMLifecycle scenarios from the 0.36.0 pre-release sweep.
They drive the real apm binary over hermetic local Git fixtures across
install, install --frozen, update, audit --ci, prune, uninstall, pack,
marketplace, export-patch, view --file, policy and user scope. They
assert disk, lockfile, receipts and exit code after every step.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
apm-spec-waiver: restores promised behavior of features merged since v0.35.0; no OpenAPM requirement changes

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…MCP config-key through canonical owners (#3649)

Fix 2: export_patch now routes .apm/ mirror classification through
plugin_parser.is_install_generated_mirror() instead of hard-coding
.apm/ prefix knowledge. The normalization owner decides what is a
mirror.

Fix 4: lockfile symlink write-guard consolidated into
refuse_lockfile_before_mutation() in deps/lockfile.py (single owner).
Both pipeline.py and uninstall/cli.py now call this owner API.
Added owner registry guard contracts-tooling-lockfile-symlink-write-guard
with a MutationCase proving its teeth.

Fix 7: MCPClientAdapter._determine_config_key promoted to public
determine_config_key(). All 17 call sites (adapters, integrators,
ownership, cleanup) updated. No cross-module private access.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Distributed compile replaced a hand-authored subdirectory AGENTS.md or
CLAUDE.md that carries no APM marker, then treated the replaced file as
generated output and reported it as orphaned. The canonical owner
hand_authored_root_context_blocks_write now applies its marker rule to
catalog context filenames at any depth, the AGENTS.md and CLAUDE.md call
sites route every placement through it, and nested Git repository skips
are decided before protection so their accounting is unchanged. The
static guard pins the any-depth rule, with mutation cases.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…3656)

When apm uninstall stopped because a tracked target file was edited or a
user file sat in a managed skill directory, it had already removed the
package's other target files but left apm.lock.yaml claiming all of them.
The target-contraction owner (reconcile_target_deployed_files) now reports
what each selected dependency still owns through SelectedCleanupOutcome,
and the refusal applies it via DeploymentLedgerCodec.replace_legacy_owners
and writes the lockfile, so it claims only files still on disk while
apm.yml keeps the package for the retry. Preserved profile rows stay
claimed. The retained-edit warning now carries its [!] symbol.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…file uninstall (#3661)

A global uninstall retained for another Claude/Hermes profile removed rows
under every USER_ROOT_ENV_VARS target's selected root, so a HERMES_HOME
profile uninstall also deleted ~/.claude files (and vice versa).
profile_scope now shares one other-profile record walk and removes only the
selected roots of the runtimes whose profiles split the package.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A transparent registry proxy records the proxy host and registry_prefix
instead of the upstream host, so drift classified every such row as a
provider change and --frozen refused the lock the proxy had just written.
ArtifactoryRouter now owns the proxy routing target (promoted from the
resolver's private copy) and answers whether a dep routes to a locked proxy
row; drift, download-ref replay and the cached-commit owner reuse it.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The explicit --policy and auto-discovery branches now share one discovery
call that always forwards no_cache, so 'apm audit --ci --no-cache' fetches
the org policy fresh as documented.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…tives (#3658)

main's source-dependency owner (#3606) already runs the allow and deny
checks over effective direct deps plus locked transitives. This keeps
the installed-CLI guard that install and audit --ci agree.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…elative hook scripts (#3670)

- apm pack on a branch-ref marketplace package no longer suggests the
  nonexistent --allow-head flag; it names the real recovery command
  (apm marketplace package set <pkg> --ref <tag-or-sha>).
- marketplace package add/set --ref verify the ref on the entry's own host
  through the explicit-ref owner shared with marketplace check
  (ref_resolver.explicit_ref_error, package_entry_coordinates): a missing
  tag or unreachable remote exits 2 without changing apm.yml; --no-verify
  keeps the opt-out. Previously a non-default host looked 'network
  unavailable' and any missing tag was stored with exit 0.
- apm pack carries hook scripts referenced as ./scripts/x from .apm/hooks
  the way install resolves them (resolve_relative_hook_script, promoted to
  public) and repoints the packed command.
- Owner record marketplace-entry-ref-verification + AC10 guard + MutationCase.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…in bundle installs (#3670)

- apm pack keeps not following own-source symlinks (matching own-project
  install), but now names each dropped link in a pack warning instead of
  dropping it silently. The existing exporter walkers record the skipped
  links; both bundle exporters warn through _emit_pack_warning.
- apm install <bundle> no longer copies a Claude plugin bundle's hooks.json
  raw into the target root or lowers hooks/ scripts through the hook
  descriptor extension (fmt.sh -> fmt.sh.json). The local-bundle routing
  owner (install/local_bundle_paths.py) skips plugin-native hook paths and
  reports one bundle_deploy_skip_warning per file; deployed-layout bundles
  keep routing their target hook files. Merging bundle hooks through the
  hook integrator is a follow-up.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…uned (#3664)

Removing a dependency prunes an emptied .claude/ or .opencode/ before MCP
stale cleanup runs, and remove_stale reused those write opt-in directories
as cleanup gates, so the recorded server stayed in .mcp.json or
opencode.json while its ledger ownership was dropped (apm uninstall and
apm install after removing the dependency).

install/mcp/ownership.py, the safe-removal owner, gains
project_mcp_cleanup_reachable: ledger-scoped cleanup (an explicit runtime
from the ownership ledger) stays reachable, otherwise the opt-in dir still
gates. remove_stale routes both gates through it; Claude removal stays
content-verified by require_removable_mcp_connections. The
install-deployment-mcp-ownership-migration guard requires that route and
rejects a raw .claude/.opencode is_dir gate in mcp_integrator.py, with a
mutation case.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
)

Merged hook targets cleared a source's earlier entries only for the
events its current hook files declare. Deleting one hook file from a
package or the root .apm/hooks while another remained left the old event
entry in .claude/settings.json and apm-hooks.json, pointing at a deleted
script, and apm audit --ci then reported drift.

hook_ownership.py gains drop_source_entries, extracted from Cursor's
inline whole-source clear. HookIntegrator now uses it for that clear and,
after merging, to drop the source's entries from every event it did not
re-declare, so hook_integrator.py shrinks. The neutral-hook-contract
guard requires both calls and forbids a second definition, with a
mutation case.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
apm mcp install forwarded to apm install --mcp with
cli.main(standalone_mode=False), which returns ctx.exit codes instead of
raising them, so a failed forwarded install (for example an org policy
block) exited 0. Run the forwarded command in standalone mode so its exit
comes from install/outcome.py and Click's error handling exactly as for
apm install. The install-deployment-outcome guard rejects
standalone_mode=False under commands/, with a mutation case.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
apm deps list showed a self-hosted GitLab dependency (type: gitlab) by its
host-blind org/repo key with Source github, while apm deps tree showed
the host-qualified key and apm uninstall only accepts that identity.
deps list now shows the key deps tree derives (_dep_display_key, extracted
from _dep_display_name) for remote locked dependencies, keeping
host-blind keys for orphan detection, and labels Source through the
canonical classify_host_provider with the declared or locked host_type.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…d hash (#3663)

Stale, orphan, contraction, prune and uninstall cleanup all route through
integration/cleanup.py::remove_stale_deployed_files. Its provenance gate
deleted any lockfile-claimed file without a recorded hash (legacy
fall-through), so a hand-edited lockfile could make a receipt-less install
delete user files. Gate 3 now keeps such files with a warning and reports
them as retained, matching the documented rule that stale files are removed
only when recorded hashes match. cowork:// rows stay exempt because install
records no hashes for them yet. enterprise/security.md now states that a
committed apm.lock.yaml is reviewed input with cleanup authority.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…3667)

apm install copies a local package with materialize_local_package, which
dereferences in-package links and materializes single files. The audit
--ci replay integrated straight from the source tree, where integrators
skip links, so a clean install of a package with a contained link reported
its deployed file as orphaned drift.

materialize_local_package is now the one raising owner of the local
package image: install (_copy_local_package), the uninstall survivor
refresh and audit replay (materialize_local_package_for_replay) all copy
through it. path_anchoring.resolve_local_dep_base owns the admission
anchor for a locked local dep. The replay's raw-directory branch, the
file-only replay materializer and the legacy-plugin normalizer's extra
copy are gone. The single-file owner guard, registry record and mutation
cases now pin the shared routes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add guard hooks-integrations-mcp-config-key-derivation to the existing
mcp-package-launcher owner in hooks-integrations.json, with a static
check in mutation_mcp_target_and_scope.py that verifies:
  - determine_config_key exists as a definition in MCPClientAdapter
  - MCP consumers (mcp_integrator, mcp_integrator_install, mcp/ownership)
    route through determine_config_key() and do not re-derive config keys
    by splitting on "/"

MutationCase proves the guard fires when the definition is renamed.
Frozen rule inventory updated in test_architecture_runner.py.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Parametrize the warm kept-edit frozen guard over project and user scope:
apm install -g, tamper with a deployed skill under the isolated HOME,
then apm install --frozen -g must exit 1 naming the path with expected
and observed hashes and leave $APM_HOME/apm.lock.yaml byte-identical;
after the user resolves the edit and runs apm install -g, --frozen -g
exits 0.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

Red-team regression sweep hardens 0.36.0 across 18 surfaces; frozen hash verification (BREAKING, req-lk-017) is the headline security win.

panel-mode=lean; personas=supply-chain-security-expert,test-coverage-expert,python-architect,apm-ceo

All three panelists agree: no blocking findings and no dissent. The supply-chain-security review passed every security-relevant surface with no regressions: the hash-required cleanup gate, frozen re-verification, host-gated proxy equivalence, isolated scratch replay, and path anchoring. On a sweep this broad (204 files, 18 fixes), that is the signal that matters most.

The test-coverage review raised three recommended findings, each with evidence. The missing direct coverage for installed_package_path is folded (5b0467c; mutation-checked unit tests plus a reachability walk through a case-variant install). The user-scope (-g) frozen deployed-hash gap was outcome: missing on a secure-by-default surface, so it carried near-blocking weight; it is now folded (097b3e3: parametrized over project and user scope, and it fails when verification is bypassed for user scope). The cowork lifecycle case passes at unit tier and needs a OneDrive fixture, so it is tracked on #3701 with the cleanup evidence model.

The python-architect finding was that MCPClientAdapter.determine_config_key had been promoted to public without registry coverage. It is folded in 47ec465: the mcp-package-launcher owner now covers config-key derivation, with a static guard against inline slash-based key derivation and one MutationCase.

Aligned with: secure by default (frozen hash verification and hash-required cleanup); governed by policy (scratch replay isolation, frozen orphan retention with an info line); portable by manifest (export-patch repository-root paths, lockfile symlink guard, case-equivalent prune lookup); pragmatic as npm (targeted install, prune and deps list agree with each other).

Panel summary

Persona B R N Takeaway
Supply Chain Security Expert 0 0 0 Cleanup gate 3 requires a matching hash; cowork and symlink exemptions are contained; frozen re-verification is correct; proxy equivalence is host-gated; scratch replay is isolated; path anchoring is sound.
Test Coverage Expert 0 3 0 Gaps: user-scope frozen hash drift, cowork and symlink lifecycle coverage, direct installed_package_path coverage. Two are folded; one is tracked.
Python Architect 0 1 0 Single-owner discipline holds across all fixes; one promoted public API lacked a registry guard, now folded.

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

Top 3 follow-ups

  1. [Test Coverage Expert] User-scope (-g) parametrization of test_frozen_deployed_hash_lifecycle.py. -- outcome=missing on a secure-by-default and governed-by-policy surface. Folded in 097b3e3.
  2. [Python Architect] Owner record, static guard and MutationCase for MCPClientAdapter.determine_config_key. -- Every other public promotion in this PR routes through an owner. Folded in 47ec465.
  3. [Test Coverage Expert] Installed-CLI lifecycle coverage for the cowork exemption and the managed final-symlink unlink. -- Unit assertions hold; a lifecycle case needs a OneDrive fixture. Tracked on [BUG] Stale cleanup still trusts a lockfile hash that matches a file APM never deployed #3701.

Recommendation

Both folds have landed on head 097b3e3, so this PR is ready to ship once CI confirms green on that head. The cowork lifecycle gap is tracked and should not hold the sweep. The BREAKING change (--frozen hash verification) has a CHANGELOG migration line and reinforces APM's secure-by-default positioning. It is a break that earns community trust rather than eroding it.


Full per-persona findings

Supply Chain Security Expert

No findings.

Test Coverage Expert

  • [recommended] Frozen deployed-hash drift detection ([BUG] apm install --frozen after an APM upgrade rewrites deployed files and then fails apm audit --ci hash drift #3654) was tested only at project scope, at tests/integration/test_frozen_deployed_hash_lifecycle.py.
    verify_deployed_file_hashes resolves paths against the deploy root, which at user scope is $HOME. No test exercised the hash-mismatch path for --global.
    Proof (missing at): tests/integration/test_frozen_deployed_hash_lifecycle.py::test_frozen_hash_drift_at_user_scope_fails_closed -- proves: apm install --frozen --global exits 1 and names drifted paths. [secure-by-default,governed-by-policy]
  • [recommended] The cleanup gate 3 cowork exemption and the managed final-symlink unlink have unit coverage but no lifecycle coverage, at src/apm_cli/integration/cleanup.py:390.
    Proof (passed): tests/unit/integration/test_cleanup_helper.py::test_cowork_stale_entry_deletes_real_file -- proves: cowork stale entries are deleted without a hash provenance check. [secure-by-default,multi-harness-support]
  • [recommended] The new installed_package_path had no direct test, at src/apm_cli/models/dependency/materialization.py:333.
    Proof (passed): tests/integration/test_prune_casing_cli.py::test_prune_casing_real_cli -- proves: prune preserves a case-equivalent GitHub package directory (direct-dependency path only). [portability-by-manifest,devx]

Python Architect

  • [recommended] MCPClientAdapter.determine_config_key was promoted to public without its own owner registry entry or boundary guard, at src/apm_cli/adapters/client/base.py:1557.
    With 17+ call sites, a future module could re-derive a config key from a name or URL without a lint flagging the split authority.
    Suggested: register config-key derivation with a boundary guard against inline re-derivation.

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

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.

🟡 Changes recommended

Batched uninstalls can delete files that separate uninstalls preserve, while symlinked-lockfile updates can modify deployments before failing to save the deployment ledger.

6 open issues
What changed in this PR

This PR addresses regressions found during the 0.36.0 lifecycle sweep (#3649), strengthening consistency between installation, audit, cleanup, and package export.

Changes:

  • Fixes dependency retention, profile-scoped cleanup, frozen-install verification, and MCP ownership handling.
  • Reuses shared logic for local-package replay, proxy routing, hook resources, and update preflights.
  • Adds regression coverage, architecture guards, and documentation for restored behavior and known limitations.
File Description
tests/​unit/​test_view_file_provenance.py Covers symlinked working-directory paths.
tests/​unit/​test_scoped_mcp_server_names.py Updates the naming-owner diagnostic.
tests/​unit/​test_prune_command.py Tests hash-gated prune cleanup.
tests/​unit/​test_prune_casing.py Patches the canonical materialization lookup.
tests/​unit/​test_plugin_exporter.py Tests skipped-link reporting.
tests/​unit/​test_mcp_command.py Tests forwarded install exit codes.
tests/​unit/​test_deps_list_tree_info.py Tests declared GitLab host labels.
tests/​unit/​test_claude_mcp.py Clarifies broadcast cleanup behavior.
tests/​unit/​test_audit_policy_command.py Covers policy cache controls.
tests/​unit/​scripts/​test_architecture_runner.py Registers new guard expectations.
tests/​unit/​models/​test_dependency_materialization.py Tests installed-path casing resolution.
tests/​unit/​integration/​test_hook_integrator_defect_regression.py Covers hook retirement and cleanup hashes.
tests/​unit/​integration/​test_deployed_files_manifest.py Supplies hash evidence for hook cleanup.
tests/​unit/​integration/​test_cleanup_helper.py Verifies unhashed files are retained.
tests/​unit/​install/​test_sources_phase3.py Tests proxy rows without commit identity.
tests/​unit/​install/​test_sources_materialisation.py Covers cached proxy commit handling.
tests/​unit/​install/​test_repo_to_subdirectory_switch.py Makes non-frozen fixture state explicit.
tests/​unit/​install/​test_replacement_source_consumers.py Updates replacement replay expectations.
tests/​unit/​install/​test_partial_subtree_reconciliation.py Protects dependencies with incomplete reachability evidence.
tests/​unit/​install/​test_mcp_self_defined_declared_keys.py Uses the public config-key owner.
tests/​unit/​install/​test_mcp_ownership.py Covers cleanup after runtime-directory pruning.
tests/​unit/​install/​test_local_edit_hint.py Separates rendering changes from local edits.
tests/​unit/​install/​test_install_local_bundle.py Tests plugin-hook skip warnings.
tests/​unit/​install/​test_frozen.py Tests withheld writes and deployed hashes.
tests/​unit/​install/​test_drift.py Supplies valid local replay packages.
tests/​unit/​install/​test_drift_detection.py Verifies scratch-tree local materialization.
tests/​unit/​install/​phases/​test_lockfile_orphan_prune.py Preserves retained orphan target attribution.
tests/​unit/​install/​phases/​test_cleanup_phase.py Tests frozen retention and unhashed claims.
tests/​unit/​compilation/​test_managed_section.py Checks safe handling of external symlinks.
tests/​unit/​commands/​test_marketplace_plugin.py Tests explicit refs and source hosts.
tests/​unit/​commands/​test_marketplace_coverage.py Covers verification failure and opt-out.
tests/​unit/​commands/​test_install_phase3w4.py Updates frozen verification message expectations.
tests/​unit/​commands/​test_install_error_handling.py Updates frozen verification message expectations.
tests/​unit/​commands/​test_export_patch.py Covers plugin mirrors and repository-relative patches.
tests/​unit/​bundle/​test_plugin_hook_resources.py Tests relative hook resource packing.
tests/​spec_conformance/​test_lockfile_reqs.py Adds frozen deployed-hash conformance coverage.
tests/​integration/​test_wave2_adapters_coverage.py Uses the public config-key API.
tests/​integration/​test_uninstall_refusal_lockfile_truth_lifecycle.py Tests truthful ownership after refused uninstall.
tests/​integration/​test_tls_trust_hint_lifecycle.py Covers TLS hints and failed-install atomicity.
tests/​integration/​test_stale_cleanup_hash_authority_lifecycle.py Protects user files claimed without hashes.
tests/​integration/​test_ssh_cache_transport_lifecycle.py Checks SSH transport across replay.
tests/​integration/​test_native_plugin_cache_replay.py Uses canonical local replay materialization.
tests/​integration/​test_mcp_slashed_server_cleanup_lifecycle.py Protects unrelated short-name MCP entries.
tests/​integration/​test_mcp_pruned_runtime_dir_cleanup_lifecycle.py Tests MCP cleanup after directory removal.
tests/​integration/​test_local_link_rejection_lifecycle.py Covers broken and escaping local links.
tests/​integration/​test_local_link_audit_replay_lifecycle.py Checks contained-link install and audit agreement.
tests/​integration/​test_kiro_prompt_lifecycle.py Verifies ownership contraction after refusal.
tests/​integration/​test_install_dir_plugin_audit_lifecycle.py Checks local plugin classification consistency.
tests/​integration/​test_frozen_undeclared_package_retention_lifecycle.py Tests frozen retention of undeclared packages.
tests/​integration/​test_dropped_direct_dependency_transitive_lifecycle.py Protects still-reachable transitive dependencies.
tests/​integration/​test_cursor_user_scope_chain_lifecycle.py Covers user-scope rule preservation and removal.
tests/​integration/​test_cursor_rules_lifecycle.py Checks truthful lock claims after refusal.
tests/​integration/​test_architecture_single_file.py Guards shared local materialization routes.
tests/​integration/​test_architecture_retained_lock_keys.py Guards canonical reachability use.
tests/​integration/​test_architecture_native_plugin_audit.py Guards hashing of canonical replay images.
tests/​integration/​test_architecture_dependency_replacement.py Updates plan-owner mutation tests.
src/​apm_cli/​models/​dependency/​materialization.py Centralizes read-only installed-path lookup.
src/​apm_cli/​marketplace/​errors.py Removes unsupported flag advice.
src/​apm_cli/​integration/​mcp_integrator.py Refines stale names and cleanup reachability.
src/​apm_cli/​integration/​mcp_integrator_install.py Uses the public config-key owner.
src/​apm_cli/​integration/​hook_source_selection.py Exposes relative hook-script resolution.
src/​apm_cli/​integration/​hook_ownership.py Adds shared source-entry retirement.
src/​apm_cli/​integration/​hook_integrator.py Retires events removed from hook sources.
src/​apm_cli/​install/​sources.py Avoids invented commits for proxy rows.
src/​apm_cli/​install/​selected_cleanup.py Records ownership remaining after cleanup.
src/​apm_cli/​install/​pipeline.py Routes update confirmation through one helper.
src/​apm_cli/​install/​phases/​lockfile.py Preserves orphan provenance and truthful write reporting.
src/​apm_cli/​install/​phases/​cleanup.py Retains undeclared packages during frozen installs.
src/​apm_cli/​install/​package_selection.py Avoids deletion under incomplete graph evidence.
src/​apm_cli/​install/​native_plugin_admission.py Verifies canonical local replay images.
src/​apm_cli/​install/​mcp/​ownership.py Centralizes project MCP cleanup reachability.
src/​apm_cli/​install/​manifest_reconcile.py Collects selected-owner cleanup outcomes.
src/​apm_cli/​install/​local_bundle_paths.py Skips unsupported plugin-hook deployment explicitly.
src/​apm_cli/​install/​helpers/​plan_inputs.py Adds symlinked-lockfile update preflight.
src/​apm_cli/​install/​drift_render.py Distinguishes rendering changes from edits.
src/​apm_cli/​install/​artifactory_resolver.py Reuses canonical proxy routing.
src/​apm_cli/​drift.py Recognizes locked proxy-route equivalence.
src/​apm_cli/​deps/​plugin_parser.py Adds generated-mirror classification.
src/​apm_cli/​deps/​path_anchoring.py Exposes local dependency admission bases.
src/​apm_cli/​deps/​file_provenance.py Anchors logical paths to deployment roots.
src/​apm_cli/​deps/​artifactory_orchestrator.py Owns proxy routing and equivalence.
src/​apm_cli/​core/​command_logger.py Reports retained files and frozen packages.
src/​apm_cli/​compilation/​root_context_protection.py Extends hand-authored protection below root.
src/​apm_cli/​compilation/​agents_compiler.py Applies protection to distributed context outputs.
src/​apm_cli/​commands/​uninstall/​profile_scope.py Refines profile-scoped survivor selection.
src/​apm_cli/​commands/​prune.py Uses shared dependency reachability.
src/​apm_cli/​commands/​mcp.py Preserves forwarded install exit behavior.
src/​apm_cli/​commands/​marketplace/​plugin/​set.py Resolves refs against entry coordinates.
src/​apm_cli/​commands/​marketplace/​plugin/​__init__.py Verifies explicit remote refs.
src/​apm_cli/​commands/​install.py Reports frozen deployed-hash verification.
src/​apm_cli/​commands/​compile/​watcher.py Broadens retained-context message wording.
src/​apm_cli/​commands/​compile/​cli.py Updates context-protection summaries.
src/​apm_cli/​commands/​audit.py Honors fresh policy fetches and rendering hints.
src/​apm_cli/​commands/​_helpers.py Shares retained-key and installed-path decisions.
src/​apm_cli/​bundle/​plugin_layout.py Defines the plugin hooks filename constant.
src/​apm_cli/​bundle/​plugin_hooks.py Packs relative hook-script resources.
src/​apm_cli/​bundle/​export_common.py Exports skipped-link warning support.
src/​apm_cli/​bundle/​agent_plugin_exporter.py Reports skipped source links.
src/​apm_cli/​adapters/​client/​opencode.py Uses public config-key derivation.
src/​apm_cli/​adapters/​client/​kiro.py Uses public config-key derivation.
src/​apm_cli/​adapters/​client/​hermes.py Uses public config-key derivation.
src/​apm_cli/​adapters/​client/​gemini.py Uses public config-key derivation.
src/​apm_cli/​adapters/​client/​cursor.py Uses public config-key derivation.
src/​apm_cli/​adapters/​client/​copilot.py Uses public config-key derivation.
src/​apm_cli/​adapters/​client/​codex.py Uses public config-key derivation.
src/​apm_cli/​adapters/​client/​claude.py Uses public config-key derivation.
src/​apm_cli/​adapters/​client/​base.py Promotes the canonical config-key API.
scripts/​architecture_linter/​checks/​transport_auth_platform.py Guards shared proxy-route decisions.
scripts/​architecture_linter/​checks/​registry_semantic_rules.py Guards distributed context protection.
scripts/​architecture_linter/​checks/​registry_owner_guards.py Updates audit-scope owner checks.
scripts/​architecture_linter/​checks/​mutation_mcp_target_and_scope.py Guards centralized MCP key derivation.
scripts/​architecture_linter/​checks/​mutation_hook_contract.py Guards shared hook retirement.
scripts/​architecture_linter/​checks/​marketplace_package_and_registration.py Requires canonical replay-image hashing.
scripts/​architecture_linter/​checks/​marketplace_legacy.py Tracks the marketplace coordinate owner.
scripts/​architecture_linter/​checks/​marketplace_bundle_and_audit.py Registers source-parsing guard ownership.
scripts/​architecture_linter/​checks/​install_single_file.py Guards shared local materialization.
scripts/​architecture_linter/​checks/​install_request_and_source.py Guards forwarded command exit handling.
scripts/​architecture_linter/​checks/​contracts_test_taxonomy.py Adds lockfile symlink preflight guard.
scripts/​architecture_linter/​checks/​contracts_dependency_replacements.py Updates update-plan routing checks.
packages/​apm-guide/​.apm/​skills/​apm-usage/​package-authoring.md Documents packing behavior and hook limitations.
packages/​apm-guide/​.apm/​skills/​apm-usage/​governance.md Documents user-scope policy limitations.
docs/​src/​content/​docs/​reference/​manifest-schema.md Describes distributed context protection.
docs/​src/​content/​docs/​reference/​cli/​uninstall.md Documents profile cleanup and truthful refusals.
docs/​src/​content/​docs/​reference/​cli/​prune.md Explains reachable dependency retention.
docs/​src/​content/​docs/​reference/​cli/​pack.md Documents source links and hook resources.
docs/​src/​content/​docs/​reference/​cli/​marketplace.md Explains explicit-ref verification.
docs/​src/​content/​docs/​reference/​cli/​export-patch.md Clarifies repository-relative patch paths.
docs/​src/​content/​docs/​reference/​cli/​deps.md Documents host-qualified dependency keys.
docs/​src/​content/​docs/​reference/​cli/​compile.md Describes nested hand-authored protection.
docs/​src/​content/​docs/​reference/​cli/​audit.md Explains rendering-change diagnostics.
docs/​src/​content/​docs/​producer/​pack-a-bundle.md Describes relative hook resource relocation.
docs/​src/​content/​docs/​integrations/​ci-cd.md Updates frozen-install integrity guidance.
docs/​src/​content/​docs/​enterprise/​security.md Documents cleanup authority and symlink refusal.
docs/​src/​content/​docs/​enterprise/​apm-policy.md Clarifies project-only policy scope.
CONFORMANCE.md Updates deployed-hash requirement coverage.
CONFORMANCE.json Records the new conformance test.
.apm/​architecture/​owners/​transport-auth-platform.json Registers proxy-route equivalence ownership.
.apm/​architecture/​owners/​marketplace-plugins.json Registers marketplace ref verification ownership.
.apm/​architecture/​owners/​install-deployment.json Updates materialization, integrity, and reachability owners.
.apm/​architecture/​owners/​hooks-integrations.json Registers MCP config-key ownership.
.apm/​architecture/​owners/​contracts-tooling.json Registers the lockfile symlink guard.

Review effort: Balanced

Comment thread src/apm_cli/bundle/plugin_hooks.py Resolved
Comment thread src/apm_cli/bundle/plugin_hooks.py Resolved
Comment thread src/apm_cli/deps/plugin_parser.py Resolved
… uninstalls (#3649)

selected_profile_survivors combined the split runtimes of every requested
package, so uninstalling two packages at once could delete files that two
separate uninstalls keep (one package split across Hermes homes, the other
across Claude profiles). The removable selected-profile prefixes are now
computed per package before survivor rows are combined.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ct (#3649)

confirm_update_plan only refused a symlinked apm.lock.yaml when the
resolved dependency plan had changes. A target-only change under
apm install --update leaves the plan unchanged but still rewrites the
deployment ledger, so files were deployed before the lockfile write
failed. An update exists to rewrite the lockfile, so it now refuses
unconditionally through refuse_lockfile_before_mutation(would_mutate=True),
after the apm update plan callback and before any download, deploy or
cleanup. Plain install, --frozen, apm lock and dry runs are unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… evidence (#3649)

A normalization receipt does not prove every .apm/ file was generated:
plugins can declare authored .apm/skills or .apm/agents sources. When such
a source shared bytes with an unrelated repository file, export-patch
dropped the real source and patched the unrelated file. The normalization
owner now maps only .apm/skills/<name>/<tail> to the source directory its
receipt records (install_generated_mirror_source), and export-patch drops a
candidate only when that proven source is itself another candidate;
otherwise the ambiguity skip is kept.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
resolve_relative_hook_script() resolved symlinks before pack validated the
resource, so a contained ./scripts/alias.sh -> fmt.sh (or a linked scripts/
directory) was packed instead of rejected. The owner gains a lexical mode,
like resolve_plugin_root_hook_script, so pack validates the unresolved path
and its ancestors through the existing hook-resource symlink rule; install
keeps resolving as before.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
)

A packed ./scripts/fmt.sh reference became ./hooks/scripts/fmt.sh, which
resolves from the consumer's working directory rather than the installed
plugin, so it could not find the bundled file. The plugin-root vocabulary
owner gains plugin_root_script_reference, which anchors the packed path on
${CLAUDE_PLUGIN_ROOT} while keeping the authored quoting (unquoted,
double- or single-quoted); pack uses it for relative script references.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…3649)

The #3665 retirement pass dropped a source's entries from events it no
longer declares only under the canonical marker. An upgraded install
whose sidecar still carries a leaf marker such as 'hooks' kept the
dropped event pointing at a deleted script. HookIntegrator now computes
the owned marker set once from _get_hook_source_markers (keeping its
ambiguity rules) and passes it to both drop_source_entries passes. The
neutral-hook-contract guard requires both passes to use it, with a
mutation case.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…lds (#3672)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit fe6f089 into main Nov 13, 2026
31 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-redteam-0-36-regression-hunt branch November 13, 2026 06:52
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 13, 2026
…termine_config_key (#3681)

#3672 promoted MCPClientAdapter.determine_config_key to public; the VS Code
override still named the old private method, so its full-reference keys were
bypassed after the rebase.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 13, 2026
…equires

Since #3672 stale cleanup deletes only files whose recorded hash still
matches, so the alias-index and released-directory tests now pass the
recorded hash of each APM-deployed member.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 13, 2026
…, graph reconciliation, approvals, manifest corner cases) (#3709)

* fix(lifecycle): reap command scripts when the APM command is interrupted (#3649)

Lifecycle command scripts run in their own session so a timeout can
killpg the tree, but Ctrl+C reaches only the foreground group. An
interrupted apm compile/install exited and released its lifecycle lock
while the pre-compile/pre-install script kept running and writing into
.apm/. _execute_command now reaps the group on any BaseException before
propagating it.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mcp): route JSON MCP config writes through the shared adapter owner (#3649)

Copilot (.github/mcp.json and the Copilot CLI user config), VS Code
(.vscode/mcp.json), Gemini and Kiro read their config with a parser that
returned {} on any JSON error and then rewrote the file, so a user
mcp.json with a JSONC comment or a trailing comma lost every user server
on apm install, with exit 0 and no warning. They now parse through the
base MCPClientAdapter owner (_parse_json_config_for_update, split out of
_read_json_config_for_update) and write through _write_json_config, so an
unparsable file is kept byte-identical and the server is reported failed,
as Cursor and OpenCode already do.

Claude's project .mcp.json now uses the same shared atomic, symlink-safe
writer; its recorded tolerate-and-rewrite parse policy is unchanged.
_write_json_config gains shared=True for committed project config files so
they keep their umask mode instead of 0600.

Static boundary: the MCPClientAdapter owner record gains the
hooks-integrations-mcp-json-config-write guard
(mutation_writes.mcp_json_config_write) with a mutation case: adapters
other than base.py may not serialize JSON straight into a config file.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(integration): fault-injection atomicity and fix-guard lifecycle scenarios (#3649)

Installed-CLI scenarios that inject one fault mid-pipeline (read-only
module store, target root replaced by a file, deployed path replaced by a
directory or a symlink, unwritable nested compile output, Ctrl+C during a
fresh install) and assert a failing exit, unchanged apm.lock.yaml and user
bytes, no staging leftovers, and convergence with apm audit --ci.
Fix guards cover MCP config merges that keep unparsable user configs and
interrupted pre-compile scripts.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(integration): user-authored same-name collision lifecycle (#3649)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(integration): skip unmanaged same-name native rules instead of overwriting (#3649)

Rule-dir formats (.claude/rules, .cursor/rules, .windsurf/rules,
.kiro/steering) treated any existing file at the derived path as
APM-owned and silently rewrote it, then recorded it so uninstall
deleted it. Route them through the shared BaseIntegrator
_check_adopt_or_skip decision like every other primitive: adopt when
the rendered output already matches, rewrite managed paths, and skip
unmanaged user-authored files unless --force (docs: enterprise/security
Collision detection).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(uninstall): never glob-delete native instruction files without a lockfile (#3649)

Without apm.lock.yaml, uninstall fell back to broad legacy globs and
deleted every .cursor/rules/*.mdc and .github/instructions/*.instructions.md,
including user-authored files. Uninstall only removes lockfile-tracked
paths (docs: reference/cli/uninstall), so drop the instruction legacy
glob like the Claude, Windsurf, Kiro and Copilot user-scope precedents.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(integration): JSONC MCP configs survive install across adapters (#3649)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(view): report user-scope provenance for every target in view -g --file (#3649)

apm install -g persists deployment rows whose scope DeploymentLedgerCodec
infers from the path, so only ~/.copilot/ rows say 'user'. view -g --file
skipped every other row and reported 'No recorded provenance' (exit 1)
for ~/.claude, ~/.cursor, ~/.agents and other user-scope files.

Add DeploymentLedgerCodec.locator_in_scope: a path-inferred scope is not
scope evidence; only a recorded scope that differs from the inference
excludes a row. Route file provenance through it and extend the
install-deployment-provenance-state guard to reject raw locator.scope
comparisons outside the codec.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(install): keep files renamed only by case on case-insensitive filesystems (#3649)

When a package renamed a primitive only by letter case (Guide.md ->
guide.md), apm update / install on macOS or Windows treated the existing
APM-owned entry as a user collision (agents, prompts, instructions were
skipped), then stale cleanup deleted the old spelling -- the same entry
the run had just written -- so the package's new files vanished and left
the lockfile, while rules were kept as 'user-edited'.

Add apm_cli.utils.paths.physical_alias, the single owner for 'another
spelling of the same directory entry' (case/NFC only, confirmed with
os.path.samefile). BaseIntegrator.check_collision treats such an alias
of a managed path as managed, and remove_stale_deployed_files renames
the aliased entry to the live spelling instead of deleting it. Extend the
install-deployment-base-integrator guard to keep both routes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(export-patch): disambiguate patch names that differ only by case (#3649)

patch_filenames disambiguated sanitizer collisions by exact name, so two
packages whose patch names differ only by case (skills/PDF vs skills/pdf)
kept distinct names that macOS and Windows fold into one file; the
second write silently replaced the first patch. Group by casefolded name.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(lifecycle): guard spaced and non-ASCII project, HOME and package paths (#3649)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(lifecycle): keep the unicode path chain independent of subdirectory patch roots (#3649)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(security): apm approve unlocks github.com dependencies (#3649)

With the executable gate on, `apm approve owner/repo` recorded the grant
under the lockfile identity (`owner/repo#<version>`), but the install gate
looked a package up by `str(dependency_ref)`, which is host-qualified
(`github.com/owner/repo#ref`): the gate called a non-existent
`canonical_string()` and fell back to it. Every dependency on the default
host therefore stayed parked after approval while `apm policy explain`
said "allowed". Non-default hosts and local paths were unaffected.

- security/executables.py owns `dependency_approval_key()`: the lockfile
  identity domain `apm approve` writes, bound to the selected source so a
  replacement still never inherits upstream approval.
- install/exec_gate.py routes `resolve_package_key` through it, and only
  parks a package when one of its DECLARED exec types stays unapproved
  (an approved hooks-only package no longer prints "parked pending
  approval").
- `apm approve --pending` resolves through the same deny-wins ladder as
  install (project, user, org layers) instead of an exact-key lookup in
  one store, so a `--user` grant no longer shows as pending.
- Architecture guard install-deployment-executable-trust-context now
  requires the gate and `--pending` to route through the owner.

apm-spec-waiver: executable trust key routing fix, no OpenAPM contract change

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(manifest): approve, deny and install --mcp keep apm.yml comments (#3649)

#2000/#2012 made `apm install PKG` / `apm uninstall PKG` rewrite apm.yml
through the ruamel round-trip pair so comments and layout survive. Two
sibling writers of the same consumer manifest still used the lossy
`load_yaml` / `dump_yaml` pair: `apm approve` / `apm deny`
(security/executables.write_project_executables) and `apm install --mcp`
(install/mcp/writer.add_mcp_to_apm_yml). Each run stripped every comment,
expanded anchors/aliases and reflowed flow-style lists.

Route both through `load_yaml_roundtrip` / `dump_yaml_roundtrip`, the
existing comment-preserving owner. The executable-trust architecture
guard now requires the round-trip read in write_project_executables.

apm-spec-waiver: manifest write formatting only, no OpenAPM contract change

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(install): racing install and uninstall converge under the lifecycle lock (#3649)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* chore(architecture): register the consumer apm.yml rewrite owner (#3649)

Folds the python-architect review of the approve/deny and install --mcp
round-trip fix: the MCP writer had no static guard. Register owner
`consumer-manifest-rewrite` (utils/yaml_io round-trip pair) with guard
install-deployment-consumer-manifest-rewrite, requiring install,
uninstall, approve/deny and install --mcp to rewrite apm.yml through
load_yaml_roundtrip / dump_yaml_roundtrip, plus its mutation case.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(install): targeted install and update re-read only the selected local packages (#3649)

Since #3571 the shared ref-recheck gate re-staged every local dependency,
so apm install PKG, apm install --update PKG and apm update PKG re-read the
current apm.yml of unselected local packages too. An unrelated sibling with
invalid YAML or an unpublished dependency failed the targeted command, and a
valid edit fetched the sibling's new dependencies into apm_modules without
locking them. Pass the selected-key set for every targeted run and let the
gate recheck a local package only inside that selection; full installs
still re-read every local package.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(lockfile): record a mixed-case parent by its canonical identity (#3649)

A parent declared as Owner/Repo on a case-insensitive host was written as
resolved_by: Owner/Repo while its lock entry is owner/repo, so deps tree
could not place the transitive, deps why lost the chain and changing the
declared casing churned the lockfile. lockfile_parent_identity now returns
the canonical repository identity for legacy locks.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(lifecycle): one lock entry across dependency spellings; diamonds fail closed (#3649)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(view): match decomposed (NFD) paths in view --file (#3687)

macOS tools such as Finder drag and drop pass NFD paths for NFC-named
files. view --file compared the query exactly, so an absolute NFD path
exited 2 ('outside the project deploy root') and a relative one exited 1
('origin is unknown') for a recorded file.

When the exact query matches nothing, retry once with its NFC spelling,
but only when utils.paths.physical_alias confirms through the filesystem
that both spellings name the same file; case variants and
normalization-sensitive filesystems keep exact-path semantics. The
install-deployment-base-integrator guard now also requires this route.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(audit): fail audit --ci when the current directory has no apm.yml (#3688)

APM resolves the project from the working directory and does not search
parent directories. From a project subdirectory or a wrong checkout path,
apm audit --ci reported 'All checks passed' and exited 0 although it
audited nothing, a false green for a CI gate.

In --ci mode, run_baseline_checks now always emits a failing
manifest-missing check when apm.yml is absent, naming the fix (run from
the project root that contains apm.yml). Bare audit keeps the advisory
warning only when APM artifacts suggest a deleted manifest.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(install): name obstructed deployment paths with a remedy (#3678)

A directory where APM deploys a file, or a file where it needs a
directory, surfaced as raw '[Errno 21] Is a directory: <abs path>'. A
target root replaced by a regular file was reported as 'Failed to resolve
APM dependencies: [Errno 17] File exists'. Compile printed the same
distributed-batch write error once per target.

utils/file_ops gains the single wording owner (obstructed_path_message,
describe_path_obstruction). The shared integration template formats
integrate failures through it into the existing DiagnosticCollector
entry; skill copies raise a real EISDIR so they share the wording.
materialize_project_target_profiles refuses an obstructed target root
with TargetRootObstructedError, in the PathTraversalError family that the
pipeline already surfaces verbatim (no 'resolve' label); mcp install keeps
its RequiredIntegrationError mapping. AgentsCompiler._merge_results
dedupes errors like warnings.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(cli): route SIGTERM through the Ctrl+C rollback path (#3676)

SIGTERM (a cancelled CI job, docker stop, a timeout) killed apm without
running any finally block: install left apm_modules/.apm-resolution-staging
and modules behind with no report, and lifecycle scripts kept running.
cli.main now installs one handler that raises KeyboardInterrupt, so the
install transaction rollback, failure-residue reporting and lifecycle
script reaping run exactly as for Ctrl+C. The handler restores default
handling first, so a second SIGTERM still terminates.

Static boundary: new owner record process-interrupt-signals (cli.py) with
guard registry-delegation-process-interrupt-signals: main must install the
handler and no other module installs a SIGTERM handler.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(install): release a removed dependency's skill dir that holds only user files (#3677)

When a removed dependency's skill directory also held a user's file,
stale cleanup deleted APM's members but filed the directory as
skipped_unmanaged. That retained the dependency's lockfile row and
pinned its apm_modules copy, so install exited 0 while audit --ci
reported every former file as unintegrated drift and suggested an
install that could never converge; deps list still showed the package.

_safe_remove_skill_directory now files such a directory (every
remaining entry untracked user content) under CleanupResult.released,
which retained never includes: the user's directory and file stay, the
row is dropped, and deps list, prune and audit --ci agree exactly as for
a plain removal. Edited or failed APM members still retain ownership.

Static boundary: the file-level deploy/cleanup owner record now selects
integration/cleanup.py and carries guard
install-deployment-cleanup-ownership-release with a mutation case.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mcp): refuse symlinked project MCP configs and invalid Claude configs

Project MCP configs that are symbolic links, or are reached through one,
are now refused like user-scope ones: MCPClientAdapter applies the policy
in _parse_json_config_for_update (so every adapter entry point gets it)
and in _write_json_config, leaves the link untouched and reports the
target as failed.

Claude Code's .mcp.json and ~/.claude.json now parse through the same
owner, so an invalid file is kept byte-identical and the server is
reported failed, as for Cursor, instead of being rewritten from scratch.

The hooks-integrations-mcp-json-config-write guard now also requires both
owner methods to apply the project symlink policy and rejects a
rewrite-from-scratch path in any adapter.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(lockfile): read an unquoted integer lockfile_version (#3692)

`lockfile_version: 1` (quotes dropped by a hand edit or a YAML tool)
failed every command with the self-contradicting "Unsupported lockfile
version 1; supported versions: 1, 2, 3". The lockfile owner
(require_supported_lockfile_version) now treats an integer as its string
form, and the validated container carries the normalized value so every
reader agrees, including the local-bundle lockfile reader. Booleans, floats and unknown versions still fail closed.

apm-spec-waiver: lockfile version parsing leniency, no OpenAPM contract change

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(config): unknown keys are a plain user error with the full key list (#3694)

`apm config get/set <typo>` printed "This error may indicate a bug in
command routing. Please report this issue." for an ordinary typo, and the
valid-key hint was a hand-maintained list per message site (unset also
offered `auto-integrate`, which it rejects).

One registry, `_CONFIG_KEYS` (name, experimental flag, unsettable), now
feeds `_valid_config_keys()`; get/set/unset reject unknown keys through a
single `_reject_unknown_key()` helper. A unit test drives every registered
key through get/set/unset to pin the registry to the dispatch.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(deps): deps list, deps tree and prune name a conflicted lockfile (#3695)

With git merge conflict markers in apm.lock.yaml, `apm deps list` and
`apm deps tree` swallowed the lockfile owner's LockfileConflictError and
exited 0 from an apm_modules scan, and `apm prune` reported "Failed to
parse apm.yml" for the lockfile. All three now surface the same
actionable conflicted-lockfile error as install, audit, outdated and
update (exit 1, path named, lockfile bytes untouched).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(manifest): refuse duplicate top-level keys in apm.yml before any write (#3691)

A merge that left two `dependencies:` blocks made bare `apm install`
(PyYAML last-wins) drop the first block's packages and clean their files
as stale, while `apm install PKG` / `apm uninstall` printed a raw ruamel
DuplicateKeyError.

New read owner models/manifest_io.py: `reject_duplicate_manifest_keys`
composes the top-level mapping (no alias/merge expansion) and raises
DuplicateManifestKeyError naming the file, key and both lines;
`load_manifest` / `load_manifest_roundtrip` read once and route every
acting apm.yml read through it -- APMPackage.from_apm_yml, project
executable trust (approve/deny, install gate), `apm run` config, and the
install PKG, uninstall, install --mcp, approve/deny and adopt rewrites.
`apm deps list` re-raises it instead of showing partial data. The shared
YAML loader is unchanged apart from a text-input round-trip twin
(load_yaml_roundtrip_str).

The consumer-manifest-rewrite owner record and its guard now require the
read routing. Docs: manifest schema and apm-usage troubleshooting.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(install): local bundle install honours apm.yml targets (#3649)

apm install <bundle> resolved targets with an explicit --target or
directory auto-detection only, so a project declaring
targets: [claude, cursor] received .github/ output and nothing for the
declared targets. Route the bundle handler through the canonical
resolve_manifest_target_decision owner (the same one apm install --mcp
uses): --target > apm.yml targets > apm config target > auto-detect.
The install-target-selection guard now requires this route.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(lockfile): link legacy mixed-case parents when reading a lockfile (#3698)

Recording parents canonically left locks written before that change with
children whose resolved_by keeps the declared casing (Acme/Parent) while the
parent entry is acme/parent, so uninstall and targeted installs on an existing
lock missed those descendants until a full install rewrote it. On read, a
legacy resolved_by that names no locked entry is mapped onto the locked entry
with the same case-insensitive identity; case-sensitive hosts are untouched.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(uninstall): remove every declaration of a package; install --dev moves it (#3693)

A package declared twice (in dependencies and devDependencies, or under two
spellings) made apm uninstall exit 'ambiguous' for every spelling, and
apm install --dev X with X in dependencies silently added a duplicate.
Uninstall now removes every declaration of the selected identity through the
selection owner (manifest_declarations_of); distinct local packages behind one
_local alias stay ambiguous. Install follows npm: --dev moves a production
declaration to devDependencies, and a plain install keeps a dev-declared
package where it is, updating that entry in place.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(resolve): reject a repository declared with its own subdirectory package (#3699)

The subdirectory package is installed inside the repository package's
apm_modules directory, so uninstalling the repository deleted it and deps
list hid it. Install and update now fail before fetching anything when root
declarations would nest (nested_materialization_pairs in the materialization
owner); a repository whose own manifest depends on its subdirectory package
still installs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mcp): report same-name MCP conflicts on every JSON adapter (#3681)

VS Code, Copilot CLI, Cursor, Gemini, Kiro, OpenCode, Windsurf and
Antigravity treated an existing connection with the requested name as
"already configured" and exited 0 even when its definition differed,
so the package server was never written. Route every runtime through
the #3239 native content comparison via one owner,
install.mcp.ownership.native_comparison_clients, driven by the adapter
capability MCPClientAdapter.compares_native_connections (JetBrains and
Hermes opt out). A differing user entry is preserved, named and exits 1
without an ownership claim; an identical one stays unclaimed.

To keep APM's own entries managed on those targets, every successful
write now records a native fingerprint (written_native_hash, read back
through the same detector view), and the base adapter accepts a matching
fingerprint as proof of an earlier write (e.g. a Gemini env value that
resolved differently). VS Code now owns its full-reference config key and
OpenCode's renderer accepts registry env/runtime overrides.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(audit): classify skipped same-name user files as unmanaged conflicts (#3682)

When install skipped a user-authored prompt, agent, command or rule that
shares a package primitive's name, apm audit --ci reported it as managed
'modified' drift with the 'apm export-patch' local-edit hint, which then
had nothing to export; a case-only variant on a case-insensitive
filesystem showed as 'unintegrated'. diff_scratch_against_project now
classifies any differing file no lockfile entry claims (and a case-only
variant occupying the destination) as the existing unmanaged-conflict
kind, so the export-patch hint only counts managed edits, and the
guidance names rename/--force for files as well as skills.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(view): strip the path anchor without the raw relative_to string form (#3687)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* refactor(security): write allowExecutables through the round-trip manifest owner (#3690)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* docs(changelog): record 0.36.0 round-2 red-team fixes (#3649)

apm-spec-waiver: round-2 red-team bug fixes restore existing documented behavior; no OpenAPM spec requirement changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(lifecycle): promote small round-2 fix guards to lifecycle smoke (#3649)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* docs(changelog): link round-2 entries to #3709

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(lifecycle): guard frozen replay of an unquoted lockfile_version (#3692)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(output-mode): audit a real manifest in the machine-output notice test (#3688)

audit --ci now fails without apm.yml (#3688), so the parametrized
machine-output cases hit SystemExit(1) before checking stdout. The update
notice already stays on stderr; give those cases a minimal apm.yml so
they keep testing a passing gate, and add a failing-gate case proving
stdout stays one JSON document when the gate exits 1.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(prune): reach the released-root trim through a valid declaration switch (#3699)

The direct and dev cases declared a repository together with its own
subdirectory package, which #3699 now rejects before resolution. They now
install the repository first and then switch the declaration to the
subdirectory package (in dependencies or devDependencies), the #2926 switch
the trim exists for; the transitive case is unchanged. #3677's released
skill directories were not involved.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mcp): keep Claude Code's trailing newline in shared JSON config writes (#3649)

Claude's project .mcp.json moved to the shared MCPClientAdapter writer,
which writes JSON without a trailing newline (the historical bytes of the
other JSON adapters), so committed .mcp.json files churned. The writer now
honours an adapter-declared json_config_trailing_newline (alongside
mcp_servers_key); Claude Code sets it, every other adapter keeps its bytes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(security): key replacement consent by the declared with: source (#3689)

#3689 keyed executable approval by `source_reference.get_unique_key()`.
For a local replacement (`replace: [{for: ..., with: {path: ../local}}]`)
the bound reference carries an absolute materialization anchor, so the
key became `local:/abs/path` and a grant for the declared `../local`
never matched: the replacement's hooks stayed parked
(test_replacement_hook_consent_stays_with_selected_source).

dependency_approval_key now drops that anchor for replacements, keying
consent by the `with:` source as the consumer declared it. An upstream
grant still never unlocks the replacement, and default-host approval
keys are unchanged.

apm-spec-waiver: executable trust key for local replacements, no OpenAPM contract change

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(pack): stop appending a duplicate dependencies key after apm init (#3691)

apm init already writes an empty dependencies block; appending a second
one is now rejected as a duplicate top-level key.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(install): release user-content skill dirs only for departing owners (#3677)

#3677 released a skill directory kept only for user content in every
cleanup pass, so narrowing a still-declared dependency's targets dropped
its directory claim from the lockfile. Release now applies only to orphan
cleanup (failed_path_retained=False, the owner is leaving the lockfile);
intra-package stale cleanup retains the claim as before, so a later
install still removes the directory once the user's file is gone. The
static guard and mutation case follow the scoped condition.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(mcp): align adapter tests with the shared JSON config owner (#3649)

VS Code update_config writes through MCPClientAdapter._write_json_config
(atomic temp file + os.replace), so patching builtins.open no longer
injects a write error; the write-error tests now fail the owner's
atomic_write_text and still assert False plus the logged/printed error.
The Claude corrupted-.mcp.json test now asserts the approved fail-closed
contract: the file is kept as-is and update_config returns False.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mcp): compare native MCP entries by JSON type, not Python equality (#3681)

Native comparison used Python equality, where True == 1, so an OpenCode
enabled: true entry matched a declaration that changed it to enabled: 1
and the managed entry was never rewritten. MCPClientAdapter.json_identical
compares sorted JSON text; the base matches_managed_server_config and
the registry-request comparison in compare_native_mcp_connection use it.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(lifecycle): expect unmanaged-conflict for the skipped Kiro prompt collision (#3682)

The user-authored .kiro/prompts/collision.md is never recorded by
install, so audit now reports it as unmanaged-conflict instead of a
managed local edit, per the approved #3682 contract.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* refactor(audit): give drift claim membership its own owner and register its guards (#3682)

Moves replay claim membership (claimed_prefixes and the unclaimed
predicate behind the #3682 unmanaged-conflict classification) from
install/drift.py into install/drift_claims.py (ReplayClaims), bringing
drift.py back under its LOC budget without raising it.

Registers the #3681/#3682 static checks as canonical owner guards
instead of guard-less registry_delegation rules:
install-deployment-mcp-native-comparison on the MCP ownership owner and
install-deployment-drift-claim-classification on the new
drift-claim-membership owner, each with a MutationCase and an entry in
the frozen rule inventory.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mcp): keep APM-written entries until their declaration changes (#3681)

Native comparison rewrote an unchanged, APM-written entry on VS Code,
Copilot, Cursor, Gemini, Kiro and OpenCode whenever its render changed
only through the install environment (GitHub auto-auth credential source
precedence, resolved env values), churning native files the previous
name-only behavior kept stable. compare_native_mcp_connection now takes
declaration_changed and returns MATCHING_MANAGED for an unchanged
declaration unless the adapter opts into refreshes_environment_renders
(Claude and Codex, which already reconcile such renders). Registry
declaration drift is now detected for every compared server, so a real
declaration change (e.g. OpenCode enabled true -> 1) still rewrites.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(mcp): align MCP and drift tests with the #3681/#3682 contracts (#3681)

Tests that encoded the pre-#3681 name-only behavior now expect a
differing same-name user connection on Cursor/OpenCode to be preserved
and reported (exit 1); scenarios meant to exercise unowned names use an
identical foreign entry instead. Name-only 'already configured'
characterisations patch native_comparison_clients to the opt-out set.
The deps-model drift test tracks its path so it stays a managed edit
(#3682). Frozen rule inventory kept in sorted order.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mcp): retain the receipt of a managed MCP entry that already matches (#3681)

A managed self-defined connection that already matches is not rewritten,
so a lockfile rebuilt without its deployment rows lost the native
fingerprint on the next install and the repaired lock differed from the
original. retain_native_receipt records the existing entry's fingerprint
when none is held.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mcp): compare VS Code entries against the render that keeps optional fields (#3681)

VS Code's write path keeps optional registry fields the existing entry
already carries, but native comparison rendered without them, so an
entry identical to what APM would write compared as a conflict.
render_server_config now passes the existing entry like
configure_mcp_server does. The reinstall test now expects that identical,
unowned entry to be left alone (no rewrite, no conflict).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* docs(lockfile-spec): wrap the MCP receipt paragraph (#3681)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(e2e): declare sibling subdirectory packages in the private fallback scenario (#3699)

The branch case declared fixture-private/private-package together with its
own subdirectory package, which install now rejects. Declare two sibling
subdirectory packages of the same private repository instead: the scenario
still proves the scoped credential fallback, locale normalization and the
subdirectory (partial clone) path; the semver case keeps the whole-repository
clone.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(manifest): refuse duplicate top-level keys on the same line (#3691)

Folds Copilot review 4558274750 on #3709. reject_duplicate_manifest_keys
compared line numbers, so two `dependencies:` entries in one flow-style
mapping (same line) reached the last-wins loader and install could remove
the first entry's deployments. Duplicates are now detected by key
identity; a same-line duplicate reports "twice on line N" and asks to
merge both entries.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* perf(install): index spelling aliases once per inventory (#3684)

physical_alias rescanned and NFC/casefold-normalized the whole candidate
inventory on every lookup, so stale cleanup cost O(stale x live) and every
existing unmanaged collision destination cost O(managed), even when no
alias existed.

The utils.paths spelling owner now offers SpellingAliasIndex (built once
per inventory; lookups hash the queried spelling and samefile only its
bucket) and stored_alias (looks up the filesystem's stored spelling of an
existing entry, plus its NFC/NFD forms for HFS+, in the inventory: a few
set lookups). Stale cleanup builds one index per call; check_collision
uses stored_alias. physical_alias stays as the one-shot wrapper. The
install-deployment-base-integrator guard and owner record follow.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(view): keep the root spelling when retrying a decomposed --file path (#3687)

The NFD retry normalized the whole absolute path, including the deploy
root. When the project (or target) root itself is stored decomposed, the
NFC path no longer matched _roots(deploy_root), so an NFD query for an
NFC-recorded member still had no provenance.

Compare query and each deploy/target root in NFC, then rebuild the
candidate as <root as spelled>/<NFC member>; physical_alias still
confirms the filesystem names one file.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(install): keep a declaration's fields when install moves or keeps it across sections (#3693)

Cross-section reconciliation ran after validation against only the
destination section, so a bare apm install X dropped the ref of X's
devDependencies declaration, and apm install --dev X moved a bare copy that
lost the production entry's ref, skills restriction or registry source.
Expose the existing declaration to validation first (borrow), so its
explicit-change rules decide what the CLI changes, then return a kept
declaration to its position (settle).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mcp): keep the VS Code full-reference config key on the public determine_config_key (#3681)

#3672 promoted MCPClientAdapter.determine_config_key to public; the VS Code
override still named the old private method, so its full-reference keys were
bypassed after the rebase.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(cleanup): give round-2 cleanup tests the recorded hashes #3663 requires

Since #3672 stale cleanup deletes only files whose recorded hash still
matches, so the alias-index and released-directory tests now pass the
recorded hash of each APM-deployed member.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: danielmeppiel <danielmeppiel@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 17, 2026
* fix(tests): restore release-gate lanes for 0.36.0

Main's tag-gate lanes (build-release push + manual-build-release) were red
on runs 43381609442, 43381682871 and 43394173235. PR CI never runs them.

Product regressions (Windows/real installs), fixed:
- Hook cleanup removed nothing on Windows: remove_stale_deployed_files
  looked up recorded hashes with POSIX keys while callers passed native
  backslash keys, so content proof failed closed (#3672, Refs #3649).
- describe_path_obstruction returned None on Windows, which reports a
  directory-for-file as EACCES and a file-for-parent as ENOENT instead of
  EISDIR/ENOTDIR (#3709, Refs #3678).
- Skill preflight refused claimed members of an unclaimed, populated skill
  directory that materialization leaves alone, failing a local bundle
  install (Refs #3625).

Stale tests (behaviour changed intentionally), updated:
- policy chain mocks now return real PolicyFetchResult (#2933, Refs #2753)
- bare-cache/downloader/anonymous-https fixtures use real Git checkouts
  (#3603, Refs #3457)
- mcp install help, registry error wording, deps why -g help
  (#3633 Refs #3588, #2803 Refs #2478, #3614 Refs #2884)
- downloader stub carries carried_licenses (#3646, Refs #3556)
- frozen-hash lifecycle uses a generic git host so -g URL validation
  uses git ls-remote instead of a live api.github.com 404 (#3672)

New Windows-shaped regression tests are marked windows_compat.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* chore: spec waiver for release-gate repair

apm-spec-waiver: restores pre-existing behaviour on Windows and in skill preflight; no OpenAPM-observable change

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: danielmeppiel <danielmeppiel@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 17, 2026
* fix(tests): restore arm64 integration lanes for 0.36.0

Gate run 44090072790 (main e9860ee) failed 27 Linux arm64 integration
tests (19 also on macOS arm64), introduced by PRs that landed after the
previous gate. PR CI never runs this corpus.

Product regression, fixed:
- On case-sensitive file systems a stale apm_modules/Test/C beside
  apm_modules/test/e made every repeat install fail ("Found multiple
  package directories"), and switching the declared casing failed with a
  false casing collision. Materialization now treats only two complete
  paths for one package as a collision and relocates into an existing
  case-variant owner directory (Refs #3698).

Stale tests, updated to intentional behaviour changes:
- #3672 (Refs #3649): stale-file removal needs a recorded hash (#3663);
  runtime-scoped MCP cleanup without marker dir (#3664); audit replays
  the install image (#3667); --frozen fails closed on edited skills
  (#3654); unverifiable marketplace ref is an error (#3670); architecture
  owner/semantic mutation matrix and audit.py re-anchor (#3659).
- #3716 (Refs #3649): unpack writes only under managed integration dirs;
  registry token via headers_for(); raw-file fetch passes allow_netrc.
- #3709: case-only user-file collisions branch on the actual file system
  (#3679, #3684); conflicted-lockfile path survives rich 80-col wrapping
  (#3695); a package and its own subdirectory package cannot both be
  declared (#3699).

apm-spec-waiver: restores pre-existing install behaviour on case-sensitive file systems; no OpenAPM-observable change

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(install): prune emptied source ancestors after cross-parent relocation

Moving Test/C/packages/a beside test/c/packages/b on a case-sensitive
file system left an empty Test/C tree that a later root dependency
test/c counted as a second package directory. relocate_path now
removes emptied source ancestors below apm_modules; rollback already
recreates them via source.parent.mkdir(parents=True).

apm-spec-waiver: restores pre-existing install behaviour on case-sensitive file systems; no OpenAPM-observable change

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: danielmeppiel <danielmeppiel@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants