Skip to content

[0.38] fix(deps): install --frozen accepts one local lib reached by two relative paths (#4731) - #4739

Merged
Daniel Meppiel (danielmeppiel) merged 11 commits into
mainfrom
danielmeppiel-4731-frozen-anchor
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 11 commits into
mainfrom
danielmeppiel-4731-frozen-anchor

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

apm install --frozen refused a lockfile that apm install had just written when a monorepo reached one local library through two relative paths (./packages/lib-05 from the root, ../lib-05 from a sibling package). Install wrote two lock rows for that one directory (./packages/lib-05 and local:packages/lib-05), both carrying _local/lib-05. The frozen replay then found two resolved_by parent candidates and raised ambiguous resolved_by parent, and apm audit --ci failed skill-subset-consistency on the duplicate row.

One anchored directory is now one dependency, decided at the owner:

  • src/apm_cli/deps/local_identity.py (new owner): root_local_dirs() / transitive_local_identity(), called by the resolver. A local edge that a package declares, whose anchored directory the root manifest also declares, takes the root declaration's identity and spelling. Install therefore writes ONE lock row; the sibling edge links to the root node. Other transitive local edges keep their anchored local: identity.
  • src/apm_cli/install/local_content_verdict.py (the --frozen / audit --ci local-content verdict) and src/apm_cli/deps/reachability.py (the declared-graph walk behind audit --ci, uninstall and prune) now route through the same owner helpers instead of re-deriving the anchored identity, so they attribute both declaring edges to that one row.
  • The collapsed node keeps install semantics: production status reaches every descendant of a production node (a root devDependency that a production sibling needs ships its subtree), and a targeted update rechecks an existing node at its own anchor.
  • Guard: contracts-tooling-local-identity (closed world, with a mutation case) refuses any other code that derives an anchored local identity, and requires the three consumers to call the owner.
  • src/apm_cli/deps/path_anchoring.py: for lockfiles written before this fix (two rows), parent candidates that anchor to the SAME directory are one parent. Candidates in DIFFERENT directories still refuse with ambiguous resolved_by parent.

The lockfile schema is unchanged. A legacy two-row lockfile replays under --frozen with its bytes unchanged (verified on the installed CLI); audit --ci and distinct per-edge selections point to apm install, which rewrites it to one row. The residual reported earlier on this PR ("two lock rows for one directory / audit skill-subset red") is fixed in this PR, so no separate bug is needed.

Follow-up, not in this PR: apm uninstall <direct dep> drops a direct dependency's lock row even when another package still needs it transitively. This already happens on main for remote packages (root declares d and e, d depends on e, apm uninstall e, then install --frozen fails "does not record everything this install deploys"). It now applies equally to a root-declared local library a sibling also reaches. Reported to the lead for its own record.

Issue and approved scope

Issue: Fixes #4731

Human scope-approval comment: the apm-scope:v1 record on #4731 (review contact Daniel Meppiel (@danielmeppiel)).

This PR completes the issue. Out of scope per the record: lockfile format changes (none: same schema, one row per anchored directory), containment or path-anchoring rules (unchanged), non-local dependencies.

Type of change

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

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)
promise: P-INV-I3 -- install --frozen and audit --ci accept the lockfile install just wrote, without changing it (source: #4731 scope record)
cell: OP=install FROZEN=on SRC=local(transitive, two spellings) PRIM=skill SCOPE=project   owner: deps/apm_resolver.py (local identity)
instrument: today test -> tests/integration/test_local_monorepo_frozen_replay_lifecycle.py::test_frozen_replays_a_lib_reached_by_two_relative_spellings (new: no monorepo two-spelling cell existed)
oracles: [I1 one lock row per directory, I3 frozen + audit --ci exit 0, lockfile bytes unchanged, deployed snapshot unchanged]
failing-before (main 899d17b4): install --frozen exit 1 "ambiguous resolved_by parent '_local/lib-05' ... (['../lib-05', './packages/lib-05'])"; with only the path_anchoring tolerance, audit --ci exit 1 "skill-subset-consistency: local:packages/lib-05: selection unverified"
passing-after: 1 passed
ledger: tests/fixtures/lifecycle_bug_ledger/bugs/4731.json
hints executed: none printed on success

Owner unit cases (tests/unit/deps/test_apm_resolver_helpers.py, TestOneAnchoredDirectoryIsOneDependency and TestOneAnchoredDirectoryNode):

  • the root spelling wins for the same directory, and another directory keeps its local: identity;
  • legacy two-row parents in one directory resolve as one parent;
  • parents in different directories still refuse (control);
  • a dev root library needed by a production sibling, and its descendants, are production (failed before);
  • a targeted sibling update rechecks the library at its own anchor (failed before).

Conformance: tests/spec_conformance/test_local_path_identity_reqs.py cites req-mf-016 (./ and ../ entries are local-path entries), which flips req-mf-016 from skipped to active in CONFORMANCE.

Local validation (through the host guard):

  • 462 targeted and neighbouring tests passed: path_anchoring, reachability, resolver edge cases and helpers, ci_checks, drift, update, git-parent resolver, locked selection evidence, transitive relative local path lifecycle, replacement source consumers, dropped-direct-dependency lifecycle.
  • Head 26cbdec: lifecycle test, owner unit cases, conformance and quality baselines: 204 passed, 1 skipped. Head cd99d2e (review follow-ups): owner unit cases 47 passed, architecture rule inventory + mutation cases 22 passed; full neighbour run delegated to PR CI and ci-integration.
  • Lint chain clean: ruff check and format (0.15.12), pylint R0801, lint-auth-signals, complexity ratchet, assertion-quality ratchet, tm006 taxonomy, architecture boundaries, Mode B (req cited, no waiver).

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

No normative requirement changes. req-mf-016 gains a behavioral conformance test (now active in CONFORMANCE).

…ambiguous (#4731)

install --frozen refused a lockfile where ./packages/lib-05 (root) and
../lib-05 (sibling) both carry _local/lib-05. Resolve every parent
candidate and refuse only when they anchor to different directories.

Adds a failing-before installed-CLI lifecycle test and an owner unit case.

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

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.38.0 milestone Nov 22, 2026
…replay

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
apm-spec-waiver: bug fix restores replay of a lockfile apm install already wrote; no normative requirement changes (anchoring and containment rules unchanged)

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

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This reverts commit 6ad79c0. The fix now cites req-mf-016 through a
conformance marker, so Mode B passes without a waiver.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A sibling's ../lib edge to a directory the root manifest declares as
./packages/lib now takes the root declaration's identity, so install
writes one lock row. The resolver owns the rule
(transitive_local_identity); the --frozen local-content verdict and the
reachability walk behind audit --ci route through it. Cites req-mf-016.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Restores the strict audit oracle relaxed in 6fbef8e: with one lock row
per anchored directory the skill-subset check passes.

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

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.

🟢 Approval recommended

There are no active review issues blocking approval of the frozen-install path-resolution change.

No open issues 🎉

What changed in this PR

Fixes #4731 by allowing frozen installs to replay monorepo lockfiles when different relative paths identify the same local library, without changing the lockfile format or path-containment rules.

Changes:

  • Resolves all local parent candidates and accepts them when they anchor to one directory; distinct directories remain ambiguous.
  • Adds unit and installed-CLI regression coverage for frozen replay, unchanged lockfile and deployed files, and audit parent resolution.
  • Adds a user-facing changelog fragment.
File Description
tests/​unit/​deps/​test_path_anchoring.py Tests equivalent parent paths and rejection of distinct directories; updates the helper mock.
tests/​integration/​test_local_monorepo_frozen_replay_lifecycle.py Covers install-to-frozen replay, artifact preservation, and audit parent resolution.
src/​apm_cli/​deps/​path_anchoring.py Compares resolved parent directories instead of rejecting multiple candidates outright.
changelog.d/​4739.fixed.md Documents the frozen-install fix for shared local libraries.

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.

🟡 Changes recommended

Production status fails to propagate to transitive dependencies, causing both plugin exporters to omit required content, while legacy frozen replay and targeted sibling updates also remain broken.

4 open issues

Review effort: Balanced

Comment thread src/apm_cli/deps/apm_resolver.py Resolved
Comment thread src/apm_cli/deps/apm_resolver.py Resolved
Comment thread src/apm_cli/deps/apm_resolver.py Resolved
Comment thread src/apm_cli/deps/apm_resolver.py Resolved
…d its owner (#4731)

- Production status now reaches every descendant of a production node, so a
  root devDependency that a production sibling also needs ships its subtree.
- A targeted update rechecks an existing node at its own reference and parent,
  not at the incoming edge's anchor.
- deps/local_identity.py owns the local node identity; the resolver, the
  --frozen verdict and the reachability walk call it, and the new
  contracts-tooling-local-identity guard (with a mutation case) refuses bypasses.

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

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

Two critical issues remain: production propagation can leave shared dependencies dev-only based on declaration order, and canonicalized rescue paths can cause uninstall to persist an incorrect parent-relative lockfile path.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

High severity Preserve declaring paths in uninstall rescue data

src/​apm_cli/​deps/​reachability.py:346

Canonicalizing ref.local_path also changes the parent-relative path returned in reachable_via, which uninstall persists during orphan rescue. With a legacy two-row lockfile, production roots a and b both declaring ../lib, and a dev root declaring ./packages/lib, uninstalling a repairs the rescued row to ('_local/b', './packages/lib'), incorrectly pointing at packages/b/packages/lib. Preserve the original declaring path for repair data while using the canonical reference for identity and selections, and add a legacy rescue regression.

4 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/deps/apm_resolver.py Resolved
Propagation now also walks edges the queue dedup dropped (recorded in
_edge_parents), so a leaf shared by two dev roots is production once a
production edge reaches one of them, in either declaration order.

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

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

Human assessment is needed because symlink canonicalization can cause queue deduplication to bypass the explicit single-file symlink refusal, accepting a dependency edge previously rejected.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 47e4a30 into main Nov 22, 2026
72 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4731-frozen-anchor branch November 22, 2026 16:01
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] install --frozen fails with 'ambiguous resolved_by parent' when a local lib is referenced via two relative paths

2 participants