feat(browser-tools): cut low-value tools
This commit is contained in:
@@ -73,28 +73,12 @@ const commandParseCases = [
|
||||
{
|
||||
name: "screenshot",
|
||||
command: { command: "screenshot", args: { browserId: BROWSER_ID } },
|
||||
expected: { command: "screenshot", args: { browserId: BROWSER_ID } },
|
||||
expected: { command: "screenshot", args: { browserId: BROWSER_ID, fullPage: false } },
|
||||
},
|
||||
{
|
||||
name: "full page screenshot",
|
||||
command: { command: "full_page_screenshot", args: { browserId: BROWSER_ID } },
|
||||
expected: { command: "full_page_screenshot", args: { browserId: BROWSER_ID } },
|
||||
},
|
||||
{
|
||||
name: "pdf",
|
||||
command: { command: "pdf", args: { browserId: BROWSER_ID } },
|
||||
expected: { command: "pdf", args: { browserId: BROWSER_ID, printBackground: true } },
|
||||
},
|
||||
{
|
||||
name: "download",
|
||||
command: {
|
||||
command: "download",
|
||||
args: { browserId: BROWSER_ID, url: "https://example.com/file.txt" },
|
||||
},
|
||||
expected: {
|
||||
command: "download",
|
||||
args: { browserId: BROWSER_ID, url: "https://example.com/file.txt" },
|
||||
},
|
||||
command: { command: "screenshot", args: { browserId: BROWSER_ID, fullPage: true } },
|
||||
expected: { command: "screenshot", args: { browserId: BROWSER_ID, fullPage: true } },
|
||||
},
|
||||
{
|
||||
name: "upload",
|
||||
@@ -107,21 +91,6 @@ const commandParseCases = [
|
||||
args: { browserId: BROWSER_ID, ref: "@e1", filePaths: ["/tmp/file.txt"] },
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "focus",
|
||||
command: { command: "focus", args: { browserId: BROWSER_ID, ref: "@e1" } },
|
||||
expected: { command: "focus", args: { browserId: BROWSER_ID, ref: "@e1" } },
|
||||
},
|
||||
{
|
||||
name: "clear",
|
||||
command: { command: "clear", args: { browserId: BROWSER_ID, ref: "@e1" } },
|
||||
expected: { command: "clear", args: { browserId: BROWSER_ID, ref: "@e1" } },
|
||||
},
|
||||
{
|
||||
name: "check",
|
||||
command: { command: "check", args: { browserId: BROWSER_ID, ref: "@e2" } },
|
||||
expected: { command: "check", args: { browserId: BROWSER_ID, ref: "@e2", checked: true } },
|
||||
},
|
||||
{
|
||||
name: "select",
|
||||
command: {
|
||||
@@ -154,61 +123,9 @@ const commandParseCases = [
|
||||
command: { command: "logs", args: { browserId: BROWSER_ID } },
|
||||
expected: { command: "logs", args: { browserId: BROWSER_ID, maxEntries: 50 } },
|
||||
},
|
||||
{
|
||||
name: "storage",
|
||||
command: { command: "storage", args: { browserId: BROWSER_ID } },
|
||||
expected: { command: "storage", args: { browserId: BROWSER_ID } },
|
||||
},
|
||||
{
|
||||
name: "environment",
|
||||
command: {
|
||||
command: "environment",
|
||||
args: {
|
||||
browserId: BROWSER_ID,
|
||||
viewport: { width: 390, height: 844, deviceScaleFactor: 3 },
|
||||
geolocation: { latitude: 37.7749, longitude: -122.4194, accuracy: 5 },
|
||||
},
|
||||
},
|
||||
expected: {
|
||||
command: "environment",
|
||||
args: {
|
||||
browserId: BROWSER_ID,
|
||||
viewport: { width: 390, height: 844, deviceScaleFactor: 3 },
|
||||
geolocation: { latitude: 37.7749, longitude: -122.4194, accuracy: 5 },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "set background",
|
||||
command: { command: "set_background", args: { browserId: BROWSER_ID, color: "red" } },
|
||||
expected: { command: "set_background", args: { browserId: BROWSER_ID, color: "red" } },
|
||||
},
|
||||
] as const;
|
||||
|
||||
const resultParseCases = [
|
||||
{
|
||||
name: "page info",
|
||||
result: {
|
||||
command: "page_info",
|
||||
tab: {
|
||||
browserId: BROWSER_ID,
|
||||
workspaceId: "workspace-1",
|
||||
url: "https://example.com",
|
||||
title: "Example",
|
||||
},
|
||||
},
|
||||
expected: {
|
||||
command: "page_info",
|
||||
tab: {
|
||||
browserId: BROWSER_ID,
|
||||
workspaceId: "workspace-1",
|
||||
url: "https://example.com",
|
||||
title: "Example",
|
||||
isActive: false,
|
||||
isLoading: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "snapshot",
|
||||
result: {
|
||||
@@ -313,7 +230,7 @@ const resultParseCases = [
|
||||
{
|
||||
name: "full page screenshot",
|
||||
result: {
|
||||
command: "full_page_screenshot",
|
||||
command: "screenshot",
|
||||
browserId: BROWSER_ID,
|
||||
mimeType: "image/png",
|
||||
dataBase64: "iVBORw0KGgo=",
|
||||
@@ -321,7 +238,7 @@ const resultParseCases = [
|
||||
height: 1200,
|
||||
},
|
||||
expected: {
|
||||
command: "full_page_screenshot",
|
||||
command: "screenshot",
|
||||
browserId: BROWSER_ID,
|
||||
mimeType: "image/png",
|
||||
dataBase64: "iVBORw0KGgo=",
|
||||
@@ -329,40 +246,6 @@ const resultParseCases = [
|
||||
height: 1200,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "pdf",
|
||||
result: {
|
||||
command: "pdf",
|
||||
browserId: BROWSER_ID,
|
||||
mimeType: "application/pdf",
|
||||
dataBase64: "JVBERg==",
|
||||
},
|
||||
expected: {
|
||||
command: "pdf",
|
||||
browserId: BROWSER_ID,
|
||||
mimeType: "application/pdf",
|
||||
dataBase64: "JVBERg==",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "download",
|
||||
result: {
|
||||
command: "download",
|
||||
browserId: BROWSER_ID,
|
||||
url: "https://example.com/file.txt",
|
||||
filePath: "/tmp/file.txt",
|
||||
totalBytes: 5,
|
||||
state: "completed",
|
||||
},
|
||||
expected: {
|
||||
command: "download",
|
||||
browserId: BROWSER_ID,
|
||||
url: "https://example.com/file.txt",
|
||||
filePath: "/tmp/file.txt",
|
||||
totalBytes: 5,
|
||||
state: "completed",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "upload",
|
||||
result: {
|
||||
@@ -378,21 +261,6 @@ const resultParseCases = [
|
||||
filePaths: ["/tmp/file.txt"],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "focus",
|
||||
result: { command: "focus", browserId: BROWSER_ID, ref: "@e1" },
|
||||
expected: { command: "focus", browserId: BROWSER_ID, ref: "@e1" },
|
||||
},
|
||||
{
|
||||
name: "clear",
|
||||
result: { command: "clear", browserId: BROWSER_ID, ref: "@e1" },
|
||||
expected: { command: "clear", browserId: BROWSER_ID, ref: "@e1" },
|
||||
},
|
||||
{
|
||||
name: "check",
|
||||
result: { command: "check", browserId: BROWSER_ID, ref: "@e2", checked: false },
|
||||
expected: { command: "check", browserId: BROWSER_ID, ref: "@e2", checked: false },
|
||||
},
|
||||
{
|
||||
name: "select",
|
||||
result: { command: "select", browserId: BROWSER_ID, ref: "@e3", value: "us" },
|
||||
@@ -437,45 +305,6 @@ const resultParseCases = [
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "storage",
|
||||
result: {
|
||||
command: "storage",
|
||||
browserId: BROWSER_ID,
|
||||
url: "https://example.com",
|
||||
cookies: [{ name: "theme", value: "dark", domain: "example.com", httpOnly: true }],
|
||||
localStorage: [{ key: "token", value: "abc" }],
|
||||
sessionStorage: [{ key: "tab", value: "1" }],
|
||||
},
|
||||
expected: {
|
||||
command: "storage",
|
||||
browserId: BROWSER_ID,
|
||||
url: "https://example.com",
|
||||
cookies: [{ name: "theme", value: "dark", domain: "example.com", httpOnly: true }],
|
||||
localStorage: [{ key: "token", value: "abc" }],
|
||||
sessionStorage: [{ key: "tab", value: "1" }],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "environment",
|
||||
result: {
|
||||
command: "environment",
|
||||
browserId: BROWSER_ID,
|
||||
viewport: { width: 390, height: 844, deviceScaleFactor: 3 },
|
||||
geolocation: { latitude: 37.7749, longitude: -122.4194, accuracy: 5 },
|
||||
},
|
||||
expected: {
|
||||
command: "environment",
|
||||
browserId: BROWSER_ID,
|
||||
viewport: { width: 390, height: 844, deviceScaleFactor: 3 },
|
||||
geolocation: { latitude: 37.7749, longitude: -122.4194, accuracy: 5 },
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "set background",
|
||||
result: { command: "set_background", browserId: BROWSER_ID, color: "red" },
|
||||
expected: { command: "set_background", browserId: BROWSER_ID, color: "red" },
|
||||
},
|
||||
] as const;
|
||||
|
||||
describe("browser automation execute RPC schemas", () => {
|
||||
@@ -526,9 +355,9 @@ describe("browser automation execute RPC schemas", () => {
|
||||
test("tab commands reject hallucinated browser ids", () => {
|
||||
const parsed = BrowserAutomationExecuteRequestSchema.safeParse({
|
||||
type: "browser.automation.execute.request",
|
||||
requestId: "req-page-info",
|
||||
requestId: "req-snapshot",
|
||||
workspaceId: "workspace-1",
|
||||
command: { command: "page_info", args: { browserId: "default" } },
|
||||
command: { command: "snapshot", args: { browserId: "default" } },
|
||||
});
|
||||
|
||||
expect(parsed).toMatchObject({
|
||||
@@ -540,13 +369,13 @@ describe("browser automation execute RPC schemas", () => {
|
||||
test("tab commands parse browser ids produced by the fallback generator", () => {
|
||||
const parsed = BrowserAutomationExecuteRequestSchema.parse({
|
||||
type: "browser.automation.execute.request",
|
||||
requestId: "req-page-info",
|
||||
requestId: "req-snapshot",
|
||||
workspaceId: "workspace-1",
|
||||
command: { command: "page_info", args: { browserId: FALLBACK_BROWSER_ID } },
|
||||
command: { command: "snapshot", args: { browserId: FALLBACK_BROWSER_ID } },
|
||||
});
|
||||
|
||||
expect(parsed.command).toEqual({
|
||||
command: "page_info",
|
||||
command: "snapshot",
|
||||
args: { browserId: FALLBACK_BROWSER_ID },
|
||||
});
|
||||
});
|
||||
@@ -658,22 +487,6 @@ describe("browser automation execute RPC schemas", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("download rejects non-http URLs at the protocol boundary", () => {
|
||||
const parsed = BrowserAutomationExecuteRequestSchema.safeParse({
|
||||
type: "browser.automation.execute.request",
|
||||
requestId: "req-download",
|
||||
command: {
|
||||
command: "download",
|
||||
args: { browserId: BROWSER_ID, url: "file:///tmp/secret.txt" },
|
||||
},
|
||||
});
|
||||
|
||||
expect(parsed).toMatchObject({
|
||||
success: false,
|
||||
error: { issues: [expect.objectContaining({ message: "URL must use http or https" })] },
|
||||
});
|
||||
});
|
||||
|
||||
test("new tab responses declare the generated browser id shape", () => {
|
||||
const parsed = BrowserAutomationExecuteResponseSchema.parse({
|
||||
type: "browser.automation.execute.response",
|
||||
@@ -705,16 +518,15 @@ describe("browser automation execute RPC schemas", () => {
|
||||
const parsed = BrowserAutomationExecuteResponseSchema.safeParse({
|
||||
type: "browser.automation.execute.response",
|
||||
payload: {
|
||||
requestId: "req-page-info",
|
||||
requestId: "req-snapshot",
|
||||
ok: true,
|
||||
result: {
|
||||
command: "page_info",
|
||||
tab: {
|
||||
browserId: "default",
|
||||
workspaceId: "workspace-1",
|
||||
url: "https://example.com",
|
||||
title: "Example",
|
||||
},
|
||||
command: "snapshot",
|
||||
browserId: "default",
|
||||
workspaceId: "workspace-1",
|
||||
url: "https://example.com",
|
||||
title: "Example",
|
||||
elements: [],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user