Module: Legion::Extensions::Planner::Helpers::PlanSchema

Extended by:
PlanSchema
Included in:
PlanSchema
Defined in:
lib/legion/extensions/planner/helpers/plan_schema.rb

Constant Summary collapse

SCHEMA =
{
  type:       :object,
  properties: {
    approach:          { type: :string },
    files_to_modify:   {
      type:  :array,
      items: {
        type:       :object,
        properties: {
          path:   { type: :string },
          action: { type: :string, enum: %w[modify create delete] },
          reason: { type: :string }
        },
        required:   %i[path action reason]
      }
    },
    files_to_read:     { type: :array, items: { type: :string } },
    test_strategy:     { type: :string },
    estimated_changes: { type: :integer }
  },
  required:   %i[approach files_to_modify test_strategy estimated_changes]
}.freeze

Instance Method Summary collapse

Instance Method Details

#schemaObject



33
34
35
# File 'lib/legion/extensions/planner/helpers/plan_schema.rb', line 33

def schema
  SCHEMA
end

#validate_plan(plan:) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/legion/extensions/planner/helpers/plan_schema.rb', line 37

def validate_plan(plan:)
  errors = []
  SCHEMA[:required].each do |field|
    errors << "Missing required field: #{field}" unless plan.key?(field) && !plan[field].nil?
  end

  errors << 'files_to_modify must not be empty' if plan[:files_to_modify].is_a?(Array) && plan[:files_to_modify].empty?

  errors << 'estimated_changes must be an integer' if plan.key?(:estimated_changes) && !plan[:estimated_changes].is_a?(Integer)

  { valid: errors.empty?, errors: errors }
end