mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 00:31:24 +00:00
chore: Enable more lint rules, disable some that trigger a lot. Will clean up later.
This commit is contained in:
@@ -296,7 +296,7 @@ export async function snapshotDom(opts: {
|
||||
awaitPromise: true,
|
||||
returnByValue: true,
|
||||
});
|
||||
const value = evaluated.result?.value as unknown;
|
||||
const value = evaluated.result?.value;
|
||||
if (!value || typeof value !== "object") return { nodes: [] };
|
||||
const nodes = (value as { nodes?: unknown }).nodes;
|
||||
return { nodes: Array.isArray(nodes) ? (nodes as DomSnapshotNode[]) : [] };
|
||||
|
||||
@@ -458,7 +458,7 @@ export async function ensureChromeExtensionRelayServer(opts: {
|
||||
if ("error" in parsed && typeof parsed.error === "string" && parsed.error.trim()) {
|
||||
pending.reject(new Error(parsed.error));
|
||||
} else {
|
||||
pending.resolve((parsed as ExtensionResponseMessage).result);
|
||||
pending.resolve(parsed.result);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -183,18 +183,18 @@ describe("color allocation", () => {
|
||||
|
||||
it("allocates next unused color from palette", () => {
|
||||
// biome-ignore lint/style/noNonNullAssertion: Test file with known array
|
||||
const usedColors = new Set([PROFILE_COLORS[0]!.toUpperCase()]);
|
||||
const usedColors = new Set([PROFILE_COLORS[0].toUpperCase()]);
|
||||
expect(allocateColor(usedColors)).toBe(PROFILE_COLORS[1]);
|
||||
});
|
||||
|
||||
it("skips multiple used colors", () => {
|
||||
const usedColors = new Set([
|
||||
// biome-ignore lint/style/noNonNullAssertion: Test file with known array
|
||||
PROFILE_COLORS[0]!.toUpperCase(),
|
||||
PROFILE_COLORS[0].toUpperCase(),
|
||||
// biome-ignore lint/style/noNonNullAssertion: Test file with known array
|
||||
PROFILE_COLORS[1]!.toUpperCase(),
|
||||
PROFILE_COLORS[1].toUpperCase(),
|
||||
// biome-ignore lint/style/noNonNullAssertion: Test file with known array
|
||||
PROFILE_COLORS[2]!.toUpperCase(),
|
||||
PROFILE_COLORS[2].toUpperCase(),
|
||||
]);
|
||||
expect(allocateColor(usedColors)).toBe(PROFILE_COLORS[3]);
|
||||
});
|
||||
|
||||
@@ -91,7 +91,7 @@ export function allocateColor(usedColors: Set<string>): string {
|
||||
// All colors used, cycle based on count
|
||||
const index = usedColors.size % PROFILE_COLORS.length;
|
||||
// biome-ignore lint/style/noNonNullAssertion: Array is non-empty constant
|
||||
return PROFILE_COLORS[index] ?? PROFILE_COLORS[0]!;
|
||||
return PROFILE_COLORS[index] ?? PROFILE_COLORS[0];
|
||||
}
|
||||
|
||||
export function getUsedColors(
|
||||
|
||||
@@ -84,7 +84,7 @@ describe("pw-role-snapshot", () => {
|
||||
expect(res.snapshot).toContain('- button "Save"');
|
||||
expect(res.snapshot).not.toContain("navigation");
|
||||
expect(res.snapshot).not.toContain("heading");
|
||||
expect(Object.keys(res.refs).sort()).toEqual(["e5", "e7"]);
|
||||
expect(Object.keys(res.refs).toSorted()).toEqual(["e5", "e7"]);
|
||||
expect(res.refs.e5).toMatchObject({ role: "link", name: "Home" });
|
||||
expect(res.refs.e7).toMatchObject({ role: "button", name: "Save" });
|
||||
});
|
||||
|
||||
@@ -55,13 +55,13 @@ describe("pw-tools-core", () => {
|
||||
() =>
|
||||
new Promise((r) => {
|
||||
resolve1 = r;
|
||||
}) as Promise<unknown>,
|
||||
}),
|
||||
)
|
||||
.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise((r) => {
|
||||
resolve2 = r;
|
||||
}) as Promise<unknown>,
|
||||
}),
|
||||
);
|
||||
|
||||
currentPage = {
|
||||
|
||||
@@ -93,7 +93,7 @@ export async function responseBodyViaPlaywright(opts: {
|
||||
bodyText = new TextDecoder("utf-8").decode(buf);
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to read response body for "${url}": ${String(err)}`);
|
||||
throw new Error(`Failed to read response body for "${url}": ${String(err)}`, { cause: err });
|
||||
}
|
||||
|
||||
const trimmed = bodyText.length > maxChars ? bodyText.slice(0, maxChars) : bodyText;
|
||||
|
||||
@@ -200,6 +200,6 @@ export async function pdfViaPlaywright(opts: {
|
||||
}): Promise<{ buffer: Buffer }> {
|
||||
const page = await getPageForTargetId(opts);
|
||||
ensurePageState(page);
|
||||
const buffer = await (page as Page).pdf({ printBackground: true });
|
||||
const buffer = await page.pdf({ printBackground: true });
|
||||
return { buffer };
|
||||
}
|
||||
|
||||
@@ -136,7 +136,8 @@ export async function setTimezoneViaPlaywright(opts: {
|
||||
} catch (err) {
|
||||
const msg = String(err);
|
||||
if (msg.includes("Timezone override is already in effect")) return;
|
||||
if (msg.includes("Invalid timezone")) throw new Error(`Invalid timezone ID: ${timezoneId}`);
|
||||
if (msg.includes("Invalid timezone"))
|
||||
throw new Error(`Invalid timezone ID: ${timezoneId}`, { cause: err });
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -207,7 +207,7 @@ export function registerBrowserAgentActRoutes(
|
||||
loadStateRaw === "load" ||
|
||||
loadStateRaw === "domcontentloaded" ||
|
||||
loadStateRaw === "networkidle"
|
||||
? (loadStateRaw as "load" | "domcontentloaded" | "networkidle")
|
||||
? loadStateRaw
|
||||
: undefined;
|
||||
const fn = toStringOrEmpty(body.fn) || undefined;
|
||||
const timeoutMs = toNumber(body.timeoutMs) ?? undefined;
|
||||
|
||||
@@ -53,7 +53,7 @@ export function registerBrowserAgentStorageRoutes(
|
||||
secure: toBoolean(cookie.secure) ?? undefined,
|
||||
sameSite:
|
||||
cookie.sameSite === "Lax" || cookie.sameSite === "None" || cookie.sameSite === "Strict"
|
||||
? (cookie.sameSite as "Lax" | "None" | "Strict")
|
||||
? cookie.sameSite
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
@@ -270,7 +270,7 @@ export function registerBrowserAgentStorageRoutes(
|
||||
const schemeRaw = toStringOrEmpty(body.colorScheme);
|
||||
const colorScheme =
|
||||
schemeRaw === "dark" || schemeRaw === "light" || schemeRaw === "no-preference"
|
||||
? (schemeRaw as "dark" | "light" | "no-preference")
|
||||
? schemeRaw
|
||||
: schemeRaw === "none"
|
||||
? null
|
||||
: undefined;
|
||||
|
||||
@@ -27,7 +27,7 @@ export async function normalizeBrowserScreenshot(
|
||||
const sideGrid = [sideStart, 1800, 1600, 1400, 1200, 1000, 800]
|
||||
.map((v) => Math.min(maxSide, v))
|
||||
.filter((v, i, arr) => v > 0 && arr.indexOf(v) === i)
|
||||
.sort((a, b) => b - a);
|
||||
.toSorted((a, b) => b - a);
|
||||
|
||||
let smallest: { buffer: Buffer; size: number } | null = null;
|
||||
|
||||
|
||||
@@ -286,11 +286,11 @@ describe("browser control server", () => {
|
||||
async () => {
|
||||
const base = await startServerAndBase();
|
||||
|
||||
const select = (await postJson(`${base}/act`, {
|
||||
const select = await postJson(`${base}/act`, {
|
||||
kind: "select",
|
||||
ref: "5",
|
||||
values: ["a", "b"],
|
||||
})) as { ok: boolean };
|
||||
});
|
||||
expect(select.ok).toBe(true);
|
||||
expect(pwMocks.selectOptionViaPlaywright).toHaveBeenCalledWith({
|
||||
cdpUrl: cdpBaseUrl,
|
||||
@@ -299,10 +299,10 @@ describe("browser control server", () => {
|
||||
values: ["a", "b"],
|
||||
});
|
||||
|
||||
const fill = (await postJson(`${base}/act`, {
|
||||
const fill = await postJson(`${base}/act`, {
|
||||
kind: "fill",
|
||||
fields: [{ ref: "6", type: "textbox", value: "hello" }],
|
||||
})) as { ok: boolean };
|
||||
});
|
||||
expect(fill.ok).toBe(true);
|
||||
expect(pwMocks.fillFormViaPlaywright).toHaveBeenCalledWith({
|
||||
cdpUrl: cdpBaseUrl,
|
||||
@@ -310,11 +310,11 @@ describe("browser control server", () => {
|
||||
fields: [{ ref: "6", type: "textbox", value: "hello" }],
|
||||
});
|
||||
|
||||
const resize = (await postJson(`${base}/act`, {
|
||||
const resize = await postJson(`${base}/act`, {
|
||||
kind: "resize",
|
||||
width: 800,
|
||||
height: 600,
|
||||
})) as { ok: boolean };
|
||||
});
|
||||
expect(resize.ok).toBe(true);
|
||||
expect(pwMocks.resizeViewportViaPlaywright).toHaveBeenCalledWith({
|
||||
cdpUrl: cdpBaseUrl,
|
||||
@@ -323,10 +323,10 @@ describe("browser control server", () => {
|
||||
height: 600,
|
||||
});
|
||||
|
||||
const wait = (await postJson(`${base}/act`, {
|
||||
const wait = await postJson(`${base}/act`, {
|
||||
kind: "wait",
|
||||
timeMs: 5,
|
||||
})) as { ok: boolean };
|
||||
});
|
||||
expect(wait.ok).toBe(true);
|
||||
expect(pwMocks.waitForViaPlaywright).toHaveBeenCalledWith({
|
||||
cdpUrl: cdpBaseUrl,
|
||||
@@ -336,10 +336,10 @@ describe("browser control server", () => {
|
||||
textGone: undefined,
|
||||
});
|
||||
|
||||
const evalRes = (await postJson(`${base}/act`, {
|
||||
const evalRes = await postJson(`${base}/act`, {
|
||||
kind: "evaluate",
|
||||
fn: "() => 1",
|
||||
})) as { ok: boolean; result?: unknown };
|
||||
});
|
||||
expect(evalRes.ok).toBe(true);
|
||||
expect(evalRes.result).toBe("ok");
|
||||
expect(pwMocks.evaluateViaPlaywright).toHaveBeenCalledWith({
|
||||
@@ -358,17 +358,17 @@ describe("browser control server", () => {
|
||||
cfgEvaluateEnabled = false;
|
||||
const base = await startServerAndBase();
|
||||
|
||||
const waitRes = (await postJson(`${base}/act`, {
|
||||
const waitRes = await postJson(`${base}/act`, {
|
||||
kind: "wait",
|
||||
fn: "() => window.ready === true",
|
||||
})) as { error?: string };
|
||||
});
|
||||
expect(waitRes.error).toContain("browser.evaluateEnabled=false");
|
||||
expect(pwMocks.waitForViaPlaywright).not.toHaveBeenCalled();
|
||||
|
||||
const res = (await postJson(`${base}/act`, {
|
||||
const res = await postJson(`${base}/act`, {
|
||||
kind: "evaluate",
|
||||
fn: "() => 1",
|
||||
})) as { error?: string };
|
||||
});
|
||||
|
||||
expect(res.error).toContain("browser.evaluateEnabled=false");
|
||||
expect(pwMocks.evaluateViaPlaywright).not.toHaveBeenCalled();
|
||||
@@ -441,17 +441,14 @@ describe("browser control server", () => {
|
||||
expect(consoleRes.ok).toBe(true);
|
||||
expect(Array.isArray(consoleRes.messages)).toBe(true);
|
||||
|
||||
const pdf = (await postJson(`${base}/pdf`, {})) as {
|
||||
ok: boolean;
|
||||
path?: string;
|
||||
};
|
||||
const pdf = await postJson(`${base}/pdf`, {});
|
||||
expect(pdf.ok).toBe(true);
|
||||
expect(typeof pdf.path).toBe("string");
|
||||
|
||||
const shot = (await postJson(`${base}/screenshot`, {
|
||||
const shot = await postJson(`${base}/screenshot`, {
|
||||
element: "body",
|
||||
type: "jpeg",
|
||||
})) as { ok: boolean; path?: string };
|
||||
});
|
||||
expect(shot.ok).toBe(true);
|
||||
expect(typeof shot.path).toBe("string");
|
||||
});
|
||||
|
||||
@@ -306,9 +306,9 @@ describe("browser control server", () => {
|
||||
it("agent contract: navigation + common act commands", async () => {
|
||||
const base = await startServerAndBase();
|
||||
|
||||
const nav = (await postJson(`${base}/navigate`, {
|
||||
const nav = await postJson(`${base}/navigate`, {
|
||||
url: "https://example.com",
|
||||
})) as { ok: boolean; targetId?: string };
|
||||
});
|
||||
expect(nav.ok).toBe(true);
|
||||
expect(typeof nav.targetId).toBe("string");
|
||||
expect(pwMocks.navigateViaPlaywright).toHaveBeenCalledWith({
|
||||
@@ -317,12 +317,12 @@ describe("browser control server", () => {
|
||||
url: "https://example.com",
|
||||
});
|
||||
|
||||
const click = (await postJson(`${base}/act`, {
|
||||
const click = await postJson(`${base}/act`, {
|
||||
kind: "click",
|
||||
ref: "1",
|
||||
button: "left",
|
||||
modifiers: ["Shift"],
|
||||
})) as { ok: boolean };
|
||||
});
|
||||
expect(click.ok).toBe(true);
|
||||
expect(pwMocks.clickViaPlaywright).toHaveBeenNthCalledWith(1, {
|
||||
cdpUrl: cdpBaseUrl,
|
||||
@@ -343,11 +343,11 @@ describe("browser control server", () => {
|
||||
/'selector' is not supported/i,
|
||||
);
|
||||
|
||||
const type = (await postJson(`${base}/act`, {
|
||||
const type = await postJson(`${base}/act`, {
|
||||
kind: "type",
|
||||
ref: "1",
|
||||
text: "",
|
||||
})) as { ok: boolean };
|
||||
});
|
||||
expect(type.ok).toBe(true);
|
||||
expect(pwMocks.typeViaPlaywright).toHaveBeenNthCalledWith(1, {
|
||||
cdpUrl: cdpBaseUrl,
|
||||
@@ -358,10 +358,10 @@ describe("browser control server", () => {
|
||||
slowly: false,
|
||||
});
|
||||
|
||||
const press = (await postJson(`${base}/act`, {
|
||||
const press = await postJson(`${base}/act`, {
|
||||
kind: "press",
|
||||
key: "Enter",
|
||||
})) as { ok: boolean };
|
||||
});
|
||||
expect(press.ok).toBe(true);
|
||||
expect(pwMocks.pressKeyViaPlaywright).toHaveBeenCalledWith({
|
||||
cdpUrl: cdpBaseUrl,
|
||||
@@ -369,10 +369,10 @@ describe("browser control server", () => {
|
||||
key: "Enter",
|
||||
});
|
||||
|
||||
const hover = (await postJson(`${base}/act`, {
|
||||
const hover = await postJson(`${base}/act`, {
|
||||
kind: "hover",
|
||||
ref: "2",
|
||||
})) as { ok: boolean };
|
||||
});
|
||||
expect(hover.ok).toBe(true);
|
||||
expect(pwMocks.hoverViaPlaywright).toHaveBeenCalledWith({
|
||||
cdpUrl: cdpBaseUrl,
|
||||
@@ -380,10 +380,10 @@ describe("browser control server", () => {
|
||||
ref: "2",
|
||||
});
|
||||
|
||||
const scroll = (await postJson(`${base}/act`, {
|
||||
const scroll = await postJson(`${base}/act`, {
|
||||
kind: "scrollIntoView",
|
||||
ref: "2",
|
||||
})) as { ok: boolean };
|
||||
});
|
||||
expect(scroll.ok).toBe(true);
|
||||
expect(pwMocks.scrollIntoViewViaPlaywright).toHaveBeenCalledWith({
|
||||
cdpUrl: cdpBaseUrl,
|
||||
@@ -391,11 +391,11 @@ describe("browser control server", () => {
|
||||
ref: "2",
|
||||
});
|
||||
|
||||
const drag = (await postJson(`${base}/act`, {
|
||||
const drag = await postJson(`${base}/act`, {
|
||||
kind: "drag",
|
||||
startRef: "3",
|
||||
endRef: "4",
|
||||
})) as { ok: boolean };
|
||||
});
|
||||
expect(drag.ok).toBe(true);
|
||||
expect(pwMocks.dragViaPlaywright).toHaveBeenCalledWith({
|
||||
cdpUrl: cdpBaseUrl,
|
||||
|
||||
Reference in New Issue
Block a user