Skip to content

Add ProcessStartOptions class with platform-aware path resolution#124271

Merged
adamsitnik merged 36 commits intomainfrom
copilot/add-processstartoptions-class
Feb 18, 2026
Merged

Add ProcessStartOptions class with platform-aware path resolution#124271
adamsitnik merged 36 commits intomainfrom
copilot/add-processstartoptions-class

Conversation

Copy link
Contributor

Copilot AI commented Feb 11, 2026

Description

Adds ProcessStartOptions class providing explicit path resolution and process configuration with platform-specific semantics.

Changes

API Surface

  • ProcessStartOptions(string fileName) - resolves executable path and validates existence
  • Properties: FileName, Arguments, Environment, WorkingDirectory, InheritedHandles, KillOnParentExit, CreateNewProcessGroup
  • Arguments, Environment, InheritedHandles use lazy allocation
  • Environment populated from Environment.GetEnvironmentVariables() using Dictionary<string, string?>
  • Null validation on Arguments and InheritedHandles setters
  • Constructor throws FileNotFoundException with localized message when path cannot be resolved or file doesn't exist

Path Resolution

  • Windows: appends .exe (except when path contains separators, ends with ., or has extension) → System32 → PATH (using ; separator)
  • Unix: PATH only (using : separator)
  • Current directory accessed only with explicit ./ (Unix) or .\ (Windows) prefix
  • Returns rooted, fully-qualified paths via Path.GetFullPath for non-fully-qualified inputs

Implementation Structure

  • ProcessUtils partial class consolidates shared logic:
    • ProcessUtils.cs - shared FindProgramInPath with comment explaining Unix permission checking
    • ProcessUtils.Windows.cs - private IsExecutable (forwards to File.Exists)
    • ProcessUtils.Unix.cs - private IsExecutable (validates executable permissions)
  • Process.Unix.cs calls ProcessStartOptions.ResolvePath (eliminates duplicate Process.ResolvePath)
  • Process.IsExecutable made internal for reuse
  • Uses Environment.SystemDirectory instead of duplicating GetSystemDirectoryW
  • Caches Windows directory in s_cachedWindowsDirectory
  • Localized error string SR.FileNotFoundResolvePath

Tests

  • 25 tests across 3 partial class files (base, Windows, Unix)
  • Target-typed new() syntax, [Theory] with [InlineData] for parameterized tests
  • Platform-specific assertions: EndsWith for paths (handles symlink variations), Path.GetFullPath for macOS /tmp symlinks
  • Conditional attributes: IsNotWindowsNanoServer, IsNotWindowsServerCore
  • Tests validate: lazy initialization, path resolution, platform separators, error cases

Customer Impact

Provides safer, more explicit alternative to ProcessStartInfo for scenarios requiring validated executable paths and controlled environment inheritance.

Testing

  • Manual: Library builds successfully
  • Automated: 25 unit tests covering path resolution, lazy initialization, platform-specific behavior, error cases

Example

// Resolves and validates path during construction
var options = new ProcessStartOptions("cmd");
Console.WriteLine(options.FileName); // C:\Windows\System32\cmd.exe

// Lazy-allocated collections
options.Arguments.Add("/c");
options.Arguments.Add("echo test");

// Environment inherits current process, modifiable
options.Environment["MY_VAR"] = "value";

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.

Copilot AI and others added 3 commits February 11, 2026 14:07
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ProcessStartOptions class to System.Diagnostics namespace Add ProcessStartOptions class with platform-aware path resolution Feb 11, 2026
Copilot AI requested a review from adamsitnik February 11, 2026 14:16
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please address my feedback

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot address my feedback

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please address my feedback

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot AI requested a review from adamsitnik February 11, 2026 18:49
@adamsitnik adamsitnik requested a review from jkotas February 17, 2026 18:49
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot AI force-pushed the copilot/add-processstartoptions-class branch from bc6543b to c056741 Compare February 17, 2026 19:58
Copilot AI changed the title Add ProcessStartOptions class with simplified path resolution Add ProcessStartOptions class with platform-aware path resolution Feb 17, 2026
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot address my feedback

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
@jkotas
Copy link
Member

jkotas commented Feb 17, 2026

@copilot Address all feedback that was not addressed yet

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…mment

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@adamsitnik
Copy link
Member

/ba-g all build and test failures are known

@adamsitnik adamsitnik merged commit 823bec2 into main Feb 18, 2026
145 of 150 checks passed
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.

4 participants

Comments