Repository navigation
fix(audit): audit --ci after update -g no longer demands empty ~/.apm/apm_modules - #3797
Conversation
…are locked `apm update -g` on a user manifest with no APM packages (MCP/LSP servers or ~/.apm's own content) takes the service-only path, which never creates ~/.apm/apm_modules. `apm audit --ci` then refused with "installed package materialization is missing" because the command equated an absent directory with missing materialization; `apm install -g` only passed because its resolve phase always creates an empty apm_modules. The decision now lives in one owner, install/audit_replay.py (resolve_ci_audit_materialization): live modules are used as-is, a project checkout gets the lock-pinned scratch replay, and the user workspace refuses only when its lockfile records packages (still fail-closed when the lockfile is unreadable). commands/audit.py delegates; the install-deployment-audit-replay architecture rule now pins that delegation, the user-scope package predicate and the single owner of the refusal message, with mutation proofs. Lifecycle fixtures generated by tagged v0.35.1 and v0.36.0 releases prove update -g then audit --ci is green; packaged user installs still fail closed when apm_modules is gone and project scope is unchanged. Fixes #3781 apm-spec-waiver: audit-side materialization routing fix; no OpenAPM manifest, lockfile or resolver contract changes Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the package-free global audit fix.
No open issues 🎉
What changed in this PR
Fixes #3781 by allowing apm audit --ci after apm update -g when the user lockfile contains no packages, without requiring an empty ~/.apm/apm_modules directory. Missing package materialization still fails audit, and project scratch replay remains unchanged.
Changes:
- Centralizes materialization decisions in
resolve_ci_audit_materialization, with the audit command delegating to it. - Adds unit, lifecycle, and architecture-mutation coverage, backed by fixtures from releases 0.35.1 and 0.36.0.
- Updates audit documentation, the usage guide, and the changelog.
| File | Description |
|---|---|
tests/unit/install/test_ci_audit_materialization.py |
Tests materialization routing and failure handling. |
tests/integration/test_global_update_audit_materialization_lifecycle.py |
Covers global update/audit and unchanged project behavior. |
tests/integration/test_architecture_install_compound_mutations.py |
Verifies enforcement of centralized materialization decisions. |
tests/fixtures/user_global_update_audit/v0.36.0/home/.copilot/mcp-config.json |
Seeds 0.36.0 Copilot MCP configuration. |
tests/fixtures/user_global_update_audit/v0.36.0/home/.copilot/agents/kit-agent.agent.md |
Seeds the 0.36.0 deployed Copilot agent. |
tests/fixtures/user_global_update_audit/v0.36.0/home/.claude/agents/kit-agent.md |
Seeds the 0.36.0 deployed Claude agent. |
tests/fixtures/user_global_update_audit/v0.36.0/home/.claude.json |
Seeds 0.36.0 Claude MCP configuration. |
tests/fixtures/user_global_update_audit/v0.36.0/home/.apm/apm.yml |
Supplies the package-free 0.36.0 user manifest. |
tests/fixtures/user_global_update_audit/v0.36.0/home/.apm/apm.lock.yaml |
Preserves 0.36.0 lock state with deployment fingerprints. |
tests/fixtures/user_global_update_audit/v0.36.0/home/.apm/agents/kit-agent.agent.md |
Supplies the 0.36.0 user-local agent source. |
tests/fixtures/user_global_update_audit/v0.35.1/home/.copilot/mcp-config.json |
Seeds 0.35.1 Copilot MCP configuration. |
tests/fixtures/user_global_update_audit/v0.35.1/home/.copilot/agents/kit-agent.agent.md |
Seeds the 0.35.1 deployed Copilot agent. |
tests/fixtures/user_global_update_audit/v0.35.1/home/.claude/agents/kit-agent.md |
Seeds the 0.35.1 deployed Claude agent. |
tests/fixtures/user_global_update_audit/v0.35.1/home/.claude.json |
Seeds 0.35.1 Claude MCP configuration. |
tests/fixtures/user_global_update_audit/v0.35.1/home/.apm/apm.yml |
Supplies the package-free 0.35.1 user manifest. |
tests/fixtures/user_global_update_audit/v0.35.1/home/.apm/apm.lock.yaml |
Preserves legacy lock state without a Copilot fingerprint. |
tests/fixtures/user_global_update_audit/v0.35.1/home/.apm/agents/kit-agent.agent.md |
Supplies the 0.35.1 user-local agent source. |
tests/fixtures/user_global_update_audit/README.md |
Documents fixture provenance and regeneration. |
tests/fixtures/user_global_update_audit/generate_fixtures.py |
Generates isolated fixtures using tagged release sources. |
src/apm_cli/install/audit_replay.py |
Owns workspace materialization requirements and replay routing. |
src/apm_cli/commands/audit.py |
Delegates materialization decisions to the shared owner. |
scripts/architecture_linter/checks/install_frozen_and_audit.py |
Guards delegation and prevents duplicate refusal logic. |
packages/apm-guide/.apm/skills/apm-usage/commands.md |
Explains the package-free user-workspace exception. |
docs/src/content/docs/reference/cli/audit.md |
Clarifies when global audit requires installed modules. |
CHANGELOG.md |
Records the audit regression fix. |
.gitignore |
Allows Copilot state within the new fixture tree. |
.apm/architecture/owners/install-deployment.json |
Registers the expanded materialization-owner responsibility. |
Review effort: Balanced
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 2 | 0 | Right owner and a more honest invariant than mkdir-in-update. The user-scope predicate misses lockfile-recorded bundle staging, and the gate guard misses APM_MODULES_DIR. |
| Test Coverage Expert | 0 | 3 | 0 | Done-when promises are pinned; both released-fixture lifecycle cases fail pre-fix and pass on the PR. Gaps: no test pins self-entry exclusion or audit's no-write promise on the new path. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 4 follow-ups
- [Python Architect] Make the user-scope predicate 'package deps OR
LockFile.local_staging_slugs()'. Add a unit case (local_staged_files, zero packages, noapm_modules) that must error, and point the arch-lint body check at the predicate. -- Without this, audit can pass a user workspace whose lockfile-recorded bundle staging is missing. - [Test Coverage Expert] Snapshot the isolated home before and after the passing user
audit --ci, and assert nothing changed andapm_modulesis still absent. -- The new no-apm_modulespath has no test proving audit writes nothing. - [Python Architect] Exclude
APM_MODULES_DIRas well as the literalapm_modulesin the_audit_ci_gateguard, with a mutation proof inserting(cfg.project_root / APM_MODULES_DIR).exists(). -- Otherwise the old directory-existence gate could come back through the constant unnoticed. - [Test Coverage Expert] Add a lockfile shape with only
local_deployed_files(self-entry '.') to the unit parametrize, asserting it counts as package-free. -- Pins self-entry exclusion so a refactor can't bring audit --ci fails after update -g: package materialization missing under ~/.apm/apm_modules #3781 back.
Recommendation
Merge for 0.36.1 after the author folds the four recommended items into this PR, as planned. The fix itself is correct, and the regression is proven by released-fixture tests that failed before it. The one fold to verify before merge is the staging-slug predicate with its error-path unit case. The other three are cheap guard and test hardening.
Full per-persona findings
Python Architect
- [recommended] The user-scope predicate counts only package deps and ignores lockfile-recorded local bundle staging under apm_modules//.apm/ at
src/apm_cli/install/audit_replay.py:175
A second lockfile record (local_staged_files, [BUG] Installing a bundle for Codex, Gemini or OpenCode always failsapm audit --ciwith missing deployed files #3705) also points into apm_modules and is reachable at user scope via local bundle installs. With zero package deps and a deleted~/.apm/apm_modules, the old gate refused; the new owner passes.
Suggested: predicate = package deps orlocal_staging_slugs(); add a unit error case; retarget the arch-lint body check. - [recommended] The gate-side guard forbids the literal 'apm_modules' but not the APM_MODULES_DIR constant at
scripts/architecture_linter/checks/install_frozen_and_audit.py:721
Copying the owner's(project_root / APM_MODULES_DIR).exists()back into_audit_ci_gatewould pass the substring check and reinstate a second authority.
Suggested: also excludeAPM_MODULES_DIR; add a mutation proof.
Test Coverage Expert
- [recommended] No test pins that a user lockfile whose only content is the workspace's own (self-entry '.') counts as package-free at
tests/unit/install/test_ci_audit_materialization.py:61
Suggested: add alocal_deployed_files-only lockfile shape to the no-packages parametrize. - [recommended] The new no-apm_modules user audit path has no before/after snapshot proving audit --ci writes nothing under ~/.apm at
tests/integration/test_global_update_audit_materialization_lifecycle.py:112
Suggested: bracket the green audit with a home snapshot; assert unchanged andapm_modulesabsent. - [recommended] Affirmation: re-ran the Done-when traps. Pre-fix src: 2 failed (v0.35.1, v0.36.0), 3 passed; PR: unit + lifecycle 16 passed;
test_required_global_audit_rule_matrix_for_external_roots2 passed.
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
Fold the #3797 panel findings: - LockFile.records_modules_content() owns "does this lockfile record content under apm_modules/": package dependencies or lockfile-proven local bundle staging. resolve_ci_audit_materialization uses it, so a user lockfile with staged bundle content still fails closed when ~/.apm/apm_modules is gone. - install-deployment-audit-replay pins that predicate body and also forbids the APM_MODULES_DIR constant in _audit_ci_gate; two new mutation proofs. - Unit cases for self-content-only (passes) and staging-only (refuses) lockfiles; the lifecycle green audit is bracketed by a home snapshot to prove it writes nothing and leaves apm_modules absent. apm-spec-waiver: audit-side materialization routing fix; no OpenAPM manifest, lockfile or resolver contract changes Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
…ction Co-authored-by: Copilot App <[email protected]>
#3789 landed the RT3 retired-shape heal lifecycle with a strict xfail on the user `update -g` then `audit --ci` cases. With the #3781 fix those cases pass for real (12 passed incl. user-v0.35.1-update and user-v0.36.0-update), so the xfail marker, its sentinel exception and the special-case raise go. .gitignore keeps both fixture-tree `.copilot/` negations. Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 0 | 0 | Both prior findings resolved; no new architecture issues in the delta. |
| Test Coverage Expert | 0 | 0 | 0 | Both prior gaps fixed; no new gaps. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Recommendation
Ready for maintainer review on 2bea4d2: CI is green, both delta panelists found nothing new, the four earlier follow-ups are folded with exact-head evidence, and Copilot recommends approval with no inline comments.
Folded in this run
- (panel) User-scope predicate counts lockfile-recorded local bundle staging via
LockFile.records_modules_content()-- resolved in fce73e8. - (panel) Home snapshot proves the green user
audit --ciwrites nothing and leavesapm_modulesabsent -- resolved in fce73e8. - (panel)
_audit_ci_gateguard also forbidsAPM_MODULES_DIR, with a mutation proof -- resolved in fce73e8. - (panel) Unit case: self-content-only (
local_deployed_files) user lockfile needs noapm_modules-- resolved in fce73e8.
Copilot signals reviewed
- Review on 614242a: approval recommended, zero inline comments; no new comments on later heads (2 fetch rounds, drained).
Regression-trap evidence (mutation-break gate)
tests/integration/test_global_update_audit_materialization_lifecycle.py::test_global_update_then_audit_passes_for_released_user_lockfiles[v0.35.1|v0.36.0]-- deleted the fix (src/reverted to main); both cases FAILED as expected; fix restored.tests/unit/install/test_ci_audit_materialization.py::test_user_workspace_with_modules_content_reports_missing_materialization[staging]-- deletedor self.local_staging_slugs()fromLockFile.records_modules_content; test FAILED as expected; guard restored.tests/integration/test_architecture_install_compound_mutations.pyaudit-replay cases -- each mutation (owner delegation, identity compare, predicate, staging half,apm_modules/APM_MODULES_DIRprobes, refusal ownership) makesinstall-deployment-audit-replayfire.
Lint contract
ruff check and ruff format --check (0.15.12) on src/ tests/ and the architecture linter paths are silent; pylint R0801 10.00/10; scripts/lint-auth-signals.sh and scripts/lint-architecture-boundaries.sh clean.
CI
All required checks pass on 2bea4d2 (Lint, Build & Test shards, Lifecycle Smoke shards, PR Binary Smoke, Architecture Ratchet/Scaling, Spec conformance, Windows gates, CodeQL analyze) (after 0 CI fix iteration(s)).
Mergeability status
| PR | head SHA | CEO stance | iters | folds | defers | Copilot rounds | CI | mergeable | mergeStateStatus | notes |
|---|---|---|---|---|---|---|---|---|---|---|
| #3797 | 2bea4d2 |
ship_now | 2 | 4 | 0 | 2 | green | MERGEABLE | BLOCKED | pending required review |
Convergence
2 outer iteration(s); 2 Copilot round(s). Final panel stance: ship_now.
Ready for maintainer review.
Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors.
Re-verified the sweep's recorded findings on environment-variables, targets-matrix, install-packages, registries, registry-http-api and governance-guide against current main (after #3785, #3774, #3782, #3743, #3797 merged) and fixed what is still drifted. Refs #3800 Co-authored-by: danielmeppiel <[email protected]> Co-authored-by: Copilot App <[email protected]>
Description
User scenario. A user manifest (
~/.apm/apm.yml) with no APM packages -- only MCP/LSP servers and/or~/.apm's own content (~/.apm/agents, ...) -- and no~/.apm/apm_modules(fresh machine, dotfile sync, or a cleaned cache).apm update -gsucceeds, thencd ~/.apm && apm audit --cifails with "installed package materialization is missing at ~/.apm/apm_modules".apm install -gin the same state passes.Root cause. Two code paths disagreed on what "materialized" means:
apm install -galways runs the resolve phase, whichmkdirs an empty~/.apm/apm_moduleseven when nothing is installed into it.apm update -gon a manifest with no APM packages takes the service-only path (_handle_service_only_update), which reconciles MCP/LSP and never createsapm_modules.apm audit --ci(commands/audit.py::_audit_ci_gate) refused any user workspace whoseapm_modulesdirectory was absent, equating "directory missing" with "materialization missing" even when the lockfile records zero packages.So audit depended on an incidental empty directory. Pinned or floating package deps do not reproduce (verified hermetically):
update -gre-materializes them. The issue text says "at least one package dependency"; the oracle (RT3 heal fixtures) and my repro both show the defect is the package-less user lockfile.Fix (one owner). The decision "where does
apm audit --cireach installed package materialization, and does this workspace need any" moves into the existing CI-audit materialization owner,install/audit_replay.py, asresolve_ci_audit_materialization:apm_modules/-> used as-is (unchanged);prepare_ci_audit_replay(unchanged);$APM_HOME) without it -> refuse with the same message andapm install --globalhint only when the lockfile records content under apm_modules (LockFile.records_modules_content(): package dependencies or lockfile-proven local bundle staging); an unreadable lockfile still fails closed; an MCP/LSP-only or self-content-only lockfile needs nothing.commands/audit.pynow only delegates. Install and update therefore share one audit verdict regardless of whether an empty directory exists.Static guard. Extended the existing
install-deployment-audit-replayrule (.apm/architecture/owners/install-deployment.json,scripts/architecture_linter/checks/install_frozen_and_audit.py): the owner must keep the resolved-identity comparison, thelockfile.records_modules_content()predicate (whose LockFile body must cover both packages and staging slugs) and theprepare_ci_audit_replay(delegation;_audit_ci_gatemust callresolve_ci_audit_materializationand must not callget_workspace_deploy_root/prepare_ci_audit_replayor referenceapm_modules/APM_MODULES_DIR; the "installed package materialization is missing" refusal may only appear in the owner. Mutation proofs intests/integration/test_architecture_install_compound_mutations.py(3 existing cases retargeted, 5 new:audit-replay-user-scope-package-predicate,audit-replay-modules-content-staging,audit-replay-command-modules-probe,audit-replay-command-modules-constant-probe,audit-replay-command-owned-refusal).Fixtures.
tests/fixtures/user_global_update_audit/{v0.35.1,v0.36.0}are real~/.apmstates written by the tagged releases (v0.35.1787a97c,v0.36.01759e1e) via the included generator (README documents regeneration). The generator pinsimportlib.metadata'sapm-cliversion so the lockfileapm_versionis the release's (0.35.1 copilot deploymentcontent_hash: null, 0.36.0 fingerprinted)..gitignoreun-ignores.copilot/under this fixture tree only, because the repo-wide.copilot/ignore would otherwise drop the Copilot seeds.Out of scope (per the scope record): dependency selection/parsing, new audit checks. No change to update or install materialization.
Panel (lean) advisory: #3797 (comment) -- all four recommended findings folded in fce73e8.
Issue and approved scope
Issue: Fixes #3781
Human scope-approval comment: #3781 (comment)
Does this PR complete the issue, or what remains? Completes it. Follow-up for the 0.36.1 harness track: once #3789 and this PR are both on main, the
#3781strict xfail intests/integration/test_mcp_retired_shape_heal_lifecycle.py(carried by #3789) must be removed.Type of change
Testing
Validation evidence (macOS,
.venveditable install,APM_BINARY_PATH=.venv/bin/apm, hermetic: temp HOME, local git origins, no network):.venv/bin/python -m pytest tests/unit/install/test_ci_audit_materialization.py tests/unit/policy/test_ci_skill_subset_replay.py tests/unit/deps -p no:xdist -q -k "materialization or subset or staging or lockfile"records_modules_contentreverted to packages-only (mutation-break)[staging]), 12 passedAPM_BINARY_PATH=.venv/bin/apm .venv/bin/python -m pytest tests/integration/test_global_update_audit_materialization_lifecycle.py -p no:xdist -qsrc/reverted tomain(fix removed)[v0.35.1],[v0.36.0]: audit afterupdate -gfails, "materialization is missing"), 3 passed (genuine-missing refusal and project scope unchanged).venv/bin/python -m pytest tests/integration/test_architecture_install_compound_mutations.py tests/integration/test_architecture_owner_rule_mutations.py -p no:xdist -q -k auditbash scripts/lint-architecture-boundaries.shruff check/ruff format --check(0.15.12, uv.lock pin) onsrc/ tests/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/ scripts/windows_native_symlink_probe_entry.pypython -m pylint --disable=all --enable=R0801 --min-similarity-lines=10 --fail-on=R0801 src/apm_cli/ scripts/...bash scripts/lint-auth-signals.shLifecycle coverage:
update -gthenaudit --cifrom~/.apmgreen for 0.35.1- and 0.36.0-written user lockfiles, with a home snapshot proving the audit writes nothing (and again afterinstall -g); a user lockfile with a plain package still fails closed onskill-subset-consistencyanddriftwhen~/.apm/apm_modulesis removed, andupdate -grestores it; project-scopeinstall+update+audit --cigreen with packages and service-only, warm and cold (noapm_modules).Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedapm-spec-waiver:line: audit-side materialization routing only; no manifest, lockfile or resolver contract change.)