mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-02 04:41:11 +00:00
test: continue vitest threads migration
This commit is contained in:
@@ -7,13 +7,17 @@ import { captureEnv } from "../test-utils/env.js";
|
||||
import { sanitizeBinaryOutput } from "./shell-utils.js";
|
||||
|
||||
const isWin = process.platform === "win32";
|
||||
const shellEnvMocks = vi.hoisted(() => ({
|
||||
getShellPathFromLoginShell: vi.fn(() => "/custom/bin:/opt/bin"),
|
||||
resolveShellEnvFallbackTimeoutMs: vi.fn(() => 1234),
|
||||
}));
|
||||
|
||||
vi.mock("../infra/shell-env.js", async (importOriginal) => {
|
||||
const mod = await importOriginal<typeof import("../infra/shell-env.js")>();
|
||||
return {
|
||||
...mod,
|
||||
getShellPathFromLoginShell: vi.fn(() => "/custom/bin:/opt/bin"),
|
||||
resolveShellEnvFallbackTimeoutMs: vi.fn(() => 1234),
|
||||
getShellPathFromLoginShell: shellEnvMocks.getShellPathFromLoginShell,
|
||||
resolveShellEnvFallbackTimeoutMs: shellEnvMocks.resolveShellEnvFallbackTimeoutMs,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -51,8 +55,56 @@ vi.mock("../infra/exec-approvals.js", async (importOriginal) => {
|
||||
return { ...mod, resolveExecApprovals: () => approvals };
|
||||
});
|
||||
|
||||
const { createExecTool } = await import("./bash-tools.exec.js");
|
||||
const { getShellPathFromLoginShell } = await import("../infra/shell-env.js");
|
||||
let createExecTool: typeof import("./bash-tools.exec.js").createExecTool;
|
||||
|
||||
async function loadFreshBashExecPathModulesForTest() {
|
||||
vi.resetModules();
|
||||
vi.doMock("../infra/shell-env.js", async (importOriginal) => {
|
||||
const mod = await importOriginal<typeof import("../infra/shell-env.js")>();
|
||||
return {
|
||||
...mod,
|
||||
getShellPathFromLoginShell: shellEnvMocks.getShellPathFromLoginShell,
|
||||
resolveShellEnvFallbackTimeoutMs: shellEnvMocks.resolveShellEnvFallbackTimeoutMs,
|
||||
};
|
||||
});
|
||||
vi.doMock("../infra/exec-approvals.js", async (importOriginal) => {
|
||||
const mod = await importOriginal<typeof import("../infra/exec-approvals.js")>();
|
||||
const approvals: ExecApprovalsResolved = {
|
||||
path: "/tmp/exec-approvals.json",
|
||||
socketPath: "/tmp/exec-approvals.sock",
|
||||
token: "token",
|
||||
defaults: {
|
||||
security: "full",
|
||||
ask: "off",
|
||||
askFallback: "full",
|
||||
autoAllowSkills: false,
|
||||
},
|
||||
agent: {
|
||||
security: "full",
|
||||
ask: "off",
|
||||
askFallback: "full",
|
||||
autoAllowSkills: false,
|
||||
},
|
||||
allowlist: [],
|
||||
file: {
|
||||
version: 1,
|
||||
socket: { path: "/tmp/exec-approvals.sock", token: "token" },
|
||||
defaults: {
|
||||
security: "full",
|
||||
ask: "off",
|
||||
askFallback: "full",
|
||||
autoAllowSkills: false,
|
||||
},
|
||||
agents: {},
|
||||
},
|
||||
};
|
||||
return { ...mod, resolveExecApprovals: () => approvals };
|
||||
});
|
||||
const bashExec = await import("./bash-tools.exec.js");
|
||||
return {
|
||||
createExecTool: bashExec.createExecTool,
|
||||
};
|
||||
}
|
||||
|
||||
const normalizeText = (value?: string) =>
|
||||
sanitizeBinaryOutput(value ?? "")
|
||||
@@ -69,8 +121,13 @@ const normalizePathEntries = (value?: string) =>
|
||||
describe("exec PATH login shell merge", () => {
|
||||
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
envSnapshot = captureEnv(["PATH", "SHELL"]);
|
||||
shellEnvMocks.getShellPathFromLoginShell.mockReset();
|
||||
shellEnvMocks.getShellPathFromLoginShell.mockReturnValue("/custom/bin:/opt/bin");
|
||||
shellEnvMocks.resolveShellEnvFallbackTimeoutMs.mockReset();
|
||||
shellEnvMocks.resolveShellEnvFallbackTimeoutMs.mockReturnValue(1234);
|
||||
({ createExecTool } = await loadFreshBashExecPathModulesForTest());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -83,7 +140,7 @@ describe("exec PATH login shell merge", () => {
|
||||
}
|
||||
process.env.PATH = "/usr/bin";
|
||||
|
||||
const shellPathMock = vi.mocked(getShellPathFromLoginShell);
|
||||
const shellPathMock = shellEnvMocks.getShellPathFromLoginShell;
|
||||
shellPathMock.mockClear();
|
||||
shellPathMock.mockReturnValue("/custom/bin:/opt/bin");
|
||||
|
||||
@@ -115,7 +172,7 @@ describe("exec PATH login shell merge", () => {
|
||||
}
|
||||
process.env.PATH = "/usr/bin";
|
||||
|
||||
const shellPathMock = vi.mocked(getShellPathFromLoginShell);
|
||||
const shellPathMock = shellEnvMocks.getShellPathFromLoginShell;
|
||||
shellPathMock.mockClear();
|
||||
|
||||
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
|
||||
@@ -160,7 +217,7 @@ describe("exec PATH login shell merge", () => {
|
||||
process.env.SHELL = unregisteredShellPath;
|
||||
|
||||
try {
|
||||
const shellPathMock = vi.mocked(getShellPathFromLoginShell);
|
||||
const shellPathMock = shellEnvMocks.getShellPathFromLoginShell;
|
||||
shellPathMock.mockClear();
|
||||
shellPathMock.mockImplementation((opts) =>
|
||||
opts.env.SHELL?.trim() === unregisteredShellPath ? null : "/custom/bin:/opt/bin",
|
||||
|
||||
Reference in New Issue
Block a user