Skip to content

Conversation

tech-sushant
Copy link
Collaborator

This pull request introduces a new set of tools and supporting infrastructure for integrating Percy visual testing into the BrowserStack MCP server, alongside refactoring and modularizing SDK tool registration. The changes enable automated detection of test files, updating tests with Percy snapshot commands, running Percy scans, and fetching visual change summaries, all exposed as MCP server tools. Additionally, the BrowserStack SDK tool registration is streamlined for better maintainability.

Percy visual testing integration:

  • Added registerPercyTools in src/tools/percy-sdk.ts to register MCP tools for setting up Percy, listing test files, updating test files with Percy commands, running Percy scans, fetching Percy changes, and managing build approvals. Each tool is modular, error-handled, and uses a shared in-memory store for state.
  • Implemented fetchPercyChanges in src/tools/percy-change.ts to retrieve and summarize visual changes detected by Percy between builds, supporting review workflows.
  • Added addListTestFiles in src/tools/list-test-files.ts to detect and store test file paths in memory, enabling later updates with Percy commands.
  • Created updateTestsWithPercyCommands in src/tools/add-percy-snapshots.ts to update test files with Percy snapshot commands for visual testing, using the in-memory store for file tracking.
  • Introduced a shared testFilePathsMap in src/lib/inmemory-store.ts to persist test file paths by UUID for cross-tool access.

SDK tool registration refactoring:

  • Refactored addSDKTools to registerRunBrowserStackTestsTool in src/tools/bstack-sdk.ts, simplifying the registration and invocation logic for the BrowserStack SDK tool and delegating the main handler to runTestsOnBrowserStackHandler.

Server factory updates:

  • Registered the new Percy tools by adding addPercyTools to the tool loader array in src/server-factory.ts, ensuring Percy integration is available in the MCP server. [1] [2]

@tech-sushant tech-sushant requested a review from Copilot September 2, 2025 11:32
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces a comprehensive Percy visual testing integration for the BrowserStack MCP server while refactoring and modularizing the existing SDK tool registration. The main purpose is to enable automated visual testing workflows through Percy Web and Percy Automate integrations, with supporting infrastructure for test file detection, snapshot command injection, and visual change analysis.

Key changes include:

  • Complete Percy integration system with multiple testing modes (Web, Automate, BrowserStack SDK)
  • Modularized SDK utilities architecture with common shared components
  • New tools for test file detection, Percy snapshot management, and visual change analysis

Reviewed Changes

Copilot reviewed 52 out of 52 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/tools/sdk-utils/types.ts Removed legacy SDK type definitions (moved to common)
src/tools/sdk-utils/percy/types.ts Removed old Percy type definitions (replaced by modular approach)
src/tools/sdk-utils/percy-web/types.ts Added Percy Web configuration mapping types
src/tools/sdk-utils/percy-web/index.ts Added Percy Web utilities export module
src/tools/sdk-utils/percy-web/handler.ts Added Percy Web standalone mode handler
src/tools/sdk-utils/percy-web/frameworks.ts Added comprehensive Percy Web framework configurations
src/tools/sdk-utils/percy-web/fetchPercyToken.ts Added Percy token fetching utility
src/tools/sdk-utils/percy-web/constants.ts Added extensive Percy Web setup instructions
src/tools/sdk-utils/percy-bstack/types.ts Added Percy + BrowserStack SDK configuration types
src/tools/sdk-utils/percy-bstack/instructions.ts Added Percy + BrowserStack instruction utilities
src/tools/sdk-utils/percy-bstack/index.ts Added Percy + BrowserStack utilities export
src/tools/sdk-utils/percy-bstack/handler.ts Added combined Percy + BrowserStack SDK handler
src/tools/sdk-utils/percy-bstack/frameworks.ts Added Percy + BrowserStack framework configurations
src/tools/sdk-utils/percy-bstack/constants.ts Added Percy + BrowserStack setup instructions
src/tools/sdk-utils/percy-automate/types.ts Added Percy Automate configuration types
src/tools/sdk-utils/percy-automate/index.ts Added Percy Automate utilities export
src/tools/sdk-utils/percy-automate/handler.ts Added Percy Automate standalone handler
src/tools/sdk-utils/percy-automate/frameworks.ts Added Percy Automate framework configurations
src/tools/sdk-utils/percy-automate/constants.ts Added comprehensive Percy Automate instructions
src/tools/sdk-utils/instructions.ts Removed legacy instruction utilities (moved to common)
src/tools/sdk-utils/handler.ts Added unified SDK handler with Percy integration logic
src/tools/sdk-utils/common/utils.ts Added common utilities for Percy support checking and result formatting
src/tools/sdk-utils/common/types.ts Added shared SDK types and enums
src/tools/sdk-utils/common/schema.ts Added Zod schemas for SDK tool parameters
src/tools/sdk-utils/common/instructionUtils.ts Added core instruction configuration utilities
src/tools/sdk-utils/common/index.ts Added common utilities export module
src/tools/sdk-utils/common/formatUtils.ts Added instruction formatting utilities
src/tools/sdk-utils/common/constants.ts Added shared constants and Percy instruction templates
src/tools/sdk-utils/commands.ts Removed legacy SDK commands (moved to bstack module)
src/tools/sdk-utils/bstack/sdkHandler.ts Added BrowserStack SDK only handler
src/tools/sdk-utils/bstack/index.ts Added BrowserStack SDK utilities export
src/tools/sdk-utils/bstack/frameworks.ts Added BrowserStack SDK framework configurations
src/tools/sdk-utils/bstack/constants.ts Added comprehensive BrowserStack SDK instructions
src/tools/sdk-utils/bstack/configUtils.ts Added BrowserStack configuration file utilities
src/tools/sdk-utils/bstack/commands.ts Added BrowserStack SDK setup commands
src/tools/run-percy-scan.ts Added Percy scan execution tool
src/tools/review-agent-utils/percy-snapshots.ts Added Percy snapshot ID fetching utilities
src/tools/review-agent-utils/percy-diffs.ts Added Percy snapshot diff analysis utilities
src/tools/review-agent-utils/percy-builds.ts Added Percy build information utilities
src/tools/review-agent-utils/percy-approve-reject.ts Added Percy build approval/rejection utilities
src/tools/review-agent-utils/build-counts.ts Added Percy build counting utilities
src/tools/percy-snapshot-utils/utils.ts Added Percy snapshot command injection utilities
src/tools/percy-snapshot-utils/types.ts Added test file detection types
src/tools/percy-snapshot-utils/detect-test-files.ts Added comprehensive test file detection logic
src/tools/percy-snapshot-utils/constants.ts Added test file detection patterns and configurations
src/tools/percy-sdk.ts Added Percy tools registration module
src/tools/percy-change.ts Added Percy visual change fetching tool
src/tools/list-test-files.ts Added test file listing and storage tool
src/tools/bstack-sdk.ts Refactored to simplified BrowserStack SDK tool registration
src/tools/add-percy-snapshots.ts Added Percy snapshot command injection tool
src/server-factory.ts Added Percy tools to server tool registration
src/lib/inmemory-store.ts Added test file paths storage map
Comments suppressed due to low confidence (1)

src/tools/percy-snapshot-utils/constants.ts:1

  • This SUPPORTED_CONFIGURATIONS export appears to be duplicated from the bstack/constants.ts file and may cause conflicts. The export should be removed from this file since it's already defined in the bstack module.
import { z } from "zod";

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 19 to 40
async function walkDir(dir: string, extensions: string[]): Promise<string[]> {
const result: string[] = [];
try {
const entries = await fs.promises.readdir(dir, { withFileTypes: true });

for (const entry of entries) {
const fullPath = path.join(dir, entry.name);

if (entry.isDirectory()) {
if (!EXCLUDED_DIRS.has(entry.name) && !entry.name.startsWith(".")) {
result.push(...(await walkDir(fullPath, extensions)));
}
} else if (extensions.some((ext) => entry.name.endsWith(ext))) {
result.push(fullPath);
}
}
} catch {
logger.error(`Failed to read directory: ${dir}`);
}

return result;
}
Copy link
Preview

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recursive directory traversal could be inefficient for large directory structures. Consider adding a depth limit parameter to prevent excessive recursion and improve performance for projects with deeply nested directories.

Copilot uses AI. Check for mistakes.

@gaurav-singh-9227 gaurav-singh-9227 merged commit bd0fc04 into browserstack:main Sep 10, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants