The working tree is now clean except for the fix. Done — summary:
Root cause
apm install was failing on the second run for unpinned virtual single-file dependencies (e.g. .../.apm/instructions/testing.instructions.md from Azure DevOps):
- SHA resolution is unsupported for ADO (
git_reference_resolver.py:239 returns None), so these deps get no resolved_commit in the lockfile — hence the cache-pin: ... has no resolved_commit warnings in the issue's log.
- Both cache-serving checks — the pre-download skip (
phases/download.py) and _resolve_download_strategy (phases/integrate.py) — required either a resolved_commit or source == "registry". Unpinned virtual-file deps matched neither, so every plain apm install re-fetched the current branch tip (that's why they never showed (cached)).
FreshDependencySource then compared the fresh fetch against the lockfile's content_hash and hard-exited (sys.exit(1)) on any difference — even though the cached install still matched the lockfile byte-for-byte. As soon as the upstream branch moved, every install after the first failed with "Content hash mismatch ... may indicate a supply-chain attack."
I reproduced this end-to-end (ADO-shaped repo, subdir packages + virtual instruction deps, upstream content changing between installs → run 2 exits 1), then verified the fix.
Fix (2 production files, no new interfaces)
src/apm_cli/install/phases/integrate.py — _resolve_download_strategy: new fallback branch — a locked dep with no resolved_commit but a recorded content_hash is served from cache when _should_skip_redownload verifies the on-disk content against the lockfile (mirrors the existing registry-dep branch). Sets lockfile_match_via_content_hash_only so the heal chain semantics stay intact. Skipped on --update/--refresh and on manifest ref changes.
src/apm_cli/install/phases/download.py — the parallel pre-download phase gets the same skip, since it would otherwise overwrite the verified cache with the branch tip before integrate runs.
Verified semantics: plain installs are now idempotent and replay the lock (npm model); --update still fetches new upstream content and re-pins the hash; a tampered/corrupt cache still fails verification and is re-downloaded; ref changes still force re-fetch.
Tests
- 3 new cases in
tests/unit/install/test_integrate_orchestration.py (cache served on hash match; mismatch still re-downloads; --update bypasses).
- New
tests/unit/install/phases/test_download_phase.py (4 cases for the pre-download skip).
- Full unit suite: 15,819 passed; integration suite: 9,031 passed with 4 failures that are environment artifacts unrelated to the change (root user defeats permission-denied tests, live PyPI version banner, host auth tooling).
ruff check/format clean; git diff --check clean. Changes left uncommitted.