Skip to content

Add Rails engine for remote eval server#114

Merged
David Elner (delner) merged 6 commits intomainfrom
eval-server-rails-engine
Mar 19, 2026
Merged

Add Rails engine for remote eval server#114
David Elner (delner) merged 6 commits intomainfrom
eval-server-rails-engine

Conversation

@Qard
Copy link
Contributor

Summary

  • Extracts Services::ListService and Services::EvalService from the existing Rack handlers so business logic is shared between the Rack and Rails adapters with no duplication
  • Adds Braintrust::Server::Rails::Engine — a mountable Rails::Engine using ActionController::API and ActionController::Live for SSE streaming
  • Reuses existing auth strategies (ClerkToken, NoAuth) and CORS middleware unchanged
  • Adds a rails-server appraisal (actionpack ~> 8.0, rack-test) and full test coverage for services and engine controllers

Usage

# config/initializers/braintrust_server.rb
require "braintrust/server/rails"

Braintrust::Server::Rails::Engine.configure do |config|
  config.evaluators = { "my-eval" => MyEval.new }
  config.auth = :clerk_token  # or :none
end

# config/routes.rb
mount Braintrust::Server::Rails::Engine, at: "/braintrust"

Test plan

  • bundle exec appraisal server rake test — existing Rack server tests pass (0 failures)
  • bundle exec appraisal rails-server rake test — new Rails engine tests pass (0 failures)
  • bundle exec standardrb — linting clean

🤖 Generated with Claude Code

Copy link
Collaborator

@delner David Elner (delner) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think this is off to a great start! I left some comments of some changes that are probably worth making, the most important of which would be sorting out names/namespaces.

I also would request that we add:

  1. A readme update: probably to the existing Dev Server section, perhaps as its own subsection. We can highlight Running as a Rack app vs Running as a Rails Engine.
  2. A Rails generator that scans the evaluators/ folder and generates the braintrust_server config for the Engine: presumably it would link "slug --> Evaluator class" for each found where the slug is a formatted class name by default. The sum UX would then be (1) define your Evaluators in evaluators/ then (2) run the generator.

Copy link
Collaborator

@delner David Elner (delner) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good! I particularly like the service object helpers. Most of my code feedback is minor. The only change I think we should make before merging this is adding something to the README. Otherwise I'm happy with this.

Stephen Belanger (Qard) and others added 6 commits March 19, 2026 19:04
Exposes the same eval dev server endpoints (health, list, eval) as a
mountable Rails engine so Rails apps can embed the server without a
separate Rack process.

- Extract Services::ListService and Services::EvalService from Rack
  handlers so business logic is shared between Rack and Rails adapters
- Add Braintrust::Server::Rails::Engine (ActionController::API,
  ActionController::Live for SSE streaming, isolate_namespace)
- Reuse existing auth strategies and CORS middleware unchanged
- Add rails-server appraisal (actionpack ~> 8.0 + rack-test)
- Add service unit tests and Rails engine/controller integration tests

Usage:
  # config/initializers/braintrust_server.rb
  Braintrust::Server::Rails::Engine.configure do |config|
    config.evaluators = { "my-eval" => MyEval.new }
    config.auth = :clerk_token
  end

  # config/routes.rb
  mount Braintrust::Server::Rails::Engine, at: "/braintrust"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Collaborator

@delner David Elner (delner) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very happy with this. Thank you Stephen Belanger (@Qard) for your diligence (and patience!) getting this put together :)

@delner David Elner (delner) merged commit 2a4fb97 into main Mar 19, 2026
7 checks passed
@delner David Elner (delner) deleted the eval-server-rails-engine branch March 19, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants