Class: Woods::Resilience::IndexValidator

Inherits:
Object
  • Object
show all
Includes:
FilenameUtils
Defined in:
lib/woods/resilience/index_validator.rb

Overview

Validates the integrity of a codebase index output directory.

Checks that:

  • Each type directory has a valid ‘_index.json`

  • All files referenced in the index exist on disk

  • Content hashes (source_hash) match the actual source_code

  • No stale unit files exist that aren’t listed in the index

Examples:

validator = IndexValidator.new(index_dir: "tmp/woods")
report = validator.validate
puts report.errors if !report.valid?

Defined Under Namespace

Classes: ValidationReport

Instance Method Summary collapse

Methods included from FilenameUtils

#collision_safe_filename, #safe_filename

Constructor Details

#initialize(index_dir:) ⇒ IndexValidator

Returns a new instance of IndexValidator.

Parameters:

  • index_dir (String)

    Path to the codebase index output directory



34
35
36
# File 'lib/woods/resilience/index_validator.rb', line 34

def initialize(index_dir:)
  @index_dir = index_dir
end

Instance Method Details

#validateValidationReport

Validate the index directory and return a report.

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/woods/resilience/index_validator.rb', line 41

def validate
  warnings = []
  errors = []

  unless Dir.exist?(@index_dir)
    errors << "Index directory does not exist: #{@index_dir}"
    return ValidationReport.new(valid?: false, warnings: warnings, errors: errors)
  end

  type_dirs = Dir.children(@index_dir).filter_map do |name|
    full_path = File.join(@index_dir, name)
    full_path if File.directory?(full_path)
  end

  type_dirs.each do |type_dir|
    validate_type_directory(type_dir, warnings, errors)
  end

  ValidationReport.new(valid?: errors.empty?, warnings: warnings, errors: errors)
end