Skip to content

Make Configuration introspectable#268

Draft
broken-circle wants to merge 1 commit into
swiftlang:mainfrom
broken-circle:introspectable-configuration-206
Draft

Make Configuration introspectable#268
broken-circle wants to merge 1 commit into
swiftlang:mainfrom
broken-circle:introspectable-configuration-206

Conversation

@broken-circle
Copy link
Copy Markdown
Contributor

Closes #206.

This PR adds public introspection of Arguments, Executable, and Environment so callers generating subprocess configurations can unit-test them without spawning a subprocess. The current storage of these types is opaque, leaving callers with only string-based descriptions to parse.

Design

  • Arguments conforms to RandomAccessCollection<Arguments.Value>, where Value is a public mirror of the internal StringOrRawBytes. A Value enum was chosen over lossy UTF-8 decoding so callers constructing arguments from [UInt8] on POSIX can verify the exact bytes.

  • Arguments.executablePathOverride is exposed as a separate public property rather than folded into iteration. Folding would make argv[0] ambiguous between an override and a regular first argument, and would prevent callers from distinguishing the two cases in tests. The internal stored property is renamed to _executablePathOverride to free the name for the public accessor.

  • Executable and Environment expose their contents through new Representation mirror enums rather than exposing their internal storage types directly, decoupling the public introspection surface from internal storage. Environment.Key.path is promoted from package to public so callers can use it as a canonical reference to the PATH key.

Testing

The full test suite passes locally on macOS, and on windows-latest and ubuntu-latest using GitHub Actions.

@broken-circle broken-circle force-pushed the introspectable-configuration-206 branch from eabae88 to bbd9ecb Compare May 18, 2026 20:05
@jakepetroules
Copy link
Copy Markdown
Contributor

The capability is nice, but I'm a little concerned about the use of enums in public API -- usually that's discouraged. I'm not sure what other good options there are, though.

@allevato
Copy link
Copy Markdown
Member

Making it a @nonexhaustive enum would avoid the issues that tended to cause problems with evolution for enum-based APIs, I think?

@broken-circle
Copy link
Copy Markdown
Contributor Author

Nice, I was just wondering if something like @nonexhaustive existed. Reading SE-0487, it seems appropriate here.

We could annotate Arguments.Value and Executable.Representation with @frozen, since their cases are exhaustive. Environment.Representation can be @nonexhaustive.

Package.swift specifies Swift 6.2+, so we're good on that front.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Make Configuration, Arguments, and Environment more open for testing purposes

3 participants