Load the proxy pool at startup, and stop old settings files zeroing new defaults

The pool was empty until someone pressed Refresh, which also meant the parser
would have had nothing to work with. A ProxyPoolLoader now fills it once at
launch; startup does not await it, because blocking on a public list being
reachable would be the wrong trade, and it never throws. The proxy page joins
the same operation rather than starting a second download, so it reports the
outcome whether it is opened during the load or long after.

That change surfaced a worse bug underneath. The first run still loaded zero
entries with no error logged at all, which turned out to be the feed source
never being asked: options said UseFeed=False and Protocols=None. Neither is
reachable from the UI — both are default(T).

The cause is that AppSettings kept its defaults on property initialisers, and
the source-generated deserialiser does not run them. Reflection-based
deserialisation of "{}" keeps them; the generated context does not. So a
settings.json written before a setting existed came back with default(T) for it:
the proxy feed switched off, the protocol filter empty, the probe timeout zero
and the probe URL blank — and the app looked like the network had failed.

Defaults now live on primary constructor parameters, which STJ applies for
absent JSON members on both paths, so an older file upgrades cleanly. The
regression test writes a settings file from before the proxy settings existed
and asserts each one comes back at its default. ToProxyOptions also treats an
empty protocol filter as "all", since a hand-edited file that matches nothing is
the least useful possible reading of it.

Also quietens IHttpClientFactory to Warning: four Information lines per request
buried everything the app said, and a proxy sweep makes thousands of them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Leonid Pershin
2026-08-13 18:33:41 +03:00
co-authored by Claude Opus 5
parent 8b552470b7
commit 85656e70b0
11 changed files with 432 additions and 48 deletions
@@ -1,4 +1,5 @@
using AvParser.Core.Proxies;
using AvParser.Infrastructure.Proxies;
using AvParser.UI.Tests.Fakes;
using AvParser.UI.ViewModels;
using Microsoft.Extensions.Logging.Abstractions;
@@ -23,6 +24,7 @@ public class ProxiesViewModelTests
var page = new ProxiesViewModel(
pool,
custom,
new ProxyPoolLoader(pool, NullLogger<ProxyPoolLoader>.Instance),
NullLogger<ProxiesViewModel>.Instance,
ImmediateSequencer.Instance
);
@@ -37,11 +39,40 @@ public class ProxiesViewModelTests
private static Task Run<TResult>(ReactiveUI.ReactiveCommand<RxVoid, TResult> command) =>
command.Execute().ToTask(TestContext.Current.CancellationToken);
/// <summary>Polls until the throttled rebuild has caught up, or gives up.</summary>
/// <remarks>
/// The page coalesces pool changes over 250 ms, so anything driven by the pool rather than by
/// a command needs to be waited for rather than asserted on the next line.
/// </remarks>
private static async Task WaitUntil(Func<bool> condition)
{
for (var attempt = 0; attempt < 50 && !condition(); attempt++)
{
await Task.Delay(20, TestContext.Current.CancellationToken);
}
}
[Fact]
public void Starts_empty()
public async Task The_pool_loads_without_the_user_pressing_refresh()
{
var (page, _, _) = Build("a", "b");
// Deliberately no RefreshCommand: opening the page joins the startup load, which is what
// stops the list from being empty until someone presses the button.
await WaitUntil(() => page.TotalCount == 2);
page.TotalCount.ShouldBe(2);
page.Proxies.Count.ShouldBe(2);
page.StatusMessage.ShouldNotBeNull();
}
[Fact]
public async Task An_empty_pool_stays_empty()
{
var (page, _, _) = Build();
await WaitUntil(() => page.StatusMessage is not null);
page.Proxies.ShouldBeEmpty();
page.TotalCount.ShouldBe(0);
}
@@ -79,6 +110,7 @@ public class ProxiesViewModelTests
var page = new ProxiesViewModel(
pool,
custom,
new ProxyPoolLoader(pool, NullLogger<ProxyPoolLoader>.Instance),
NullLogger<ProxiesViewModel>.Instance,
ImmediateSequencer.Instance
);
@@ -160,6 +192,7 @@ public class ProxiesViewModelTests
var page = new ProxiesViewModel(
pool,
custom,
new ProxyPoolLoader(pool, NullLogger<ProxyPoolLoader>.Instance),
NullLogger<ProxiesViewModel>.Instance,
ImmediateSequencer.Instance
);