Skip to content

fix(git): pin core.symlinks=true so package hashes match across platforms - #3545

Merged
Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-issue-3457-delivery
Nov 12, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-issue-3457-delivery

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

fix(git): pin core.symlinks=true so package hashes match across platforms

TL;DR

APM hides user and system Git config from dependency children, so Git for Windows records core.symlinks=false and writes every in-repo link as a small text file. The package content_hash then differs from the Linux/macOS hash for the same commit and apm install --frozen fails on Windows with a lockfile generated elsewhere. This PR pins core.symlinks=true on every APM clone and checkout and, when the host cannot create symlinks, fails before hashing with a diagnostic that names the package and the Windows requirement.

Important

This deliberately replaces the link-text fallback that #3145 (#3137) preserved for non-admin Windows accounts. Under the approved #3457 scope, a package with in-repo links on a host without symlink capability now fails with a clear diagnostic instead of installing link text with a non-portable hash. Packages without links are unaffected. The native Windows Native Symlink Acceptance job is re-pointed to prove the new contract.

Problem (WHY)

  • _materialize_git_config_snapshot froze whatever core.symlinks it saw, including the false that git init writes on Windows when global config is hidden, so APM clones wrote link text (reporter: microsoft/[email protected], 74 mode-120000 entries, sha256:5ef3cc66… vs Linux sha256:9328e637…).
  • Local cache checkouts (GitCache, shared-bare consumers, checkout_git_worktree) ran under the auth env with no symlink setting at all, so they inherited the same false.
  • Old Windows cache shards keep link text and would keep producing the wrong hash after a fix unless they are rematerialized.
  • [!] When a link cannot be created, the old flow either installed link text or surfaced a later Content hash mismatch, which does not tell the user what to fix.

Why these matter: the lockfile contract requires that the same pinned commit produces the same content_hash on every platform (issue #3457 "Expected behavior"); the approved scope is the apm-scope:v1 record.

Approach (WHAT)

# Fix
1 One owner in utils/git_env.py: git_symlink_pin_args() (-c core.symlinks=true) for local commands, and the network config materializer always emits core.symlinks=true (dropping inherited, capability and caller values).
2 GitSymlinkCapabilityError + raise_for_symlink_capability() classify Git's unable to create symlink failure (through wrapped causes) into one named diagnostic.
3 Route clone (clone_git_worktree), cached checkout (GitCache via _safe_git_args), shared-bare checkout (materialize_from_bare) and the uncached fallback (checkout_git_worktree, sparse fetch) through the pin and the diagnostic.
4 Cache shards persist core.symlinks = true; shards without it are rematerialized on hit, mirroring the existing core.autocrlf heal.
5 The downloader re-raises the diagnostic instead of falling back from cache to clone, sparse to clone, or retrying transports.
6 Checkout results are classified even on exit 0: native Windows git checkout prints unable to create symlink yet exits 0 (observed in the native job). If a commit-pinned clone fails on a link at the default-branch HEAD, it retries with --no-checkout and materializes only the pinned commit.

Implementation (HOW)

  • src/apm_cli/utils/git_env.py — git_symlink_pin_entry (single source of the key/value), git_symlink_pin_args, GitSymlinkCapabilityError, raise_for_symlink_capability; materializer pins instead of retaining (removes _symlink_entry_wins); clone_git_worktree and checkout_git_worktree classify failures (checkout_git_worktree gains package=).
  • src/apm_cli/cache/git_cache.py — _safe_git_args adds the pin; staged shards record both pins; _checkout_has_materialization_pins gates cache hits and write-dedup; checkout failures raise the diagnostic after cleaning the stage.
  • src/apm_cli/deps/bare_cache.py — materialize_from_bare pins clone/sparse/checkout/repair and accepts package= for the diagnostic.
  • src/apm_cli/deps/github_downloader.py — passes the package label and re-raises GitSymlinkCapabilityError from cache, shared-bare, clone and checkout paths.
  • scripts/architecture_linter/checks/transport_auth_platform.py, .apm/architecture/owners/transport-auth-platform.json — extend the existing transport-platform-git-child-environment guard: required owner symbols in git_env.py, required pin/diagnostic use in git_cache.py/bare_cache.py, and a ban on literal core.symlinks= outside git_env.py.
  • Native gate (tests/integration/test_windows_native_symlink.py, scripts/windows_native_symlink_probe_entry.py, probe unit test) — the standard-user case now requires the diagnostic; the negative control inverts the pin (drop-symlink-pin) and must fail.
  • Docs — consumer/install-packages.md, contributing/integration-testing.md, apm-guide dependencies.md describe the new requirement; CHANGELOG Fixed entry.

Diagrams

Legend: where the pin and the diagnostic apply on the install path; boxed nodes are new behavior.

flowchart LR
    DL[github_downloader.download_package] --> GC[GitCache.get_checkout]
    DL --> CL[clone_git_worktree]
    DL --> CO[checkout_git_worktree]
    DL --> MB[materialize_from_bare]
    GC -->|_safe_git_args| PIN["-c core.symlinks=true"]
    CO --> PIN
    MB --> PIN
    CL -->|git_network_env materializer| PIN
    PIN --> GIT{git checkout}
    GIT -->|real symlinks| HASH[copy + compute_package_hash = POSIX hash]
    GIT -->|unable to create symlink| ERR["GitSymlinkCapabilityError: names package + Developer Mode"]
    ERR --> EXIT[apm install exits nonzero, no lockfile]
Loading

Trade-offs

Benefits

  1. A Linux-generated lockfile verifies on Windows with symlink capability for packages with in-repo links.
  2. Non-capable hosts get one actionable error naming the package instead of a later Content hash mismatch.
  3. No cache-to-clone or transport retries after a capability failure.
  4. One guarded owner for the setting; a stray core.symlinks= literal fails the architecture lint.

Validation

Lint mirror (merged with origin/main 59549ac)
$ uv run --extra dev ruff check src/ tests/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/ scripts/windows_native_symlink_probe_entry.py
All checks passed!
$ uv run --extra dev ruff format --check src/ tests/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/ scripts/windows_native_symlink_probe_entry.py
2097 files already formatted
$ uv run --extra dev python -m pylint --disable=all --enable=R0801 --min-similarity-lines=10 --fail-on=R0801 src/apm_cli/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/
Your code has been rated at 10.00/10
$ bash scripts/lint-auth-signals.sh
[+] auth-signal lint clean
$ bash scripts/lint-architecture-boundaries.sh
(no findings)

File-length: github_downloader.py 2050 lines (< 2100). No new relative_to or yaml.dump patterns.

Tests
$ uv run --extra dev pytest tests/unit/cache tests/unit/deps tests/unit/test_windows_native_symlink_probe.py \
    tests/unit/test_windows_native_symlink_workflow.py tests/test_github_downloader.py tests/unit/utils \
    tests/integration/test_git_hook_env_isolation.py tests/integration/test_deps_coverage.py \
    tests/integration/test_architecture_owner_rule_mutations.py
3280 tests: all pass after fixture updates (shards now carry the symlinks pin; checkout call assertions include package=)
$ uv run --extra dev pytest tests/unit/install/test_symlink_capability_install.py tests/integration/test_git_cache_hermetic.py ...
passed

Red on main: 17 of 22 real-Git cases in tests/unit/cache/test_git_symlink_config.py fail on 59549aca5.
Mutation-break: setting _SYMLINK_PIN_VALUE = "false" fails 27 of 29 real-Git cache/clone cases; removing the downloader re-raise fails 2 of 3 downloader cases.

Scenario Evidence

Scenario (user promise) Test Principle
Clone, checkout and uncached fallback carry core.symlinks=true tests/unit/cache/test_git_symlink_config.py::test_network_env_pins_symlinks_true, ::test_checkout_pins_symlinks_over_isolated_caller_env, tests/unit/cache/test_git_cache_symlinks.py::test_safe_git_args_pin_real_symlinks, ::test_bare_materialization_pins_symlinks_over_caller_env Portability
A package with an in-repo link yields the POSIX content_hash (runs natively on the Windows windows_compat lane) test_git_symlink_config.py::test_clone_records_the_posix_content_hash, test_git_cache_symlinks.py::test_cached_checkout_materializes_links_with_posix_hash Reproducibility
No symlink capability: install fails before hashing, names the package, nonzero exit tests/unit/install/test_symlink_capability_install.py, tests/unit/cache/test_git_symlink_pin.py, tests/integration/test_windows_native_symlink.py (native standard user) Fail loud
Old cache shards heal test_git_cache_symlinks.py::test_cache_hit_rematerializes_shard_missing_symlink_pin Reproducibility
Packages without links unaffected existing test_git_cache_autocrlf.py, test_git_cache_hermetic.py, downloader suites No regression

How to test

  • uv run --extra dev pytest tests/unit/cache/test_git_symlink_config.py tests/unit/cache/test_git_cache_symlinks.py tests/unit/cache/test_git_symlink_pin.py tests/unit/deps/test_github_downloader_symlink_capability.py tests/unit/install/test_symlink_capability_install.py
  • On Windows with Developer Mode: apm install a project depending on microsoft/aspire-skills#v0.0.4 with an empty APM_CACHE_DIR; the lockfile records sha256:9328e637….
  • Check the Windows Native Symlink Acceptance job: baseline passes, drop-symlink-pin mutation fails, restored passes.

Issue and approved scope

Issue: Fixes #3457

Human scope-approval comment: #3457 (comment) (Review contact: Daniel Meppiel (@danielmeppiel))

This PR completes the posted Scope and Done when. Out of scope items are untouched.

Type of change

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

Testing

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

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

apm-spec-waiver: remote package content_hash is reserved for OpenAPM v0.2; this fixes platform materialization only

…orms

APM hides user and system Git config from dependency children. Git for
Windows then records core.symlinks=false and writes each in-repo link as
a text file holding its target path, so the package content_hash differs
from the POSIX hash of the same commit and `apm install --frozen` fails
with a lockfile generated on Linux or macOS.

- git_env owns the pin (git_symlink_pin_args and the network config
  materializer) and the GitSymlinkCapabilityError diagnostic.
- Clone, cached checkout, shared-bare checkout and the uncached fallback
  all carry core.symlinks=true; cached shards record the pin and older
  shards are rematerialized on hit.
- A host that cannot create symlinks fails before hashing with an error
  naming the package and the Windows Developer Mode requirement; cache
  and transport fallbacks no longer retry it.
- The native Windows standard-user gate now proves the diagnostic
  instead of the previous link-text fallback.

Fixes #3457

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 20:48
apm-spec-waiver: remote package content_hash is reserved for OpenAPM v0.2; this fixes platform materialization only

Co-authored-by: Copilot App <[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

Uncached installs can fail on unrelated default-branch symlinks or retry downloads after capability failures, while an incorrect cleanup path and platform-dependent fixtures undermine regression tests.

5 open issues
What changed in this PR

This PR addresses #3457 by forcing real symlinks in dependency Git checkouts, preventing link-text files from producing different package hashes across platforms. It deliberately replaces the earlier fallback behavior with an actionable error when the host cannot create symlinks.

Changes:

  • Centralizes the symlink pin and capability diagnostic, applying them across clone and checkout paths.
  • Rematerializes older cache entries and propagates capability failures.
  • Updates regression tests, Windows acceptance checks, architecture guards, and documentation.
File Description
tests/​unit/​test_windows_native_symlink_probe.py Updates diagnostic case and mutation expectations.
tests/​unit/​install/​test_symlink_capability_install.py Tests install failure before hashing or lockfile creation.
tests/​unit/​deps/​test_github_downloader_symlink_capability.py Tests capability-error propagation and retry suppression.
tests/​unit/​deps/​test_github_downloader_phase3.py Updates checkout expectations with package labels.
tests/​unit/​deps/​test_github_downloader_error_handling.py Updates checkout expectations with package labels.
tests/​unit/​cache/​test_proxy_compat.py Adds the symlink pin to cache fixtures.
tests/​unit/​cache/​test_git_symlink_precedence.py Removes obsolete precedence tests.
tests/​unit/​cache/​test_git_symlink_pin.py Tests the canonical pin and error classification.
tests/​unit/​cache/​test_git_symlink_config.py Replaces precedence checks with pin and hash regressions.
tests/​unit/​cache/​test_git_cache.py Updates cache fixtures with both materialization pins.
tests/​unit/​cache/​test_git_cache_symlinks.py Adds cache, rematerialization, and shared-bare regressions.
tests/​unit/​cache/​test_git_cache_recency.py Updates the cache fixture for pin validation.
tests/​unit/​cache/​test_git_cache_hardening.py Updates the cache fixture for pin validation.
tests/​test_github_downloader.py Verifies the package label passed to checkout.
tests/​integration/​test_windows_native_symlink.py Requires a capability diagnostic instead of link-text fallback.
tests/​integration/​test_git_cache_hermetic.py Updates cache fixtures and subprocess counts.
src/​apm_cli/​utils/​git_env.py Owns the symlink pin and capability diagnostic.
src/​apm_cli/​deps/​github_downloader.py Propagates capability errors and passes package labels.
src/​apm_cli/​deps/​bare_cache.py Pins shared-bare checkouts and classifies failures.
src/​apm_cli/​cache/​git_cache.py Pins materialization and rebuilds older checkout shards.
scripts/​windows_native_symlink_probe_entry.py Updates native diagnostic and mutation checks.
scripts/​architecture_linter/​checks/​transport_auth_platform.py Adds pin ownership and consumer guards.
packages/​apm-guide/​.apm/​skills/​apm-usage/​dependencies.md Documents symlink requirements for agent guidance.
docs/​src/​content/​docs/​contributing/​integration-testing.md Updates the native Windows acceptance contract.
docs/​src/​content/​docs/​consumer/​install-packages.md Documents capability errors and cache migration.
CHANGELOG.md Records the portability fix and changed fallback behavior.
.apm/​architecture/​owners/​transport-auth-platform.json Registers ownership of the dependency symlink pin.

Review effort: Balanced

Comment thread src/apm_cli/deps/github_downloader.py Resolved
Comment thread src/apm_cli/deps/github_downloader.py Resolved
Comment thread src/apm_cli/cache/git_cache.py Resolved
Native Windows git checkout prints 'unable to create symlink' but exits 0
without symlink privilege (observed in the Windows Native Symlink
Acceptance job). Classify completed checkout output too, and make the
shared test fixture write LF bytes on Windows.

apm-spec-waiver: remote package content_hash is reserved for OpenAPM v0.2; this fixes platform materialization only

Co-authored-by: Copilot App <[email protected]>
- Expose git_symlink_pin_entry() from git_env; the cache marker, the
  config materializer and the -c args all derive from it, and the
  architecture guard forbids quoted core.symlinks literals elsewhere.
- Classify sparse-checkout results before the exit-code check and let the
  capability error escape, so no re-clone follows a known failure.
- Commit-pinned clones skip the default-branch checkout, so an unrelated
  link at HEAD cannot fail a package that has none.
- Fix the cache test's checkout root so stage cleanup is really asserted.

apm-spec-waiver: remote package content_hash is reserved for OpenAPM v0.2; this fixes platform materialization only

Co-authored-by: Copilot App <[email protected]>
Commit-pinned downloads keep cloning with a checkout (the native
download-denied recovery probe depends on that sequence) and only retry
with --no-checkout when the default-branch clone hits the symlink
capability error, so a link at HEAD cannot fail a commit without links.

apm-spec-waiver: remote package content_hash is reserved for OpenAPM v0.2; this fixes platform materialization only

Co-authored-by: Copilot App <[email protected]>
Resolve git_env.py conflict: keep both the core.symlinks pin helpers
(this PR) and git_autocrlf_pin_args (#3409); checkout_git_worktree now
applies both pins and keeps symlink-capability classification.

Co-authored-by: Copilot App <[email protected]>
Keep the PR changelog bullet under [Unreleased] after the 0.35.1 release cut.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit cbd9f2b into main Nov 12, 2026
31 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-issue-3457-delivery branch November 12, 2026 09:17
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 12, 2026
…3603)

* fix(git): materialize package links from Git objects on every host

Dependency checkouts now pin core.symlinks=false, so Git writes each
in-repo link as link text and never needs OS symlink capability. One
owner, utils/git_sparse.materialize_tracked_symlinks, resolves every
tracked mode-120000 entry in the package scope against the checked-out
commit's tree (POSIX component-wise resolution, containment, 40-hop and
directory-cycle bounds) and writes the target's checkout bytes and
executable bit, or expands a directory link. The result is the tree a
POSIX checkout yields when its links are followed, so content_hash is
identical on Linux, macOS and Windows without Developer Mode, and
--frozen replays a lockfile from any platform.

Escaping, broken and cyclic links are rejected before hashing. Shared
cache shards materialize leniently and the package consumer validates
strictly; shards without the new apm.linkMaterialization marker heal
on hit. Out-of-cone targets resolve from objects, so sparse cones no
longer widen (#2707). The now-unreachable symlink capability diagnostic
from #3545 is removed.

Fixes #3457

apm-spec-waiver: Git checkout link handling is not an OpenAPM statement; materialized links reach req-sc-015 as regular, scanned files.

Co-authored-by: Copilot App <[email protected]>

* docs(changelog): reference #3603 for the link materialization entry

Co-authored-by: Copilot App <[email protected]>

* test(links): root the install lifecycle under a short temp dir for Windows MAX_PATH

Co-authored-by: Copilot App <[email protected]>

* fix(links): bound expansion, reject host-unsafe entries, cover path: fetches

Review follow-ups on the Git-object link owner:
- a shared 100000-entry budget rejects acyclic fan-out before it grows
  exponentially;
- expanded source and destination entry names must be plain portable
  paths (no "..", backslash, colon or NUL), so a POSIX-authored
  "..\\..\\x" cannot escape the checkout on Windows;
- a component after a file, including "", "." and "..", is ENOTDIR;
- link blobs load on demand, and out-of-tree reads take attributes from
  the commit (--attr-source=HEAD, Git 2.40+, with fallback);
- the path: sparse file transport resolves a tracked link through the
  owner instead of returning its link text.

Co-authored-by: Copilot App <[email protected]>

* test(gitlab): allow the local ls-tree link lookup in the sparse transport contract

Co-authored-by: Copilot App <[email protected]>

* test(links): make the unsafe-name and transport link tests portable to Windows

Co-authored-by: Copilot App <[email protected]>

* test(links): feed mktree bytes so Windows does not append CR to entry names

Co-authored-by: Copilot App <[email protected]>

* test(links): cover monorepo subdirectory installs and the full-clone fallback

Panel follow-ups (test-coverage-expert):
- the real-binary lifecycle now runs for a whole-repo and a subdirectory
  package whose links leave the package path; both pin a golden
  content_hash, replay with --frozen from a cold cache and reject
  escaping, broken and cyclic links before any lock is written;
- a real-Git test drives download_subdirectory_package through the
  full-clone fallback and asserts the installed tree is link content.

Co-authored-by: Copilot App <[email protected]>

---------

Co-authored-by: danielmeppiel <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 12, 2026
Name what users observe (an error naming the Git command and offending
byte), cover apm update and other Git-running commands, and keep the
entry next to, not between, the related #3545 symlink entries.

Addresses panel follow-ups from doc-writer (FU-2, FU-3).

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 12, 2026
…#3626)

* fix(install): decode Git output as UTF-8 regardless of Windows locale

On hosts whose locale codec is not UTF-8 (cp936/GBK on Simplified Chinese
Windows), subprocess text mode decoded Git output with the locale codec and
crashed `apm install` inside the Windows reader thread (#3056).

Add run_git_text() to the Git child-process owner (utils/git_env.py): it
decodes UTF-8 with surrogateescape so decoding never fails mid-stream, then
raises GitOutputDecodeError if a successful command's stdout is not valid
UTF-8, and renders stderr / failed-command output with visible backslash
escapes so existing failure handling is unchanged. Route the install-path Git
text-mode calls through it, decode the progress clone stream as UTF-8, and add
the transport-platform-git-output-decoding architecture guard.

Fixes #3056

Co-authored-by: Copilot App <[email protected]>

* docs(changelog): reference #3626 for the Git output decoding fix

Co-authored-by: Copilot App <[email protected]>

* fix(cache): remove staged trees when Git output decoding fails

GitOutputDecodeError subclasses subprocess.SubprocessError, not
CalledProcessError or TimeoutExpired, so a rejected checkout or bare
clone output escaped _create_checkout() and _ensure_bare_repo() (and its
partial-clone fallback) without removing the .inc.* staging tree. Catch
SubprocessError in those three handlers so the stage is removed and the
failure is still raised as the existing RuntimeError, chained to the
named decode error. Regression tests prove no stage or shard remains;
each handler was mutation-broken to confirm its test fails without it.

Addresses Copilot inline on src/apm_cli/cache/git_cache.py:834.

Co-authored-by: Copilot App <[email protected]>

* test(git): guard URL-free decode diagnostics; tighten helper types

Add a parametrized regression proving GitOutputDecodeError names only
'git <subcommand>' and never echoes URLs, tokens, paths or option
values; mutation-broken by dropping the option-value skip (5 of 6 cases
fail). Treat --config-env as a value-taking global option, which Git
accepts in the separated form. Type _escaped_git_text and
_strict_git_text with overloads so CompletedProcess[str] assignments
stay typed, and skip the codec round-trip for empty output.

Addresses panel follow-ups from test-coverage-expert (FU-1),
python-architect (FU-4) and performance-expert (FU-5).

Co-authored-by: Copilot App <[email protected]>

* docs(changelog): describe the Git decode error users actually see

Name what users observe (an error naming the Git command and offending
byte), cover apm update and other Git-running commands, and keep the
entry next to, not between, the related #3545 symlink entries.

Addresses panel follow-ups from doc-writer (FU-2, FU-3).

Co-authored-by: Copilot App <[email protected]>

* fix(cache): count a sparse probe decode error as incomplete

The #3071 sparse completeness probe documents that probe failures count
as incomplete so the shard is rebuilt, but it caught only
CalledProcessError and TimeoutExpired, so a GitOutputDecodeError from
non-UTF-8 ls-files output escaped the cache-hit path. Catch
SubprocessError there and in the best-effort pin write, matching the
other cache handlers in this PR. Regression test mutation-broken.

Co-authored-by: Copilot App <[email protected]>

* test(git): ignore shard lock files in the checkout cleanup regression

On Linux the shard lock leaves a <variant>.lock file next to the
checkout; assert that no stage or published shard remains, as the bare
clone regression already does. Fixes the Build & Test Shard 2 failure.

Co-authored-by: Copilot App <[email protected]>

---------

Co-authored-by: danielmeppiel <[email protected]>
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] Package content hash differs on Windows for packages with in-repo symlinks, so --frozen fails

2 participants