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
2 changes: 1 addition & 1 deletion src/Aspire.Cli/DotNet/DotNetCliRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private string GetMsBuildServerValue()

internal static string GetBackchannelSocketPath()
{
return CliPathHelper.CreateSocketPath("cli.sock");
return CliPathHelper.CreateUnixDomainSocketPath("cli.sock");
}

private async Task<int> ExecuteAsync(
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Cli/Projects/AppHostServerProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal sealed class AppHostServerProjectFactory(
{
public async Task<IAppHostServerProject> CreateAsync(string appPath, CancellationToken cancellationToken = default)
{
var socketPath = CliPathHelper.CreateSocketPath("apphost.sock");
var socketPath = CliPathHelper.CreateGuestAppHostSocketPath("apphost.sock");

// Priority 1: Check for dev mode (ASPIRE_REPO_ROOT or running from Aspire source repo)
var repoRoot = AspireRepositoryDetector.DetectRepositoryRoot(appPath);
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Cli/Projects/GuestAppHostProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ await GenerateCodeViaRpcAsync(
/// </summary>
private static string GetBackchannelSocketPath()
{
return CliPathHelper.CreateSocketPath("cli.sock");
return CliPathHelper.CreateUnixDomainSocketPath("cli.sock");
}

/// <summary>
Expand Down
10 changes: 8 additions & 2 deletions src/Aspire.Cli/Utils/CliPathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ internal static string GetAspireHomeDirectory()
/// Creates a randomized CLI-managed socket path.
/// </summary>
/// <param name="socketPrefix">The socket file prefix.</param>
internal static string CreateSocketPath(string socketPrefix)
internal static string CreateUnixDomainSocketPath(string socketPrefix)
Copy link
Member Author

Choose a reason for hiding this comment

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

We should rename this

Suggested change
internal static string CreateUnixDomainSocketPath(string socketPrefix)
internal static string CreateBackChannelSocketPath(string socketPrefix)

=> CreateSocketPath(socketPrefix, isGuestAppHost: false);

internal static string CreateGuestAppHostSocketPath(string socketPrefix)
=> CreateSocketPath(socketPrefix, isGuestAppHost: true);

private static string CreateSocketPath(string socketPrefix, bool isGuestAppHost)
{
var socketName = $"{socketPrefix}.{BackchannelConstants.CreateRandomIdentifier()}";

if (OperatingSystem.IsWindows())
if (isGuestAppHost && OperatingSystem.IsWindows())
{
return socketName;
}
Expand Down
23 changes: 20 additions & 3 deletions tests/Aspire.Cli.Tests/Utils/CliPathHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace Aspire.Cli.Tests.Utils;
public class CliPathHelperTests(ITestOutputHelper outputHelper)
{
[Fact]
public void CreateSocketPath_UsesRandomizedIdentifier()
public void CreateGuestAppHostSocketPath_UsesRandomizedIdentifier()
{
using var workspace = TemporaryWorkspace.Create(outputHelper);

var socketPath1 = CliPathHelper.CreateSocketPath("apphost.sock");
var socketPath2 = CliPathHelper.CreateSocketPath("apphost.sock");
var socketPath1 = CliPathHelper.CreateGuestAppHostSocketPath("apphost.sock");
var socketPath2 = CliPathHelper.CreateGuestAppHostSocketPath("apphost.sock");

Assert.NotEqual(socketPath1, socketPath2);

Expand All @@ -31,4 +31,21 @@ public void CreateSocketPath_UsesRandomizedIdentifier()
Assert.Matches("^apphost\\.sock\\.[a-f0-9]{12}$", Path.GetFileName(socketPath2));
}
}

[Fact]
public void CreateUnixDomainSocketPath_UsesRandomizedIdentifier()
{
using var workspace = TemporaryWorkspace.Create(outputHelper);

var socketPath1 = CliPathHelper.CreateUnixDomainSocketPath("apphost.sock");
var socketPath2 = CliPathHelper.CreateUnixDomainSocketPath("apphost.sock");

Assert.NotEqual(socketPath1, socketPath2);

var expectedDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".aspire", "cli", "runtime", "sockets");
Assert.Equal(expectedDirectory, Path.GetDirectoryName(socketPath1));
Assert.Equal(expectedDirectory, Path.GetDirectoryName(socketPath2));
Assert.Matches("^apphost\\.sock\\.[a-f0-9]{12}$", Path.GetFileName(socketPath1));
Assert.Matches("^apphost\\.sock\\.[a-f0-9]{12}$", Path.GetFileName(socketPath2));
}
}
Loading