Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion apps/server/src/resourceTelemetry/ResourceMonitorBinary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,44 @@ 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";

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;
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/resourceTelemetry/ResourceMonitorBinary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
Loading