1+ #!/usr/bin/env node
2+
3+ /**
4+ * Basic validation script for Playwright MCP YAML template
5+ * Validates the YAML structure and schema compliance
6+ */
7+
8+ import fs from 'fs' ;
9+ import path from 'path' ;
10+ import yaml from 'yaml' ;
11+ import { fileURLToPath } from 'url' ;
12+
13+ const __filename = fileURLToPath ( import . meta. url ) ;
14+ const __dirname = path . dirname ( __filename ) ;
15+
16+ // Simple validation function - in production you'd want to import the actual schemas
17+ function validatePlaywrightTemplate ( ) {
18+ try {
19+ // Path to the YAML template
20+ const templatePath = path . join ( __dirname , '../playwright-mcp-integration/playwright-mcp.yaml' ) ;
21+
22+ console . log ( '🔍 Validating Playwright MCP template...' ) ;
23+ console . log ( `📁 Template path: ${ templatePath } ` ) ;
24+
25+ // Check if file exists
26+ if ( ! fs . existsSync ( templatePath ) ) {
27+ console . error ( '❌ Template file not found at:' , templatePath ) ;
28+ process . exit ( 1 ) ;
29+ }
30+
31+ // Read and parse YAML
32+ const templateContent = fs . readFileSync ( templatePath , 'utf-8' ) ;
33+ const parsedTemplate = yaml . parse ( templateContent ) ;
34+
35+ // Basic structure validation
36+ if ( ! parsedTemplate || typeof parsedTemplate !== 'object' ) {
37+ console . error ( '❌ Invalid YAML structure' ) ;
38+ process . exit ( 1 ) ;
39+ }
40+
41+ if ( ! parsedTemplate . items || ! Array . isArray ( parsedTemplate . items ) ) {
42+ console . error ( '❌ Missing or invalid items array' ) ;
43+ process . exit ( 1 ) ;
44+ }
45+
46+ if ( parsedTemplate . items . length === 0 ) {
47+ console . error ( '❌ No items found in template' ) ;
48+ process . exit ( 1 ) ;
49+ }
50+
51+ // Validate the first (and expected only) item
52+ const mcpItem = parsedTemplate . items [ 0 ] ;
53+
54+ // Check required fields
55+ const requiredFields = [ 'id' , 'type' , 'name' , 'description' , 'url' , 'content' ] ;
56+ for ( const field of requiredFields ) {
57+ if ( ! mcpItem [ field ] ) {
58+ console . error ( `❌ Missing required field: ${ field } ` ) ;
59+ process . exit ( 1 ) ;
60+ }
61+ }
62+
63+ // Validate type
64+ if ( mcpItem . type !== 'mcp' ) {
65+ console . error ( `❌ Invalid type. Expected 'mcp', got '${ mcpItem . type } '` ) ;
66+ process . exit ( 1 ) ;
67+ }
68+
69+ // Validate content structure
70+ if ( ! Array . isArray ( mcpItem . content ) ) {
71+ console . error ( '❌ Content must be an array of installation methods' ) ;
72+ process . exit ( 1 ) ;
73+ }
74+
75+ // Validate each installation method
76+ for ( let i = 0 ; i < mcpItem . content . length ; i ++ ) {
77+ const method = mcpItem . content [ i ] ;
78+
79+ if ( ! method . name || ! method . content ) {
80+ console . error ( `❌ Installation method ${ i + 1 } missing name or content` ) ;
81+ process . exit ( 1 ) ;
82+ }
83+
84+ // Validate JSON content
85+ try {
86+ const parsedContent = JSON . parse ( method . content ) ;
87+ if ( ! parsedContent . command || ! parsedContent . args ) {
88+ console . error ( `❌ Installation method '${ method . name } ' missing command or args` ) ;
89+ process . exit ( 1 ) ;
90+ }
91+ } catch ( error ) {
92+ console . error ( `❌ Invalid JSON in installation method '${ method . name } ':` , error . message ) ;
93+ process . exit ( 1 ) ;
94+ }
95+ }
96+
97+ // Validate URL format
98+ try {
99+ new URL ( mcpItem . url ) ;
100+ } catch ( error ) {
101+ console . error ( `❌ Invalid URL format: ${ mcpItem . url } ` ) ;
102+ process . exit ( 1 ) ;
103+ }
104+
105+ console . log ( '✅ Template validation passed!' ) ;
106+ console . log ( `📋 Found ${ mcpItem . content . length } installation methods` ) ;
107+ console . log ( `🔗 URL: ${ mcpItem . url } ` ) ;
108+ console . log ( `👤 Author: ${ mcpItem . author || 'Not specified' } ` ) ;
109+
110+ return true ;
111+
112+ } catch ( error ) {
113+ console . error ( '❌ Validation failed:' , error . message ) ;
114+ process . exit ( 1 ) ;
115+ }
116+ }
117+
118+ // Run validation if this script is executed directly
119+ if ( import . meta. url === `file://${ process . argv [ 1 ] } ` ) {
120+ validatePlaywrightTemplate ( ) ;
121+ }
122+
123+ export { validatePlaywrightTemplate } ;
0 commit comments