Skip to content

fix(audit): audit --ci accepts a clean install -g of a user-root agent with a context link (#4832) - #4880

Merged
Daniel Meppiel (danielmeppiel) merged 7 commits into
mainfrom
danielmeppiel-p2-4832-user-root-context-links
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 7 commits into
mainfrom
danielmeppiel-p2-4832-user-root-context-links

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

After a clean apm install -g, apm audit --ci reported drift for a user-root agent (~/.apm/agents) that links to a context file. Audit replay computed context and memory links from its scratch target directory, while install computed them from the live ~/.copilot/agents, so the link text differed.

  • UnifiedLinkResolver now maps the target through the deployment frame for context and memory links too (_live_target_location), as asset links already did. The frame only shapes link text; replay writes stay in scratch.
  • A dependency replayed from scratch projects its context source through deployment_package_root (as asset links do); other scratch paths map through the frame; live and external sources are unchanged.
  • init_link_resolver sets the frame for every package, including the $HOME user root.
  • In run_replay, a lock self-entry (claimed root files) replays with the frame and its live source root. No self-entry is synthesized.

Issue and approved scope

Issue: Fixes #4832

Human scope-approval comment: #4832 (comment)

Does this PR complete the issue, or what remains? Completes it: the install -g -> audit --ci regression passes, and the edited-agent control still reports drift.

Type of change

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

Testing

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

New tests: tests/integration/test_user_root_primitives_lockfile_lifecycle.py::test_install_g_then_audit_accepts_a_user_root_context_link (clean audit passes; edited deployed agent still drifts with exit 1) and tests/unit/compilation/test_link_resolver.py::TestReplayFrameTranslation::test_replay_renders_context_links_in_live_deployment_frame. test_install_g_then_audit_accepts_a_dependency_context_link (user scope) and tests/integration/test_local_link_audit_replay_lifecycle.py::test_local_dependency_context_link_audits_clean_and_tracks_edits (project scope) plus test_replay_projects_a_scratch_dependency_context_link_to_its_live_package cover a scratch-materialized dependency. Bug ledger row: tests/fixtures/lifecycle_bug_ledger/bugs/4832.json.

Validation evidence:

  • Red-first: with the src/ changes reverted to origin/main, the user-root and user-scope dependency integration tests and the unit tests fail; without the dependency projection, the project-scope dependency test fails too. All pass with the fix. Earlier: both original tests fail (audit exit 1, 1 of 15 check(s) failed; unit link text mismatch); restored, both pass.
  • After the review fold: pytest -n auto tests/unit/{compilation,install,integration,policy} tests/unit/test_audit_ci_command.py + 16 audit/link/drift integration modules: 9247 passed; 246 env-only failures (test_unix_install_ownership.py, same on main).
  • Before the fold: uv run --extra dev pytest -q -n auto tests/unit tests/integration/test_global_update_audit_materialization_lifecycle.py tests/integration/test_user_root_primitives_lockfile_lifecycle.py tests/integration/*drift* tests/integration/*audit* tests/integration/*replay*: 29858 passed. 260 failures are local-environment-only (root user ownership, IPv6 guard, git env); the identical set fails on origin/main in the same container.
  • Released-lockfile guard test_global_update_then_audit_passes_for_released_user_lockfiles[v0.35.1|v0.36.0]: passed.
  • tests/quality/test_lifecycle_bug_ledger.py tests/quality/test_test_taxonomy.py: 38 passed.
  • Lint chain (ruff check, ruff format --check, pylint R0801, lint-auth-signals, complexity ratchet vs origin/main, taxonomy allowances, obligation status ratchet, YAML/file-length/relative_to guards, architecture boundaries, tm006): all clean.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

If this PR changes behaviour that an OpenAPM v0.1 req-XXX covers,
confirm the three-step ritual in the
development guide:

  • 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.

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

A critical link-resolution issue leaves scratch-materialized dependency sources pointing into scratch rather than their installed location, requiring corrected source mapping and a clean install/audit regression test.

1 open issue
What changed in this PR

This PR addresses #4832: false drift reported by apm audit --ci after a clean global install of a user-root agent with a context link. It aligns replay link rendering with live deployment paths while keeping writes in scratch.

Changes:

  • Shares deployment-target mapping across context, memory, and asset links.
  • Passes deployment coordinates to all replayed packages, including user-root self-entries.
  • Adds regression coverage, an edited-agent drift control, and release documentation.
File Description
tests/​unit/​compilation/​test_link_resolver.py Tests matching context-link rendering during install and replay.
tests/​integration/​test_user_root_primitives_lockfile_lifecycle.py Tests clean global-install audits and detection of deployed-agent edits.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4832.json Records the regression and its coverage.
src/​apm_cli/​integration/​base_integrator.py Sets the deployment frame for every package.
src/​apm_cli/​install/​drift.py Supplies live source and deployment coordinates for self-entry replay.
src/​apm_cli/​compilation/​link_resolver.py Reuses live-target mapping for context, memory, and asset links.
changelog.d/​4880.fixed.md Documents the user-visible audit fix.

Review effort: Balanced

…yment frame (#4832)

UnifiedLinkResolver._resolve_context_link computed context and memory
links from the replay's scratch target directory, so after a clean
apm install -g a user-root agent linking ../context/notes.context.md
drifted under audit --ci. Context links now map the target through the
deployment frame, as asset links already did; init_link_resolver sets
the frame for every package (the $HOME user root included), and a lock
self-entry (claimed root files) replays with the frame and its live
source root. No self-entry is synthesized. Writes stay in scratch.

Stacked on #4684 (a668d29).

apm-spec-waiver: audit replay link text only; no manifest, lockfile or resolver contract changes

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…ckage (#4832)

Copilot review: a dependency replayed from scratch kept its context link
source in scratch while the target mapped live. Context sources now project
through deployment_package_root like asset links; scratch paths outside the
package map through the frame; live and external sources are unchanged.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

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

A symlinked APM root still produces false dependency drift because replay paths differ from installation paths, requiring root resolution and a regression test.

1 open issue
1 resolved since last review

Review effort: Balanced

…ical paths (#4832)

Copilot review: a symlinked APM_HOME or ~/.apm made the projection emit the
symlink spelling while install linked from the physical path discovery
registered. Projected package and frame roots now resolve; asset-link
handling is unchanged.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

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.

🔵 Needs a closer look

The folded fix changes shared project replay and self-entry framing beyond the linked human approval’s scope, requiring maintainer confirmation of expanded authorization.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

🔵 Needs a closer look

The PR changes project self-entry framing and project-scope dependencies beyond the linked human scope approval, requiring maintainer confirmation that the broader replay scope is authorized.

No open issues 🎉

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit edd1429 into main Nov 23, 2026
72 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-p2-4832-user-root-context-links branch November 23, 2026 07:16
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Fold the changelog.d fragments for #4858, #4868, #4870, #4880 and #4908 into [0.38.1].

Co-authored-by: Copilot App <[email protected]>
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.

[BUG] audit --ci reports drift after a clean install -g for a user-root agent with a context link

2 participants