docs: document sandbox runtime tests · openclaw/openclaw@3da0803
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies runtime plugin loading can reuse a compatible gateway startup registry. |
1 | 2 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 3 | import { createEmptyPluginRegistry } from "../plugins/registry-empty.js"; |
3 | 4 | import type { PluginRegistry } from "../plugins/registry-types.js"; |
@@ -27,6 +28,7 @@ const [{ ensureRuntimePluginsLoaded }, { clearPluginLoaderCache, testing }] = aw
|
27 | 28 | ]); |
28 | 29 | |
29 | 30 | function createRegistryWithPlugin(pluginId: string): PluginRegistry { |
| 31 | +// Minimal active registry carrying just enough plugin identity for reuse checks. |
30 | 32 | const registry = createEmptyPluginRegistry(); |
31 | 33 | registry.plugins.push({ |
32 | 34 | id: pluginId, |
@@ -47,6 +49,7 @@ afterEach(() => {
|
47 | 49 | |
48 | 50 | describe("ensureRuntimePluginsLoaded registry reuse", () => { |
49 | 51 | it("reuses the compatible gateway startup registry on the dispatch caller path", () => { |
| 52 | +// Matching cache key plus gateway-bindable mode means no second plugin load. |
50 | 53 | const config = { plugins: { allow: ["telegram"] } }; |
51 | 54 | const activeRegistry = createRegistryWithPlugin("telegram"); |
52 | 55 | activeRegistry.coreGatewayMethodNames = ["sessions.get", "sessions.list"]; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies runtime plugin loading scope, disablement, and gateway-bindable mode. |
1 | 2 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 3 | |
3 | 4 | const hoisted = vi.hoisted(() => ({ |
@@ -26,6 +27,7 @@ describe("ensureRuntimePluginsLoaded", () => {
|
26 | 27 | let ensureRuntimePluginsLoaded: typeof import("./runtime-plugins.js").ensureRuntimePluginsLoaded; |
27 | 28 | |
28 | 29 | beforeEach(async () => { |
| 30 | +// Reset modules so each case sees fresh mocked runtime-plugin dependencies. |
29 | 31 | hoisted.getCurrentPluginMetadataSnapshot.mockReset(); |
30 | 32 | hoisted.getCurrentPluginMetadataSnapshot.mockReturnValue(undefined); |
31 | 33 | hoisted.ensureStandaloneRuntimePluginRegistryLoaded.mockReset(); |
@@ -85,6 +87,7 @@ describe("ensureRuntimePluginsLoaded", () => {
|
85 | 87 | }); |
86 | 88 | |
87 | 89 | it("scopes runtime plugin loading to the current gateway startup plan", () => { |
| 90 | +// Startup metadata narrows runtime loading to plugins already planned for gateway startup. |
88 | 91 | const config = {} as never; |
89 | 92 | hoisted.getCurrentPluginMetadataSnapshot.mockReturnValue({ |
90 | 93 | startup: { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies agent-specific sandbox config, workspace roots, and Docker setup commands. |
1 | 2 | import { EventEmitter } from "node:events"; |
2 | 3 | import path from "node:path"; |
3 | 4 | import { Readable } from "node:stream"; |
@@ -14,6 +15,7 @@ const spawnCalls: SpawnCall[] = [];
|
14 | 15 | |
15 | 16 | vi.mock("node:child_process", () => ({ |
16 | 17 | execFile: (...args: unknown[]) => { |
| 18 | +// Docker availability probes should succeed without invoking real Docker. |
17 | 19 | const callback = args.findLast( |
18 | 20 | (arg): arg is (error: null, stdout: string, stderr: string) => void => |
19 | 21 | typeof arg === "function", |
@@ -55,6 +57,7 @@ let resolveSandboxConfigForAgent: typeof import("./sandbox/config.js").resolveSa
|
55 | 57 | let resolveSandboxRuntimeStatus: typeof import("./sandbox/runtime-status.js").resolveSandboxRuntimeStatus; |
56 | 58 | |
57 | 59 | async function resolveContext(config: OpenClawConfig, sessionKey: string, workspaceDir: string) { |
| 60 | +// Convenience wrapper keeps session-key specific sandbox context assertions compact. |
58 | 61 | return resolveSandboxContext({ |
59 | 62 | config, |
60 | 63 | sessionKey, |
@@ -63,6 +66,7 @@ async function resolveContext(config: OpenClawConfig, sessionKey: string, worksp
|
63 | 66 | } |
64 | 67 | |
65 | 68 | function expectDockerSetupCommand(command: string) { |
| 69 | +// Setup commands are executed through docker exec in the resolved container. |
66 | 70 | expect( |
67 | 71 | spawnCalls.some( |
68 | 72 | (call) => |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies Docker create arguments for sandbox hardening and configured passthrough. |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | import { OPENCLAW_CLI_ENV_VALUE } from "../infra/openclaw-exec-env.js"; |
3 | 4 | import { buildSandboxCreateArgs } from "./sandbox/docker.js"; |
@@ -8,6 +9,7 @@ describe("buildSandboxCreateArgs", () => {
|
8 | 9 | overrides: Partial<SandboxDockerConfig> = {}, |
9 | 10 | binds?: string[], |
10 | 11 | ): SandboxDockerConfig { |
| 12 | +// Baseline config keeps each Docker argument case focused on one override. |
11 | 13 | return { |
12 | 14 | image: "openclaw-sandbox:bookworm-slim", |
13 | 15 | containerPrefix: "openclaw-sbx-", |
@@ -39,6 +41,7 @@ describe("buildSandboxCreateArgs", () => {
|
39 | 41 | } |
40 | 42 | |
41 | 43 | function valuesForFlag(args: string[], flag: string): string[] { |
| 44 | +// Docker flags are positional, so collect repeated flag values for assertions. |
42 | 45 | const values: string[] = []; |
43 | 46 | for (let i = 0; i < args.length; i += 1) { |
44 | 47 | if (args[i] === flag) { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies sandbox tool-policy resolution and blocked-tool explanation text. |
1 | 2 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 3 | import type { OpenClawConfig } from "../config/config.js"; |
3 | 4 | import { resolveSandboxConfigForAgent } from "./sandbox/config.js"; |
@@ -10,6 +11,7 @@ const { toolPolicyAuditInfo } = vi.hoisted(() => ({
|
10 | 11 | |
11 | 12 | vi.mock("../logging/subsystem.js", () => ({ |
12 | 13 | createSubsystemLogger: () => ({ |
| 14 | +// Audit logging is asserted without touching the real subsystem logger. |
13 | 15 | info: toolPolicyAuditInfo, |
14 | 16 | }), |
15 | 17 | })); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies sandbox media paths resolve through bridge and workspace-only guards. |
1 | 2 | import { describe, expect, it, vi } from "vitest"; |
2 | 3 | import { |
3 | 4 | createSandboxBridgeReadFile, |
@@ -44,6 +45,7 @@ describe("createSandboxBridgeReadFile", () => {
|
44 | 45 | }); |
45 | 46 | |
46 | 47 | it("keeps workspace-only container paths under the sandbox workspace mount", async () => { |
| 48 | +// Container paths must stay inside the remote workspace mount when workspaceOnly is set. |
47 | 49 | const resolvePath = vi.fn(({ filePath }: { filePath: string }) => { |
48 | 50 | if (filePath === "/tmp/sandbox-root") { |
49 | 51 | return { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。