fix(cli): bound container runtime probes (#109199)

Co-authored-by: Peter Steinberger <steipete@gmail.com>
Co-authored-by: Peter Steinberger <peter@steipete.me>
This commit is contained in:
mushuiyu886
2026-07-16 16:54:23 -07:00
committed by GitHub
co-authored by Peter Steinberger Peter Steinberger
parent 2a52e45e2b
commit 91df2d1812
2 changed files with 19 additions and 9 deletions
+7 -7
View File
@@ -406,7 +406,7 @@ describe("maybeRunCliInContainer", () => {
1,
"podman",
["inspect", "--format", "{{.State.Running}}", "demo"],
{ encoding: "utf8" },
{ encoding: "utf8", killSignal: "SIGKILL", timeout: 10_000 },
);
expect(spawnSync).toHaveBeenNthCalledWith(
3,
@@ -459,7 +459,7 @@ describe("maybeRunCliInContainer", () => {
2,
"docker",
["inspect", "--format", "{{.State.Running}}", "demo"],
{ encoding: "utf8" },
{ encoding: "utf8", killSignal: "SIGKILL", timeout: 10_000 },
);
expect(spawnSync).toHaveBeenNthCalledWith(
3,
@@ -516,13 +516,13 @@ describe("maybeRunCliInContainer", () => {
1,
"podman",
["inspect", "--format", "{{.State.Running}}", "demo"],
{ encoding: "utf8" },
{ encoding: "utf8", killSignal: "SIGKILL", timeout: 10_000 },
);
expect(spawnSync).toHaveBeenNthCalledWith(
2,
"docker",
["inspect", "--format", "{{.State.Running}}", "demo"],
{ encoding: "utf8" },
{ encoding: "utf8", killSignal: "SIGKILL", timeout: 10_000 },
);
expect(spawnSync).toHaveBeenNthCalledWith(
3,
@@ -570,13 +570,13 @@ describe("maybeRunCliInContainer", () => {
1,
"podman",
["inspect", "--format", "{{.State.Running}}", "demo"],
{ encoding: "utf8" },
{ encoding: "utf8", killSignal: "SIGKILL", timeout: 10_000 },
);
expect(spawnSync).toHaveBeenNthCalledWith(
2,
"docker",
["inspect", "--format", "{{.State.Running}}", "demo"],
{ encoding: "utf8" },
{ encoding: "utf8", killSignal: "SIGKILL", timeout: 10_000 },
);
});
@@ -681,7 +681,7 @@ describe("maybeRunCliInContainer", () => {
1,
"podman",
["inspect", "--format", "{{.State.Running}}", "flag-demo"],
{ encoding: "utf8" },
{ encoding: "utf8", killSignal: "SIGKILL", timeout: 10_000 },
);
});
+12 -2
View File
@@ -30,6 +30,7 @@ type ContainerRuntimeExec = {
};
const CONTAINER_ALLOW_LOOPBACK_PROXY_URL_ENV = "OPENCLAW_CONTAINER_ALLOW_LOOPBACK_PROXY_URL";
const CONTAINER_RUNTIME_PROBE_TIMEOUT_MS = 10_000;
export function parseCliContainerArgs(argv: string[]): CliContainerParseResult {
let container: string | null = null;
@@ -74,8 +75,17 @@ function isContainerRunning(params: {
params.exec.command,
[...params.exec.argsPrefix, "inspect", "--format", "{{.State.Running}}", params.containerName],
params.exec.command === "sudo"
? { encoding: "utf8", stdio: ["inherit", "pipe", "inherit"] }
: { encoding: "utf8" },
? {
encoding: "utf8",
killSignal: "SIGKILL",
stdio: ["inherit", "pipe", "inherit"],
timeout: CONTAINER_RUNTIME_PROBE_TIMEOUT_MS,
}
: {
encoding: "utf8",
killSignal: "SIGKILL",
timeout: CONTAINER_RUNTIME_PROBE_TIMEOUT_MS,
},
);
return result.status === 0 && result.stdout.trim() === "true";
}