Skip to content

Commit cd69df4

Browse files
yordist3dotggclaudeonly21miljuliusmarminge
authored
fix(server): find the resource monitor when the server runs from its build output (pingdotgg#23965)
Signed-off-by: Yordis Prieto <[email protected]> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Victor Vogel <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Joseph Vidal <[email protected]> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: fixfon <[email protected]> Co-authored-by: Utkarsh Patil <[email protected]> Co-authored-by: Yukun Shan <[email protected]> Co-authored-by: Akshar Patel <[email protected]> Co-authored-by: Ben Davis <[email protected]>
1 parent c8c9ccf commit cd69df4

2 files changed

Lines changed: 61 additions & 24 deletions

File tree

‎apps/server/src/resourceTelemetry/ResourceMonitorBinary.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
33
import { afterEach, assert, describe, it, vi } from "@effect/vitest";
44
import * as Effect from "effect/Effect";
55
import * as FileSystem from "effect/FileSystem";
6+
import * as Path from "effect/Path";
67

78
import * as ServerConfig from "../config.ts";
89
import * as ResourceMonitorBinary from "./ResourceMonitorBinary.ts";
@@ -88,6 +89,51 @@ describe("ResourceMonitorBinary", () => {
8889
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
8990
);
9091

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+
91137
it.effect("rejects bundled glibc binaries on musl Linux hosts", () =>
92138
Effect.gen(function* () {
93139
const fileSystem = yield* FileSystem.FileSystem;

‎apps/server/src/resourceTelemetry/ResourceMonitorBinary.ts‎

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -146,37 +146,28 @@ export const make = Effect.fn("resourceTelemetry.resourceMonitorBinary.make")(fu
146146
environment.T3CODE_RESOURCE_MONITOR_PATH,
147147
config.resourceMonitorPath,
148148
].filter((candidate): candidate is string => Boolean(candidate));
149+
const cargoOutputDirectories =
150+
rustTarget === undefined
151+
? []
152+
: [
153+
path.join("target", rustTarget, "release"),
154+
path.join("target", "release"),
155+
path.join("target", "debug"),
156+
];
157+
const sourceCandidates = [
158+
path.resolve(import.meta.dirname, "../../../../native/resource-monitor"),
159+
path.resolve(import.meta.dirname, "../../../native/resource-monitor"),
160+
].flatMap((crateDirectory) =>
161+
cargoOutputDirectories.map((directory) => path.join(crateDirectory, directory, executableName)),
162+
);
149163
const bundledCandidates =
150164
platformKey === undefined || rustTarget === undefined
151165
? []
152166
: [
153167
path.resolve(import.meta.dirname, "resource-monitor", platformKey, executableName),
154168
path.resolve(import.meta.dirname, "resource-monitor", executableName),
155169
path.resolve(import.meta.dirname, "../resource-monitor", executableName),
156-
path.resolve(
157-
import.meta.dirname,
158-
"../../../../native/resource-monitor/target",
159-
rustTarget,
160-
"release",
161-
executableName,
162-
),
163-
path.resolve(
164-
import.meta.dirname,
165-
"../../../native/resource-monitor/target",
166-
rustTarget,
167-
"release",
168-
executableName,
169-
),
170-
path.resolve(
171-
import.meta.dirname,
172-
"../../../../native/resource-monitor/target/release",
173-
executableName,
174-
),
175-
path.resolve(
176-
import.meta.dirname,
177-
"../../../../native/resource-monitor/target/debug",
178-
executableName,
179-
),
170+
...sourceCandidates,
180171
];
181172
if (overrideCandidates.length === 0 && bundledCandidates.length === 0) {
182173
return ResourceMonitorBinary.of({

0 commit comments

Comments
 (0)