| author | |
| committer | |
| log | 8dfee385721d5a0d613803da430e7b2276fadec5 |
| tree | 49c72d763b9711c93b542e14f6fe8e0f2b5c23a9 |
| parent | 8f43ceda4034c3f660dfd3fa3ca4abe67141b67f |
| signature | Signed by PGP key B5690EEEBB952194 |
Co-authored-by: Yash Singh <saiansh2525@gmail.com>2 files changed, 30 insertions(+), 3 deletions(-)
apps/server/src/resourceTelemetry/ResourceMonitorBinary.test.ts+22| ... | @@ -115,6 +115,28 @@ describe("ResourceMonitorBinary", () => { | ... | @@ -115,6 +115,28 @@ describe("ResourceMonitorBinary", () => { |
| 115 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 115 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 116 | ); | 116 | ); |
| 117 | 117 | ||
| 118 | it.effect("rejects a directory override", () => | ||
| 119 | Effect.gen(function* () { | ||
| 120 | const fileSystem = yield* FileSystem.FileSystem; | ||
| 121 | const baseDir = yield* fileSystem.makeTempDirectoryScoped({ | ||
| 122 | prefix: "t3-resource-monitor-binary-", | ||
| 123 | }); | ||
| 124 | |||
| 125 | const service = yield* ResourceMonitorBinary.make().pipe( | ||
| 126 | Effect.provide(ServerConfig.layerTest(process.cwd(), baseDir)), | ||
| 127 | Effect.provideService(HostProcess.Platform, "win32"), | ||
| 128 | Effect.provideService(HostProcess.Architecture, "arm64"), | ||
| 129 | Effect.provideService(HostProcess.Environment, { | ||
| 130 | T3CODE_RESOURCE_MONITOR_PATH: baseDir, | ||
| 131 | }), | ||
| 132 | ); | ||
| 133 | const error = yield* Effect.flip(service.resolve); | ||
| 134 | |||
| 135 | assert.instanceOf(error, ResourceMonitorBinary.ResourceMonitorBinaryNotExecutable); | ||
| 136 | assert.equal(error.path, baseDir); | ||
| 137 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | ||
| 138 | ); | ||
| 139 | |||
| 118 | it.effect("rejects unsupported platform and architecture pairs", () => | 140 | it.effect("rejects unsupported platform and architecture pairs", () => |
| 119 | Effect.gen(function* () { | 141 | Effect.gen(function* () { |
| 120 | const fileSystem = yield* FileSystem.FileSystem; | 142 | const fileSystem = yield* FileSystem.FileSystem; |
apps/server/src/resourceTelemetry/ResourceMonitorBinary.ts+8-3| ... | @@ -196,9 +196,14 @@ export const make = Effect.fn("resourceTelemetry.resourceMonitorBinary.make")(fu | ... | @@ -196,9 +196,14 @@ export const make = Effect.fn("resourceTelemetry.resourceMonitorBinary.make")(fu |
| 196 | const exists = yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false)); | 196 | const exists = yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false)); |
| 197 | if (!exists) continue; | 197 | if (!exists) continue; |
| 198 | 198 | ||
| 199 | if (platform !== "win32") { | 199 | const stat = yield* fileSystem.stat(candidate).pipe(Effect.option); |
| 200 | const stat = yield* fileSystem.stat(candidate).pipe(Effect.option); | 200 | if (Option.isSome(stat)) { |
| 201 | if (Option.isSome(stat) && (stat.value.mode & 0o111) === 0) { | 201 | // Directories are executable-looking on win32, where the exec-bit test |
| 202 | // below is skipped, and only fail later at spawn. | ||
| 203 | const unusable = | ||
| 204 | stat.value.type === "Directory" || | ||
| 205 | (platform !== "win32" && (stat.value.mode & 0o111) === 0); | ||
| 206 | if (unusable) { | ||
| 202 | return yield* new ResourceMonitorBinaryNotExecutable({ | 207 | return yield* new ResourceMonitorBinaryNotExecutable({ |
| 203 | path: candidate, | 208 | path: candidate, |
| 204 | mode: stat.value.mode, | 209 | mode: stat.value.mode, |