agentleFS
crystal-autobotcrystal-autobot/autobot/.claude/skills/autobot-test/SKILL.md

autobot-test

Skill47 starsChanged 8 months agoMITView on GitHub

Testing guidelines for Autobot with AAA pattern and Crystal spec best practices

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 6 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Always test error paths:

    line 104
  2. Very specific:

    Avoid not_nil! in tests. Use safe nil handling instead:

    line 132
  3. Distinctive:

    Test security constraints explicitly:

    line 172
  4. Distinctive:

    Keep tests fast (< 1s per test ideally)

    line 188
  5. Very specific:

    Use before_each/after_each for setup/teardown

    line 189
  6. Distinctive:

    Avoid real network calls (mock HTTP)

    line 190
  7. Distinctive:

    Avoid real file system operations when possible

    line 191
  8. Distinctive:

    Use this skill when:

    line 205

≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Testing Standards

AAA Pattern

Structure all tests with Arrange-Act-Assert and require the spec helper:

require "../spec_helper"

describe "MyFeature" do
  it "does something expected" do
    # Arrange
    tool = Autobot::Tools::MyTool.new
    params = {"key" => JSON::Any.new("value")}
    
    # Act
    result = tool.execute(params)
    
    # Assert
    result.success?.should be_true
    result.content.should contain("expected")
  end
end

Test File Organization

Mirror source structure:

spec/
├── autobot/
│   ├── providers/
│   │   ├── http_provider_spec.cr
│   │   └── registry_spec.cr
│   ├── tools/
│   │   ├── web_spec.cr
│   │   └── exec_spec.cr
│   └── config/
│       └── schema_spec.cr
├── spec_helper.cr
└── security_spec.cr

Running Tests

# Run all tests
crystal spec

# Run specific file
crystal spec spec/autobot/tools/web_spec.cr

# Run specific test by line number
crystal spec spec/autobot/tools/web_spec.cr:42

# Run with verbose output
crystal spec -v

# Run with color (default)
crystal spec --color

Mocking External Services

HTTP Provider Mocking:

class MockHttpProvider < Autobot::Providers::HttpProvider
  property responses = [] of HTTP::Client::Response
  property call_count = 0

  def post(path : String, body : Hash) : HTTP::Client::Response
    @call_count += 1
    responses.shift? || HTTP::Client::Response.new(500, body: "{}").tap { |r| r.consume_body_io }
  end
end

Tool Execution Mocking:

# Use dependency injection or monkey-patch for tests
class TestableExecTool < Autobot::Tools::ExecTool
  property captured_commands = [] of String

  def execute_system_command(cmd)
    @captured_commands << cmd
    {output: "mock output", exit_code: 0}
  end
end

Testing Error Conditions

Always test error paths:

it "handles missing parameters" do
  tool = Autobot::Tools::MyTool.new
  result = tool.execute({} of String => JSON::Any)
  
  result.error?.should be_true
  result.content.should contain("missing")
end

it "handles rate limiting" do
  limiter = Autobot::Tools::RateLimiter.new(
    per_tool_limits: {"exec" => Autobot::Tools::RateLimiter::Limit.new(
      max_calls: 1,
      window_seconds: 60
    )}
  )
  
  limiter.record_call("exec", "session")
  error = limiter.check_limit("exec", "session")
  
  error.should_not be_nil
  error.should contain("max 1 calls")
end

Avoiding not_nil!

Avoid not_nil! in tests. Use safe nil handling instead:

# Bad
result.content.not_nil!.should contain("text")

# Good
if content = result.content
  content.should contain("text")
else
  fail("Expected content to not be nil")
end

Shared Examples

For common test patterns:

macro test_provider_interface
  describe "provider interface" do
    it "returns a name" do
      provider.name.should be_a(String)
      provider.name.should_not be_empty
    end

    it "returns a display name" do
      provider.display_name.should be_a(String)
    end
  end
end

# Usage
describe Autobot::Providers::MyProvider do
  provider = Autobot::Providers::MyProvider.new(api_key: "test")
  test_provider_interface
end

Security Testing

Test security constraints explicitly:

describe "SSRF protection" do
  it "blocks private IPs" do
    tool = Autobot::Tools::WebFetchTool.new
    
    %w[http://127.0.0.1/secret http://10.0.0.1/].each do |url|
      result = tool.execute({"url" => JSON::Any.new(url)})
      result.access_denied?.should be_true
    end
  end
end

Test Performance

  • Keep tests fast (< 1s per test ideally)
  • Use before_each/after_each for setup/teardown
  • Avoid real network calls (mock HTTP)
  • Avoid real file system operations when possible

Coverage

Test these scenarios:

  • Happy path (normal operation)
  • Invalid inputs
  • Missing required parameters
  • Error conditions (network, auth, etc.)
  • Edge cases (empty strings, max values, etc.)
  • Security constraints (private IPs, path traversal, etc.)

When to Use

Use this skill when:

  • Writing new tests
  • Debugging test failures
  • Refactoring test code
  • Setting up test infrastructure
  • Reviewing test coverage

Related Skills: autobot-tool, autobot-provider

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.