Class: OllamaChat::Tools::RunTests

Inherits:
Object
  • Object
show all
Includes:
Concern
Defined in:
lib/ollama_chat/tools/run_tests.rb

Overview

Tool for executing RSpec / Test‑Unit test suites.

The tool is registered under the name “run_tests“ and exposes a single function that accepts a “path“ (file or directory) and an optional “coverage“ flag. The implementation simply spawns the configured test runner (RSpec or Minitest) and streams its output back to the caller.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concern

#name, #to_hash, #valid_json?

Class Method Details

.register_nameString

Register the tool name used by the OllamaChat runtime.

Returns:

  • (String)


12
# File 'lib/ollama_chat/tools/run_tests.rb', line 12

def self.register_name = 'run_tests'

Instance Method Details

#execute(tool_call, **opts) ⇒ String

Execute the tool with the provided arguments.

Parameters:

  • tool_call (ToolCall)

    the tool invocation containing arguments

  • opts (Hash)

    additional options (currently unused)

Returns:

  • (String)

    JSON containing “success“, “path“, “output“ and “status“



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ollama_chat/tools/run_tests.rb', line 45

def execute(tool_call, **opts)
  path            = tool_call.function.arguments.path
  coverage        = tool_call.function.arguments.coverage || false
  output, success = run_tests(path, coverage)
  {
    success: success,
    path: path,
    output: output,
    status: success ? 'passed' : 'failed'
  }.to_json
end

#toolTool

Build the OpenAI function schema for the tool.

Returns:

  • (Tool)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ollama_chat/tools/run_tests.rb', line 16

def tool
  Tool.new(
    type: 'function',
    function: Tool::Function.new(
      name: 'run_tests',
      description: 'Run RSpec / Test-Unit tests for a file or directory path',
      parameters: Tool::Function::Parameters.new(
        type: 'object',
        properties: {
          path: Tool::Function::Parameters::Property.new(
            type: 'string',
            description: 'Path to file or directory to run tests for (default: spec/)'
          ),
          coverage: Tool::Function::Parameters::Property.new(
            type: 'boolean',
            description: 'True if coverage data should be created, (default: false)'
          )
        },
        required: %w[ path ]
      )
    )
  )
end