fix(server): a directory no longer resolves as the resource monitor binary (#16838)
Co-authored-by: Yash Singh <[email protected]>
This commit is contained in:
1 parent
8f43ceda40
commit
8dfee38572
2 files changed
+30
-3
No files matched your search
@@ -115,6 +115,28 @@ describe("ResourceMonitorBinary", () => {
|
||||
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
|
||||
it.effect("rejects a directory override", () =>
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
|
||||
prefix: "t3-resource-monitor-binary-",
|
||||
});
|
||||
|
||||
const service = yield* ResourceMonitorBinary.make().pipe(
|
||||
Effect.provide(ServerConfig.layerTest(process.cwd(), baseDir)),
|
||||
Effect.provideService(HostProcess.Platform, "win32"),
|
||||
Effect.provideService(HostProcess.Architecture, "arm64"),
|
||||
Effect.provideService(HostProcess.Environment, {
|
||||
T3CODE_RESOURCE_MONITOR_PATH: baseDir,
|
||||
}),
|
||||
);
|
||||
const error = yield* Effect.flip(service.resolve);
|
||||
|
||||
assert.instanceOf(error, ResourceMonitorBinary.ResourceMonitorBinaryNotExecutable);
|
||||
assert.equal(error.path, baseDir);
|
||||
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
|
||||
it.effect("rejects unsupported platform and architecture pairs", () =>
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
|
||||
@@ -196,9 +196,14 @@ export const make = Effect.fn("resourceTelemetry.resourceMonitorBinary.make")(fu
|
||||
const exists = yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false));
|
||||
if (!exists) continue;
|
||||
|
||||
if (platform !== "win32") {
|
||||
const stat = yield* fileSystem.stat(candidate).pipe(Effect.option);
|
||||
if (Option.isSome(stat) && (stat.value.mode & 0o111) === 0) {
|
||||
const stat = yield* fileSystem.stat(candidate).pipe(Effect.option);
|
||||
if (Option.isSome(stat)) {
|
||||
// Directories are executable-looking on win32, where the exec-bit test
|
||||
// below is skipped, and only fail later at spawn.
|
||||
const unusable =
|
||||
stat.value.type === "Directory" ||
|
||||
(platform !== "win32" && (stat.value.mode & 0o111) === 0);
|
||||
if (unusable) {
|
||||
return yield* new ResourceMonitorBinaryNotExecutable({
|
||||
path: candidate,
|
||||
mode: stat.value.mode,
|
||||
|
||||
Reference in new issue
Block a user