-
Notifications
You must be signed in to change notification settings - Fork 23
Improve validation for bash and cache-memory type unions #3535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Added validateBashToolValue() function with explicit type validation - Added validateCacheMemoryToolValue() function with structure validation - Validates retention-days range (1-90) - Provides helpful error messages for common mistakes - Added unit tests for both validation functions - Added integration tests to verify compilation errors - Schema validation catches most type errors first (as designed) Co-authored-by: pelikhan <[email protected]>
Updated integration tests to only test cases that our custom validation catches (like duplicate cache IDs), since JSON schema validation catches type errors first. This is consistent with the layered validation approach. Co-authored-by: pelikhan <[email protected]>
There was a problem hiding this 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 PR introduces a new validation architecture for tool configurations in the workflow compiler, specifically for bash and cache-memory tools. The changes refactor existing validation logic to be more centralized and consistent, while adding comprehensive test coverage.
Key Changes
- Added centralized
ValidateToolsConfigurationfunction to validate tool configurations during compilation - Extracted bash validation logic into a dedicated
validateBashToolValuefunction inclaude_tools.go - Refactored cache-memory validation by extracting it into
validateCacheMemoryToolValueincache.gowith stricter type checking and field validation - Added comprehensive unit tests (
bash_validation_test.go,cache_memory_validation_test.go) and integration tests (tools_validation_integration_test.go)
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/tools_validation.go |
New centralized validation entry point that validates bash and cache-memory tool configurations |
pkg/workflow/compiler.go |
Integrated the new validation call after MCP validation and before HTTP transport validation |
pkg/workflow/claude_tools.go |
Added validateBashToolValue function with defensive validation in the engine expansion code |
pkg/workflow/cache.go |
Refactored validateCacheMemoryToolValue with stricter validation, type checking, and field validation |
pkg/workflow/bash_validation_test.go |
Comprehensive unit tests for bash tool validation covering all value types and error cases |
pkg/workflow/cache_memory_validation_test.go |
Comprehensive unit tests for cache-memory validation covering all configurations and error scenarios |
pkg/workflow/tools_validation_integration_test.go |
Integration tests verifying end-to-end compilation with various tool configurations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| entry := CacheMemoryEntry{ | ||
| ID: "default", | ||
| Key: generateDefaultCacheKey("default"), | ||
| } | ||
|
|
||
| // Parse custom key | ||
| // Validate and parse fields | ||
| if id, exists := configMap["id"]; exists { | ||
| if idStr, ok := id.(string); ok { | ||
| entry.ID = idStr | ||
| } else { | ||
| return nil, fmt.Errorf("'id' field must be a string, got %T", id) | ||
| } | ||
| } |
Copilot
AI
Nov 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: When an object configuration provides a custom id but no key, the default key generated will incorrectly use "default" as the ID instead of the custom ID.
The issue is that the key is initialized at line 67 with generateDefaultCacheKey("default") before the ID is parsed from the config (lines 71-77). This means that a configuration like:
cache-memory:
id: sessionWould generate key memory-${{ github.workflow }}-${{ github.run_id }} (using "default") instead of memory-session-${{ github.workflow }}-${{ github.run_id }}.
Suggested fix: Parse the id field first, then generate the default key based on that ID. The array configuration handling (lines 148-161) demonstrates the correct approach:
- Parse the ID
- Set default if empty
- Generate key using the final ID
| // Check for unknown fields | ||
| validFields := map[string]bool{ | ||
| "id": true, | ||
| "key": true, | ||
| "description": true, | ||
| "retention-days": true, | ||
| } | ||
| for field := range configMap { | ||
| if !validFields[field] { | ||
| return nil, fmt.Errorf("unknown field '%s'. Valid fields: id, key, description, retention-days", field) | ||
| } | ||
| } |
Copilot
AI
Nov 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code duplication: The validFields map is defined identically in three places (object handling line 113-118, and array handling line 197-202). This duplicated logic makes maintenance harder and error-prone if the valid fields ever need to change.
Consider extracting this to a package-level variable or a helper function:
var cacheMemoryValidFields = map[string]bool{
"id": true,
"key": true,
"description": true,
"retention-days": true,
}
func validateCacheMemoryFields(fields map[string]any, prefix string) error {
for field := range fields {
if !cacheMemoryValidFields[field] {
return fmt.Errorf("%sunknown field '%s'. Valid fields: id, key, description, retention-days", prefix, field)
}
}
return nil
}
Enhanced validation quality for
bashandcache-memoryfields to match the comprehensive validation already in place forpermissionsandnetworkfields.Changes
Bash field validation (
pkg/workflow/claude_tools.go)validateBashToolValue()with explicit type checking (null/boolean/array)Cache-memory field validation (
pkg/workflow/cache.go)validateCacheMemoryToolValue()with structure validationparseRetentionDays()helper for numeric type coercionIntegration (
pkg/workflow/compiler.go,pkg/workflow/tools_validation.go)ValidateToolsConfiguration()entry pointValidation Architecture
Error Message Examples
Duplicate cache IDs:
Invalid bash type:
Test Coverage
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.