31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
// @effect-diagnostics nodeBuiltinImport:off
|
|
import * as NodeChildProcess from "node:child_process";
|
|
|
|
import { describe, expect, it } from "@effect/vitest";
|
|
|
|
import { AGENT_OOM_SCORE_ADJ, agentScopeCommand } from "./AgentScope.ts";
|
|
import * as HostProcess from "./HostProcess.ts";
|
|
|
|
describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("agentScopeCommand", () => {
|
|
it("raises the OOM score and execs the command with its arguments in the same process", () => {
|
|
const launch = agentScopeCommand({
|
|
command: "/bin/sh",
|
|
args: [
|
|
"-c",
|
|
'printf "%s\\n" "$$" "$(cat /proc/self/oom_score_adj)" "$@"',
|
|
"agent",
|
|
"a b",
|
|
"$HOME",
|
|
],
|
|
});
|
|
const child = NodeChildProcess.spawnSync(launch.command, [...launch.args], {
|
|
encoding: "utf8",
|
|
});
|
|
const [pid, score, ...args] = child.stdout.trimEnd().split("\n");
|
|
// The command runs as the spawned process, so signals and PIDs still reach it.
|
|
expect(Number(pid)).toBe(child.pid);
|
|
expect(Number(score)).toBe(AGENT_OOM_SCORE_ADJ);
|
|
expect(args).toEqual(["a b", "$HOME"]);
|
|
});
|
|
});
|