Class: CovLoupe::Tools::ProjectValidateTool

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/cov_loupe/tools/project_validate_tool.rb

Constant Summary

Constants inherited from BaseTool

BaseTool::COMMON_PROPERTIES, BaseTool::DEFAULT_SORT_ORDER, BaseTool::ERROR_MODE_PROPERTY, BaseTool::FILE_INPUT_SCHEMA, BaseTool::PATH_PROPERTY, BaseTool::SORT_ORDER_PROPERTY, BaseTool::TRACKED_GLOBS_PROPERTY

Class Method Summary collapse

Methods inherited from BaseTool

call_with_file_payload, coverage_schema, create_configured_model, create_model, default_model_options, handle_mcp_error, input_schema_def, model_config_for, resolve_output_chars, respond_json, with_error_handling

Class Method Details

.call(code: nil, file: nil, root: nil, resultset: nil, raise_on_stale: nil, error_mode: 'log', output_chars: nil, server_context:) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cov_loupe/tools/project_validate_tool.rb', line 37

def call(code: nil, file: nil, root: nil, resultset: nil, raise_on_stale: nil,
  error_mode: 'log', output_chars: nil, server_context:)
  # Normalize output_chars before error handling so errors also get converted
  output_chars_sym = resolve_output_chars(output_chars, server_context)
  with_error_handling('ProjectValidateTool',
    error_mode: error_mode, output_chars: output_chars_sym) do
    model, config = create_configured_model(
      server_context: server_context,
      root:           root,
      resultset:      resultset,
      raise_on_stale: raise_on_stale
    )

    result = if code && file
      raise UsageError, "Only one of 'code' or 'file' must be provided, not both"
    elsif code
      PredicateEvaluator.evaluate_code(code, model)
    elsif file
      # Resolve file path relative to root if needed
      predicate_path = File.expand_path(file, config[:root])
      PredicateEvaluator.evaluate_file(predicate_path, model)
    else
      raise UsageError, "Either 'code' or 'file' must be provided"
    end

    respond_json({ result: result }, name: 'validate_result.json', pretty: true,
      output_chars: output_chars_sym)
  end
end