From 8475e3c683fee1e793c6437203d8fc30d1b1e33e Mon Sep 17 00:00:00 2001 From: bkntr <888122+bkntr@users.noreply.github.com> Date: Wed, 5 Aug 2026 00:02:40 +0530 Subject: [PATCH] fix(server): skip Linux libc detection on Windows --- .../ResourceMonitorBinary.test.ts | 32 ++++++++++++++++++- .../ResourceMonitorBinary.ts | 4 +-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/apps/server/src/resourceTelemetry/ResourceMonitorBinary.test.ts b/apps/server/src/resourceTelemetry/ResourceMonitorBinary.test.ts index 4c3afa97abf..243556b6e3b 100644 --- a/apps/server/src/resourceTelemetry/ResourceMonitorBinary.test.ts +++ b/apps/server/src/resourceTelemetry/ResourceMonitorBinary.test.ts @@ -4,7 +4,7 @@ import { HostProcessEnvironment, HostProcessPlatform, } from "@t3tools/shared/hostProcess"; -import { assert, describe, it } from "@effect/vitest"; +import { afterEach, assert, describe, expect, it, vi } from "@effect/vitest"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; @@ -12,6 +12,36 @@ import { ServerConfig } from "../config.ts"; import * as ResourceMonitorBinary from "./ResourceMonitorBinary.ts"; describe("ResourceMonitorBinary", () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + it.effect("skips Linux libc detection on Windows", () => + Effect.gen(function* () { + const getReport = vi.spyOn(process.report, "getReport").mockImplementation(() => { + throw new Error("Linux libc detection must not run on Windows"); + }); + const fileSystem = yield* FileSystem.FileSystem; + const baseDir = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "t3-resource-monitor-binary-", + }); + const binaryPath = `${baseDir}/t3-resource-monitor.exe`; + yield* fileSystem.writeFileString(binaryPath, "binary"); + + const service = yield* ResourceMonitorBinary.make().pipe( + Effect.provide(ServerConfig.layerTest(process.cwd(), baseDir)), + Effect.provideService(HostProcessPlatform, "win32"), + Effect.provideService(HostProcessArchitecture, "arm64"), + Effect.provideService(HostProcessEnvironment, { + T3CODE_RESOURCE_MONITOR_PATH: binaryPath, + }), + ); + + assert.equal(yield* service.resolve, binaryPath); + expect(getReport).not.toHaveBeenCalled(); + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), + ); + it.effect("resolves an executable override", () => Effect.gen(function* () { const fileSystem = yield* FileSystem.FileSystem; diff --git a/apps/server/src/resourceTelemetry/ResourceMonitorBinary.ts b/apps/server/src/resourceTelemetry/ResourceMonitorBinary.ts index 1f14df51866..c93bc54a1fb 100644 --- a/apps/server/src/resourceTelemetry/ResourceMonitorBinary.ts +++ b/apps/server/src/resourceTelemetry/ResourceMonitorBinary.ts @@ -106,7 +106,7 @@ export function resourceMonitorPlatformKey( export function resourceMonitorRustTarget( platform: NodeJS.Platform, architecture: NodeJS.Architecture, - linuxLibc: ResourceMonitorLinuxLibc, + linuxLibc?: ResourceMonitorLinuxLibc, ): string | undefined { if (platform === "darwin") { return architecture === "arm64" @@ -142,7 +142,7 @@ export const make = Effect.fn("resourceTelemetry.resourceMonitorBinary.make")(fu const platform = yield* HostProcessPlatform; const architecture = yield* HostProcessArchitecture; const environment = yield* HostProcessEnvironment; - const linuxLibc = yield* ResourceMonitorHostLinuxLibc; + const linuxLibc = platform === "linux" ? yield* ResourceMonitorHostLinuxLibc : undefined; const executableName = binaryName(platform); const platformKey = resourceMonitorPlatformKey(platform, architecture); const rustTarget = resourceMonitorRustTarget(platform, architecture, linuxLibc);