

























@@ -0,0 +1,90 @@
1+import { execFileSync } from "node:child_process";
2+import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3+import { tmpdir } from "node:os";
4+import path from "node:path";
5+import { afterEach, describe, expect, it } from "vitest";
6+7+const tempDirs: string[] = [];
8+9+function makeTempBin(prefix: string) {
10+const dir = mkdtempSync(path.join(tmpdir(), prefix));
11+tempDirs.push(dir);
12+return dir;
13+}
14+15+function writeExecutable(filePath: string, contents: string) {
16+writeFileSync(filePath, contents, "utf8");
17+chmodSync(filePath, 0o755);
18+}
19+20+function resolveDockerRunArgs(pathPrefix: string) {
21+const script = [
22+"source scripts/lib/live-docker-auth.sh",
23+"ARGS=()",
24+"openclaw_live_init_docker_run_args ARGS 42s",
25+"printf '%s\\n' \"${ARGS[@]}\"",
26+].join("\n");
27+28+return execFileSync("/bin/bash", ["-c", script], {
29+cwd: process.cwd(),
30+encoding: "utf8",
31+env: {
32+ ...process.env,
33+PATH: pathPrefix,
34+},
35+}).trimEnd().split("\n");
36+}
37+38+afterEach(() => {
39+while (tempDirs.length > 0) {
40+rmSync(tempDirs.pop()!, { force: true, recursive: true });
41+}
42+});
43+44+describe("scripts/lib/live-docker-auth.sh", () => {
45+it("adds a kill-after grace period when timeout supports it", () => {
46+const binDir = makeTempBin("openclaw-live-docker-auth-gnu-");
47+writeExecutable(
48+path.join(binDir, "timeout"),
49+[
50+"#!/bin/sh",
51+'if [ "$1" = "--kill-after=1s" ] && [ "$2" = "1s" ] && [ "$3" = "true" ]; then',
52+" exit 0",
53+"fi",
54+"exit 64",
55+"",
56+].join("\n"),
57+);
58+59+expect(resolveDockerRunArgs(binDir)).toEqual([
60+"timeout",
61+"--kill-after=30s",
62+"42s",
63+"docker",
64+"run",
65+]);
66+});
67+68+it("falls back to plain timeout when kill-after is unavailable", () => {
69+const binDir = makeTempBin("openclaw-live-docker-auth-plain-");
70+writeExecutable(
71+path.join(binDir, "timeout"),
72+[
73+"#!/bin/sh",
74+'if [ "$1" = "--kill-after=1s" ]; then',
75+" exit 1",
76+"fi",
77+"exit 0",
78+"",
79+].join("\n"),
80+);
81+82+expect(resolveDockerRunArgs(binDir)).toEqual(["timeout", "42s", "docker", "run"]);
83+});
84+85+it("uses docker directly when timeout is unavailable", () => {
86+const binDir = makeTempBin("openclaw-live-docker-auth-no-timeout-");
87+88+expect(resolveDockerRunArgs(binDir)).toEqual(["docker", "run"]);
89+});
90+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。