Documentation
¶
Overview ¶
Package validate provides validation tools for the CB-56 Multi-Step Change Execution Framework. These tools enable syntax checking, test execution, and change validation before applying modifications to the codebase.
Thread Safety: All tools are safe for concurrent use.
Index ¶
- Variables
- func RegisterValidateTools(registry *tools.Registry, config *Config)
- func StaticValidateToolDefinitions() []tools.ToolDefinition
- type BreakingChangeType
- type BreakingInput
- type BreakingOutput
- type CallerInfo
- type Config
- type ImpactInput
- type ImpactOutput
- type SyntaxError
- type SyntaxInput
- type SyntaxOutput
- type SyntaxTool
- type SyntaxWarning
- type TestFailure
- type TestInput
- type TestOutput
- type TestScope
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFileNotFound is returned when a file cannot be found. ErrFileNotFound = errors.New("file not found") // ErrFileTooLarge is returned when a file exceeds the size limit. ErrFileTooLarge = errors.New("file exceeds maximum size limit") // ErrUnsupportedLanguage is returned for unsupported languages. ErrUnsupportedLanguage = errors.New("unsupported language") // ErrInvalidInput is returned for invalid input parameters. ErrInvalidInput = errors.New("invalid input") // ErrValidationTimeout is returned when validation times out. ErrValidationTimeout = errors.New("validation timed out") )
Functions ¶
func RegisterValidateTools ¶
RegisterValidateTools registers all validation tools with the registry.
Description:
Registers all CB-56 validation tools (validate_syntax, run_tests, etc.) with the provided tool registry. These tools support the Multi-Step Change Execution Framework for safe code modifications.
Inputs:
registry - The tool registry to register with. config - Configuration for validation tools.
Example:
registry := tools.NewRegistry()
config := validate.NewConfig("/path/to/project")
validate.RegisterValidateTools(registry, config)
Thread Safety: This function is safe to call once during initialization.
func StaticValidateToolDefinitions ¶
func StaticValidateToolDefinitions() []tools.ToolDefinition
StaticValidateToolDefinitions returns tool definitions without requiring config.
Description:
Returns the definitions for all validation tools. These can be used for query classification without initializing the full tool system.
Outputs:
[]tools.ToolDefinition - The static tool definitions.
Thread Safety: This function is safe for concurrent use.
Types ¶
type BreakingChangeType ¶
type BreakingChangeType string
BreakingChangeType categorizes breaking changes.
const ( // BreakingTypeSignature indicates a function signature change. BreakingTypeSignature BreakingChangeType = "signature" // BreakingTypeRemoval indicates a symbol was removed. BreakingTypeRemoval BreakingChangeType = "removal" // BreakingTypeType indicates a type change. BreakingTypeType BreakingChangeType = "type" // BreakingTypeVisibility indicates a visibility change (export -> unexport). BreakingTypeVisibility BreakingChangeType = "visibility" // BreakingTypeRename indicates a symbol rename. BreakingTypeRename BreakingChangeType = "rename" )
type BreakingInput ¶
type BreakingInput struct {
// Symbol is the symbol being changed.
Symbol string `json:"symbol"`
// ChangeType describes the kind of change.
ChangeType BreakingChangeType `json:"change_type"`
// NewValue is the new name/type/signature.
NewValue string `json:"new_value,omitempty"`
}
BreakingInput defines input for breaking change detection.
func (*BreakingInput) Validate ¶
func (i *BreakingInput) Validate() error
Validate checks if the input parameters are valid.
type BreakingOutput ¶
type BreakingOutput struct {
// IsBreaking indicates if the change is breaking.
IsBreaking bool `json:"is_breaking"`
// Severity indicates the impact level.
Severity string `json:"severity"` // low, medium, high, critical
// AffectedCallers lists callers that would break.
AffectedCallers []CallerInfo `json:"affected_callers,omitempty"`
// Suggestion provides a recommendation.
Suggestion string `json:"suggestion,omitempty"`
}
BreakingOutput contains breaking change analysis results.
type CallerInfo ¶
type CallerInfo struct {
// Name is the caller function/method name.
Name string `json:"name"`
// FilePath is where the caller is defined.
FilePath string `json:"file_path"`
// Line is the line number of the call.
Line int `json:"line"`
// Package is the caller's package.
Package string `json:"package,omitempty"`
}
CallerInfo describes a caller that would be affected.
type Config ¶
type Config struct {
// WorkingDir is the project root directory for resolving relative paths.
WorkingDir string
// MaxFileSize is the maximum file size to validate (bytes).
// Default: 10MB.
MaxFileSize int64
// Timeout is the default timeout for validation operations (seconds).
// Default: 30.
Timeout int
}
Config holds configuration for validation tools.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with sensible defaults.
type ImpactInput ¶
type ImpactInput struct {
// Symbols are the symbols being changed.
Symbols []string `json:"symbols"`
// ChangeType describes the kind of change.
ChangeType string `json:"change_type"`
}
ImpactInput defines input for impact estimation.
func (*ImpactInput) Validate ¶
func (i *ImpactInput) Validate() error
Validate checks if the input parameters are valid.
type ImpactOutput ¶
type ImpactOutput struct {
// FilesAffected is the count of files that would change.
FilesAffected int `json:"files_affected"`
// LinesEstimated is the estimated lines that would change.
LinesEstimated int `json:"lines_estimated"`
// CallersAffected is the count of affected callers.
CallersAffected int `json:"callers_affected"`
// TestsToRun is the estimated number of tests to run.
TestsToRun int `json:"tests_to_run"`
// RiskLevel indicates the change risk.
RiskLevel string `json:"risk_level"` // low, medium, high, critical
// FileList is the list of affected files.
FileList []string `json:"file_list,omitempty"`
}
ImpactOutput contains impact estimation results.
type SyntaxError ¶
type SyntaxError struct {
// Line is the 1-indexed line number.
Line int `json:"line"`
// Column is the 0-indexed column number.
Column int `json:"column"`
// Message describes the error.
Message string `json:"message"`
// ErrorType categorizes the error (syntax, missing, unexpected).
ErrorType string `json:"error_type"`
// Context is the code snippet around the error.
Context string `json:"context,omitempty"`
// Suggestion provides a fix recommendation.
Suggestion string `json:"suggestion,omitempty"`
}
SyntaxError represents a syntax error with location information.
type SyntaxInput ¶
type SyntaxInput struct {
// FilePath is the path to the file to validate.
// Can be absolute or relative to working directory.
FilePath string `json:"file_path,omitempty"`
// Content is the code content to validate.
// If provided, takes precedence over file_path.
Content string `json:"content,omitempty"`
// Language overrides language detection.
// Supported: go, python, javascript, typescript, rust, bash.
Language string `json:"language,omitempty"`
}
SyntaxInput defines input parameters for syntax validation.
func (*SyntaxInput) Validate ¶
func (i *SyntaxInput) Validate() error
Validate checks if the input parameters are valid.
type SyntaxOutput ¶
type SyntaxOutput struct {
// Valid indicates if the syntax is correct.
Valid bool `json:"valid"`
// Language is the detected or specified language.
Language string `json:"language"`
// Errors contains all syntax errors found.
Errors []SyntaxError `json:"errors,omitempty"`
// Warnings contains non-fatal syntax warnings.
Warnings []SyntaxWarning `json:"warnings,omitempty"`
// ParseTime is how long parsing took (milliseconds).
ParseTime int64 `json:"parse_time_ms"`
}
SyntaxOutput contains the result of syntax validation.
type SyntaxTool ¶
type SyntaxTool struct {
// contains filtered or unexported fields
}
SyntaxTool implements the validate_syntax tool (CB-56a).
Description:
SyntaxTool uses tree-sitter to check if code is syntactically valid before applying changes. It supports Go, Python, JavaScript, TypeScript, Rust, and Bash. Returns structured errors with line/column positions.
Thread Safety: SyntaxTool is safe for concurrent use.
func NewSyntaxTool ¶
func NewSyntaxTool(config *Config) *SyntaxTool
NewSyntaxTool creates a new validate_syntax tool.
Description:
Creates a SyntaxTool configured with the provided configuration. The config specifies the working directory for resolving relative paths.
Inputs:
config - Configuration for the syntax tool.
Outputs:
*SyntaxTool - The configured tool, never nil.
func (*SyntaxTool) Category ¶
func (t *SyntaxTool) Category() tools.ToolCategory
Category returns the tool category.
func (*SyntaxTool) Definition ¶
func (t *SyntaxTool) Definition() tools.ToolDefinition
Definition returns the tool's parameter schema.
func (*SyntaxTool) Execute ¶
func (t *SyntaxTool) Execute(ctx context.Context, params tools.TypedParams) (*tools.Result, error)
Execute validates syntax for the given file or content.
Description:
Validates code syntax using tree-sitter. Can validate either: 1. A file on disk (via file_path parameter) 2. Content provided directly (via content parameter) When both file_path and content are provided, content takes precedence.
Inputs:
ctx - Context for cancellation and tracing. params - Parameters including file_path, content, and optional language.
Outputs:
*tools.Result - Validation result with errors/warnings. error - Non-nil if validation fails catastrophically.
type SyntaxWarning ¶
type SyntaxWarning struct {
// Line is the 1-indexed line number.
Line int `json:"line"`
// Column is the 0-indexed column number.
Column int `json:"column"`
// Message describes the warning.
Message string `json:"message"`
// WarningType categorizes the warning.
WarningType string `json:"warning_type"`
}
SyntaxWarning represents a non-fatal syntax warning.
type TestFailure ¶
type TestFailure struct {
// TestName is the name of the failing test.
TestName string `json:"test_name"`
// Package is the package containing the test.
Package string `json:"package"`
// Message describes the failure.
Message string `json:"message"`
// File is the file where the failure occurred.
File string `json:"file,omitempty"`
// Line is the line number of the failure.
Line int `json:"line,omitempty"`
// Output is the test-specific output.
Output string `json:"output,omitempty"`
}
TestFailure represents a single test failure.
type TestInput ¶
type TestInput struct {
// Scope determines which tests to run.
Scope TestScope `json:"scope"`
// Target is the path, pattern, or package to test.
// Interpretation depends on scope.
Target string `json:"target"`
// Timeout is the maximum time for test execution (seconds).
Timeout int `json:"timeout,omitempty"`
// Verbose enables verbose test output.
Verbose bool `json:"verbose,omitempty"`
// Coverage enables coverage collection.
Coverage bool `json:"coverage,omitempty"`
}
TestInput defines input parameters for test execution.
type TestOutput ¶
type TestOutput struct {
// Passed is the count of passing tests.
Passed int `json:"passed"`
// Failed is the count of failing tests.
Failed int `json:"failed"`
// Skipped is the count of skipped tests.
Skipped int `json:"skipped"`
// Duration is total execution time (milliseconds).
Duration int64 `json:"duration_ms"`
// Failures contains details of failed tests.
Failures []TestFailure `json:"failures,omitempty"`
// Coverage is the coverage percentage (0-100).
Coverage float64 `json:"coverage_pct,omitempty"`
// Output is the raw test output.
Output string `json:"output"`
}
TestOutput contains the result of test execution.
type TestScope ¶
type TestScope string
TestScope defines the scope of test execution.
const ( // TestScopeFile runs tests in a single file. TestScopeFile TestScope = "file" // TestScopePackage runs tests in a package. TestScopePackage TestScope = "package" // TestScopeAffected runs tests affected by recent changes. // Uses call graph to find tests covering modified code. TestScopeAffected TestScope = "affected" // TestScopeAll runs the full test suite. TestScopeAll TestScope = "all" )