Skip to content

Commit 814ccaf

Browse files
Fix headless CLI workflow stability
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ff0823e commit 814ccaf

File tree

5 files changed

+90
-46
lines changed

5 files changed

+90
-46
lines changed

src/UniGetUI.Avalonia/ViewModels/DialogPages/InstallOptionsViewModel.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ partial void OnSelectedProfileChanged(string? value)
112112
[ObservableProperty] private bool _skipMinorChecked;
113113
[ObservableProperty] private bool _autoUpdateChecked;
114114

115-
partial void OnAdminCheckedChanged(bool _) => Refresh();
116-
partial void OnInteractiveCheckedChanged(bool _) => Refresh();
117-
partial void OnSkipHashCheckedChanged(bool _) => Refresh();
118-
partial void OnSelectedVersionChanged(string? _) => Refresh();
115+
partial void OnAdminCheckedChanged(bool value) => Refresh();
116+
partial void OnInteractiveCheckedChanged(bool value) => Refresh();
117+
partial void OnSkipHashCheckedChanged(bool value) => Refresh();
118+
partial void OnSelectedVersionChanged(string? value) => Refresh();
119119

120120
// ── Architecture / Scope / Location tab ───────────────────────────────────
121121
[ObservableProperty] private bool _archEnabled;
@@ -129,8 +129,8 @@ partial void OnSelectedProfileChanged(string? value)
129129
[ObservableProperty] private string _locationText = "";
130130
[ObservableProperty] private bool _locationEnabled;
131131

132-
partial void OnSelectedArchChanged(string? _) => Refresh();
133-
partial void OnSelectedScopeChanged(string? _) => Refresh();
132+
partial void OnSelectedArchChanged(string? value) => Refresh();
133+
partial void OnSelectedScopeChanged(string? value) => Refresh();
134134

135135
// ── CLI params tab ────────────────────────────────────────────────────────
136136
[ObservableProperty] private string _paramsInstall = "";

src/UniGetUI.Avalonia/ViewModels/SidebarViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public partial class SidebarViewModel : ViewModelBase
2323
partial void OnUpdatesBadgeCountChanged(int value) =>
2424
UpdatesBadgeVisible = value > 0;
2525

26-
partial void OnUpdatesBadgeVisibleChanged(bool _)
26+
partial void OnUpdatesBadgeVisibleChanged(bool value)
2727
{
2828
OnPropertyChanged(nameof(UpdatesBadgeExpandedVisible));
2929
OnPropertyChanged(nameof(UpdatesBadgeCompactVisible));
3030
}
3131

32-
partial void OnBundlesBadgeVisibleChanged(bool _)
32+
partial void OnBundlesBadgeVisibleChanged(bool value)
3333
{
3434
OnPropertyChanged(nameof(BundlesBadgeExpandedVisible));
3535
OnPropertyChanged(nameof(BundlesBadgeCompactVisible));

src/UniGetUI.Interface.BackgroundApi/BackgroundApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ await HandlePackageActionAsync(
310310
);
311311
}
312312

313-
private async Task HandlePackageActionAsync(
313+
private static async Task HandlePackageActionAsync(
314314
HttpContext context,
315315
Func<AutomationPackageActionRequest, Task<AutomationPackageOperationResult>> action
316316
)

src/UniGetUI.Interface.Telemetry/TelemetryHandler.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,7 @@ private static bool CredentialsConfigured()
7272
private const string IndexPrefix = "";
7373
#endif
7474

75-
private static readonly HttpClient _httpClient;
76-
77-
static TelemetryHandler()
78-
{
79-
_httpClient = new HttpClient(CoreTools.GenericHttpClientParameters)
80-
{
81-
Timeout = TimeSpan.FromSeconds(30),
82-
};
83-
_httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(CoreData.UserAgentString);
84-
}
75+
private static readonly HttpClient _httpClient = CreateHttpClient();
8576

8677
private static readonly Settings.K[] SettingsToSend =
8778
[
@@ -101,6 +92,16 @@ static TelemetryHandler()
10192

10293
// -------------------------------------------------------------------------
10394

95+
private static HttpClient CreateHttpClient()
96+
{
97+
var httpClient = new HttpClient(CoreTools.GenericHttpClientParameters)
98+
{
99+
Timeout = TimeSpan.FromSeconds(30),
100+
};
101+
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(CoreData.UserAgentString);
102+
return httpClient;
103+
}
104+
104105
public static async Task InitializeAsync()
105106
{
106107
try

testing/automation/run-cli-e2e.ps1

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,33 @@ try {
7878
return $text | ConvertFrom-Json
7979
}
8080

81+
function Wait-ForCliCondition {
82+
param(
83+
[Parameter(Mandatory = $true)]
84+
[string[]] $Arguments,
85+
[Parameter(Mandatory = $true)]
86+
[scriptblock] $Condition,
87+
[Parameter(Mandatory = $true)]
88+
[string] $FailureMessage,
89+
[int] $TimeoutSeconds = 90,
90+
[int] $DelaySeconds = 3
91+
)
92+
93+
$deadline = (Get-Date).AddSeconds($TimeoutSeconds)
94+
$lastResponse = $null
95+
96+
do {
97+
$lastResponse = Invoke-CliJson -Arguments $Arguments
98+
if (& $Condition $lastResponse) {
99+
return $lastResponse
100+
}
101+
102+
Start-Sleep -Seconds $DelaySeconds
103+
} while ((Get-Date) -lt $deadline)
104+
105+
throw "$FailureMessage`nLast payload: $($lastResponse | ConvertTo-Json -Depth 8)"
106+
}
107+
81108
$deadline = (Get-Date).AddMinutes(2)
82109
do {
83110
Start-Sleep -Seconds 2
@@ -106,53 +133,69 @@ try {
106133
throw "install-package failed: $($install | ConvertTo-Json -Depth 8)"
107134
}
108135

109-
$installed = Invoke-CliJson -Arguments @('list-installed', '--manager', '.NET Tool')
136+
$installed = Wait-ForCliCondition `
137+
-Arguments @('list-installed', '--manager', '.NET Tool') `
138+
-FailureMessage 'list-installed did not include dotnetsay after installation' `
139+
-Condition {
140+
param($response)
141+
@($response.packages | Where-Object { $_.id -eq 'dotnetsay' }).Count -gt 0
142+
}
110143
$installedDotnetsay = @($installed.packages | Where-Object { $_.id -eq 'dotnetsay' })
111-
if ($installedDotnetsay.Count -eq 0) {
112-
throw "list-installed did not include dotnetsay after installation"
113-
}
114144

115-
if (-not ($installedDotnetsay.version -contains '2.1.4')) {
116-
throw "Expected dotnetsay version 2.1.4 after install. Found: $($installedDotnetsay.version -join ', ')"
117-
}
145+
$installed = Wait-ForCliCondition `
146+
-Arguments @('list-installed', '--manager', '.NET Tool') `
147+
-FailureMessage 'dotnetsay did not report version 2.1.4 after installation' `
148+
-Condition {
149+
param($response)
150+
@($response.packages | Where-Object { $_.id -eq 'dotnetsay' -and $_.version -eq '2.1.4' }).Count -gt 0
151+
}
152+
$installedDotnetsay = @($installed.packages | Where-Object { $_.id -eq 'dotnetsay' })
118153

119-
$updates = Invoke-CliJson -Arguments @('get-updates', '--manager', '.NET Tool')
154+
$updates = Wait-ForCliCondition `
155+
-Arguments @('get-updates', '--manager', '.NET Tool') `
156+
-FailureMessage 'get-updates did not report dotnetsay after installing 2.1.4' `
157+
-Condition {
158+
param($response)
159+
@($response.updates | Where-Object { $_.id -eq 'dotnetsay' }).Count -gt 0
160+
}
120161
$updatableDotnetsay = @($updates.updates | Where-Object { $_.id -eq 'dotnetsay' })
121-
if ($updatableDotnetsay.Count -eq 0) {
122-
throw "get-updates did not report dotnetsay after installing 2.1.4"
123-
}
124162

125163
$update = Invoke-CliJson -Arguments @('update-package', '--manager', '.NET Tool', '--package-id', 'dotnetsay')
126164
if ($update.status -ne 'success') {
127165
throw "update-package failed: $($update | ConvertTo-Json -Depth 8)"
128166
}
129167

130-
$installedAfterUpdate = Invoke-CliJson -Arguments @('list-installed', '--manager', '.NET Tool')
168+
$installedAfterUpdate = Wait-ForCliCondition `
169+
-Arguments @('list-installed', '--manager', '.NET Tool') `
170+
-FailureMessage 'list-installed did not include an updated dotnetsay version after update' `
171+
-Condition {
172+
param($response)
173+
@($response.packages | Where-Object { $_.id -eq 'dotnetsay' -and $_.version -ne '2.1.4' }).Count -gt 0
174+
}
131175
$updatedDotnetsay = @($installedAfterUpdate.packages | Where-Object { $_.id -eq 'dotnetsay' })
132-
if ($updatedDotnetsay.Count -eq 0) {
133-
throw "list-installed did not include dotnetsay after update"
134-
}
135176

136-
if ($updatedDotnetsay.version -contains '2.1.4') {
137-
throw "dotnetsay still reports version 2.1.4 after update"
138-
}
139-
140-
$updatesAfterUpdate = Invoke-CliJson -Arguments @('get-updates', '--manager', '.NET Tool')
177+
$updatesAfterUpdate = Wait-ForCliCondition `
178+
-Arguments @('get-updates', '--manager', '.NET Tool') `
179+
-FailureMessage 'dotnetsay still appears in get-updates after update' `
180+
-Condition {
181+
param($response)
182+
@($response.updates | Where-Object { $_.id -eq 'dotnetsay' }).Count -eq 0
183+
}
141184
$remainingDotnetsayUpdate = @($updatesAfterUpdate.updates | Where-Object { $_.id -eq 'dotnetsay' })
142-
if ($remainingDotnetsayUpdate.Count -ne 0) {
143-
throw "dotnetsay still appears in get-updates after update"
144-
}
145185

146186
$uninstall = Invoke-CliJson -Arguments @('uninstall-package', '--manager', '.NET Tool', '--package-id', 'dotnetsay', '--scope', 'Global')
147187
if ($uninstall.status -ne 'success') {
148188
throw "uninstall-package failed: $($uninstall | ConvertTo-Json -Depth 8)"
149189
}
150190

151-
$installedAfterUninstall = Invoke-CliJson -Arguments @('list-installed', '--manager', '.NET Tool')
191+
$installedAfterUninstall = Wait-ForCliCondition `
192+
-Arguments @('list-installed', '--manager', '.NET Tool') `
193+
-FailureMessage 'dotnetsay still appears in list-installed after uninstall' `
194+
-Condition {
195+
param($response)
196+
@($response.packages | Where-Object { $_.id -eq 'dotnetsay' }).Count -eq 0
197+
}
152198
$remainingDotnetsay = @($installedAfterUninstall.packages | Where-Object { $_.id -eq 'dotnetsay' })
153-
if ($remainingDotnetsay.Count -ne 0) {
154-
throw "dotnetsay still appears in list-installed after uninstall"
155-
}
156199
}
157200
finally {
158201
Stop-Daemon

0 commit comments

Comments
 (0)