Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions apps/server/src/terminal/Manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions apps/server/src/terminal/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading