Skip to content

fix: preserve user PATH in streamCommand instead of overwriting it#123

Merged
Cyb3rDudu merged 1 commit into
Mcrich23:mainfrom
mvanhorn:fix/111-preserve-user-path
Jun 30, 2026
Merged

fix: preserve user PATH in streamCommand instead of overwriting it#123
Cyb3rDudu merged 1 commit into
Mcrich23:mainfrom
mvanhorn:fix/111-preserve-user-path

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

container-compose up now keeps the user's inherited PATH when it spawns container run, so installs outside the standard Homebrew/system locations (for example Nix at /run/current-system/sw/bin/container) are found instead of failing with env: container: No such file or directory.

Why this matters

In streamCommand (Sources/Container-Compose/Commands/ComposeUp.swift), the child PATH was built with ProcessInfo.processInfo.environment.merging(["PATH": "/usr/local/bin:..."]) { _, new in new }. The { _, new in new } closure replaced the inherited PATH with the hardcoded six directories, so any container binary outside those dirs was invisible to the streamed container run path (issue #111). The fix builds the child PATH from the user's existing PATH and only appends standard fallback directories that are not already present, preserving custom entries.

Testing

Added mergedExecutablePath(existing:fallback:) as a pure helper in Sources/Container-Compose/Helper Functions.swift and covered it with three new cases in Tests/Container-Compose-StaticTests/HelperFunctionsTests.swift (user order preserved with no duplicate fallback dirs, a custom /run/current-system/sw/bin entry survives, and empty/unset PATH falls back to the six standard dirs). Ran swift build (succeeds) and swift test --filter HelperFunctionsTests (21 tests pass).

Fixes #111

streamCommand replaced the inherited PATH with a hardcoded list via a
{ _, new in new } merge, hiding container binaries installed outside the
standard Homebrew/system dirs (e.g. Nix). Build the child PATH from the
user's PATH plus any missing standard fallback dirs via a new pure helper
mergedExecutablePath(existing:fallback:).

Fixes Mcrich23#111
@Cyb3rDudu Cyb3rDudu merged commit 634b4a7 into Mcrich23:main Jun 30, 2026
1 check passed
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.

Fails when container isn't installed in hardcoded path

2 participants