Skip to content

Commit 0f2a80f

Browse files
committed
fix(server): a directory no longer resolves as the resource monitor binary
1 parent 611132c commit 0f2a80f

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,28 @@ describe("ResourceMonitorBinary", () => {
119119
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
120120
);
121121

122+
it.effect("rejects a directory override", () =>
123+
Effect.gen(function* () {
124+
const fileSystem = yield* FileSystem.FileSystem;
125+
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
126+
prefix: "t3-resource-monitor-binary-",
127+
});
128+
129+
const service = yield* ResourceMonitorBinary.make().pipe(
130+
Effect.provide(ServerConfig.layerTest(process.cwd(), baseDir)),
131+
Effect.provideService(HostProcessPlatform, "win32"),
132+
Effect.provideService(HostProcessArchitecture, "arm64"),
133+
Effect.provideService(HostProcessEnvironment, {
134+
T3CODE_RESOURCE_MONITOR_PATH: baseDir,
135+
}),
136+
);
137+
const error = yield* Effect.flip(service.resolve);
138+
139+
assert.instanceOf(error, ResourceMonitorBinary.ResourceMonitorBinaryNotExecutable);
140+
assert.equal(error.path, baseDir);
141+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
142+
);
143+
122144
it.effect("rejects unsupported platform and architecture pairs", () =>
123145
Effect.gen(function* () {
124146
const fileSystem = yield* FileSystem.FileSystem;

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,14 @@ export const make = Effect.fn("resourceTelemetry.resourceMonitorBinary.make")(fu
200200
const exists = yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false));
201201
if (!exists) continue;
202202

203-
if (platform !== "win32") {
204-
const stat = yield* fileSystem.stat(candidate).pipe(Effect.option);
205-
if (Option.isSome(stat) && (stat.value.mode & 0o111) === 0) {
203+
const stat = yield* fileSystem.stat(candidate).pipe(Effect.option);
204+
if (Option.isSome(stat)) {
205+
// Directories are executable-looking on win32, where the exec-bit test
206+
// below is skipped, and only fail later at spawn.
207+
const unusable =
208+
stat.value.type === "Directory" ||
209+
(platform !== "win32" && (stat.value.mode & 0o111) === 0);
210+
if (unusable) {
206211
return yield* new ResourceMonitorBinaryNotExecutable({
207212
path: candidate,
208213
mode: stat.value.mode,

0 commit comments

Comments
 (0)