惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
F
Fortinet All Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
V
Visual Studio Blog
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
L
LangChain Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
P
Proofpoint News Feed
博客园_首页
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Check Point Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
Fix default sandbox image fallback for python3-dependent ...
vincentkoc · 2026-04-28 · via Recent Commits to openclaw:main

@@ -0,0 +1,116 @@

1+

import { EventEmitter } from "node:events";

2+

import { Readable } from "node:stream";

3+

import { beforeEach, describe, expect, it, vi } from "vitest";

4+

import { DEFAULT_SANDBOX_IMAGE } from "./constants.js";

5+6+

type SpawnCall = {

7+

command: string;

8+

args: string[];

9+

};

10+11+

type MockDockerChild = EventEmitter & {

12+

stdout: Readable;

13+

stderr: Readable;

14+

stdin: { end: (input?: string | Buffer) => void };

15+

kill: (signal?: NodeJS.Signals) => void;

16+

};

17+18+

const spawnState = vi.hoisted(() => ({

19+

calls: [] as SpawnCall[],

20+

imageExists: true,

21+

}));

22+23+

function createMockDockerChild(): MockDockerChild {

24+

const child = new EventEmitter() as MockDockerChild;

25+

child.stdout = new Readable({ read() {} });

26+

child.stderr = new Readable({ read() {} });

27+

child.stdin = { end: () => undefined };

28+

child.kill = () => undefined;

29+

return child;

30+

}

31+32+

function spawnDockerProcess(command: string, args: string[]) {

33+

spawnState.calls.push({ command, args });

34+

const child = createMockDockerChild();

35+36+

let code = 0;

37+

let stderr = "";

38+

if (command !== "docker") {

39+

code = 1;

40+

stderr = `unexpected command: ${command}`;

41+

} else if (args[0] === "image" && args[1] === "inspect") {

42+

code = spawnState.imageExists ? 0 : 1;

43+

stderr = spawnState.imageExists ? "" : `Error response from daemon: No such image: ${args[2]}`;

44+

} else if (args[0] === "pull" || args[0] === "tag") {

45+

code = 0;

46+

} else {

47+

code = 1;

48+

stderr = `unexpected docker args: ${args.join(" ")}`;

49+

}

50+51+

queueMicrotask(() => {

52+

if (stderr) {

53+

child.stderr.emit("data", Buffer.from(stderr));

54+

}

55+

child.emit("close", code);

56+

});

57+

return child;

58+

}

59+60+

async function createChildProcessMock() {

61+

const actual = await vi.importActual<typeof import("node:child_process")>("node:child_process");

62+

return {

63+

...actual,

64+

spawn: spawnDockerProcess,

65+

};

66+

}

67+68+

vi.mock("node:child_process", async () => createChildProcessMock());

69+70+

let ensureDockerImage: typeof import("./docker.js").ensureDockerImage;

71+72+

async function loadFreshDockerModuleForTest() {

73+

vi.resetModules();

74+

vi.doMock("node:child_process", async () => createChildProcessMock());

75+

({ ensureDockerImage } = await import("./docker.js"));

76+

}

77+78+

describe("ensureDockerImage", () => {

79+

beforeEach(async () => {

80+

spawnState.calls.length = 0;

81+

spawnState.imageExists = true;

82+

await loadFreshDockerModuleForTest();

83+

});

84+85+

it("returns when the configured image already exists", async () => {

86+

await ensureDockerImage(DEFAULT_SANDBOX_IMAGE);

87+88+

expect(spawnState.calls).toEqual([

89+

{

90+

command: "docker",

91+

args: ["image", "inspect", DEFAULT_SANDBOX_IMAGE],

92+

},

93+

]);

94+

});

95+96+

it("does not satisfy the missing default sandbox image by tagging plain Debian", async () => {

97+

spawnState.imageExists = false;

98+99+

let err: unknown;

100+

try {

101+

await ensureDockerImage(DEFAULT_SANDBOX_IMAGE);

102+

} catch (caught) {

103+

err = caught;

104+

}

105+106+

expect(err).toBeInstanceOf(Error);

107+

expect((err as Error).message).toContain("scripts/sandbox-setup.sh");

108+

expect((err as Error).message).toContain("python3");

109+

expect(spawnState.calls).toEqual([

110+

{

111+

command: "docker",

112+

args: ["image", "inspect", DEFAULT_SANDBOX_IMAGE],

113+

},

114+

]);

115+

});

116+

});