chore: test list tabs (#208)

This commit is contained in:
Pavel Feldman
2025-04-17 00:58:02 -07:00
committed by GitHub
parent 7e4a964b0a
commit 4b261286bf
14 changed files with 66 additions and 58 deletions

View File

@@ -37,7 +37,6 @@ const wait: ToolFactory = captureSnapshot => ({
await new Promise(f => setTimeout(f, Math.min(10000, validatedParams.time * 1000)));
return {
code: [`// Waited for ${validatedParams.time} seconds`],
action: async () => ({}),
captureSnapshot,
waitForNetwork: false,
};
@@ -59,7 +58,6 @@ const close: Tool = {
await context.close();
return {
code: [`// Internal to close the page`],
action: async () => ({}),
captureSnapshot: false,
waitForNetwork: false,
};
@@ -91,7 +89,6 @@ const resize: ToolFactory = captureSnapshot => ({
const action = async () => {
await tab.page.setViewportSize({ width: validatedParams.width, height: validatedParams.height });
return {};
};
return {

View File

@@ -45,7 +45,6 @@ const uploadFile: ToolFactory = captureSnapshot => ({
const action = async () => {
await modalState.fileChooser.setFiles(validatedParams.paths);
context.clearModalState(modalState);
return {};
};
return {

View File

@@ -49,7 +49,6 @@ const install: Tool = {
});
return {
code: [`// Browser ${channel} installed`],
action: async () => ({}),
captureSnapshot: false,
waitForNetwork: false,
};

View File

@@ -41,7 +41,7 @@ const pressKey: ToolFactory = captureSnapshot => ({
`await page.keyboard.press('${validatedParams.key}');`,
];
const action = () => tab.page.keyboard.press(validatedParams.key).then(() => ({}));
const action = () => tab.page.keyboard.press(validatedParams.key);
return {
code,

View File

@@ -44,7 +44,6 @@ const navigate: ToolFactory = captureSnapshot => ({
return {
code,
action: async () => ({}),
captureSnapshot,
waitForNetwork: false,
};
@@ -71,7 +70,6 @@ const goBack: ToolFactory = captureSnapshot => ({
return {
code,
action: async () => ({}),
captureSnapshot,
waitForNetwork: false,
};
@@ -96,7 +94,6 @@ const goForward: ToolFactory = captureSnapshot => ({
];
return {
code,
action: async () => ({}),
captureSnapshot,
waitForNetwork: false,
};

View File

@@ -47,7 +47,7 @@ const pdf: Tool = {
return {
code,
action: async () => tab.page.pdf({ path: fileName }).then(() => ({})),
action: async () => tab.page.pdf({ path: fileName }).then(() => {}),
captureSnapshot: false,
waitForNetwork: false,
};

View File

@@ -77,7 +77,7 @@ const moveMouse: Tool = {
`// Move mouse to (${validatedParams.x}, ${validatedParams.y})`,
`await page.mouse.move(${validatedParams.x}, ${validatedParams.y});`,
];
const action = () => tab.page.mouse.move(validatedParams.x, validatedParams.y).then(() => ({}));
const action = () => tab.page.mouse.move(validatedParams.x, validatedParams.y);
return {
code,
action,
@@ -113,7 +113,6 @@ const click: Tool = {
await tab.page.mouse.move(validatedParams.x, validatedParams.y);
await tab.page.mouse.down();
await tab.page.mouse.up();
return {};
};
return {
code,
@@ -157,7 +156,6 @@ const drag: Tool = {
await tab.page.mouse.down();
await tab.page.mouse.move(validatedParams.endX, validatedParams.endY);
await tab.page.mouse.up();
return {};
};
return {
@@ -196,7 +194,6 @@ const type: Tool = {
await tab.page.keyboard.type(validatedParams.text);
if (validatedParams.submit)
await tab.page.keyboard.press('Enter');
return {};
};
if (validatedParams.submit) {

View File

@@ -40,7 +40,6 @@ const snapshot: Tool = {
return {
code: [`// <internal code to capture accessibility snapshot>`],
action: async () => ({}),
captureSnapshot: true,
waitForNetwork: false,
};
@@ -72,7 +71,7 @@ const click: Tool = {
return {
code,
action: () => locator.click().then(() => ({})),
action: () => locator.click(),
captureSnapshot: true,
waitForNetwork: true,
};
@@ -107,7 +106,7 @@ const drag: Tool = {
return {
code,
action: () => startLocator.dragTo(endLocator).then(() => ({})),
action: () => startLocator.dragTo(endLocator),
captureSnapshot: true,
waitForNetwork: true,
};
@@ -134,7 +133,7 @@ const hover: Tool = {
return {
code,
action: () => locator.hover().then(() => ({})),
action: () => locator.hover(),
captureSnapshot: true,
waitForNetwork: true,
};
@@ -181,7 +180,7 @@ const type: Tool = {
return {
code,
action: () => steps.reduce((acc, step) => acc.then(step), Promise.resolve()).then(() => ({})),
action: () => steps.reduce((acc, step) => acc.then(step), Promise.resolve()),
captureSnapshot: true,
waitForNetwork: true,
};
@@ -212,7 +211,7 @@ const selectOption: Tool = {
return {
code,
action: () => locator.selectOption(validatedParams.values).then(() => ({})),
action: () => locator.selectOption(validatedParams.values).then(() => {}),
captureSnapshot: true,
waitForNetwork: true,
};

View File

@@ -28,12 +28,18 @@ const listTabs: Tool = {
inputSchema: zodToJsonSchema(z.object({})),
},
handle: async () => {
handle: async context => {
await context.ensureTab();
return {
code: [`// <internal code to list tabs>`],
action: async () => ({}),
captureSnapshot: false,
waitForNetwork: false,
resultOverride: {
content: [{
type: 'text',
text: await context.listTabsMarkdown(),
}],
},
};
},
};
@@ -60,7 +66,6 @@ const selectTab: ToolFactory = captureSnapshot => ({
return {
code,
action: async () => ({}),
captureSnapshot,
waitForNetwork: false
};
@@ -91,7 +96,6 @@ const newTab: ToolFactory = captureSnapshot => ({
];
return {
code,
action: async () => ({}),
captureSnapshot,
waitForNetwork: false
};
@@ -119,7 +123,6 @@ const closeTab: ToolFactory = captureSnapshot => ({
];
return {
code,
action: async () => ({}),
captureSnapshot,
waitForNetwork: false
};

View File

@@ -36,9 +36,10 @@ export type ModalState = FileUploadModalState;
export type ToolResult = {
code: string[];
action: () => Promise<{ content?: (ImageContent | TextContent)[] }>;
action?: () => Promise<{ content?: (ImageContent | TextContent)[] } | undefined | void>;
captureSnapshot: boolean;
waitForNetwork: boolean;
resultOverride?: { content?: (ImageContent | TextContent)[] };
};
export type Tool = {