openclaw/src/agents/exec-defaults.test.ts
2026-04-08 04:39:27 +01:00

107 lines
2.3 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import type { SessionEntry } from "../config/sessions.js";
import * as execApprovals from "../infra/exec-approvals.js";
import { resolveExecDefaults } from "./exec-defaults.js";
describe("resolveExecDefaults", () => {
beforeEach(() => {
vi.restoreAllMocks();
vi.spyOn(execApprovals, "loadExecApprovals").mockReturnValue({
version: 1,
agents: {},
});
});
it("does not advertise node routing when exec host is pinned to gateway", () => {
expect(
resolveExecDefaults({
cfg: {
tools: {
exec: {
host: "gateway",
},
},
},
sandboxAvailable: false,
}).canRequestNode,
).toBe(false);
});
it("keeps node routing available when exec host is auto", () => {
expect(
resolveExecDefaults({
cfg: {
tools: {
exec: {
host: "auto",
},
},
},
sandboxAvailable: true,
}),
).toMatchObject({
host: "auto",
effectiveHost: "sandbox",
canRequestNode: true,
});
});
it("honors session-level exec host overrides", () => {
const sessionEntry = {
execHost: "node",
} as SessionEntry;
expect(
resolveExecDefaults({
cfg: {
tools: {
exec: {
host: "gateway",
},
},
},
sessionEntry,
sandboxAvailable: false,
}).canRequestNode,
).toBe(true);
});
it("uses host approval defaults for gateway when exec policy is unset", () => {
expect(
resolveExecDefaults({
cfg: {
tools: {
exec: {
host: "auto",
},
},
},
sandboxAvailable: false,
}),
).toMatchObject({
host: "auto",
effectiveHost: "gateway",
security: "full",
ask: "off",
});
});
it("keeps sandbox deny by default when auto resolves to sandbox", () => {
expect(
resolveExecDefaults({
cfg: {
tools: {
exec: {
host: "auto",
},
},
},
sandboxAvailable: true,
}),
).toMatchObject({
host: "auto",
effectiveHost: "sandbox",
security: "deny",
ask: "off",
});
});
});