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"); } }