3
import { afterEach, assert, describe, it, vi } from "@effect/vitest";
4
import * as Effect from "effect/Effect";
5
import * as FileSystem from "effect/FileSystem";
6
+import * as Path from "effect/Path";
7
8
import * as ServerConfig from "../config.ts";
9
import * as ResourceMonitorBinary from "./ResourceMonitorBinary.ts";
89
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
90
);
91
92
+ it.effect.each(["release", "debug"])(
93
+ "resolves a cargo %s binary from the built server layout",
94
+ (profile) =>
95
+ Effect.gen(function* () {
96
+ const fileSystem = yield* FileSystem.FileSystem;
97
+ const path = yield* Path.Path;
98
+ const baseDir = yield* fileSystem.makeTempDirectoryScoped({
99
+ prefix: "t3-resource-monitor-binary-",
100
+ });
101
+ const projectDirectory = path.join(baseDir, "repo");
102
+ const distDirectory = path.join(projectDirectory, "apps", "server", "dist");
103
+ const binaryDirectory = path.join(
104
+ projectDirectory,
105
+ "native",
106
+ "resource-monitor",
107
+ "target",
108
+ profile,
109
+ );
110
+ const binaryPath = path.join(binaryDirectory, "t3-resource-monitor.exe");
111
+ yield* fileSystem.makeDirectory(distDirectory, { recursive: true });
112
+ yield* fileSystem.makeDirectory(binaryDirectory, { recursive: true });
113
+ yield* fileSystem.writeFileString(binaryPath, "binary");
114
+ yield* fileSystem.chmod(binaryPath, 0o755);
115
+
116
+ const service = yield* ResourceMonitorBinary.make().pipe(
117
+ // The bundled module lives in dist rather than src/resourceTelemetry.
118
+ Effect.provideService(Path.Path, {
119
+ ...path,
120
+ resolve: (...segments) =>
121
+ path.resolve(
122
+ ...segments.map((segment) =>
123
+ segment === import.meta.dirname ? distDirectory : segment,
124
+ ),
125
+ ),
126
+ }),
127
+ Effect.provide(ServerConfig.layerTest(projectDirectory, baseDir)),
128
+ Effect.provideService(HostProcess.Platform, "win32"),
129
+ Effect.provideService(HostProcess.Architecture, "arm64"),
130
+ Effect.provideService(HostProcess.Environment, {}),
131
+ );
132
+
133
+ assert.equal(yield* service.resolve, binaryPath);
134
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
135
+ );
136
+
137
it.effect("rejects bundled glibc binaries on musl Linux hosts", () =>
138
Effect.gen(function* () {
139
const fileSystem = yield* FileSystem.FileSystem;