| 1 | // @effect-diagnostics nodeBuiltinImport:off |
| 2 | import * as NodeChildProcess from "node:child_process"; |
| 3 | |
| 4 | import { describe, expect, it } from "@effect/vitest"; |
| 5 | |
| 6 | import { AGENT_OOM_SCORE_ADJ, agentScopeCommand } from "./AgentScope.ts"; |
| 7 | import * as HostProcess from "./HostProcess.ts"; |
| 8 | |
| 9 | describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("agentScopeCommand", () => { |
| 10 | it("raises the OOM score and execs the command with its arguments in the same process", () => { |
| 11 | const launch = agentScopeCommand({ |
| 12 | command: "/bin/sh", |
| 13 | args: [ |
| 14 | "-c", |
| 15 | 'printf "%s\\n" "$$" "$(cat /proc/self/oom_score_adj)" "$@"', |
| 16 | "agent", |
| 17 | "a b", |
| 18 | "$HOME", |
| 19 | ], |
| 20 | }); |
| 21 | const child = NodeChildProcess.spawnSync(launch.command, [...launch.args], { |
| 22 | encoding: "utf8", |
| 23 | }); |
| 24 | const [pid, score, ...args] = child.stdout.trimEnd().split("\n"); |
| 25 | // The command runs as the spawned process, so signals and PIDs still reach it. |
| 26 | expect(Number(pid)).toBe(child.pid); |
| 27 | expect(Number(score)).toBe(AGENT_OOM_SCORE_ADJ); |
| 28 | expect(args).toEqual(["a b", "$HOME"]); |
| 29 | }); |
| 30 | }); |