The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | // @effect-diagnostics nodeBuiltinImport:off |
| 2 | import * as NodeChildProcess from "node:child_process"; |
| 3 | import * as NodeFS from "node:fs"; |
| 4 | import * as NodeOS from "node:os"; |
| 5 | import * as NodePath from "node:path"; |
| 6 | |
| 7 | import { describe, expect, it } from "@effect/vitest"; |
| 8 | |
| 9 | import { AGENT_OOM_SCORE_ADJ, agentScopeCommand, agentScopeLauncherScript } from "./AgentScope.ts"; |
| 10 | import * as HostProcess from "./HostProcess.ts"; |
| 11 | |
| 12 | describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("agentScopeCommand", () => { |
| 13 | it("raises the OOM score and execs the command with its arguments in the same process", () => { |
| 14 | const launch = agentScopeCommand({ |
| 15 | command: "/bin/sh", |
| 16 | args: [ |
| 17 | "-c", |
| 18 | 'printf "%s\\n" "$$" "$(cat /proc/self/oom_score_adj)" "$@"', |
| 19 | "agent", |
| 20 | "a b", |
| 21 | "$HOME", |
| 22 | ], |
| 23 | }); |
| 24 | const child = NodeChildProcess.spawnSync(launch.command, [...launch.args], { |
| 25 | encoding: "utf8", |
| 26 | }); |
| 27 | const [pid, score, ...args] = child.stdout.trimEnd().split("\n"); |
| 28 | expect(Number(pid)).toBe(child.pid); |
| 29 | expect(Number(score)).toBe(AGENT_OOM_SCORE_ADJ); |
| 30 | expect(args).toEqual(["a b", "$HOME"]); |
| 31 | |
| 32 | const directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-agent-launcher-")); |
| 33 | try { |
| 34 | const launcher = NodePath.join(directory, "launch's"); |
| 35 | NodeFS.writeFileSync(launcher, agentScopeLauncherScript(launch), { mode: 0o700 }); |
| 36 | const launched = NodeChildProcess.spawnSync(launcher, ["--flag", "it's"], { |
| 37 | encoding: "utf8", |
| 38 | }); |
| 39 | const [launchedPid, launchedScore, ...launchedArgs] = launched.stdout.trimEnd().split("\n"); |
| 40 | expect(Number(launchedPid)).toBe(launched.pid); |
| 41 | expect(Number(launchedScore)).toBe(AGENT_OOM_SCORE_ADJ); |
| 42 | expect(launchedArgs).toEqual(["a b", "$HOME", "--flag", "it's"]); |
| 43 | } finally { |
| 44 | NodeFS.rmSync(directory, { recursive: true, force: true }); |
| 45 | } |
| 46 | }); |
| 47 | }); |