Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/issue-classifier.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .github/workflows/release.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/stale-repo-identifier.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/super-linter.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions pkg/workflow/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ func (c *Compiler) extractCacheMemoryConfig(toolsConfig *ToolsConfig) (*CacheMem
entry.RetentionDays = &retentionDaysIntValue
}
// Validate retention-days bounds
if entry.RetentionDays != nil && (*entry.RetentionDays < 1 || *entry.RetentionDays > 90) {
return nil, fmt.Errorf("retention-days must be between 1 and 90, got %d", *entry.RetentionDays)
if entry.RetentionDays != nil {
if err := validateIntRange(*entry.RetentionDays, 1, 90, "retention-days"); err != nil {
return nil, err
}
}
}

Expand Down Expand Up @@ -189,8 +191,10 @@ func (c *Compiler) extractCacheMemoryConfig(toolsConfig *ToolsConfig) (*CacheMem
entry.RetentionDays = &retentionDaysIntValue
}
// Validate retention-days bounds
if entry.RetentionDays != nil && (*entry.RetentionDays < 1 || *entry.RetentionDays > 90) {
return nil, fmt.Errorf("retention-days must be between 1 and 90, got %d", *entry.RetentionDays)
if entry.RetentionDays != nil {
if err := validateIntRange(*entry.RetentionDays, 1, 90, "retention-days"); err != nil {
return nil, err
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/workflow/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func validateAndNormalizePort(port int) (int, error) {
}

// Validate port is in valid range (1-65535)
if port < 1 || port > 65535 {
return 0, fmt.Errorf("port must be between 1 and 65535, got %d", port)
if err := validateIntRange(port, 1, 65535, "port"); err != nil {
return 0, err
}

return port, nil
Expand Down
16 changes: 8 additions & 8 deletions pkg/workflow/repo_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
entry.MaxFileSize = int(sizeUint64)
}
// Validate max-file-size bounds
if entry.MaxFileSize < 1 || entry.MaxFileSize > 104857600 {
return nil, fmt.Errorf("max-file-size must be between 1 and 104857600 bytes, got %d", entry.MaxFileSize)
if err := validateIntRange(entry.MaxFileSize, 1, 104857600, "max-file-size"); err != nil {
return nil, err
}
}

Expand All @@ -181,8 +181,8 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
entry.MaxFileCount = int(countUint64)
}
// Validate max-file-count bounds
if entry.MaxFileCount < 1 || entry.MaxFileCount > 1000 {
return nil, fmt.Errorf("max-file-count must be between 1 and 1000, got %d", entry.MaxFileCount)
if err := validateIntRange(entry.MaxFileCount, 1, 1000, "max-file-count"); err != nil {
return nil, err
}
}

Expand Down Expand Up @@ -262,8 +262,8 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
entry.MaxFileSize = int(sizeUint64)
}
// Validate max-file-size bounds
if entry.MaxFileSize < 1 || entry.MaxFileSize > 104857600 {
return nil, fmt.Errorf("max-file-size must be between 1 and 104857600 bytes, got %d", entry.MaxFileSize)
if err := validateIntRange(entry.MaxFileSize, 1, 104857600, "max-file-size"); err != nil {
return nil, err
}
}

Expand All @@ -277,8 +277,8 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
entry.MaxFileCount = int(countUint64)
}
// Validate max-file-count bounds
if entry.MaxFileCount < 1 || entry.MaxFileCount > 1000 {
return nil, fmt.Errorf("max-file-count must be between 1 and 1000, got %d", entry.MaxFileCount)
if err := validateIntRange(entry.MaxFileCount, 1, 1000, "max-file-count"); err != nil {
return nil, err
}
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/workflow/repo_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,25 +366,25 @@ func TestRepoMemoryMaxFileSizeValidation(t *testing.T) {
name: "invalid zero size",
maxFileSize: 0,
wantError: true,
errorText: "max-file-size must be between 1 and 104857600 bytes, got 0",
errorText: "max-file-size must be between 1 and 104857600, got 0",
},
{
name: "invalid negative size",
maxFileSize: -1,
wantError: true,
errorText: "max-file-size must be between 1 and 104857600 bytes, got -1",
errorText: "max-file-size must be between 1 and 104857600, got -1",
},
{
name: "invalid size exceeds maximum",
maxFileSize: 104857601,
wantError: true,
errorText: "max-file-size must be between 1 and 104857600 bytes, got 104857601",
errorText: "max-file-size must be between 1 and 104857600, got 104857601",
},
{
name: "invalid large size",
maxFileSize: 200000000,
wantError: true,
errorText: "max-file-size must be between 1 and 104857600 bytes, got 200000000",
errorText: "max-file-size must be between 1 and 104857600, got 200000000",
},
}

Expand Down Expand Up @@ -445,13 +445,13 @@ func TestRepoMemoryMaxFileSizeValidationArray(t *testing.T) {
name: "invalid size in array (zero)",
maxFileSize: 0,
wantError: true,
errorText: "max-file-size must be between 1 and 104857600 bytes, got 0",
errorText: "max-file-size must be between 1 and 104857600, got 0",
},
{
name: "invalid size in array (exceeds max)",
maxFileSize: 104857601,
wantError: true,
errorText: "max-file-size must be between 1 and 104857600 bytes, got 104857601",
errorText: "max-file-size must be between 1 and 104857600, got 104857601",
},
}

Expand Down
38 changes: 38 additions & 0 deletions pkg/workflow/validation_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Package workflow provides validation helper functions for agentic workflow compilation.
//
// This file contains reusable validation helpers for common validation patterns
// such as integer range validation, used across multiple workflow configuration
// validation functions.
//
// For the validation architecture overview, see validation.go.
package workflow

import "fmt"

// validateIntRange validates that a value is within the specified inclusive range [min, max].
// It returns an error if the value is outside the range, with a descriptive message
// including the field name and the actual value.
//
// Parameters:
// - value: The integer value to validate
// - min: The minimum allowed value (inclusive)
// - max: The maximum allowed value (inclusive)
// - fieldName: A human-readable name for the field being validated (used in error messages)
//
// Returns:
// - nil if the value is within range
// - error with a descriptive message if the value is outside the range
//
// Example:
//
// err := validateIntRange(port, 1, 65535, "port")
// if err != nil {
// return err
// }
func validateIntRange(value, min, max int, fieldName string) error {
if value < min || value > max {
return fmt.Errorf("%s must be between %d and %d, got %d",
fieldName, min, max, value)
}
return nil
}
Loading