From e7b98cac744b1b27b2179aeef4551f26b123d10d Mon Sep 17 00:00:00 2001 From: Josh Gratton Date: Mon, 22 Jun 2026 14:08:39 -0400 Subject: [PATCH] Align backend code with app conventions; clear lint debt Lint: - providerMaintenanceRunner: drop the shell:win32 spawn option to match upstream main (which removed it), clearing the no-global-process-runtime error. No WSL/desktop behavior change (server-side provider maintenance). - DesktopBackendConfiguration.test: the runSync-safety test deliberately uses ManagedRuntime + Effect.runSync to replicate the sync IPC handler's exact path; add a justified oxlint-disable (converting to it.effect would mask a regression to async-only resolution). Normalize internal error classes from Data.TaggedError to Schema.TaggedErrorClass, matching the app's normalized error style: BackendTimeoutError, BackendProcessBootstrapEncodeError, BackendProcessSpawnError, DesktopBackendPoolInstanceAlreadyRegisteredError, DesktopBackendPoolCannotUnregisterPrimaryError, and DesktopLogFileWriterConfigurationError. Tags, fields, and messages are unchanged; this is type-level normalization only. Verified: desktop + server typecheck clean, full lint green, and the converted-error tests pass. --- apps/desktop/src/app/DesktopObservability.ts | 12 +++---- .../DesktopBackendConfiguration.test.ts | 2 ++ .../src/backend/DesktopBackendManager.ts | 32 +++++++++++-------- .../desktop/src/backend/DesktopBackendPool.ts | 16 ++++++---- .../src/provider/providerMaintenanceRunner.ts | 11 +------ 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/apps/desktop/src/app/DesktopObservability.ts b/apps/desktop/src/app/DesktopObservability.ts index a9bb86ab24..2247b76a6a 100644 --- a/apps/desktop/src/app/DesktopObservability.ts +++ b/apps/desktop/src/app/DesktopObservability.ts @@ -2,7 +2,6 @@ import { PRIMARY_LOCAL_ENVIRONMENT_ID } from "@t3tools/contracts"; import { makeLocalFileTracer, makeTraceSink } from "@t3tools/shared/observability"; import { parsePersistedServerObservabilitySettings } from "@t3tools/shared/serverSettings"; import * as Context from "effect/Context"; -import * as Data from "effect/Data"; import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; @@ -98,12 +97,13 @@ export function makeComponentLogger(component: string): DesktopComponentLogger { }; } -class DesktopLogFileWriterConfigurationError extends Data.TaggedError( +class DesktopLogFileWriterConfigurationError extends Schema.TaggedErrorClass()( "DesktopLogFileWriterConfigurationError", -)<{ - readonly option: "maxBytes" | "maxFiles"; - readonly value: number; -}> { + { + option: Schema.Literals(["maxBytes", "maxFiles"]), + value: Schema.Number, + }, +) { override get message() { return `${this.option} must be >= 1 (received ${this.value})`; } diff --git a/apps/desktop/src/backend/DesktopBackendConfiguration.test.ts b/apps/desktop/src/backend/DesktopBackendConfiguration.test.ts index d73506c9df..228bfed91a 100644 --- a/apps/desktop/src/backend/DesktopBackendConfiguration.test.ts +++ b/apps/desktop/src/backend/DesktopBackendConfiguration.test.ts @@ -493,6 +493,7 @@ describe("DesktopBackendConfiguration", () => { // a live async effect — otherwise runSync throws in the handler. Build the // real WSL layer (not the sync test stub) and resolve the label with a // top-level runSync, exactly as the handler does. + // oxlint-disable-next-line t3code/no-manual-effect-runtime-in-tests -- This test intentionally replicates the sync IPC handler's runSync path to catch a regression to async-only resolution; it.effect would mask it. const runtime = ManagedRuntime.make( DesktopBackendConfiguration.layer.pipe( Layer.provideMerge(serverExposureLayer), @@ -516,6 +517,7 @@ describe("DesktopBackendConfiguration", () => { const configuration = await runtime.runPromise( DesktopBackendConfiguration.DesktopBackendConfiguration, ); + // oxlint-disable-next-line t3code/no-manual-effect-runtime-in-tests -- Same reason: this is the synchronous resolution the IPC handler performs. const label = Effect.runSync(configuration.resolvePrimaryLabel); assert.equal(typeof label, "string"); } finally { diff --git a/apps/desktop/src/backend/DesktopBackendManager.ts b/apps/desktop/src/backend/DesktopBackendManager.ts index 23ef8294e4..361980fa9e 100644 --- a/apps/desktop/src/backend/DesktopBackendManager.ts +++ b/apps/desktop/src/backend/DesktopBackendManager.ts @@ -25,7 +25,6 @@ import * as Brand from "effect/Brand"; import * as Cause from "effect/Cause"; -import * as Data from "effect/Data"; import * as Duration from "effect/Duration"; import * as Effect from "effect/Effect"; import * as Exit from "effect/Exit"; @@ -104,29 +103,36 @@ interface BackendProcessExit { readonly result: Result.Result; } -export class BackendTimeoutError extends Data.TaggedError("BackendTimeoutError")<{ - readonly url: URL; -}> { +export class BackendTimeoutError extends Schema.TaggedErrorClass()( + "BackendTimeoutError", + { + url: Schema.instanceOf(URL), + }, +) { override get message() { return `Timed out waiting for backend readiness at ${this.url.href}.`; } } -class BackendProcessBootstrapEncodeError extends Data.TaggedError( +class BackendProcessBootstrapEncodeError extends Schema.TaggedErrorClass()( "BackendProcessBootstrapEncodeError", -)<{ - readonly entryPath: string; - readonly cause: Schema.SchemaError; -}> { + { + entryPath: Schema.String, + cause: Schema.Defect(), + }, +) { override get message() { return `Failed to encode the desktop backend bootstrap payload for ${this.entryPath}.`; } } -class BackendProcessSpawnError extends Data.TaggedError("BackendProcessSpawnError")<{ - readonly executablePath: string; - readonly cause: PlatformError.PlatformError; -}> { +class BackendProcessSpawnError extends Schema.TaggedErrorClass()( + "BackendProcessSpawnError", + { + executablePath: Schema.String, + cause: Schema.Defect(), + }, +) { override get message() { return `Failed to spawn the desktop backend process at ${this.executablePath}.`; } diff --git a/apps/desktop/src/backend/DesktopBackendPool.ts b/apps/desktop/src/backend/DesktopBackendPool.ts index a5f0b349ca..668e404d7a 100644 --- a/apps/desktop/src/backend/DesktopBackendPool.ts +++ b/apps/desktop/src/backend/DesktopBackendPool.ts @@ -80,11 +80,11 @@ // envs, routes pickFolder by env id. (38e8477a) import * as Context from "effect/Context"; -import * as Data from "effect/Data"; import * as Effect from "effect/Effect"; import * as Exit from "effect/Exit"; import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; +import * as Schema from "effect/Schema"; import * as Scope from "effect/Scope"; import * as SynchronizedRef from "effect/SynchronizedRef"; @@ -111,11 +111,12 @@ export type BackendInstanceSpec = DesktopBackendManager.BackendInstanceSpec; // Caller tried to register an id that's already in the pool. The pool // refuses overwrites so two independent orchestrators racing on the // same id surface as a typed failure instead of one silently winning. -export class DesktopBackendPoolInstanceAlreadyRegisteredError extends Data.TaggedError( +export class DesktopBackendPoolInstanceAlreadyRegisteredError extends Schema.TaggedErrorClass()( "DesktopBackendPoolInstanceAlreadyRegisteredError", -)<{ - readonly id: BackendInstanceId; -}> { + { + id: Schema.String, + }, +) { override get message() { return `Backend instance "${this.id}" is already registered in the pool.`; } @@ -124,9 +125,10 @@ export class DesktopBackendPoolInstanceAlreadyRegisteredError extends Data.Tagge // Primary instance is registered for the pool's lifetime. Unregister is // a no-op for it today (no real callers), but if someone wires it up // later it's a clear bug rather than something to "handle". -export class DesktopBackendPoolCannotUnregisterPrimaryError extends Data.TaggedError( +export class DesktopBackendPoolCannotUnregisterPrimaryError extends Schema.TaggedErrorClass()( "DesktopBackendPoolCannotUnregisterPrimaryError", -)<{}> { + {}, +) { override get message() { return "Refusing to unregister the primary backend from the pool."; } diff --git a/apps/server/src/provider/providerMaintenanceRunner.ts b/apps/server/src/provider/providerMaintenanceRunner.ts index 91120b48be..f04e97a13e 100644 --- a/apps/server/src/provider/providerMaintenanceRunner.ts +++ b/apps/server/src/provider/providerMaintenanceRunner.ts @@ -76,16 +76,7 @@ const runProviderMaintenanceCommandWithSpawner = Effect.fn("ProviderMaintenanceR const collectCommandResult = Effect.fn("ProviderMaintenanceRunner.collectCommandResult")( function* () { const child = yield* input.spawner - .spawn( - ChildProcess.make(input.command, [...input.args], { - // The update executable is usually a launcher shim (e.g. `npm` -> - // `npm.cmd`, `pnpm` -> `pnpm.cmd`). On Windows a bare-name spawn - // does not resolve PATHEXT, so it fails with ENOENT; run through - // the shell so the shim resolves, matching how every other - // provider command is spawned on Windows. - shell: process.platform === "win32", - }), - ) + .spawn(ChildProcess.make(input.command, [...input.args])) .pipe( Effect.mapError( (cause) =>