fix(agent): skip git shims on PATH and check git in Windows self-test #93

Merged
HumanBean merged 1 commit from Jer9/Beanstalk:fix/windows-git-shim into main 2026-11-20 15:26:24 +00:00
Contributor

Fixes #92

On Windows systems using Scoop or similar package managers, git.exe on PATH is a shim launcher (e.g. accompanied by git.shim) that executes the real binary located outside the directory granted to the Windows sandbox. Because MinGit.OnPath previously treated any git.exe on PATH as usable, Workspace.EnsureGitAsync skipped fetching MinGit (#62), and WinHost.Git granted only the shims folder to the AppContainer sandbox—causing commands like scripts/dev_packs.py to fail with exit 1 inside the sandbox. In addition, setup and self-test lacked in-sandbox verification of git execution.

What changed

  • Skip package-manager shims (agent/Core/MinGit.cs):
    • Added MinGit.Find and MinGit.ShimOf to detect and skip package-manager shims: Scoop sibling .shim files, Chocolatey sibling choco.exe/chocolatey.exe or chocolatey\bin directories, immediate shims directories, and reparse points (FileAttributes.ReparsePoint), while preserving small real wrapper executables such as Git for Windows' cmd\git.exe and bin\git.exe. Safely handles quoted or empty PATH elements.
    • Added MinGit.Fetched to verify an existing <data>\mingit\cmd\git.exe installation stamped by .beanstalk-mingit.
  • Align host git selection (agent/Core/Workspace.cs):
    • Updated Workspace.EnsureGitAsync to use MinGit.Find, logging when shims are skipped and recording Workspace.GitPath when a valid non-shim git.exe is selected on PATH.
  • Align sandbox git grants (agent/Core/WindowsPlan.cs, agent/Core/WindowsSandbox.cs):
    • Extracted pure helper WinGit.Folder for sandbox directory determination and normalisation.
    • Replaced the duplicate unquoted PATH scan in WinHost.Git() with MinGit.OnPath(Env("PATH")), falling back to Workspace.GitPath ?? MinGit.Fetched(Path.Combine(data, "mingit")).
    • Added ModeChoice.FailWhenFailed = { "git" } so git is not marked Required before MinGit is downloaded (allowing skip during initial setup), while failing the mode if git is present in the sandbox but fails.
    • No AppContainer sandbox grants or security boundaries were loosened.
  • In-sandbox git verification and diagnostic logging (agent/Core/WindowsSelfTest.cs):
    • Added git for the sandbox: diagnostic header and scrubbed logging in WinSelfTest.
    • In WinSelfTest.Probe, added GitInside() to resolve git on sandbox PATH and execute git --version with LC_ALL=C, reporting @@check git pass|fail|skip with detail scrubbed before writing to sandbox-check.json.
  • Unit checks (agent/tests/agent_core/SetupChecks.cs, agent/tests/agent_core/WindowsChecks.cs):
    • Added comprehensive unit checks for MinGit.Find, MinGit.ShimOf, MinGit.Fetched, WinGit.Folder, and ModeChoice evaluation of git passes/skips/failures across cross-platform mock environments.

How it was tested

  • dotnet build agent/Beanstalk.Agent.slnx -c Release -p:RestoreLockedMode=true: passed with 0 warnings and 0 errors.
  • beanstalk-agent.dll --self-check: passed (beanstalk-agent dev, exit code 0).
  • python -I -B agent/tests/test_release.py: passed (0 failures).
  • Direct sandbox-probe checks on compiled binary:
    • Valid git on PATH: emitted @@check git pass git version 2.56.0.windows.4.
    • No git on PATH: emitted @@check git skip no git on the sandbox's PATH.
    • Intentionally broken git: emitted @@check git fail git --version: exit 1: (no output).
  • Self-test logging and data scrubbing checks:
    • Verified across multiple scratch configurations (Scoop + Program Files Git, Scoop-only, Scoop + pre-fetched MinGit in custom data directory, user directory git).
    • Confirmed headers and logs scrub <data>, <home>, and <user> paths, and that sandbox-check.json contains no raw personal/user paths.
  • python -I -B agent/tests/test_agent_core.py --dotnet ... --strict:
    • On this machine, both main (e431624) and fix/windows-git-shim encounter a pre-existing SetupChecks.cs:56 IOException (LinuxPython.UnpackAsync tar symlink creation fails when Windows Developer Mode is disabled).
    • In a temporary scratch archive where that tar symlink entry was substituted with a regular file, all 1977 checks passed across all 30 test sections (setup: 58 checks, windows: 144 checks) plus test_windows_python_fix.py (6 tests OK).
  • Note on AppContainer probes in automated worker session: child processes in this headless session encounter 0xC0000142 STATUS_DLL_INIT_FAILED due to window station access restrictions, identical to main.
Fixes https://git.magicbean.dev/MagicBeanDev/Beanstalk/issues/92 On Windows systems using Scoop or similar package managers, `git.exe` on `PATH` is a shim launcher (e.g. accompanied by `git.shim`) that executes the real binary located outside the directory granted to the Windows sandbox. Because `MinGit.OnPath` previously treated any `git.exe` on `PATH` as usable, `Workspace.EnsureGitAsync` skipped fetching MinGit (#62), and `WinHost.Git` granted only the `shims` folder to the AppContainer sandbox—causing commands like `scripts/dev_packs.py` to fail with exit 1 inside the sandbox. In addition, setup and self-test lacked in-sandbox verification of `git` execution. ## What changed - **Skip package-manager shims (`agent/Core/MinGit.cs`):** - Added `MinGit.Find` and `MinGit.ShimOf` to detect and skip package-manager shims: Scoop sibling `.shim` files, Chocolatey sibling `choco.exe`/`chocolatey.exe` or `chocolatey\bin` directories, immediate `shims` directories, and reparse points (`FileAttributes.ReparsePoint`), while preserving small real wrapper executables such as Git for Windows' `cmd\git.exe` and `bin\git.exe`. Safely handles quoted or empty `PATH` elements. - Added `MinGit.Fetched` to verify an existing `<data>\mingit\cmd\git.exe` installation stamped by `.beanstalk-mingit`. - **Align host git selection (`agent/Core/Workspace.cs`):** - Updated `Workspace.EnsureGitAsync` to use `MinGit.Find`, logging when shims are skipped and recording `Workspace.GitPath` when a valid non-shim `git.exe` is selected on `PATH`. - **Align sandbox git grants (`agent/Core/WindowsPlan.cs`, `agent/Core/WindowsSandbox.cs`):** - Extracted pure helper `WinGit.Folder` for sandbox directory determination and normalisation. - Replaced the duplicate unquoted `PATH` scan in `WinHost.Git()` with `MinGit.OnPath(Env("PATH"))`, falling back to `Workspace.GitPath ?? MinGit.Fetched(Path.Combine(data, "mingit"))`. - Added `ModeChoice.FailWhenFailed = { "git" }` so `git` is not marked `Required` before MinGit is downloaded (allowing `skip` during initial setup), while failing the mode if `git` is present in the sandbox but fails. - No AppContainer sandbox grants or security boundaries were loosened. - **In-sandbox git verification and diagnostic logging (`agent/Core/WindowsSelfTest.cs`):** - Added `git for the sandbox:` diagnostic header and scrubbed logging in `WinSelfTest`. - In `WinSelfTest.Probe`, added `GitInside()` to resolve `git` on sandbox `PATH` and execute `git --version` with `LC_ALL=C`, reporting `@@check git pass|fail|skip` with detail scrubbed before writing to `sandbox-check.json`. - **Unit checks (`agent/tests/agent_core/SetupChecks.cs`, `agent/tests/agent_core/WindowsChecks.cs`):** - Added comprehensive unit checks for `MinGit.Find`, `MinGit.ShimOf`, `MinGit.Fetched`, `WinGit.Folder`, and `ModeChoice` evaluation of `git` passes/skips/failures across cross-platform mock environments. ## How it was tested - `dotnet build agent/Beanstalk.Agent.slnx -c Release -p:RestoreLockedMode=true`: passed with 0 warnings and 0 errors. - `beanstalk-agent.dll --self-check`: passed (`beanstalk-agent dev`, exit code 0). - `python -I -B agent/tests/test_release.py`: passed (0 failures). - Direct `sandbox-probe` checks on compiled binary: - Valid git on PATH: emitted `@@check git pass git version 2.56.0.windows.4`. - No git on PATH: emitted `@@check git skip no git on the sandbox's PATH`. - Intentionally broken git: emitted `@@check git fail git --version: exit 1: (no output)`. - Self-test logging and data scrubbing checks: - Verified across multiple scratch configurations (Scoop + Program Files Git, Scoop-only, Scoop + pre-fetched MinGit in custom data directory, user directory git). - Confirmed headers and logs scrub `<data>`, `<home>`, and `<user>` paths, and that `sandbox-check.json` contains no raw personal/user paths. - `python -I -B agent/tests/test_agent_core.py --dotnet ... --strict`: - On this machine, both `main` (`e431624`) and `fix/windows-git-shim` encounter a pre-existing `SetupChecks.cs:56` `IOException` (`LinuxPython.UnpackAsync` tar symlink creation fails when Windows Developer Mode is disabled). - In a temporary scratch archive where that tar symlink entry was substituted with a regular file, all 1977 checks passed across all 30 test sections (`setup: 58 checks`, `windows: 144 checks`) plus `test_windows_python_fix.py` (6 tests OK). - Note on AppContainer probes in automated worker session: child processes in this headless session encounter `0xC0000142 STATUS_DLL_INIT_FAILED` due to window station access restrictions, identical to `main`.
fix(agent): skip git shims on PATH and check git in Windows self-test
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Coordinator tests (pull_request) Blocked by required conditions
CI / Agent build and checks (pull_request) Blocked by required conditions
CI / Coordinator image (pull_request) Blocked by required conditions
e61ad9063b
Package-manager shims for git (such as Scoop's git.exe + git.shim or Chocolatey's shim) launch the real binary from outside the directory granted to the Windows sandbox, causing scripts/dev_packs.py to fail with exit 1 inside AppContainer (#92).

Skip shims in MinGit.Find / MinGit.OnPath (without rejecting small real launchers like Git for Windows' cmd\git.exe), share that lookup between Workspace.EnsureGitAsync and WinHost.Git (falling back to MinGit when no non-shim git is on PATH, including an already-fetched <data>\mingit), log sandbox git selection, and verify git --version inside WinSelfTest.Probe (skipping when MinGit has not been fetched yet, failing the mode only if git is present and fails).

Assisted-by: Antigravity

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Co-Authored-By: Gemini 4 Hydrogen <[email protected]>
Jer9 changed title from WIP: fix(agent): skip git shims on PATH and check git in Windows self-test to fix(agent): skip git shims on PATH and check git in Windows self-test 2026-11-18 13:34:25 +00:00
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Coordinator tests (pull_request) Blocked by required conditions
CI / Agent build and checks (pull_request) Blocked by required conditions
CI / Coordinator image (pull_request) Blocked by required conditions
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Beanstalk!93
No description provided.