Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion scripts/ocx-run
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ echo "started=$(date -Is) name=$name limit=$limit cmd=$*" > "$status"

# setsid gives the job its own process group so a timeout kills the children too;
# --kill-after upgrades to SIGKILL for a process that ignores SIGTERM.
setsid timeout --signal=TERM --kill-after=60s "$limit" "$@" > "$log" 2>&1 &
(CDPATH= cd -- "$workdir" && exec setsid timeout --signal=TERM --kill-after=60s "$limit" "$@") > "$log" 2>&1 &
job=$!
echo "$job" > "$pidf"

Expand Down
44 changes: 44 additions & 0 deletions tests/ocx-run.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, expect, test } from "bun:test";
import {
mkdirSync,
mkdtempSync,
readFileSync,
realpathSync,
rmSync,
} from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";

const repoRoot = fileURLToPath(new URL("../", import.meta.url));
const runner = join(repoRoot, "scripts", "ocx-run");

describe("ocx-run", () => {
test.skipIf(process.platform !== "linux")(
"runs the command from a requested workdir containing spaces",
() => {
const root = mkdtempSync(join(tmpdir(), "ocx-run-"));
const workdirName = "requested workdir";
const workdir = join(root, workdirName);
const cdPath = join(root, "cdpath");
const stateDir = join(root, "state");
const name = "workdir";

try {
mkdirSync(workdir);
mkdirSync(join(cdPath, workdirName), { recursive: true });
const result = Bun.spawnSync(["bash", runner, name, workdirName, "5s", "pwd", "-P"], {
cwd: root,
env: { ...process.env, CDPATH: cdPath, OCX_RUN_DIR: stateDir },
stdout: "pipe",
stderr: "pipe",
});

expect(result.exitCode).toBe(0);
expect(readFileSync(join(stateDir, `${name}.log`), "utf8")).toBe(`${realpathSync(workdir)}\n`);
} finally {
rmSync(root, { recursive: true, force: true });
}
},
);
});
Loading