mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:31:23 +00:00
fix: stabilize ci test typings and mocks
This commit is contained in:
@@ -3,10 +3,12 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|||||||
import { wrapToolWorkspaceRootGuardWithOptions } from "./pi-tools.read.js";
|
import { wrapToolWorkspaceRootGuardWithOptions } from "./pi-tools.read.js";
|
||||||
import type { AnyAgentTool } from "./pi-tools.types.js";
|
import type { AnyAgentTool } from "./pi-tools.types.js";
|
||||||
|
|
||||||
const assertSandboxPath = vi.fn(async () => ({ resolved: "/tmp/root", relative: "" }));
|
const mocks = vi.hoisted(() => ({
|
||||||
|
assertSandboxPath: vi.fn(async () => ({ resolved: "/tmp/root", relative: "" })),
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock("./sandbox-paths.js", () => ({
|
vi.mock("./sandbox-paths.js", () => ({
|
||||||
assertSandboxPath: (...args: unknown[]) => assertSandboxPath(...args),
|
assertSandboxPath: mocks.assertSandboxPath,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
function createToolHarness() {
|
function createToolHarness() {
|
||||||
@@ -26,7 +28,7 @@ describe("wrapToolWorkspaceRootGuardWithOptions", () => {
|
|||||||
const root = "/tmp/root";
|
const root = "/tmp/root";
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
assertSandboxPath.mockClear();
|
mocks.assertSandboxPath.mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("maps container workspace paths to host workspace root", async () => {
|
it("maps container workspace paths to host workspace root", async () => {
|
||||||
@@ -37,7 +39,7 @@ describe("wrapToolWorkspaceRootGuardWithOptions", () => {
|
|||||||
|
|
||||||
await wrapped.execute("tc1", { path: "/workspace/docs/readme.md" });
|
await wrapped.execute("tc1", { path: "/workspace/docs/readme.md" });
|
||||||
|
|
||||||
expect(assertSandboxPath).toHaveBeenCalledWith({
|
expect(mocks.assertSandboxPath).toHaveBeenCalledWith({
|
||||||
filePath: path.resolve(root, "docs", "readme.md"),
|
filePath: path.resolve(root, "docs", "readme.md"),
|
||||||
cwd: root,
|
cwd: root,
|
||||||
root,
|
root,
|
||||||
@@ -52,7 +54,7 @@ describe("wrapToolWorkspaceRootGuardWithOptions", () => {
|
|||||||
|
|
||||||
await wrapped.execute("tc2", { path: "file:///workspace/docs/readme.md" });
|
await wrapped.execute("tc2", { path: "file:///workspace/docs/readme.md" });
|
||||||
|
|
||||||
expect(assertSandboxPath).toHaveBeenCalledWith({
|
expect(mocks.assertSandboxPath).toHaveBeenCalledWith({
|
||||||
filePath: path.resolve(root, "docs", "readme.md"),
|
filePath: path.resolve(root, "docs", "readme.md"),
|
||||||
cwd: root,
|
cwd: root,
|
||||||
root,
|
root,
|
||||||
@@ -67,7 +69,7 @@ describe("wrapToolWorkspaceRootGuardWithOptions", () => {
|
|||||||
|
|
||||||
await wrapped.execute("tc3", { path: "/workspace-two/secret.txt" });
|
await wrapped.execute("tc3", { path: "/workspace-two/secret.txt" });
|
||||||
|
|
||||||
expect(assertSandboxPath).toHaveBeenCalledWith({
|
expect(mocks.assertSandboxPath).toHaveBeenCalledWith({
|
||||||
filePath: "/workspace-two/secret.txt",
|
filePath: "/workspace-two/secret.txt",
|
||||||
cwd: root,
|
cwd: root,
|
||||||
root,
|
root,
|
||||||
|
|||||||
@@ -8,17 +8,16 @@ const mocks = vi.hoisted(() => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../../channels/plugins/message-actions.js", () => ({
|
vi.mock("../../channels/plugins/message-actions.js", () => ({
|
||||||
dispatchChannelMessageAction: (...args: unknown[]) => mocks.dispatchChannelMessageAction(...args),
|
dispatchChannelMessageAction: mocks.dispatchChannelMessageAction,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("./message.js", () => ({
|
vi.mock("./message.js", () => ({
|
||||||
sendMessage: (...args: unknown[]) => mocks.sendMessage(...args),
|
sendMessage: mocks.sendMessage,
|
||||||
sendPoll: (...args: unknown[]) => mocks.sendPoll(...args),
|
sendPoll: mocks.sendPoll,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../../media/local-roots.js", () => ({
|
vi.mock("../../media/local-roots.js", () => ({
|
||||||
getAgentScopedMediaLocalRoots: (...args: unknown[]) =>
|
getAgentScopedMediaLocalRoots: mocks.getAgentScopedMediaLocalRoots,
|
||||||
mocks.getAgentScopedMediaLocalRoots(...args),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import { executePollAction, executeSendAction } from "./outbound-send-service.js";
|
import { executePollAction, executeSendAction } from "./outbound-send-service.js";
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ describe("handleSystemRunInvoke mac app exec host routing", () => {
|
|||||||
stdout: "app-ok",
|
stdout: "app-ok",
|
||||||
stderr: "",
|
stderr: "",
|
||||||
timedOut: false,
|
timedOut: false,
|
||||||
truncated: false,
|
|
||||||
exitCode: 0,
|
exitCode: 0,
|
||||||
error: null,
|
error: null,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user