Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 24, 2025

Eliminates duplicated validation code across port, max-file-size, max-file-count, and retention-days constraints by introducing a reusable helper.

Changes

New validation helper (pkg/workflow/validation_helpers.go)

  • validateIntRange(value, min, max int, fieldName string) error - Single source of truth for range validation
  • Consistent error message format across all constraints

Refactored validations

  • Port (gateway.go): 1-65535
  • Max-file-size (repo_memory.go): 1-104857600 bytes
  • Max-file-count (repo_memory.go): 1-1000 files
  • Retention-days (cache.go): 1-90 days

Before:

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)
}

After:

if err := validateIntRange(entry.MaxFileSize, 1, 104857600, "max-file-size"); err != nil {
    return nil, err
}

Test coverage

  • 28 new test cases for validation helper (boundary conditions + real-world constraints)
  • Existing test suites verified: 39 tests covering all 4 fields with min/max/zero/negative/overflow cases
Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Create validation helpers and boundary tests</issue_title>
<issue_description>## Objective

Create reusable validation helper functions and comprehensive boundary value tests for the 4 newly validated constraint fields.

Context

After fixing the 4 specific constraint validations, we need:

  1. Reusable validation helpers to prevent code duplication
  2. Comprehensive tests to ensure boundary conditions are properly handled
  3. Documentation of validation patterns for future development

Approach

Part 1: Validation Helpers

Create validation utility functions in appropriate location (e.g., pkg/workflow/validation.go or new pkg/workflow/validation_helpers.go):

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
}

Part 2: Unit Tests

Create or update test files to cover boundary conditions for each field:

  • pkg/workflow/gateway_test.go - Port validation tests
  • pkg/workflow/repo_memory_test.go - File size/count/retention tests

Test cases for each field:

  • Minimum valid value (should pass)
  • Maximum valid value (should pass)
  • Below minimum (should fail with clear error)
  • Above maximum (should fail with clear error)
  • Zero value (should fail if minimum > 0)
  • Negative value (should fail)

Files to Create/Modify

  • Create or update: pkg/workflow/validation_helpers.go - Reusable validation functions
  • Update: pkg/workflow/gateway_test.go - Port boundary tests
  • Update: pkg/workflow/repo_memory_test.go - File size/count/retention boundary tests

Acceptance Criteria

  • Validation helper function created and documented
  • Port field has 6+ test cases (min, max, below, above, zero, negative)
  • Max-file-size field has 6+ test cases
  • Max-file-count field has 6+ test cases
  • Retention-days field has 6+ test cases
  • All tests pass with make test-unit
  • Code coverage maintained or improved
    Related to [plan] Fix missing constraint validations in parser/compiler #7524

AI generated by Plan Command for discussion #7454

Comments on the Issue (you are @copilot in this section)


💡 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.

- Create pkg/workflow/validation_helpers.go with reusable validateIntRange function
- Create comprehensive tests in validation_helpers_test.go (12 basic + 16 real-world test cases)
- Refactor port validation in gateway.go to use helper
- Refactor max-file-size validation in repo_memory.go to use helper (2 locations)
- Refactor max-file-count validation in repo_memory.go to use helper (2 locations)
- Refactor retention-days validation in cache.go to use helper (2 locations)
- Update error messages in repo_memory_test.go to match new format
- All refactored validations maintain same behavior with cleaner code

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Create validation helpers and boundary tests Add validation helpers and refactor constraint validations Dec 24, 2025
Copilot AI requested a review from mnkiefer December 24, 2025 23:09
@pelikhan pelikhan marked this pull request as ready for review December 24, 2025 23:40
@pelikhan pelikhan merged commit c3ee441 into main Dec 24, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/create-validation-helpers-tests branch December 24, 2025 23:40
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.

[plan] Create validation helpers and boundary tests

3 participants