Skip to content

Extract validation functions from interactive forms - #7243

Merged
pelikhan merged 3 commits into
mainfrom
copilot/extract-validation-functions
Dec 22, 2025
Merged

Extract validation functions from interactive forms#7243
pelikhan merged 3 commits into
mainfrom
copilot/extract-validation-functions

Conversation

CopilotAI commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

Inline validation logic in the interactive workflow builder made testing and reuse difficult. This extracts validation into dedicated, testable functions.

Changes

  • New pkg/cli/validators.go: Exports ValidateWorkflowName(string) error with regex pattern for alphanumeric, hyphen, underscore validation
  • New pkg/cli/validators_test.go: 35 test cases covering valid inputs, invalid characters, edge cases, and error messages
  • Updated pkg/cli/interactive.go: Replaced inline validator with function call, removed unused imports (errors, regexp)
  • Updated pkg/cli/interactive_test.go: Refactored existing tests to use extracted function

Before/After

// Before: inline validation in form builderhuh.NewInput().
Validate(func(sstring) error {
ifs=="" {
returnerrors.New("workflow name cannot be empty")
}
if!workflowNameRegex.MatchString(s) {
returnerrors.New("workflow name must contain only alphanumeric characters, hyphens, and underscores")
}
returnnil
})
// After: reusable validation functionhuh.NewInput().
Validate(ValidateWorkflowName)

The validation behavior is unchanged. Additional validators can now be added to the same file.

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Extract validation functions from interactive forms</issue_title>
<issue_description>## Objective

Extract inline validation logic into separate, testable functions in a new pkg/cli/validators.go file.

Context

Currently, validation logic is defined inline within the form builder, making it difficult to test, reuse, and maintain. Extracting these into dedicated functions improves code quality and enables unit testing.

Approach

  1. Create pkg/cli/validators.go with exported validation functions
  2. Extract existing validation logic from interactive.go:
    • Workflow name validation (alphanumeric, hyphens, underscores)
    • Any other field validations currently inline
  3. Update the form builder to use these functions
  4. Add unit tests in pkg/cli/validators_test.go

Example structure:

// pkg/cli/validators.gopackage cli
import (
"errors""regexp"
)
varworkflowNameRegex=regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)
funcValidateWorkflowName(sstring) error {
ifs=="" {
returnerrors.New("workflow name cannot be empty")
}
if!workflowNameRegex.MatchString(s) {
returnerrors.New("workflow name must contain only alphanumeric characters, hyphens, and underscores")
}
returnnil
}
// Then in interactive.go:huh.NewInput().
Title("Workflow Name").
Value(&name).
Validate(ValidateWorkflowName)

Files to Create

  • Create: pkg/cli/validators.go - Validation functions
  • Create: pkg/cli/validators_test.go - Unit tests

Files to Modify

  • Update: pkg/cli/interactive.go - Use extracted validation functions

Acceptance Criteria

AI generated by Plan Command for discussion #7214

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.

CopilotAIand others added 2 commits December 22, 2025 13:11
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
- Created pkg/cli/validators.go with ValidateWorkflowName function
- Created pkg/cli/validators_test.go with comprehensive unit tests
- Updated pkg/cli/interactive.go to use extracted validator
- Removed inline validation logic and unused imports
- Updated existing tests to use new validation function
- All tests passing
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
CopilotAI changed the title [WIP] Extract validation functions from interactive formsExtract validation functions from interactive formsDec 22, 2025
CopilotAI requested a review from mnkieferDecember 22, 2025 13:19
@pelikhan
pelikhan marked this pull request as ready for review December 22, 2025 14:41
@pelikhan
pelikhan merged commit d4359b0 into mainDec 22, 2025
4 checks passed
@pelikhan
pelikhan deleted the copilot/extract-validation-functions branch December 22, 2025 14:46
Sign up for freeto 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] Extract validation functions from interactive forms

3 participants

@pelikhan@mnkiefer