Skip to content

[0.37 candidate] fix(lockfile): user-scope bundle rows keep scope: user (#3995) - #4024

Merged
Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
danielmeppiel-3995-user-scope-bundle-rows
Nov 20, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
danielmeppiel-3995-user-scope-bundle-rows

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

TL;DR

After apm install -g <bundle>, the bundle's rows in $APM_HOME/apm.lock.yaml said scope: project. The bundle writer had no scope, and every ledger rebuild re-derived scope from the path prefix, where only .copilot/ counts as user. This PR fixes it inside the canonical owner, DeploymentLedgerCodec, using the existing per-row scope field. No lock field, lockfile version or spec changes.

Fixes #3995

Note

Restacked directly above #4026: base danielmeppiel-miniature-happiness at 2d129a05, which sits on #4008 at 3560d7f8 on #3290; head 10740d2c. Only this PR's 3 commits were rebased (git rebase --onto 2d129a05 d8873601). The patch is byte-identical to the previous head apart from CHANGELOG context; the only conflict was the CHANGELOG line, kept at the bottom of Fixed, and there were no docs conflicts. CI does not run for a non-main base, so the evidence below is local, from this cloud workspace.

Problem (WHY)

  • record_local_bundle_files took no scope, so its rows got the path-prefix guess (legacy_scope): project for every -g path except .copilot/.
  • _rebuild_from_legacy runs on every ledger write and re-derives scope. Its carry-over key includes scope, and bundle paths are excluded from preferred locators, so even a correct user row flipped back to project on the next unrelated -g install.
  • [!] -g --frozen and audit --ci passed regardless. The label was misleading to anyone reading the lock, and to locator_in_scope, which only excludes a row from another scope when its recorded scope differs from the guess.

Approach (WHAT)

# Fix
1 record_local_bundle_files(..., *, scope: InstallScope, ...): required and keyword-only, with no default, so the owner never guesses. The rows it writes record that scope.
2 _rebuild_from_legacy carries the recorded scope of each surviving bundle claim. It reads _bundle_scopes, taking the prior ledger first and then supplied provenance, and only when one source records a single scope for that path. Owners, hash and target attribution come from the rebuild as before.
3 replace_legacy_owner(..., provenance=...) passes provenance bundle scopes, so a freshly built lockfile keeps them too.
4 The only caller, install/local_bundle_handler.py, passes its existing scope (USER for -g).

Implementation (HOW)

  • src/apm_cli/core/deployment_ledger.py: the new _bundle_scopes() collects recorded bundle scopes and leaves an ambiguous path to the rebuild's own scope. _mark_local_bundle_paths(..., scopes=) re-keys a row whose scope changes, since the key includes scope. legacy_scope and locator_in_scope are unchanged.
  • src/apm_cli/install/local_bundle_handler.py: one keyword argument added.
  • Tests: the existing callers now pass scope=InstallScope.PROJECT. tests/unit/core/test_bundle_row_scope.py is new, with 9 cases. tests/integration/test_user_scope_bundle_rows_lifecycle.py is new and uses the installed CLI with isolated HOME and APM_HOME.
  • Docs: in reference/lockfile-spec.md, row scope now reads "project, or user for rows in the user lockfile". One CHANGELOG line, at the bottom of Fixed.

Trade-offs

  • Reused the per-row scope field rather than adding a bundle-scope field, as the record requires. No lock migration and no version bump.
  • An ambiguous claim falls back to the rebuild's scope. If one path is claimed with both scopes in a single source, the rebuild's scope wins rather than one being picked arbitrarily. This cannot occur in a per-scope lockfile.
  • Out of scope, as the record states: other row kinds keep legacy_scope, and the 0.37 known-issue release note is not touched.

Benefits

  1. User-lock bundle rows read scope: user on install and after any later -g install.
  2. locator_in_scope(row, "project") is now False for those rows, so they stay out of project provenance lookups.
  3. Project bundles are unchanged (scope: project), with no new lock data.

Validation (local; base 2d129a05, head 10740d2c)

Check Command Result
ruff (uv.lock pin 0.15.12) uvx [email protected] check src/ tests/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/ and uvx [email protected] format --check (same paths) All checks passed; 2490 files already formatted
Duplication uv run --extra dev python -m pylint --disable=all --enable=R0801 --min-similarity-lines=10 --fail-on=R0801 src/apm_cli/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/ 10.00/10
File length, YAML I/O, relative_to the ci.yml one-liners (2100-line cap) no violations
Auth-signal lint bash scripts/lint-auth-signals.sh clean
Architecture linter bash scripts/lint-architecture-boundaries.sh exit 0
Touched unit suites uv run --extra dev pytest -q -n 2 tests/unit/core/test_bundle_row_scope.py tests/unit/core/test_deployment_state.py tests/unit/deps/test_lockfile_local_staging.py tests/unit/install/test_empty_replacement_table.py tests/unit/install/test_local_rows_need_reconciling.py tests/unit/install/test_architecture_invariants.py 118 passed
Lifecycle (installed CLI) APM_BINARY_PATH=$PWD/.venv/bin/apm uv run --extra dev pytest -q -n 2 tests/integration/test_user_scope_bundle_rows_lifecycle.py tests/integration/test_local_bundle_mcp_lifecycle.py tests/integration/test_install_local_bundle_e2e.py tests/integration/test_global_install_e2e.py tests/integration/test_local_shared_root_skill_cleanup.py tests/integration/test_global_audit_deploy_root.py tests/integration/test_lock_derived_expected_state_lifecycle.py tests/integration/test_mcp_dependency_targets_lifecycle.py 118 passed
Spec conformance uv run --extra dev pytest -q -n 2 -p no:randomly tests/spec_conformance 649 passed, 9 failed; the same 9 fail on the unmodified base 2d129a05 (test_mode_b_detector 8, test_resolution_reqs 1; sandbox git)

Mutation checks (unchanged by the rebase): with src/ reverted, all original unit tests fail and the lifecycle test fails with assert 'project' == 'user'. The two follow-up tests each fail under a targeted mutation of their rule.

Scenario Evidence

# Scenario (user promise) Principle(s) Test(s) proving it Type
1 After apm install -g <bundle> and another unrelated -g install, the bundle rows keep their home-relative path, scope: user, owners and hash; -g --frozen and audit --ci from $APM_HOME pass Governed by policy, Portability by manifest tests/integration/test_user_scope_bundle_rows_lifecycle.py::test_user_bundle_rows_keep_user_scope_across_an_unrelated_rebuild (regression trap for #3995)
tests/unit/core/test_bundle_row_scope.py::test_unrelated_rebuild_keeps_user_scope_owners_and_hash
integration, unit
2 A project bundle still records scope: project Governed by policy tests/integration/test_user_scope_bundle_rows_lifecycle.py::test_project_bundle_rows_keep_project_scope integration
3 User rows stay out of project provenance lookups Secure by default tests/unit/core/test_bundle_row_scope.py::test_user_rows_stay_out_of_project_lookups unit
4 The writer cannot omit the scope (the owner never fails open) Secure by default tests/unit/core/test_bundle_row_scope.py::test_bundle_writer_requires_an_explicit_scope unit
5 A freshly built lock keeps the scope from supplied provenance Governed by policy tests/unit/core/test_bundle_row_scope.py::test_supplied_provenance_carries_the_bundle_scope unit
6 An ambiguous claim (two scopes in one source) keeps the path-inferred scope and is never defaulted to user; when the prior lock and provenance disagree, the prior lock wins Secure by default, Governed by policy tests/unit/core/test_bundle_row_scope.py::test_ambiguous_claim_in_one_source_keeps_the_path_inferred_scope
tests/unit/core/test_bundle_row_scope.py::test_prior_ledger_scope_wins_over_disagreeing_provenance
unit

How to test

  • apm install -g <packed-bundle> --target claude, then grep -A3 'skills/<name>/SKILL.md' ~/.apm/apm.lock.yaml: expect scope: user.
  • apm install -g <some-other-package> --target claude: the bundle rows are unchanged.
  • From ~/.apm: apm install -g --frozen --target claude and apm audit --ci both pass.
  • In a project, apm install <packed-bundle>: the rows say scope: project.

Issue and approved scope

Issue: Fixes #3995

Human scope-approval comment: #3995 (comment) (eligibility.cjs: record-present, review contact Daniel Meppiel (@danielmeppiel)).

This PR completes the issue's approved scope. The 0.37 known-issue release note is out of scope here.

Type of change

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

Testing

  • Tested locally
  • All existing tests pass (environment-only failures are identical on the base)
  • Added tests for new functionality (if applicable)

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md (bottom of Fixed).
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • N/A -- this PR does not change OpenAPM-observable behaviour. No spec, manifest or requirement change; the scope field already exists.

Co-authored-by: Copilot [email protected]

@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-3995-user-scope-bundle-rows branch from 96032d9 to 361d523 Compare November 20, 2026 00:52
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-3995-user-scope-bundle-rows branch from 361d523 to c6608d5 Compare November 20, 2026 01:18
@danielmeppiel
Daniel Meppiel (danielmeppiel) changed the base branch from danielmeppiel-0-37-owner-hardening-b to danielmeppiel-miniature-happiness November 20, 2026 01:18
The bundle writer takes its install scope as a required keyword-only
argument, and a ledger rebuild carries the scope of an unambiguous
surviving bundle claim (prior ledger or supplied provenance) instead of
re-deriving it from the path prefix. Owners, hashes and target
attribution are kept; project bundles stay project. No lock field or
version change.

Refs #3995

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-3995-user-scope-bundle-rows branch from c6608d5 to 10740d2 Compare November 20, 2026 02:11
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…ation cases (#3994)

The content-hash MutationCase block from #4024 was out of guard-id order
(test_matrix_case_order_is_deterministic); moved into sorted position.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
@danielmeppiel
Daniel Meppiel (danielmeppiel) marked this pull request as ready for review November 20, 2026 03:50
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Base automatically changed from danielmeppiel-miniature-happiness to main November 20, 2026 06:41
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 05d891d into main Nov 20, 2026
4 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-3995-user-scope-bundle-rows branch November 20, 2026 06:42
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User-scope bundle rows in ~/.apm/apm.lock.yaml are labelled scope: project

1 participant