mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 20:08:26 +00:00
chore: Fix types in tests 5/N.
This commit is contained in:
@@ -1,27 +1,31 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const browserClientMocks = vi.hoisted(() => ({
|
||||
browserCloseTab: vi.fn(async () => ({})),
|
||||
browserFocusTab: vi.fn(async () => ({})),
|
||||
browserOpenTab: vi.fn(async () => ({})),
|
||||
browserProfiles: vi.fn(async () => []),
|
||||
browserSnapshot: vi.fn(async () => ({
|
||||
ok: true,
|
||||
format: "ai",
|
||||
targetId: "t1",
|
||||
url: "https://example.com",
|
||||
snapshot: "ok",
|
||||
})),
|
||||
browserStart: vi.fn(async () => ({})),
|
||||
browserStatus: vi.fn(async () => ({
|
||||
browserCloseTab: vi.fn(async (..._args: unknown[]) => ({})),
|
||||
browserFocusTab: vi.fn(async (..._args: unknown[]) => ({})),
|
||||
browserOpenTab: vi.fn(async (..._args: unknown[]) => ({})),
|
||||
browserProfiles: vi.fn(
|
||||
async (..._args: unknown[]): Promise<Array<Record<string, unknown>>> => [],
|
||||
),
|
||||
browserSnapshot: vi.fn(
|
||||
async (..._args: unknown[]): Promise<Record<string, unknown>> => ({
|
||||
ok: true,
|
||||
format: "ai",
|
||||
targetId: "t1",
|
||||
url: "https://example.com",
|
||||
snapshot: "ok",
|
||||
}),
|
||||
),
|
||||
browserStart: vi.fn(async (..._args: unknown[]) => ({})),
|
||||
browserStatus: vi.fn(async (..._args: unknown[]) => ({
|
||||
ok: true,
|
||||
running: true,
|
||||
pid: 1,
|
||||
cdpPort: 18792,
|
||||
cdpUrl: "http://127.0.0.1:18792",
|
||||
})),
|
||||
browserStop: vi.fn(async () => ({})),
|
||||
browserTabs: vi.fn(async () => []),
|
||||
browserStop: vi.fn(async (..._args: unknown[]) => ({})),
|
||||
browserTabs: vi.fn(async (..._args: unknown[]): Promise<Array<Record<string, unknown>>> => []),
|
||||
}));
|
||||
vi.mock("../../browser/client.js", () => browserClientMocks);
|
||||
|
||||
@@ -55,7 +59,7 @@ const browserConfigMocks = vi.hoisted(() => ({
|
||||
vi.mock("../../browser/config.js", () => browserConfigMocks);
|
||||
|
||||
const nodesUtilsMocks = vi.hoisted(() => ({
|
||||
listNodes: vi.fn(async () => []),
|
||||
listNodes: vi.fn(async (..._args: unknown[]): Promise<Array<Record<string, unknown>>> => []),
|
||||
}));
|
||||
vi.mock("./nodes-utils.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./nodes-utils.js")>("./nodes-utils.js");
|
||||
@@ -101,7 +105,7 @@ describe("browser tool snapshot maxChars", () => {
|
||||
|
||||
it("applies the default ai snapshot limit", async () => {
|
||||
const tool = createBrowserTool();
|
||||
await tool.execute?.(null, { action: "snapshot", snapshotFormat: "ai" });
|
||||
await tool.execute?.("call-1", { action: "snapshot", snapshotFormat: "ai" });
|
||||
|
||||
expect(browserClientMocks.browserSnapshot).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
@@ -115,7 +119,7 @@ describe("browser tool snapshot maxChars", () => {
|
||||
it("respects an explicit maxChars override", async () => {
|
||||
const tool = createBrowserTool();
|
||||
const override = 2_000;
|
||||
await tool.execute?.(null, {
|
||||
await tool.execute?.("call-1", {
|
||||
action: "snapshot",
|
||||
snapshotFormat: "ai",
|
||||
maxChars: override,
|
||||
@@ -131,27 +135,29 @@ describe("browser tool snapshot maxChars", () => {
|
||||
|
||||
it("skips the default when maxChars is explicitly zero", async () => {
|
||||
const tool = createBrowserTool();
|
||||
await tool.execute?.(null, {
|
||||
await tool.execute?.("call-1", {
|
||||
action: "snapshot",
|
||||
snapshotFormat: "ai",
|
||||
maxChars: 0,
|
||||
});
|
||||
|
||||
expect(browserClientMocks.browserSnapshot).toHaveBeenCalled();
|
||||
const [, opts] = browserClientMocks.browserSnapshot.mock.calls.at(-1) ?? [];
|
||||
const opts = browserClientMocks.browserSnapshot.mock.calls.at(-1)?.[1] as
|
||||
| { maxChars?: number }
|
||||
| undefined;
|
||||
expect(Object.hasOwn(opts ?? {}, "maxChars")).toBe(false);
|
||||
});
|
||||
|
||||
it("lists profiles", async () => {
|
||||
const tool = createBrowserTool();
|
||||
await tool.execute?.(null, { action: "profiles" });
|
||||
await tool.execute?.("call-1", { action: "profiles" });
|
||||
|
||||
expect(browserClientMocks.browserProfiles).toHaveBeenCalledWith(undefined);
|
||||
});
|
||||
|
||||
it("passes refs mode through to browser snapshot", async () => {
|
||||
const tool = createBrowserTool();
|
||||
await tool.execute?.(null, { action: "snapshot", snapshotFormat: "ai", refs: "aria" });
|
||||
await tool.execute?.("call-1", { action: "snapshot", snapshotFormat: "ai", refs: "aria" });
|
||||
|
||||
expect(browserClientMocks.browserSnapshot).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
@@ -167,7 +173,7 @@ describe("browser tool snapshot maxChars", () => {
|
||||
browser: { snapshotDefaults: { mode: "efficient" } },
|
||||
});
|
||||
const tool = createBrowserTool();
|
||||
await tool.execute?.(null, { action: "snapshot", snapshotFormat: "ai" });
|
||||
await tool.execute?.("call-1", { action: "snapshot", snapshotFormat: "ai" });
|
||||
|
||||
expect(browserClientMocks.browserSnapshot).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
@@ -182,16 +188,18 @@ describe("browser tool snapshot maxChars", () => {
|
||||
browser: { snapshotDefaults: { mode: "efficient" } },
|
||||
});
|
||||
const tool = createBrowserTool();
|
||||
await tool.execute?.(null, { action: "snapshot", snapshotFormat: "aria" });
|
||||
await tool.execute?.("call-1", { action: "snapshot", snapshotFormat: "aria" });
|
||||
|
||||
expect(browserClientMocks.browserSnapshot).toHaveBeenCalled();
|
||||
const [, opts] = browserClientMocks.browserSnapshot.mock.calls.at(-1) ?? [];
|
||||
const opts = browserClientMocks.browserSnapshot.mock.calls.at(-1)?.[1] as
|
||||
| { mode?: string }
|
||||
| undefined;
|
||||
expect(opts?.mode).toBeUndefined();
|
||||
});
|
||||
|
||||
it("defaults to host when using profile=chrome (even in sandboxed sessions)", async () => {
|
||||
const tool = createBrowserTool({ sandboxBridgeUrl: "http://127.0.0.1:9999" });
|
||||
await tool.execute?.(null, { action: "snapshot", profile: "chrome", snapshotFormat: "ai" });
|
||||
await tool.execute?.("call-1", { action: "snapshot", profile: "chrome", snapshotFormat: "ai" });
|
||||
|
||||
expect(browserClientMocks.browserSnapshot).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
@@ -212,7 +220,7 @@ describe("browser tool snapshot maxChars", () => {
|
||||
},
|
||||
]);
|
||||
const tool = createBrowserTool();
|
||||
await tool.execute?.(null, { action: "status", target: "node" });
|
||||
await tool.execute?.("call-1", { action: "status", target: "node" });
|
||||
|
||||
expect(gatewayMocks.callGatewayTool).toHaveBeenCalledWith(
|
||||
"node.invoke",
|
||||
@@ -236,7 +244,7 @@ describe("browser tool snapshot maxChars", () => {
|
||||
},
|
||||
]);
|
||||
const tool = createBrowserTool({ sandboxBridgeUrl: "http://127.0.0.1:9999" });
|
||||
await tool.execute?.(null, { action: "status" });
|
||||
await tool.execute?.("call-1", { action: "status" });
|
||||
|
||||
expect(browserClientMocks.browserStatus).toHaveBeenCalledWith(
|
||||
"http://127.0.0.1:9999",
|
||||
@@ -256,7 +264,7 @@ describe("browser tool snapshot maxChars", () => {
|
||||
},
|
||||
]);
|
||||
const tool = createBrowserTool();
|
||||
await tool.execute?.(null, { action: "status", profile: "chrome" });
|
||||
await tool.execute?.("call-1", { action: "status", profile: "chrome" });
|
||||
|
||||
expect(browserClientMocks.browserStatus).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
@@ -292,7 +300,7 @@ describe("browser tool snapshot labels", () => {
|
||||
imagePath: "/tmp/snap.png",
|
||||
});
|
||||
|
||||
const result = await tool.execute?.(null, {
|
||||
const result = await tool.execute?.("call-1", {
|
||||
action: "snapshot",
|
||||
snapshotFormat: "ai",
|
||||
labels: true,
|
||||
@@ -335,7 +343,7 @@ describe("browser tool external content wrapping", () => {
|
||||
});
|
||||
|
||||
const tool = createBrowserTool();
|
||||
const result = await tool.execute?.(null, { action: "snapshot", snapshotFormat: "aria" });
|
||||
const result = await tool.execute?.("call-1", { action: "snapshot", snapshotFormat: "aria" });
|
||||
expect(result?.content?.[0]).toMatchObject({
|
||||
type: "text",
|
||||
text: expect.stringContaining("<<<EXTERNAL_UNTRUSTED_CONTENT>>>"),
|
||||
@@ -369,7 +377,7 @@ describe("browser tool external content wrapping", () => {
|
||||
]);
|
||||
|
||||
const tool = createBrowserTool();
|
||||
const result = await tool.execute?.(null, { action: "tabs" });
|
||||
const result = await tool.execute?.("call-1", { action: "tabs" });
|
||||
expect(result?.content?.[0]).toMatchObject({
|
||||
type: "text",
|
||||
text: expect.stringContaining("<<<EXTERNAL_UNTRUSTED_CONTENT>>>"),
|
||||
@@ -402,7 +410,7 @@ describe("browser tool external content wrapping", () => {
|
||||
});
|
||||
|
||||
const tool = createBrowserTool();
|
||||
const result = await tool.execute?.(null, { action: "console" });
|
||||
const result = await tool.execute?.("call-1", { action: "console" });
|
||||
expect(result?.content?.[0]).toMatchObject({
|
||||
type: "text",
|
||||
text: expect.stringContaining("<<<EXTERNAL_UNTRUSTED_CONTENT>>>"),
|
||||
|
||||
Reference in New Issue
Block a user