Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions src/Aspire.Cli/Agents/ClaudeCode/ClaudeCodeCliRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,20 @@ internal sealed class ClaudeCodeCliRunner(ILogger<ClaudeCodeCliRunner> logger) :

try
{
var startInfo = new ProcessStartInfo(executablePath, "--version")
var result = await Process.RunAndCaptureTextAsync(new ProcessStartInfo(executablePath, "--version")
Comment thread
eerhardt marked this conversation as resolved.
Resolved
Comment thread
eerhardt marked this conversation as resolved.
Resolved
Comment thread
eerhardt marked this conversation as resolved.
Resolved
{
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
}, cancellationToken).ConfigureAwait(false);

using var process = new Process { StartInfo = startInfo };

process.Start();

var outputTask = process.StandardOutput.ReadToEndAsync(cancellationToken);
var errorTask = process.StandardError.ReadToEndAsync(cancellationToken);

await process.WaitForExitAsync(cancellationToken).ConfigureAwait(false);

if (process.ExitCode != 0)
if (result.ExitStatus.ExitCode != 0)
{
var errorOutput = await errorTask.ConfigureAwait(false);
logger.LogDebug("Claude Code CLI returned non-zero exit code {ExitCode}: {Error}", process.ExitCode, errorOutput.Trim());
logger.LogDebug("Claude Code CLI returned non-zero exit code {ExitCode}: {Error}", result.ExitStatus.ExitCode, result.StandardError.Trim());
return null;
}

var output = await outputTask.ConfigureAwait(false);
var output = result.StandardOutput;
var versionString = output.Trim();

if (string.IsNullOrEmpty(versionString))
Expand Down
21 changes: 5 additions & 16 deletions src/Aspire.Cli/Agents/Copilot/CopilotCliRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,20 @@ internal sealed class CopilotCliRunner(ILogger<CopilotCliRunner> logger) : ICopi

try
{
var startInfo = new ProcessStartInfo(executablePath, "--version")
var result = await Process.RunAndCaptureTextAsync(new ProcessStartInfo(executablePath, "--version")
Comment thread
eerhardt marked this conversation as resolved.
Resolved
{
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
Comment thread
eerhardt marked this conversation as resolved.
Resolved
CreateNoWindow = true
};
}, cancellationToken).ConfigureAwait(false);

using var process = new Process { StartInfo = startInfo };

process.Start();

var outputTask = process.StandardOutput.ReadToEndAsync(cancellationToken);
var errorTask = process.StandardError.ReadToEndAsync(cancellationToken);

await process.WaitForExitAsync(cancellationToken).ConfigureAwait(false);

if (process.ExitCode != 0)
if (result.ExitStatus.ExitCode != 0)
{
var errorOutput = await errorTask.ConfigureAwait(false);
logger.LogDebug("GitHub Copilot CLI returned non-zero exit code {ExitCode}: {Error}", process.ExitCode, errorOutput.Trim());
logger.LogDebug("GitHub Copilot CLI returned non-zero exit code {ExitCode}: {Error}", result.ExitStatus.ExitCode, result.StandardError.Trim());
return null;
}

var output = await outputTask.ConfigureAwait(false);
var output = result.StandardOutput;

if (TryParseVersionOutput(output, out var version))
{
Expand Down
21 changes: 5 additions & 16 deletions src/Aspire.Cli/Agents/OpenCode/OpenCodeCliRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,20 @@ internal sealed class OpenCodeCliRunner(ILogger<OpenCodeCliRunner> logger) : IOp

try
{
var startInfo = new ProcessStartInfo(executablePath, "--version")
var result = await Process.RunAndCaptureTextAsync(new ProcessStartInfo(executablePath, "--version")
Comment thread
eerhardt marked this conversation as resolved.
Resolved
{
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
}, cancellationToken).ConfigureAwait(false);

using var process = new Process { StartInfo = startInfo };

process.Start();

var outputTask = process.StandardOutput.ReadToEndAsync(cancellationToken);
var errorTask = process.StandardError.ReadToEndAsync(cancellationToken);

await process.WaitForExitAsync(cancellationToken).ConfigureAwait(false);

if (process.ExitCode != 0)
if (result.ExitStatus.ExitCode != 0)
{
var errorOutput = await errorTask.ConfigureAwait(false);
logger.LogDebug("OpenCode CLI returned non-zero exit code {ExitCode}: {Error}", process.ExitCode, errorOutput.Trim());
logger.LogDebug("OpenCode CLI returned non-zero exit code {ExitCode}: {Error}", result.ExitStatus.ExitCode, result.StandardError.Trim());
return null;
}

var output = await outputTask.ConfigureAwait(false);
var output = result.StandardOutput;
var versionString = output.Trim();

if (string.IsNullOrEmpty(versionString))
Expand Down
43 changes: 10 additions & 33 deletions src/Aspire.Cli/Agents/Playwright/PlaywrightCliRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,20 @@ internal sealed class PlaywrightCliRunner(ILogger<PlaywrightCliRunner> logger) :

try
{
var startInfo = new ProcessStartInfo(executablePath, "--version")
var result = await Process.RunAndCaptureTextAsync(new ProcessStartInfo(executablePath, "--version")
Comment thread
eerhardt marked this conversation as resolved.
Resolved
{
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};

using var process = new Process { StartInfo = startInfo };
process.Start();

var outputTask = process.StandardOutput.ReadToEndAsync(cancellationToken);
var errorTask = process.StandardError.ReadToEndAsync(cancellationToken);

await process.WaitForExitAsync(cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false);

if (process.ExitCode != 0)
if (result.ExitStatus.ExitCode != 0)
{
var errorOutput = await errorTask.ConfigureAwait(false);
logger.LogDebug("playwright-cli --version returned non-zero exit code {ExitCode}: {Error}", process.ExitCode, errorOutput.Trim());
logger.LogDebug("playwright-cli --version returned non-zero exit code {ExitCode}: {Error}", result.ExitStatus.ExitCode, result.StandardError.Trim());
return null;
}

var output = await outputTask.ConfigureAwait(false);
var versionString = output.Trim().Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries).FirstOrDefault()?.Trim();
var versionString = result.StandardOutput.Trim().Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries).FirstOrDefault()?.Trim();

if (string.IsNullOrEmpty(versionString))
{
Expand Down Expand Up @@ -89,35 +78,23 @@ public async Task<bool> InstallSkillsAsync(string workingDirectory, Cancellation

try
{
var startInfo = new ProcessStartInfo(executablePath)
var startInfo = new ProcessStartInfo(executablePath, ["install", "--skills"])
{
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
WorkingDirectory = workingDirectory
};

startInfo.ArgumentList.Add("install");
startInfo.ArgumentList.Add("--skills");

using var process = new Process { StartInfo = startInfo };
process.Start();

var outputTask = process.StandardOutput.ReadToEndAsync(cancellationToken);
var errorTask = process.StandardError.ReadToEndAsync(cancellationToken);

await process.WaitForExitAsync(cancellationToken).ConfigureAwait(false);
var result = await Process.RunAndCaptureTextAsync(startInfo, cancellationToken).ConfigureAwait(false);
Comment thread
eerhardt marked this conversation as resolved.
Resolved

if (process.ExitCode != 0)
if (result.ExitStatus.ExitCode != 0)
{
var errorOutput = await errorTask.ConfigureAwait(false);
logger.LogDebug("playwright-cli install --skills returned non-zero exit code {ExitCode}: {Error}", process.ExitCode, errorOutput.Trim());
logger.LogDebug("playwright-cli install --skills returned non-zero exit code {ExitCode}: {Error}", result.ExitStatus.ExitCode, result.StandardError.Trim());
return false;
}

var output = await outputTask.ConfigureAwait(false);
logger.LogDebug("playwright-cli install --skills output: {Output}", output.Trim());
logger.LogDebug("playwright-cli install --skills output: {Output}", result.StandardOutput.Trim());
return true;
}
catch (Exception ex) when (ex is InvalidOperationException or System.ComponentModel.Win32Exception)
Expand Down
21 changes: 5 additions & 16 deletions src/Aspire.Cli/Agents/VsCode/VsCodeCliRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,20 @@ internal sealed class VsCodeCliRunner(ILogger<VsCodeCliRunner> logger) : IVsCode

try
{
var startInfo = new ProcessStartInfo(executablePath, "--version")
var result = await Process.RunAndCaptureTextAsync(new ProcessStartInfo(executablePath, "--version")
Comment thread
eerhardt marked this conversation as resolved.
Resolved
{
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
}, cancellationToken).ConfigureAwait(false);

using var process = new Process { StartInfo = startInfo };

process.Start();

var outputTask = process.StandardOutput.ReadToEndAsync(cancellationToken);
var errorTask = process.StandardError.ReadToEndAsync(cancellationToken);

await process.WaitForExitAsync(cancellationToken).ConfigureAwait(false);

if (process.ExitCode != 0)
if (result.ExitStatus.ExitCode != 0)
{
var errorOutput = await errorTask.ConfigureAwait(false);
logger.LogDebug("VS Code CLI ({Command}) returned non-zero exit code {ExitCode}: {Error}", command, process.ExitCode, errorOutput.Trim());
logger.LogDebug("VS Code CLI ({Command}) returned non-zero exit code {ExitCode}: {Error}", command, result.ExitStatus.ExitCode, result.StandardError.Trim());
return null;
}

var output = await outputTask.ConfigureAwait(false);
var output = result.StandardOutput;

if (string.IsNullOrEmpty(output))
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ protected override TrustLevel TrustCertificateCore(X509Certificate2 publicCertif
{
Log.MacOSTrustCommandStart($"{MacOSTrustCertificateCommandLine} {s_macOSTrustCertificateCommandLineArguments}{tmpFile}");
}
var processResult = CertificateProcessRunner.Run(
new ProcessStartInfo(MacOSTrustCertificateCommandLine, s_macOSTrustCertificateCommandLineArguments + tmpFile));
if (processResult.ExitCode != 0)
var exitStatus = Process.Run(new ProcessStartInfo(MacOSTrustCertificateCommandLine, s_macOSTrustCertificateCommandLineArguments + tmpFile));
if (exitStatus.ExitCode != 0)
{
Log.MacOSTrustCommandError(processResult.ExitCode);
Log.MacOSTrustCommandError(exitStatus.ExitCode);
throw new InvalidOperationException("There was an error trusting the certificate.");
}

Expand Down Expand Up @@ -174,16 +173,20 @@ public override TrustLevel GetTrustLevel(X509Certificate2 certificate)
// We can't guarantee that the temp file is in a directory with sensible permissions, but we're not exporting the private key
ExportCertificate(certificate, tmpFile, includePrivateKey: false, password: null, CertificateKeyExportFormat.Pem);

var checkTrustProcessResult = CertificateProcessRunner.Run(new ProcessStartInfo(
using var nullHandle = File.OpenNullHandle();
var checkTrustProcessStartInfo = new ProcessStartInfo(
MacOSVerifyCertificateCommandLine,
string.Format(CultureInfo.InvariantCulture, MacOSVerifyCertificateCommandLineArgumentsFormat, tmpFile))
{
RedirectStandardOutput = true,
// Do this to avoid showing output to the console when the cert is not trusted. It is trivial to export
// the cert and replicate the command to see details.
RedirectStandardError = true,
});
return checkTrustProcessResult.ExitCode == 0 ? TrustLevel.Full : TrustLevel.None;
StandardInputHandle = nullHandle,
StandardOutputHandle = nullHandle,
Comment thread
eerhardt marked this conversation as resolved.
Resolved
StandardErrorHandle = nullHandle
};

var checkTrustProcessOutput = Process.Run(checkTrustProcessStartInfo);
return checkTrustProcessOutput.ExitCode == 0 ? TrustLevel.Full : TrustLevel.None;
}
finally
{
Expand Down Expand Up @@ -228,10 +231,10 @@ private void RemoveAdminTrustRule(X509Certificate2 certificate)
certificatePath
));

var processResult = CertificateProcessRunner.Run(processInfo);
if (processResult.ExitCode != 0)
var processExitStatus = Process.Run(processInfo);
if (processExitStatus.ExitCode != 0)
{
Log.MacOSRemoveCertificateTrustRuleError(processResult.ExitCode);
Log.MacOSRemoveCertificateTrustRuleError(processExitStatus.ExitCode);
}

Log.MacOSRemoveCertificateTrustRuleEnd();
Expand Down Expand Up @@ -269,13 +272,14 @@ private void RemoveCertificateFromKeychain(string keychain, X509Certificate2 cer
Log.MacOSRemoveCertificateFromKeyChainStart(keychain, GetDescription(certificate));
}

var processResult = CertificateProcessRunner.RunAndCaptureText(processInfo);
if (processResult.ExitCode != 0)
var processOutput = Process.RunAndCaptureText(processInfo);
var exitCode = processOutput.ExitStatus.ExitCode;
if (exitCode != 0)
{
Log.MacOSRemoveCertificateFromKeyChainError(processResult.ExitCode);
Log.MacOSRemoveCertificateFromKeyChainError(exitCode);
throw new InvalidOperationException($@"There was an error removing the certificate with thumbprint '{certificate.Thumbprint}'.

{processResult.StandardOutput}{processResult.StandardError}");
{processOutput.StandardOutput}{processOutput.StandardError}");
}

Log.MacOSRemoveCertificateFromKeyChainEnd();
Expand All @@ -294,7 +298,9 @@ private static bool IsCertOnKeychain(string keychain, X509Certificate2 certifica

var subject = subjectMatch.Groups[1].Value;

// Run the find-certificate command, and look for the cert's hash in the output
// Run the find-certificate command, and look for the cert's hash in the output.
// Process.RunAndCaptureText requires stderr to be redirected too, which would change where
// security's diagnostics go, so keep reading only the redirected stdout.
using var findCertificateProcess = Process.Start(new ProcessStartInfo(
MacOSFindCertificateOnKeychainCommandLine,
string.Format(CultureInfo.InvariantCulture, MacOSFindCertificateOnKeychainCommandLineArgumentsFormat, subject, keychain))
Expand Down Expand Up @@ -363,11 +369,12 @@ private void SaveCertificateToUserKeychain(X509Certificate2 certificate)
Log.MacOSAddCertificateToKeyChainStart(s_macOSUserKeychain, GetDescription(certificate));
}

var processResult = CertificateProcessRunner.RunAndCaptureText(processInfo);
if (processResult.ExitCode != 0)
var processOutput = Process.RunAndCaptureText(processInfo);
var exitCode = processOutput.ExitStatus.ExitCode;

if (exitCode != 0)
{
var output = processResult.StandardOutput + processResult.StandardError;
Log.MacOSAddCertificateToKeyChainError(processResult.ExitCode, output);
Log.MacOSAddCertificateToKeyChainError(exitCode, processOutput.StandardOutput + processOutput.StandardError);
throw new InvalidOperationException("Failed to add the certificate to the keychain. Are you running in a non-interactive session perhaps?");
}

Expand Down
Loading
Loading