mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-01 10:20:20 +00:00
refactor: clarify docker setup cli phases
This commit is contained in:
@@ -114,6 +114,26 @@ function runDockerSetup(
|
||||
});
|
||||
}
|
||||
|
||||
async function resetDockerLog(sandbox: DockerSetupSandbox) {
|
||||
await writeFile(sandbox.logPath, "");
|
||||
}
|
||||
|
||||
async function readDockerLog(sandbox: DockerSetupSandbox) {
|
||||
return readFile(sandbox.logPath, "utf8");
|
||||
}
|
||||
|
||||
async function readDockerLogLines(sandbox: DockerSetupSandbox) {
|
||||
return (await readDockerLog(sandbox)).split("\n").filter(Boolean);
|
||||
}
|
||||
|
||||
function isGatewayStartLine(line: string) {
|
||||
return line.includes("compose") && line.includes(" up -d") && line.includes("openclaw-gateway");
|
||||
}
|
||||
|
||||
function findGatewayStartLineIndex(lines: string[]) {
|
||||
return lines.findIndex((line) => isGatewayStartLine(line));
|
||||
}
|
||||
|
||||
async function runDockerSetupWithUnsetGatewayToken(
|
||||
sandbox: DockerSetupSandbox,
|
||||
suffix: string,
|
||||
@@ -204,7 +224,7 @@ describe("scripts/docker/setup.sh", () => {
|
||||
expect(extraCompose).toContain("openclaw-home:/home/node");
|
||||
expect(extraCompose).toContain("volumes:");
|
||||
expect(extraCompose).toContain("openclaw-home:");
|
||||
const log = await readFile(activeSandbox.logPath, "utf8");
|
||||
const log = await readDockerLog(activeSandbox);
|
||||
expect(log).toContain("--build-arg OPENCLAW_DOCKER_APT_PACKAGES=ffmpeg build-essential");
|
||||
expect(log).toContain(
|
||||
"run --rm --no-deps --entrypoint node openclaw-gateway dist/index.js onboard --mode local --no-install-daemon",
|
||||
@@ -224,16 +244,12 @@ describe("scripts/docker/setup.sh", () => {
|
||||
it("avoids shared-network openclaw-cli before the gateway is started", async () => {
|
||||
const activeSandbox = requireSandbox(sandbox);
|
||||
|
||||
await writeFile(activeSandbox.logPath, "");
|
||||
await resetDockerLog(activeSandbox);
|
||||
const result = runDockerSetup(activeSandbox);
|
||||
expect(result.status).toBe(0);
|
||||
|
||||
const log = await readFile(activeSandbox.logPath, "utf8");
|
||||
const lines = log.split("\n").filter(Boolean);
|
||||
const gatewayStartIdx = lines.findIndex(
|
||||
(line) =>
|
||||
line.includes("compose") && line.includes(" up -d") && line.includes("openclaw-gateway"),
|
||||
);
|
||||
const lines = await readDockerLogLines(activeSandbox);
|
||||
const gatewayStartIdx = findGatewayStartLineIndex(lines);
|
||||
expect(gatewayStartIdx).toBeGreaterThanOrEqual(0);
|
||||
|
||||
const prestartLines = lines.slice(0, gatewayStartIdx);
|
||||
@@ -286,7 +302,7 @@ describe("scripts/docker/setup.sh", () => {
|
||||
expect(sessionsDirStat.isDirectory()).toBe(true);
|
||||
|
||||
// Verify that a root-user chown step runs before setup.
|
||||
const log = await readFile(activeSandbox.logPath, "utf8");
|
||||
const log = await readDockerLog(activeSandbox);
|
||||
const chownIdx = log.indexOf("--user root");
|
||||
const onboardIdx = log.indexOf("onboard");
|
||||
expect(chownIdx).toBeGreaterThanOrEqual(0);
|
||||
@@ -350,7 +366,7 @@ describe("scripts/docker/setup.sh", () => {
|
||||
|
||||
it("treats OPENCLAW_SANDBOX=0 as disabled", async () => {
|
||||
const activeSandbox = requireSandbox(sandbox);
|
||||
await writeFile(activeSandbox.logPath, "");
|
||||
await resetDockerLog(activeSandbox);
|
||||
|
||||
const result = runDockerSetup(activeSandbox, {
|
||||
OPENCLAW_SANDBOX: "0",
|
||||
@@ -360,7 +376,7 @@ describe("scripts/docker/setup.sh", () => {
|
||||
const envFile = await readFile(join(activeSandbox.rootDir, ".env"), "utf8");
|
||||
expect(envFile).toContain("OPENCLAW_SANDBOX=");
|
||||
|
||||
const log = await readFile(activeSandbox.logPath, "utf8");
|
||||
const log = await readDockerLog(activeSandbox);
|
||||
expect(log).toContain("--build-arg OPENCLAW_INSTALL_DOCKER_CLI=");
|
||||
expect(log).not.toContain("--build-arg OPENCLAW_INSTALL_DOCKER_CLI=1");
|
||||
expect(log).toContain("config set agents.defaults.sandbox.mode off");
|
||||
@@ -368,7 +384,7 @@ describe("scripts/docker/setup.sh", () => {
|
||||
|
||||
it("resets stale sandbox mode and overlay when sandbox is not active", async () => {
|
||||
const activeSandbox = requireSandbox(sandbox);
|
||||
await writeFile(activeSandbox.logPath, "");
|
||||
await resetDockerLog(activeSandbox);
|
||||
await writeFile(
|
||||
join(activeSandbox.rootDir, "docker-compose.sandbox.yml"),
|
||||
"services:\n openclaw-gateway:\n volumes:\n - /var/run/docker.sock:/var/run/docker.sock\n",
|
||||
@@ -381,14 +397,14 @@ describe("scripts/docker/setup.sh", () => {
|
||||
|
||||
expect(result.status).toBe(0);
|
||||
expect(result.stderr).toContain("Sandbox requires Docker CLI");
|
||||
const log = await readFile(activeSandbox.logPath, "utf8");
|
||||
const log = await readDockerLog(activeSandbox);
|
||||
expect(log).toContain("config set agents.defaults.sandbox.mode off");
|
||||
await expect(stat(join(activeSandbox.rootDir, "docker-compose.sandbox.yml"))).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("skips sandbox gateway restart when sandbox config writes fail", async () => {
|
||||
const activeSandbox = requireSandbox(sandbox);
|
||||
await writeFile(activeSandbox.logPath, "");
|
||||
await resetDockerLog(activeSandbox);
|
||||
const socketPath = join(activeSandbox.rootDir, "sandbox.sock");
|
||||
|
||||
await withUnixSocket(socketPath, async () => {
|
||||
@@ -402,15 +418,10 @@ describe("scripts/docker/setup.sh", () => {
|
||||
expect(result.stderr).toContain("Failed to set agents.defaults.sandbox.scope");
|
||||
expect(result.stderr).toContain("Skipping gateway restart to avoid exposing Docker socket");
|
||||
|
||||
const log = await readFile(activeSandbox.logPath, "utf8");
|
||||
const gatewayStarts = log
|
||||
.split("\n")
|
||||
.filter(
|
||||
(line) =>
|
||||
line.includes("compose") &&
|
||||
line.includes(" up -d") &&
|
||||
line.includes("openclaw-gateway"),
|
||||
);
|
||||
const log = await readDockerLog(activeSandbox);
|
||||
const gatewayStarts = (await readDockerLogLines(activeSandbox)).filter((line) =>
|
||||
isGatewayStartLine(line),
|
||||
);
|
||||
expect(gatewayStarts).toHaveLength(2);
|
||||
expect(log).toContain(
|
||||
"run --rm --no-deps openclaw-cli config set agents.defaults.sandbox.mode non-main",
|
||||
|
||||
Reference in New Issue
Block a user