refactor(agent): dedupe harness and command workflows

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:09 +00:00
parent 04892ee230
commit f717a13039
204 changed files with 7366 additions and 11540 deletions

View File

@@ -2,42 +2,47 @@ import { describe, expect, it } from "vitest";
import type { SandboxContext } from "./sandbox.js";
import { buildEmbeddedSandboxInfo } from "./pi-embedded-runner.js";
function createSandboxContext(overrides?: Partial<SandboxContext>): SandboxContext {
const base = {
enabled: true,
sessionKey: "session:test",
workspaceDir: "/tmp/openclaw-sandbox",
agentWorkspaceDir: "/tmp/openclaw-workspace",
workspaceAccess: "none",
containerName: "openclaw-sbx-test",
containerWorkdir: "/workspace",
docker: {
image: "openclaw-sandbox:bookworm-slim",
containerPrefix: "openclaw-sbx-",
workdir: "/workspace",
readOnlyRoot: true,
tmpfs: ["/tmp"],
network: "none",
user: "1000:1000",
capDrop: ["ALL"],
env: { LANG: "C.UTF-8" },
},
tools: {
allow: ["exec"],
deny: ["browser"],
},
browserAllowHostControl: true,
browser: {
bridgeUrl: "http://localhost:9222",
noVncUrl: "http://localhost:6080",
containerName: "openclaw-sbx-browser-test",
},
} satisfies SandboxContext;
return { ...base, ...overrides };
}
describe("buildEmbeddedSandboxInfo", () => {
it("returns undefined when sandbox is missing", () => {
expect(buildEmbeddedSandboxInfo()).toBeUndefined();
});
it("maps sandbox context into prompt info", () => {
const sandbox = {
enabled: true,
sessionKey: "session:test",
workspaceDir: "/tmp/openclaw-sandbox",
agentWorkspaceDir: "/tmp/openclaw-workspace",
workspaceAccess: "none",
containerName: "openclaw-sbx-test",
containerWorkdir: "/workspace",
docker: {
image: "openclaw-sandbox:bookworm-slim",
containerPrefix: "openclaw-sbx-",
workdir: "/workspace",
readOnlyRoot: true,
tmpfs: ["/tmp"],
network: "none",
user: "1000:1000",
capDrop: ["ALL"],
env: { LANG: "C.UTF-8" },
},
tools: {
allow: ["exec"],
deny: ["browser"],
},
browserAllowHostControl: true,
browser: {
bridgeUrl: "http://localhost:9222",
noVncUrl: "http://localhost:6080",
containerName: "openclaw-sbx-browser-test",
},
} satisfies SandboxContext;
const sandbox = createSandboxContext();
expect(buildEmbeddedSandboxInfo(sandbox)).toEqual({
enabled: true,
@@ -52,31 +57,10 @@ describe("buildEmbeddedSandboxInfo", () => {
});
it("includes elevated info when allowed", () => {
const sandbox = {
enabled: true,
sessionKey: "session:test",
workspaceDir: "/tmp/openclaw-sandbox",
agentWorkspaceDir: "/tmp/openclaw-workspace",
workspaceAccess: "none",
containerName: "openclaw-sbx-test",
containerWorkdir: "/workspace",
docker: {
image: "openclaw-sandbox:bookworm-slim",
containerPrefix: "openclaw-sbx-",
workdir: "/workspace",
readOnlyRoot: true,
tmpfs: ["/tmp"],
network: "none",
user: "1000:1000",
capDrop: ["ALL"],
env: { LANG: "C.UTF-8" },
},
tools: {
allow: ["exec"],
deny: ["browser"],
},
const sandbox = createSandboxContext({
browserAllowHostControl: false,
} satisfies SandboxContext;
browser: undefined,
});
expect(
buildEmbeddedSandboxInfo(sandbox, {