validateRuntimePackages validates that packages required by npx, pip, and uv are available
(workflowData *WorkflowData)
| 250 | |
| 251 | // validateRuntimePackages validates that packages required by npx, pip, and uv are available |
| 252 | func (c *Compiler) validateRuntimePackages(workflowData *WorkflowData) error { |
| 253 | // Detect runtime requirements |
| 254 | requirements := DetectRuntimeRequirements(workflowData) |
| 255 | runtimeValidationLog.Printf("Validating runtime packages: found %d runtime requirements", len(requirements)) |
| 256 | |
| 257 | var errors []string |
| 258 | if err := c.validateMCPScriptDependencies(workflowData); err != nil { |
| 259 | errors = append(errors, err.Error()) |
| 260 | } |
| 261 | |
| 262 | for _, req := range requirements { |
| 263 | switch req.Runtime.ID { |
| 264 | case "node": |
| 265 | // Validate npx packages used in the workflow |
| 266 | runtimeValidationLog.Print("Validating npx packages") |
| 267 | if err := c.validateNpxPackages(workflowData); err != nil { |
| 268 | if isErrNpmNotAvailable(err) { |
| 269 | // npm is not installed on this system — treat as a warning, not an error. |
| 270 | // The workflow may still compile and run successfully in environments |
| 271 | // that have npm (e.g., GitHub Actions). |
| 272 | runtimeValidationLog.Print("npm not available, skipping npx package validation") |
| 273 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage("npm not found, skipping npx package validation")) |
| 274 | c.IncrementWarningCount() |
| 275 | } else { |
| 276 | runtimeValidationLog.Printf("Npx package validation failed: %v", err) |
| 277 | errors = append(errors, err.Error()) |
| 278 | } |
| 279 | } |
| 280 | case "python": |
| 281 | // Validate pip packages used in the workflow |
| 282 | runtimeValidationLog.Print("Validating pip packages") |
| 283 | if err := c.validatePipPackages(workflowData); err != nil { |
| 284 | runtimeValidationLog.Printf("Pip package validation failed: %v", err) |
| 285 | errors = append(errors, err.Error()) |
| 286 | } |
| 287 | case "uv": |
| 288 | // Validate uv packages used in the workflow |
| 289 | runtimeValidationLog.Print("Validating uv packages") |
| 290 | if err := c.validateUvPackages(workflowData); err != nil { |
| 291 | runtimeValidationLog.Printf("Uv package validation failed: %v", err) |
| 292 | errors = append(errors, err.Error()) |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | if len(errors) > 0 { |
| 298 | runtimeValidationLog.Printf("Runtime package validation completed with %d errors", len(errors)) |
| 299 | return NewValidationError( |
| 300 | "runtime.packages", |
| 301 | fmt.Sprintf("%d package validation errors", len(errors)), |
| 302 | "runtime package validation failed", |
| 303 | fmt.Sprintf("Fix the following package issues:\n\n%s\n\nEnsure:\n1. Package names are spelled correctly\n2. Packages exist in their respective registries (npm, PyPI)\n3. Package managers (npm, pip, uv) are installed\n4. Network access is available for registry checks", strings.Join(errors, "\n")), |
| 304 | ) |
| 305 | } |
| 306 | |
| 307 | runtimeValidationLog.Print("Runtime package validation passed") |
| 308 | return nil |
| 309 | } |