Fix Biome and Stylelint formatting so pnpm lint passes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
BB-fat
2026-07-10 00:21:19 +08:00
co-authored by Cursor
parent d395faa0ab
commit 3c936982a3
29 changed files with 167 additions and 143 deletions
@@ -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 () => {
+1 -1
View File
@@ -18,6 +18,7 @@
import { ChromiumCdp } from "@/browser-driver/chromium-cdp";
import type { SessionManager } from "@/session-manager/manager";
import type { EvaluateError, EvaluateParams, EvaluateResult, RpcError } from "@/transport/types";
import { attachDialogs, markDialogCursor } from "./dialogs";
import {
type CdpRunner,
type ChromeTabsApi,
@@ -27,7 +28,6 @@ import {
lookupSession,
resolveTargetTab,
} from "./shared";
import { attachDialogs, markDialogCursor } from "./dialogs";
export interface EvaluateDeps {
cdp: CdpRunner;
+11 -9
View File
@@ -6,7 +6,6 @@
// until the user clicks Continue / Cancel, the wait times out, or the
// daemon cancels the RPC.
import type { SessionManager } from "@/session-manager/manager";
import {
HELP_CANCEL,
HELP_REQUEST,
@@ -15,6 +14,7 @@ import {
type HelpRequestMessage,
type HelpResponseMessage,
} from "@/lib/help-bridge";
import type { SessionManager } from "@/session-manager/manager";
import type {
HelpTarget,
RequestHelpParams,
@@ -22,7 +22,6 @@ import type {
ResolvedTarget,
RpcError,
} from "@/transport/types";
import { lookupSnapshotRef } from "./snapshot-ref";
import {
type CdpRunner,
type ChromeTabsApi,
@@ -32,6 +31,7 @@ import {
lookupSession,
resolveTargetTab,
} from "./shared";
import { lookupSnapshotRef } from "./snapshot-ref";
const DEFAULT_HELP_TIMEOUT_MS = 300_000;
/** Attribute the overlay highlights for resolved `ref` targets. */
@@ -46,7 +46,9 @@ export type TabNavigationUnsubscribe = () => void;
export interface RequestHelpDeps {
tabsApi: ChromeTabsApi;
windows: { update(windowId: number, info: { focused?: boolean }): Promise<chrome.windows.Window> };
windows: {
update(windowId: number, info: { focused?: boolean }): Promise<chrome.windows.Window>;
};
/** Activate a tab inside its window. */
activateTab(tabId: number): Promise<void>;
/** Send the help-request to the tab's content script and await reply. */
@@ -68,10 +70,7 @@ export function defaultWatchTabNavigation(
tabId: number,
onNavigated: () => void,
): TabNavigationUnsubscribe {
const listener = (
updatedTabId: number,
changeInfo: chrome.tabs.TabChangeInfo,
) => {
const listener = (updatedTabId: number, changeInfo: chrome.tabs.TabChangeInfo) => {
if (updatedTabId !== tabId) return;
if (changeInfo.url !== undefined || changeInfo.status === "loading") {
chrome.tabs.onUpdated.removeListener(listener);
@@ -102,7 +101,8 @@ function getDefaultDeps(): RequestHelpDeps {
else resolve(rid ?? id);
}),
),
clear: (id) => new Promise((resolve) => chrome.notifications.clear(id, (c) => resolve(c ?? false))),
clear: (id) =>
new Promise((resolve) => chrome.notifications.clear(id, (c) => resolve(c ?? false))),
},
};
}
@@ -167,7 +167,9 @@ async function selectorExists(
async function clearRefTags(cdp: CdpRunner | undefined, tabId: number): Promise<void> {
if (!cdp) return;
try {
const doc = await cdp.send<{ root?: { nodeId?: number } }>(tabId, "DOM.getDocument", { depth: 0 });
const doc = await cdp.send<{ root?: { nodeId?: number } }>(tabId, "DOM.getDocument", {
depth: 0,
});
const rootId = doc.root?.nodeId;
if (rootId === undefined) return;
const { nodeIds } = await cdp.send<{ nodeIds: number[] }>(tabId, "DOM.querySelectorAll", {
+6 -4
View File
@@ -21,10 +21,11 @@ import type {
MouseButton,
PressParams,
PressResult,
RpcError,
SelectParams,
SelectResult,
RpcError,
} from "@/transport/types";
import { attachDialogs, markDialogCursor } from "./dialogs";
import {
backendNodeToObject,
boxCentre,
@@ -33,7 +34,6 @@ import {
scrollNodeIntoView,
} from "./element-geometry";
import { rpcError } from "./errors";
import { resolveSnapshotRef } from "./snapshot-ref";
import {
type CdpRunner,
type ChromeTabsApi,
@@ -43,7 +43,7 @@ import {
lookupSession,
resolveTargetTab,
} from "./shared";
import { attachDialogs, markDialogCursor } from "./dialogs";
import { resolveSnapshotRef } from "./snapshot-ref";
export interface InteractionDeps {
cdp: CdpRunner;
@@ -858,7 +858,9 @@ export async function handleSelect(
);
}
const attrs = described.node.attributes ?? [];
const isMultiple = attrs.some((attr, idx) => idx % 2 === 0 && attr.toLowerCase() === "multiple");
const isMultiple = attrs.some(
(attr, idx) => idx % 2 === 0 && attr.toLowerCase() === "multiple",
);
if (!isMultiple && params.values.length !== 1) {
return rpcError(
"invalid_params",
+9 -5
View File
@@ -28,6 +28,7 @@ import type {
RpcError,
WaitUntil,
} from "@/transport/types";
import { attachDialogs, markDialogCursor } from "./dialogs";
import {
type CdpRunner,
type ChromeTabsApi,
@@ -37,7 +38,6 @@ import {
lookupSession,
resolveTargetTab,
} from "./shared";
import { attachDialogs, markDialogCursor } from "./dialogs";
export interface NavigationDeps {
cdp: CdpRunner;
@@ -120,9 +120,7 @@ export function lifecycleAlreadyReached(readyState: string, targetName: string):
case "DOMContentLoaded":
return readyState === "interactive" || readyState === "complete";
case "commit":
return (
readyState === "interactive" || readyState === "complete" || readyState === "loading"
);
return readyState === "interactive" || readyState === "complete" || readyState === "loading";
case "networkIdle":
// Must come from `Page.lifecycleEvent`; readyState does not imply network idle.
return false;
@@ -285,7 +283,13 @@ function startLifecycleWait(
const maybeFinishPending = () => {
if (settled || !pendingLifecycle) return;
if (!acceptLifecycleEvent(pendingLifecycle.name, pendingLifecycle.frameId, pendingLifecycle.loaderId)) {
if (
!acceptLifecycleEvent(
pendingLifecycle.name,
pendingLifecycle.frameId,
pendingLifecycle.loaderId,
)
) {
return;
}
if (lifecycleMeetsOrExceeds(pendingLifecycle.name, targetName)) {
+2 -2
View File
@@ -14,8 +14,8 @@ import type {
SnapshotParams,
SnapshotResult,
} from "@/transport/types";
import { attachDialogs, markDialogCursor } from "./dialogs";
import { nodeBoundingRect, scrollNodeIntoView } from "./element-geometry";
import { resolveSnapshotRef } from "./snapshot-ref";
import { rpcError } from "./errors";
import {
type ChromeTabsApi,
@@ -25,7 +25,7 @@ import {
type CdpRunner as SharedCdpRunner,
normaliseRef as sharedNormaliseRef,
} from "./shared";
import { attachDialogs, markDialogCursor } from "./dialogs";
import { resolveSnapshotRef } from "./snapshot-ref";
// ---------------------------------------------------------------------------
// Shared helpers (legacy aliases — observation.ts kept exporting these
+1 -1
View File
@@ -20,6 +20,7 @@ import type {
WaitForNavigationResult,
WaitUntil,
} from "@/transport/types";
import { attachDialogs, markDialogCursor } from "./dialogs";
import { cdpLifecycleName, ensureCdpReady, waitForLifecyclePassive } from "./navigation";
import {
type CdpRunner,
@@ -30,7 +31,6 @@ import {
lookupSession,
resolveTargetTab,
} from "./shared";
import { attachDialogs, markDialogCursor } from "./dialogs";
export interface WaitForNavigationDeps {
cdp: CdpRunner;