Skip to content

Commit 0dbf46c

Browse files
Copiloteerhardt
andauthored
Fix channel ordering in aspire update - staging before daily (dotnet#12760)
* Initial plan * Fix channel ordering - staging now appears before daily and PR channels Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com>
1 parent d9ecbac commit 0dbf46c

File tree

2 files changed

+104
-2
lines changed

2 files changed

+104
-2
lines changed

src/Aspire.Cli/Packaging/PackagingService.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public Task<IEnumerable<PackageChannel>> GetChannelsAsync(CancellationToken canc
5151
}
5252
}
5353

54-
var channels = new List<PackageChannel>([defaultChannel, stableChannel, dailyChannel, ..prPackageChannels]);
54+
var channels = new List<PackageChannel>([defaultChannel, stableChannel]);
5555

56-
// Add staging channel if feature is enabled
56+
// Add staging channel if feature is enabled (after stable, before daily)
5757
if (features.IsFeatureEnabled(KnownFeatures.StagingChannelEnabled, false))
5858
{
5959
var stagingChannel = CreateStagingChannel();
@@ -63,6 +63,10 @@ public Task<IEnumerable<PackageChannel>> GetChannelsAsync(CancellationToken canc
6363
}
6464
}
6565

66+
// Add daily and PR channels after staging
67+
channels.Add(dailyChannel);
68+
channels.AddRange(prPackageChannels);
69+
6670
return Task.FromResult<IEnumerable<PackageChannel>>(channels);
6771
}
6872

tests/Aspire.Cli.Tests/Packaging/PackagingServiceTests.cs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,102 @@ public async Task NuGetConfigMerger_WhenChannelRequiresGlobalPackagesFolder_Adds
229229
Assert.NotNull(globalPackagesFolderAdd);
230230
Assert.Equal(".nugetpackages", (string?)globalPackagesFolderAdd.Attribute("value"));
231231
}
232+
233+
[Fact]
234+
public async Task GetChannelsAsync_WhenStagingChannelEnabled_StagingAppearsAfterStableBeforeDaily()
235+
{
236+
// Arrange
237+
using var workspace = TemporaryWorkspace.Create(outputHelper);
238+
var tempDir = workspace.WorkspaceRoot;
239+
var hivesDir = new DirectoryInfo(Path.Combine(tempDir.FullName, ".aspire", "hives"));
240+
var cacheDir = new DirectoryInfo(Path.Combine(tempDir.FullName, ".aspire", "cache"));
241+
242+
// Create some PR hives to ensure staging appears before them
243+
hivesDir.Create();
244+
Directory.CreateDirectory(Path.Combine(hivesDir.FullName, "pr-10167"));
245+
Directory.CreateDirectory(Path.Combine(hivesDir.FullName, "pr-11832"));
246+
247+
var executionContext = new CliExecutionContext(tempDir, hivesDir, cacheDir, new DirectoryInfo(Path.Combine(Path.GetTempPath(), "aspire-test-runtimes")));
248+
249+
var features = new TestFeatures();
250+
features.SetFeature(KnownFeatures.StagingChannelEnabled, true);
251+
252+
var configuration = new ConfigurationBuilder()
253+
.AddInMemoryCollection(new Dictionary<string, string?>
254+
{
255+
["overrideStagingHash"] = "12345678"
256+
})
257+
.Build();
258+
259+
var packagingService = new PackagingService(executionContext, new FakeNuGetPackageCache(), features, configuration);
260+
261+
// Act
262+
var channels = await packagingService.GetChannelsAsync();
263+
264+
// Assert
265+
var channelNames = channels.Select(c => c.Name).ToList();
266+
267+
// Verify all expected channels are present
268+
Assert.Contains("default", channelNames);
269+
Assert.Contains("stable", channelNames);
270+
Assert.Contains("staging", channelNames);
271+
Assert.Contains("daily", channelNames);
272+
Assert.Contains("pr-10167", channelNames);
273+
Assert.Contains("pr-11832", channelNames);
274+
275+
// Verify the order: default, stable, staging, daily, pr-*
276+
var defaultIndex = channelNames.IndexOf("default");
277+
var stableIndex = channelNames.IndexOf("stable");
278+
var stagingIndex = channelNames.IndexOf("staging");
279+
var dailyIndex = channelNames.IndexOf("daily");
280+
var pr10167Index = channelNames.IndexOf("pr-10167");
281+
var pr11832Index = channelNames.IndexOf("pr-11832");
282+
283+
Assert.True(defaultIndex < stableIndex, $"default should come before stable (default: {defaultIndex}, stable: {stableIndex})");
284+
Assert.True(stableIndex < stagingIndex, $"stable should come before staging (stable: {stableIndex}, staging: {stagingIndex})");
285+
Assert.True(stagingIndex < dailyIndex, $"staging should come before daily (staging: {stagingIndex}, daily: {dailyIndex})");
286+
Assert.True(dailyIndex < pr10167Index, $"daily should come before pr-10167 (daily: {dailyIndex}, pr-10167: {pr10167Index})");
287+
Assert.True(dailyIndex < pr11832Index, $"daily should come before pr-11832 (daily: {dailyIndex}, pr-11832: {pr11832Index})");
288+
}
289+
290+
[Fact]
291+
public async Task GetChannelsAsync_WhenStagingChannelDisabled_OrderIsDefaultStableDailyPr()
292+
{
293+
// Arrange
294+
using var workspace = TemporaryWorkspace.Create(outputHelper);
295+
var tempDir = workspace.WorkspaceRoot;
296+
var hivesDir = new DirectoryInfo(Path.Combine(tempDir.FullName, ".aspire", "hives"));
297+
var cacheDir = new DirectoryInfo(Path.Combine(tempDir.FullName, ".aspire", "cache"));
298+
299+
// Create some PR hives
300+
hivesDir.Create();
301+
Directory.CreateDirectory(Path.Combine(hivesDir.FullName, "pr-12345"));
302+
303+
var executionContext = new CliExecutionContext(tempDir, hivesDir, cacheDir, new DirectoryInfo(Path.Combine(Path.GetTempPath(), "aspire-test-runtimes")));
304+
305+
var features = new TestFeatures();
306+
// Staging disabled by default
307+
var configuration = new ConfigurationBuilder().Build();
308+
309+
var packagingService = new PackagingService(executionContext, new FakeNuGetPackageCache(), features, configuration);
310+
311+
// Act
312+
var channels = await packagingService.GetChannelsAsync();
313+
314+
// Assert
315+
var channelNames = channels.Select(c => c.Name).ToList();
316+
317+
// Verify staging is not present
318+
Assert.DoesNotContain("staging", channelNames);
319+
320+
// Verify the order: default, stable, daily, pr-*
321+
var defaultIndex = channelNames.IndexOf("default");
322+
var stableIndex = channelNames.IndexOf("stable");
323+
var dailyIndex = channelNames.IndexOf("daily");
324+
var pr12345Index = channelNames.IndexOf("pr-12345");
325+
326+
Assert.True(defaultIndex < stableIndex, "default should come before stable");
327+
Assert.True(stableIndex < dailyIndex, "stable should come before daily");
328+
Assert.True(dailyIndex < pr12345Index, "daily should come before pr-12345");
329+
}
232330
}

0 commit comments

Comments
 (0)