fix(server): avoid macos path walks in terminal polling

Co-authored-by: Exotic <[email protected]>
This commit is contained in:
t3-code[bot]andExotic committed 2026-08-12 20:25:47 +00:00
1 parent 8d24b5131f
commit 96b5f889cd
2 files changed
+53 -4

No files matched your search

+47
View File
@@ -24,6 +24,7 @@ import * as Ref from "effect/Ref";
import * as Schedule from "effect/Schedule";
import * as Scope from "effect/Scope";
import * as TestClock from "effect/testing/TestClock";
import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
import { expect } from "vite-plus/test";
import * as ProcessRunner from "../processRunner.ts";
@@ -953,6 +954,52 @@ it.layer(
}),
);
it.effect("uses absolute utility paths for macOS subprocess polling", () =>
Effect.gen(function* () {
const calls: ProcessRunner.ProcessRunInput[] = [];
const runner = ProcessRunner.ProcessRunner.of({
run: (input) => {
calls.push(input);
const stdout =
input.args[0] === "-P"
? "10001\n"
: input.args[0] === "-eo"
? "10001 9000\n"
: input.args.includes("comm=")
? ""
: "/usr/bin/node\n";
return Effect.succeed({
stdout,
stderr: "",
code: ChildProcessSpawner.ExitCode(0),
timedOut: false,
stdoutTruncated: false,
stderrTruncated: false,
stdoutInvalidUtf8: false,
stderrInvalidUtf8: false,
});
},
});
const { manager } = yield* createManager(5, { subprocessPollIntervalMs: 20 }).pipe(
Effect.provideService(ProcessRunner.ProcessRunner, runner),
Effect.provide(withHostPlatform("darwin")),
);
yield* manager.open(openInput());
yield* waitFor(
Effect.sync(() => calls.length >= 4),
"1200 millis",
);
expect(calls.slice(0, 4).map(({ command }) => command)).toEqual([
"/usr/bin/pgrep",
"/bin/ps",
"/bin/ps",
"/bin/ps",
]);
}),
);
it.effect("caps persisted history to configured line limit", () =>
Effect.gen(function* () {
const { manager, ptyAdapter } = yield* createManager(3);
+6 -4
View File
@@ -703,9 +703,11 @@ const posixInspectSubprocess = Effect.fn("terminal.posixInspectSubprocess")(func
ProcessRunner.ProcessRunner
> {
const processRunner = yield* ProcessRunner.ProcessRunner;
const pgrepCommand = platform === "darwin" ? "/usr/bin/pgrep" : "pgrep";
const psCommand = platform === "darwin" ? "/bin/ps" : "ps";
const runPgrep = processRunner
.run({
command: "pgrep",
command: pgrepCommand,
args: ["-P", String(terminalPid)],
timeout: "1 second",
maxOutputBytes: 32_768,
@@ -725,7 +727,7 @@ const posixInspectSubprocess = Effect.fn("terminal.posixInspectSubprocess")(func
const runPs = processRunner
.run({
command: "ps",
command: psCommand,
args: ["-eo", "pid=,ppid="],
timeout: "1 second",
maxOutputBytes: 262_144,
@@ -776,7 +778,7 @@ const posixInspectSubprocess = Effect.fn("terminal.posixInspectSubprocess")(func
}
const runComm = processRunner.run({
command: "ps",
command: psCommand,
args: ["-p", String(childPid), "-o", "comm="],
timeout: "1 second",
maxOutputBytes: 8_192,
@@ -792,7 +794,7 @@ const posixInspectSubprocess = Effect.fn("terminal.posixInspectSubprocess")(func
if (!rawComm || rawComm.length === 0) {
const runArgs = processRunner.run({
command: "ps",
command: psCommand,
args: ["-p", String(childPid), "-o", "args="],
timeout: "1 second",
maxOutputBytes: 16_384,