mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
Fix Biome and Stylelint formatting so pnpm lint passes.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -284,6 +284,9 @@ describe("handleEvaluate", () => {
|
||||
{ session_id: "aa11", expression: "1+1", tab_id: 11 },
|
||||
{ cdp: fake.cdp, tabsApi: fake.tabsApi },
|
||||
);
|
||||
expect(res).toMatchObject({ code: "permission_denied", data: { reason: "agent_window_scope" } });
|
||||
expect(res).toMatchObject({
|
||||
code: "permission_denied",
|
||||
data: { reason: "agent_window_scope" },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,13 +36,21 @@ function baseDeps(over: Partial<RequestHelpDeps> = {}): RequestHelpDeps {
|
||||
|
||||
describe("handleRequestHelp", () => {
|
||||
it("rejects unknown session", async () => {
|
||||
const res = await handleRequestHelp(fakeManager("abcd", 99, 5), baseParams({ session_id: "zzzz" }), baseDeps());
|
||||
const res = await handleRequestHelp(
|
||||
fakeManager("abcd", 99, 5),
|
||||
baseParams({ session_id: "zzzz" }),
|
||||
baseDeps(),
|
||||
);
|
||||
expect("code" in res && res.code).toBe("not_found");
|
||||
});
|
||||
|
||||
it("brings the tab to the foreground and returns the user outcome", async () => {
|
||||
const deps = baseDeps();
|
||||
const res = await handleRequestHelp(fakeManager("abcd", 99, 5), baseParams({ tab_id: 5 }), deps);
|
||||
const res = await handleRequestHelp(
|
||||
fakeManager("abcd", 99, 5),
|
||||
baseParams({ tab_id: 5 }),
|
||||
deps,
|
||||
);
|
||||
expect(deps.windows.update).toHaveBeenCalledWith(99, { focused: true });
|
||||
expect(deps.activateTab).toHaveBeenCalledWith(5);
|
||||
expect(res).toMatchObject({ outcome: "continued", note: "ok", tab_id: 5 });
|
||||
@@ -79,7 +87,11 @@ describe("handleRequestHelp", () => {
|
||||
return unwatch;
|
||||
}),
|
||||
});
|
||||
const res = await handleRequestHelp(fakeManager("abcd", 99, 5), baseParams({ tab_id: 5 }), deps);
|
||||
const res = await handleRequestHelp(
|
||||
fakeManager("abcd", 99, 5),
|
||||
baseParams({ tab_id: 5 }),
|
||||
deps,
|
||||
);
|
||||
expect(res).toMatchObject({ outcome: "navigated", tab_id: 5 });
|
||||
expect(unwatch).toHaveBeenCalled();
|
||||
});
|
||||
@@ -107,12 +119,19 @@ describe("handleRequestHelp", () => {
|
||||
const mgr = {
|
||||
get: (id: string) =>
|
||||
id === "abcd"
|
||||
? { sessionId: "abcd", agentWindowId: 99, refStore: { resolve: () => 42 }, borrowedTabs: new Map() }
|
||||
? {
|
||||
sessionId: "abcd",
|
||||
agentWindowId: 99,
|
||||
refStore: { resolve: () => 42 },
|
||||
borrowedTabs: new Map(),
|
||||
}
|
||||
: null,
|
||||
findByWindowId: (wid: number) => (wid === 99 ? { sessionId: "abcd" } : null),
|
||||
} as unknown as SessionManager;
|
||||
const deps = baseDeps({
|
||||
cdp: { send: vi.fn(async () => ({ object: { objectId: "obj-1" } })) } as unknown as RequestHelpDeps["cdp"],
|
||||
cdp: {
|
||||
send: vi.fn(async () => ({ object: { objectId: "obj-1" } })),
|
||||
} as unknown as RequestHelpDeps["cdp"],
|
||||
});
|
||||
const res = await handleRequestHelp(
|
||||
mgr,
|
||||
@@ -177,7 +196,11 @@ describe("handleRequestHelp", () => {
|
||||
throw new Error("no receiver");
|
||||
}),
|
||||
});
|
||||
const res = await handleRequestHelp(fakeManager("abcd", 99, 5), baseParams({ tab_id: 5 }), deps);
|
||||
const res = await handleRequestHelp(
|
||||
fakeManager("abcd", 99, 5),
|
||||
baseParams({ tab_id: 5 }),
|
||||
deps,
|
||||
);
|
||||
expect("code" in res && res.code).toBe("protocol_error");
|
||||
});
|
||||
|
||||
@@ -254,7 +277,11 @@ describe("handleRequestHelp", () => {
|
||||
it("returns cancelled when the signal aborts", async () => {
|
||||
const ac = new AbortController();
|
||||
const deps = baseDeps({ signal: ac.signal, sendToTab: vi.fn(() => new Promise(() => {})) });
|
||||
const p = handleRequestHelp(fakeManager("abcd", 99, 5), baseParams({ tab_id: 5, timeout_ms: 60_000 }), deps);
|
||||
const p = handleRequestHelp(
|
||||
fakeManager("abcd", 99, 5),
|
||||
baseParams({ tab_id: 5, timeout_ms: 60_000 }),
|
||||
deps,
|
||||
);
|
||||
ac.abort();
|
||||
const res = await p;
|
||||
expect("code" in res ? res.code : (res as { outcome: string }).outcome).toMatch(/cancelled/);
|
||||
|
||||
@@ -982,4 +982,3 @@ describe("handleSelect", () => {
|
||||
expect(fake.sent.some((c) => c.method === "Runtime.callFunctionOn")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { SessionManager } from "@/session-manager/manager";
|
||||
import type { CdpRunner } from "@/tools/shared";
|
||||
import {
|
||||
eventLoaderIsRelevant,
|
||||
handleNavigate,
|
||||
handleNavigateBack,
|
||||
handleNavigateForward,
|
||||
handleReload,
|
||||
lifecycleAlreadyReached,
|
||||
eventLoaderIsRelevant,
|
||||
lifecycleMeetsOrExceeds,
|
||||
shouldTrustReadyStateProbe,
|
||||
} from "../navigation";
|
||||
@@ -60,10 +60,7 @@ function makeFakeCdp(opts?: {
|
||||
};
|
||||
const events: EventListener[] = [];
|
||||
const sent: Array<{ tabId: number; method: string; params?: object }> = [];
|
||||
const methodHandlers: Record<
|
||||
string,
|
||||
(tabId: number, params?: object) => object
|
||||
> = {
|
||||
const methodHandlers: Record<string, (tabId: number, params?: object) => object> = {
|
||||
"Page.enable": () => ({}),
|
||||
"Page.setLifecycleEventsEnabled": () => ({}),
|
||||
"Page.navigate": () => {
|
||||
@@ -72,9 +69,7 @@ function makeFakeCdp(opts?: {
|
||||
name: opts.fireLifecycleDuringNavigate,
|
||||
frameId: opts.fireLifecycleDuringNavigateFrameId ?? opts.navigateFrameId ?? "frame-1",
|
||||
loaderId:
|
||||
opts.fireLifecycleDuringNavigateLoaderId ??
|
||||
opts.navigateLoaderId ??
|
||||
"loader-after",
|
||||
opts.fireLifecycleDuringNavigateLoaderId ?? opts.navigateLoaderId ?? "loader-after",
|
||||
};
|
||||
for (const listener of [...events]) {
|
||||
listener({ tabId: 4 }, "Page.lifecycleEvent", payload);
|
||||
@@ -208,9 +203,7 @@ describe("lifecycleMeetsOrExceeds", () => {
|
||||
|
||||
describe("eventLoaderIsRelevant", () => {
|
||||
it("rejects events from the pre-navigation loader", () => {
|
||||
expect(
|
||||
eventLoaderIsRelevant("loader-before", { beforeLoaderId: "loader-before" }),
|
||||
).toBe(false);
|
||||
expect(eventLoaderIsRelevant("loader-before", { beforeLoaderId: "loader-before" })).toBe(false);
|
||||
expect(
|
||||
eventLoaderIsRelevant("loader-after", {
|
||||
beforeLoaderId: "loader-before",
|
||||
|
||||
@@ -42,8 +42,7 @@ function makeScreenshotDeps(
|
||||
opts.get ??
|
||||
vi.fn(async (tabId: number) => ({ id: tabId, windowId: 100, active: true }) as chrome.tabs.Tab);
|
||||
const query =
|
||||
opts.query ??
|
||||
vi.fn(async () => [{ id: 7, windowId: 100, active: true } as chrome.tabs.Tab]);
|
||||
opts.query ?? vi.fn(async () => [{ id: 7, windowId: 100, active: true } as chrome.tabs.Tab]);
|
||||
const captureVisibleTab =
|
||||
opts.captureVisibleTab ?? vi.fn(async () => `data:image/png;base64,${TINY_PNG}`);
|
||||
const tabsApi = { get, query };
|
||||
@@ -118,7 +117,11 @@ describe("handleScreenshot", () => {
|
||||
const res = await handleScreenshot(
|
||||
sm,
|
||||
{ session_id: "aa11" },
|
||||
makeScreenshotDeps({ captureVisibleTab: vi.fn(), get: emptyGet, query: vi.fn(async () => []) }),
|
||||
makeScreenshotDeps({
|
||||
captureVisibleTab: vi.fn(),
|
||||
get: emptyGet,
|
||||
query: vi.fn(async () => []),
|
||||
}),
|
||||
);
|
||||
expect(res).toMatchObject({ code: "not_found" });
|
||||
});
|
||||
|
||||
@@ -139,9 +139,13 @@ describe("handleSessionStop with auto-return", () => {
|
||||
resetAgentOverlays: vi.fn(async () => {}),
|
||||
} satisfies AgentOverlayResetApi;
|
||||
|
||||
const res = await handleSessionStop(sm, { session_id: "aa11" }, {
|
||||
tabManagement: { tabs, windows, agentOverlayReset },
|
||||
});
|
||||
const res = await handleSessionStop(
|
||||
sm,
|
||||
{ session_id: "aa11" },
|
||||
{
|
||||
tabManagement: { tabs, windows, agentOverlayReset },
|
||||
},
|
||||
);
|
||||
|
||||
if ("code" in res) throw new Error(`unexpected error: ${JSON.stringify(res)}`);
|
||||
expect(agentOverlayReset.resetAgentOverlays).toHaveBeenCalledWith(7, "aa11");
|
||||
|
||||
@@ -20,9 +20,7 @@ describe("lookupSession", () => {
|
||||
expect(lookupSession(sm, { session_id: "" }, "tool.test")).toMatchObject({
|
||||
code: "invalid_params",
|
||||
});
|
||||
expect(
|
||||
lookupSession(sm, { session_id: 42 as unknown as string }, "tool.test"),
|
||||
).toMatchObject({
|
||||
expect(lookupSession(sm, { session_id: 42 as unknown as string }, "tool.test")).toMatchObject({
|
||||
code: "invalid_params",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -292,7 +292,10 @@ describe("handleTabClose", () => {
|
||||
};
|
||||
const { api } = makeTabMutationApi(state);
|
||||
const res = await handleTabClose(sm, { session_id: "aa11", tab_id: 9 }, { tabs: api });
|
||||
expect(res).toMatchObject({ code: "permission_denied", data: { reason: "agent_window_scope" } });
|
||||
expect(res).toMatchObject({
|
||||
code: "permission_denied",
|
||||
data: { reason: "agent_window_scope" },
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects when another session has borrowed the tab", async () => {
|
||||
@@ -338,7 +341,10 @@ describe("handleTabSelect", () => {
|
||||
};
|
||||
const { api } = makeTabMutationApi(state);
|
||||
const res = await handleTabSelect(sm, { session_id: "aa11", tab_id: 3 }, { tabs: api });
|
||||
expect(res).toMatchObject({ code: "permission_denied", data: { reason: "agent_window_scope" } });
|
||||
expect(res).toMatchObject({
|
||||
code: "permission_denied",
|
||||
data: { reason: "agent_window_scope" },
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a borrowed tab that is no longer in the Agent Window", async () => {
|
||||
@@ -352,7 +358,10 @@ describe("handleTabSelect", () => {
|
||||
};
|
||||
const { api } = makeTabMutationApi(state);
|
||||
const res = await handleTabSelect(sm, { session_id: "aa11", tab_id: 3 }, { tabs: api });
|
||||
expect(res).toMatchObject({ code: "permission_denied", data: { reason: "agent_window_scope" } });
|
||||
expect(res).toMatchObject({
|
||||
code: "permission_denied",
|
||||
data: { reason: "agent_window_scope" },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -444,7 +453,10 @@ describe("handleTabBorrow", () => {
|
||||
};
|
||||
const { api } = makeTabMutationApi(state);
|
||||
const res = await handleTabBorrow(sm, { session_id: "aa11", tab_id: 7 }, { tabs: api });
|
||||
expect(res).toMatchObject({ code: "permission_denied", data: { reason: "agent_window_scope" } });
|
||||
expect(res).toMatchObject({
|
||||
code: "permission_denied",
|
||||
data: { reason: "agent_window_scope" },
|
||||
});
|
||||
});
|
||||
|
||||
it("returns cancelled when the approver declines", async () => {
|
||||
|
||||
Reference in New Issue
Block a user