




























@@ -25,14 +25,38 @@ function resolveDockerRunArgs(pathPrefix: string) {
2525"printf '%s\\n' \"${ARGS[@]}\"",
2626].join("\n");
272728-return execFileSync("/bin/bash", ["-c", script], {
28+const output = execFileSync("/bin/bash", ["-c", script], {
2929cwd: process.cwd(),
3030encoding: "utf8",
3131env: {
3232 ...process.env,
3333PATH: pathPrefix,
3434},
35-}).trimEnd().split("\n");
35+}).trimEnd();
36+return output ? output.split("\n") : [];
37+}
38+39+function failDockerRunArgs(pathPrefix: string) {
40+const script = [
41+"source scripts/lib/live-docker-auth.sh",
42+"ARGS=()",
43+"openclaw_live_init_docker_run_args ARGS 42s",
44+].join("\n");
45+46+try {
47+execFileSync("/bin/bash", ["-c", script], {
48+cwd: process.cwd(),
49+encoding: "utf8",
50+env: {
51+ ...process.env,
52+PATH: pathPrefix,
53+},
54+stdio: ["ignore", "pipe", "pipe"],
55+});
56+} catch (error) {
57+return error as { status?: number; stderr?: Buffer | string };
58+}
59+throw new Error("Expected live Docker run arg initialization to fail");
3660}
37613862afterEach(() => {
@@ -82,9 +106,36 @@ describe("scripts/lib/live-docker-auth.sh", () => {
82106expect(resolveDockerRunArgs(binDir)).toEqual(["timeout", "42s", "docker", "run"]);
83107});
8410885-it("uses docker directly when timeout is unavailable", () => {
109+it("uses gtimeout when timeout is unavailable", () => {
110+const binDir = makeTempBin("openclaw-live-docker-auth-gtimeout-");
111+writeExecutable(
112+path.join(binDir, "gtimeout"),
113+[
114+"#!/bin/sh",
115+'if [ "$1" = "--kill-after=1s" ] && [ "$2" = "1s" ] && [ "$3" = "true" ]; then',
116+" exit 0",
117+"fi",
118+"exit 64",
119+"",
120+].join("\n"),
121+);
122+123+expect(resolveDockerRunArgs(binDir)).toEqual([
124+"gtimeout",
125+"--kill-after=30s",
126+"42s",
127+"docker",
128+"run",
129+]);
130+});
131+132+it("fails fast when timeout is unavailable", () => {
86133const binDir = makeTempBin("openclaw-live-docker-auth-no-timeout-");
134+const error = failDockerRunArgs(binDir);
8713588-expect(resolveDockerRunArgs(binDir)).toEqual(["docker", "run"]);
136+expect(error.status).toBe(127);
137+expect(String(error.stderr)).toContain(
138+"timeout command not found; cannot bound live Docker run after 42s",
139+);
89140});
90141});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。