fix(tests): stop Ui.Tests order-dependent flakiness on shared Loc.Current

Loc.Current (src/ClaudeDo.Ui/Localization/Loc.cs) is a process-wide mutable
static; which localizer is active depended on xUnit's parallel test
scheduling. Ui.Tests: disable collection parallelization (cheap, pure VM
suite) and install the real localizer in a module initializer so no test
can ever observe the uninitialized key-echo default. Worker.Tests: install
the same module initializer but leave parallelization on — disabling it
measured a 27% wall-clock regression on its real-SQLite/git suite, and the
initializer alone already removes the race. AgentConfigEditorViewModelTests
now installs its own localizer instead of relying on ambient state.
This commit is contained in:
Mika Kuns
2026-09-02 12:55:51 +02:00
parent 56bc1651a8
commit dc1e67d07b
3 changed files with 51 additions and 0 deletions
@@ -1,4 +1,5 @@
using ClaudeDo.Data.Models;
using ClaudeDo.Localization;
using ClaudeDo.Ui.Localization;
using ClaudeDo.Ui.Services;
using ClaudeDo.Ui.ViewModels.Agent;
@@ -9,6 +10,18 @@ namespace ClaudeDo.Ui.Tests.ViewModels;
public class AgentConfigEditorViewModelTests
{
public AgentConfigEditorViewModelTests()
{
// Loc.T(...) is read below without installing a localizer via a ViewModel constructor
// (unlike its sibling test classes) — install one directly so this class doesn't depend
// on whichever neighbour test happened to run first and set Loc.Current.
var dir = AppContext.BaseDirectory;
while (dir is not null && !Directory.Exists(Path.Combine(dir, "src", "ClaudeDo.Localization", "locales")))
dir = Path.GetDirectoryName(dir);
Loc.Current = new Localizer(
LocaleStore.Load(Path.Combine(dir!, "src", "ClaudeDo.Localization", "locales")), "en");
}
private sealed class FakeWorker : StubWorkerClient
{
public AppSettingsDto? App;