I've completed the fix. Here's my checklist review:
1. Reproduced the reported error
Yes. I built a hermetic repro that drives the real install pipeline with an Azure-DevOps-shaped single-file dependency (dev.azure.com/org/project/repo/.apm/instructions/x.instructions.md) whose file API is mocked. Such deps get no resolved_commit in apm.lock.yaml (APM can't cheaply resolve a SHA on non-GitHub hosts — hence the user's cache-pin: ... has no resolved_commit warnings), so they are re-downloaded from the floating branch on every install. As soon as the upstream bytes differ from the recorded content_hash, FreshDependencySource calls sys.exit(1) with exactly the reported message — and because the install aborts before the lockfile is rewritten, every subsequent apm install fails identically ("fails consistently the second time"). Verified on the unpatched tree: run 2 and run 3 both exit 1 with Content hash mismatch ... supply-chain attack.
2. Confirmed the fix resolves the error
Yes. src/apm_cli/install/sources.py now gates the hard-fail on lockfile_pin_is_immutable(dep_locked_chk): the byte-equality check is only meaningful when the re-download replayed an immutable identity (resolved_commit SHA, or a registry resolved_hash). For unpinnable/floating deps APM accepts the new content, records the fresh hash (so the lockfile self-heals), and emits a Content changed for unpinned dependency <pkg> ... add #tag or #sha warning. Re-running the repro: install 1 OK, install 2 (content changed) succeeds with a warning and deploys the new content, install 3 is silent.
3. Edge cases
- Pinned deps keep the hard-fail: verified end-to-end (lockfile with
resolved_commit, tampered bytes, wiped cache → still exits 1) and by the existing unit test test_hash_mismatch_calls_sys_exit.
resolved_commit == "cached" sentinel and None entries are treated as unpinned (no immutable identity to verify against).
- Registry deps with
resolved_hash stay in the strict regime; MagicMock-based locked entries in tests still resolve as "pinned", so no silent behaviour change for existing tests.
--update/expected-hash-change/heal-chain paths are untouched; --frozen is enforced structurally elsewhere and is unaffected.
4. Ran existing tests
Full unit suite: 15 812 passed. Full integration suite: 9 032 passed with 3 failures that I verified are pre-existing on a clean tree (permission-denied tests running as root + one ADO preflight test). Focused suites (tests/unit/install, sources/content-hash-related integration files) all pass. I also reverted the repo-tree pollution (apm.lock.yaml, .github/…, .agents/…) that the integration suite generated, so the diff contains only my intended changes: the fix plus CHANGELOG and docs updates describing the pinned vs. unpinned regimes.