Skip to content

Commit 6bd5f26

Browse files
committed
fix: remove duplicate provider probes in tests
1 parent 86f0a89 commit 6bd5f26

3 files changed

Lines changed: 60 additions & 25 deletions

File tree

DotPilot.Core/Providers/Services/AgentProviderStatusSnapshotReader.cs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ private static async ValueTask<ProviderStatusProbeResult> BuildProviderStatusAsy
105105
}
106106
else
107107
{
108-
installedVersion = AgentSessionCommandProbe.ReadVersion(executablePath, ["--version"]);
109-
actions.Add(new ProviderActionDescriptor("Open CLI", "CLI detected on PATH.", $"{profile.CommandName} --version"));
110-
111108
var metadata = await ResolveMetadataAsync(profile, executablePath, cancellationToken).ConfigureAwait(false);
112-
installedVersion = ResolveInstalledVersion(
113-
installedVersion,
114-
metadata.InstalledVersion,
115-
profile.CommandName);
109+
installedVersion = metadata.InstalledVersion;
110+
if (!LooksLikeInstalledVersion(installedVersion, profile.CommandName))
111+
{
112+
installedVersion = AgentSessionCommandProbe.ReadVersion(executablePath, ["--version"]);
113+
}
114+
115+
actions.Add(new ProviderActionDescriptor("Open CLI", "CLI detected on PATH.", $"{profile.CommandName} --version"));
116116
suggestedModelName = ResolveSuggestedModel(profile.DefaultModelName, metadata.SuggestedModelName);
117117
supportedModelNames = ResolveSupportedModels(
118118
profile.DefaultModelName,
@@ -195,21 +195,6 @@ private static string ResolveSuggestedModel(string defaultModelName, string? sug
195195
: suggestedModelName;
196196
}
197197

198-
private static string? ResolveInstalledVersion(
199-
string? probedInstalledVersion,
200-
string? discoveredInstalledVersion,
201-
string commandName)
202-
{
203-
if (LooksLikeInstalledVersion(discoveredInstalledVersion, commandName))
204-
{
205-
return discoveredInstalledVersion;
206-
}
207-
208-
return string.IsNullOrWhiteSpace(probedInstalledVersion)
209-
? discoveredInstalledVersion
210-
: probedInstalledVersion;
211-
}
212-
213198
private static bool LooksLikeInstalledVersion(string? installedVersion, string commandName)
214199
{
215200
if (string.IsNullOrWhiteSpace(installedVersion))

DotPilot.Tests/ChatSessions/Execution/AgentSessionServiceTests.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,32 @@ private async ValueTask DisposeAsyncCore()
639639
await _provider.DisposeAsync();
640640
if (!string.IsNullOrWhiteSpace(_tempRootPath) && Directory.Exists(_tempRootPath))
641641
{
642-
Directory.Delete(_tempRootPath, recursive: true);
642+
await DeleteDirectoryWithRetryAsync(_tempRootPath);
643+
}
644+
}
645+
}
646+
647+
private static async Task DeleteDirectoryWithRetryAsync(string path)
648+
{
649+
for (var attempt = 0; attempt < 5; attempt++)
650+
{
651+
if (!Directory.Exists(path))
652+
{
653+
return;
654+
}
655+
656+
try
657+
{
658+
Directory.Delete(path, recursive: true);
659+
return;
660+
}
661+
catch (IOException) when (attempt < 4)
662+
{
663+
await Task.Delay(100);
664+
}
665+
catch (UnauthorizedAccessException) when (attempt < 4)
666+
{
667+
await Task.Delay(100);
643668
}
644669
}
645670
}

DotPilot.Tests/Workspace/Services/StartupWorkspaceHydrationTests.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public async Task EnsureHydratedAsyncKeepsHydrationRetryableAfterATransientWorks
6060
hydration.IsHydrating.Should().BeFalse();
6161
hydration.IsReady.Should().BeFalse();
6262

63-
Directory.Delete(databasePath);
63+
await DeleteDirectoryWithRetryAsync(databasePath);
6464

6565
await hydration.EnsureHydratedAsync(CancellationToken.None);
6666

@@ -71,7 +71,7 @@ public async Task EnsureHydratedAsyncKeepsHydrationRetryableAfterATransientWorks
7171
{
7272
if (Directory.Exists(rootPath))
7373
{
74-
Directory.Delete(rootPath, recursive: true);
74+
await DeleteDirectoryWithRetryAsync(rootPath);
7575
}
7676
}
7777
}
@@ -104,4 +104,29 @@ public ValueTask DisposeAsync()
104104
return Provider.DisposeAsync();
105105
}
106106
}
107+
108+
private static async Task DeleteDirectoryWithRetryAsync(string path)
109+
{
110+
for (var attempt = 0; attempt < 5; attempt++)
111+
{
112+
if (!Directory.Exists(path))
113+
{
114+
return;
115+
}
116+
117+
try
118+
{
119+
Directory.Delete(path, recursive: true);
120+
return;
121+
}
122+
catch (IOException) when (attempt < 4)
123+
{
124+
await Task.Delay(100);
125+
}
126+
catch (UnauthorizedAccessException) when (attempt < 4)
127+
{
128+
await Task.Delay(100);
129+
}
130+
}
131+
}
107132
}

0 commit comments

Comments
 (0)