Skip to content

Environment.updating(_:) on a .custom environment causes inheritance #191

@maxchuquimia

Description

@maxchuquimia

Describe the bug
When using the instance function Environment.updating(_:) on any existing instance of Environment, Subprocess simply adds the new values to the .inherit environment rather than the instance itself.

To Reproduce

Consider this program that uses a .custom environment and the env command to print the subprocess' perceived environment:

let pristineEnv: Environment = .custom(["A": "1"])

let result1 = try await run(
    .name("env"),
    environment: pristineEnv,
    output: .string(limit: 4096)
)

// Print 1
print(result1.standardOutput ?? "")

let result2 = try await run(
    .name("env"),
    environment: pristineEnv.updating(["B": "2"]),
    output: .string(limit: 4096)
)

// Print 2
print(result2.standardOutput ?? "")

Expected behavior

  • At Print 1
    • ✅ The printed environment is exactly "A=1\n"
      • This is expected as the environment is .custom (i.e. not .inherited from the calling process)
  • At Print 2
    • ✅ The printed environment includes "B=2"
    • ❌ The printed environment does not include "A=1"
    • ❌ The printed environment includes the entire inherited environment (e.g. USER, HOME etc)

Environment:

  • macOS 15.6
  • swiftlang-6.1.0.110.21 clang-1700.0.13.3

Additional context
This report is based on my assumption about how the .updating function should work based on it's name, apologies if this behaviour is intended.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions