Class: Aidp::Harness::ConfigValidator
- Inherits:
-
Object
- Object
- Aidp::Harness::ConfigValidator
- Defined in:
- lib/aidp/harness/config_validator.rb
Overview
Configuration validator for harness
Instance Method Summary collapse
-
#config_exists? ⇒ Boolean
Check if configuration file exists.
-
#config_file_path ⇒ Object
Get configuration file path.
-
#create_example_config ⇒ Object
Create example configuration file.
-
#errors ⇒ Object
Get validation errors.
-
#export_config(format = :yaml) ⇒ Object
Export configuration to different formats.
-
#fix_common_issues ⇒ Object
Fix common configuration issues.
-
#harness_config ⇒ Object
Get harness configuration with defaults.
-
#initialize(project_dir = Dir.pwd) ⇒ ConfigValidator
constructor
A new instance of ConfigValidator.
-
#load_and_validate ⇒ Object
Load and validate configuration.
-
#provider_config(provider_name) ⇒ Object
Get provider configuration with defaults.
-
#provider_configured?(provider_name) ⇒ Boolean
Check if provider is properly configured.
-
#summary ⇒ Object
Get configuration summary.
-
#valid? ⇒ Boolean
Check if configuration is valid.
-
#validate_config(config_data = nil) ⇒ Object
Validate configuration data (public method for external use).
-
#validate_existing ⇒ Object
Validate existing configuration.
-
#validate_provider(provider_name) ⇒ Object
Validate specific provider configuration.
-
#validated_config ⇒ Object
Get configuration with defaults applied.
-
#warnings ⇒ Object
Get validation warnings.
Constructor Details
#initialize(project_dir = Dir.pwd) ⇒ ConfigValidator
Returns a new instance of ConfigValidator.
11 12 13 14 15 16 |
# File 'lib/aidp/harness/config_validator.rb', line 11 def initialize(project_dir = Dir.pwd) @project_dir = project_dir @config_file = find_config_file @config = nil @validation_result = nil end |
Instance Method Details
#config_exists? ⇒ Boolean
Check if configuration file exists
71 72 73 |
# File 'lib/aidp/harness/config_validator.rb', line 71 def config_exists? !@config_file.nil? end |
#config_file_path ⇒ Object
Get configuration file path
66 67 68 |
# File 'lib/aidp/harness/config_validator.rb', line 66 def config_file_path @config_file end |
#create_example_config ⇒ Object
Create example configuration file
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/aidp/harness/config_validator.rb', line 76 def create_example_config return false if config_exists? example_config = ConfigSchema.generate_example config_path = Aidp::ConfigPaths.config_file(@project_dir) Aidp::ConfigPaths.ensure_config_dir(@project_dir) File.write(config_path, YAML.dump(example_config)) true end |
#errors ⇒ Object
Get validation errors
56 57 58 |
# File 'lib/aidp/harness/config_validator.rb', line 56 def errors @validation_result&.dig(:errors) || [] end |
#export_config(format = :yaml) ⇒ Object
Export configuration to different formats
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/aidp/harness/config_validator.rb', line 210 def export_config(format = :yaml) return nil unless @config_file load_config validate_config config = validated_config return nil unless config case format when :yaml YAML.dump(config) when :json require "json" JSON.pretty_generate(config) when :ruby "CONFIG = #{config.inspect}" else raise ArgumentError, "Unsupported format: #{format}" end end |
#fix_common_issues ⇒ Object
Fix common configuration issues
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/aidp/harness/config_validator.rb', line 88 def fix_common_issues return false unless @config_file && @config original_config = @config.dup # Fix string/symbol key inconsistencies @config = normalize_keys(@config) # Apply missing defaults @config = ConfigSchema.apply_defaults(@config) # Fix common validation issues fix_validation_issues # Check if any changes were made if @config != original_config # Write fixed configuration back to file File.write(@config_file, YAML.dump(@config)) true else false end end |
#harness_config ⇒ Object
Get harness configuration with defaults
198 199 200 201 202 203 204 205 206 207 |
# File 'lib/aidp/harness/config_validator.rb', line 198 def harness_config return nil unless @config_file load_config harness_config = @config[:harness] || @config["harness"] || {} # Apply defaults harness_schema = ConfigSchema::SCHEMA[:harness] ConfigSchema.apply_section_defaults(harness_config, harness_schema) end |
#load_and_validate ⇒ Object
Load and validate configuration
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/aidp/harness/config_validator.rb', line 19 def load_and_validate unless @config_file @validation_result = { valid: false, errors: ["No configuration file found"], warnings: [] } return @validation_result end load_config validate_config @validation_result end |
#provider_config(provider_name) ⇒ Object
Get provider configuration with defaults
160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/aidp/harness/config_validator.rb', line 160 def provider_config(provider_name) return nil unless @config_file load_config providers_config = @config[:providers] || @config["providers"] || {} provider_config = providers_config[provider_name] || providers_config[provider_name.to_sym] return nil unless provider_config # Apply defaults for this provider providers_schema = ConfigSchema::SCHEMA[:providers][:pattern_properties][/^[a-zA-Z0-9_-]+$/] ConfigSchema.apply_section_defaults(provider_config, providers_schema) end |
#provider_configured?(provider_name) ⇒ Boolean
Check if provider is properly configured
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/aidp/harness/config_validator.rb', line 175 def provider_configured?(provider_name) return false unless @config_file load_config providers_config = @config[:providers] || @config["providers"] || {} provider_config = providers_config[provider_name] || providers_config[provider_name.to_sym] return false unless provider_config # Basic validation provider_type = provider_config[:type] || provider_config["type"] return false unless provider_type # For usage-based providers, check for required fields if provider_type == "usage_based" max_tokens = provider_config[:max_tokens] || provider_config["max_tokens"] return false unless max_tokens&.positive? end true end |
#summary ⇒ Object
Get configuration summary
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/aidp/harness/config_validator.rb', line 113 def summary return {error: "No configuration file found"} unless @config_file load_config summary = { config_file: @config_file, valid: valid?, errors_count: errors.size, warnings_count: warnings.size, harness_configured: !(@config[:harness] || @config["harness"]).nil?, providers_count: 0, providers: [] } providers_config = @config[:providers] || @config["providers"] || {} summary[:providers_count] = providers_config.size summary[:providers] = providers_config.keys.map(&:to_s) summary end |
#valid? ⇒ Boolean
Check if configuration is valid
51 52 53 |
# File 'lib/aidp/harness/config_validator.rb', line 51 def valid? @validation_result&.dig(:valid) || false end |
#validate_config(config_data = nil) ⇒ Object
Validate configuration data (public method for external use)
232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/aidp/harness/config_validator.rb', line 232 def validate_config(config_data = nil) if config_data # Validate provided configuration data @config = config_data end return unless @config # Don't override validation result if it was already set due to loading errors return if @validation_result && !@validation_result[:valid] @validation_result = ConfigSchema.validate(@config) end |
#validate_existing ⇒ Object
Validate existing configuration
35 36 37 38 39 40 41 |
# File 'lib/aidp/harness/config_validator.rb', line 35 def validate_existing return {valid: false, errors: ["No configuration file found"], warnings: []} unless @config_file load_config validate_config @validation_result end |
#validate_provider(provider_name) ⇒ Object
Validate specific provider configuration
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/aidp/harness/config_validator.rb', line 135 def validate_provider(provider_name) return {valid: false, errors: ["No configuration file found"], warnings: []} unless @config_file load_config providers_config = @config[:providers] || @config["providers"] || {} provider_config = providers_config[provider_name] || providers_config[provider_name.to_sym] return {valid: false, errors: ["Provider '#{provider_name}' not found"], warnings: []} unless provider_config # Create a minimal config with harness section and just this provider for validation test_config = { harness: { max_retries: 2, default_provider: provider_name, fallback_providers: [provider_name] }, providers: { provider_name => provider_config } } ConfigSchema.validate(test_config) end |
#validated_config ⇒ Object
Get configuration with defaults applied
44 45 46 47 48 |
# File 'lib/aidp/harness/config_validator.rb', line 44 def validated_config return nil unless @validation_result&.dig(:valid) ConfigSchema.apply_defaults(@config) end |
#warnings ⇒ Object
Get validation warnings
61 62 63 |
# File 'lib/aidp/harness/config_validator.rb', line 61 def warnings @validation_result&.dig(:warnings) || [] end |