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.
38 lines
1.8 KiB
C#
38 lines
1.8 KiB
C#
using System.Runtime.CompilerServices;
|
|
using ClaudeDo.Localization;
|
|
using ClaudeDo.Ui.Localization;
|
|
using ClaudeDo.Ui.Services;
|
|
|
|
namespace ClaudeDo.Worker.Tests;
|
|
|
|
internal static class TestSetup
|
|
{
|
|
// Runs once when this test assembly loads, before any test executes. UiVm/*Tests.cs construct
|
|
// real TasksIslandViewModel instances, whose LoadForListAsync/ReorderAsync/ReconcileTickAsync
|
|
// call OperationTiming.Shared.Record directly — without a redirect those writes land in the
|
|
// live app's ~/.todo-app/logs/operation-timing.ndjson (see ClaudeDo.Ui.Tests' TestSetup for
|
|
// the same trap on the Ui.Tests side).
|
|
[ModuleInitializer]
|
|
internal static void RedirectOperationTimingAwayFromRealAppData()
|
|
{
|
|
var path = Path.Combine(Path.GetTempPath(), "claudedo-worker-tests", $"operation-timing-{Environment.ProcessId}.ndjson");
|
|
OperationTiming.Shared = new OperationTiming(path);
|
|
}
|
|
|
|
// Installs the real localizer before any test runs, mirroring ClaudeDo.Ui.Tests' TestSetup,
|
|
// so a UiVm test that reads Loc.T without setting up its own localizer doesn't depend on
|
|
// ambient state left by whichever test class happened to run first. Deliberately does NOT
|
|
// also disable test parallelization here (unlike Ui.Tests) — measured 14m49s -> 18m46s
|
|
// (+27%) on this project's real-SQLite/git suite, too costly for a test-only ordering issue
|
|
// that the module initializer alone already closes.
|
|
[ModuleInitializer]
|
|
internal static void InstallRealLocalizer()
|
|
{
|
|
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");
|
|
}
|
|
}
|