From b909b888b3afc8142a6090dc05e1b570bc058001 Mon Sep 17 00:00:00 2001 From: Ismael Marin Date: Sun, 13 Sep 2026 20:42:22 -0600 Subject: [PATCH 1/3] feat: fixture-backed create-service-object eval Ship a fat OrdersController and passing starting tests so the agent extracts ProcessOrder instead of inventing a codebase. Add a condensed skill and a bench test that the fixtures exist and stay green. --- CHANGELOG.md | 3 ++ .../create-service-object/basic/criteria.json | 2 +- .../basic/orders_controller.rb | 20 ++++++++++ .../basic/orders_controller_test.rb | 37 +++++++++++++++++++ .../create-service-object/basic/task.md | 27 +++++++++++--- skills/create-service-object/SKILL.md | 37 +++++++++++++++++++ .../evals/create_service_object_basic_test.rb | 32 ++++++++++++++++ 7 files changed, 152 insertions(+), 6 deletions(-) create mode 100644 evals/skills/create-service-object/basic/orders_controller.rb create mode 100644 evals/skills/create-service-object/basic/orders_controller_test.rb create mode 100644 skills/create-service-object/SKILL.md create mode 100644 test/evals/create_service_object_basic_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 215b26b..bebcb17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Fixture-backed `evals/skills/create-service-object/basic`: fat `OrdersController`, passing starting tests, and a condensed `skills/create-service-object/SKILL.md`. + ### Documentation - Align user docs with shipped 1.3.1: OpenRouter and mock in the provider list, Azure env var `SKILL_BENCH_AZURE_OPENAI_API_KEY`, Mistral key via `skill-bench.json` (no env mapping). - Document `--cache` and `--mock` in `skill-bench --help`. diff --git a/evals/skills/create-service-object/basic/criteria.json b/evals/skills/create-service-object/basic/criteria.json index fb4eaca..a883c5a 100644 --- a/evals/skills/create-service-object/basic/criteria.json +++ b/evals/skills/create-service-object/basic/criteria.json @@ -1,5 +1,5 @@ { - "context": "Evaluate ruby task", + "context": "Evaluate whether skill context helps extract inline order processing from OrdersController into a ProcessOrder PORO with .call and { success:, response: }", "dimensions": [ { "name": "correctness", "max_score": 30 }, { "name": "skill_adherence", "max_score": 25 }, diff --git a/evals/skills/create-service-object/basic/orders_controller.rb b/evals/skills/create-service-object/basic/orders_controller.rb new file mode 100644 index 0000000..422d0d9 --- /dev/null +++ b/evals/skills/create-service-object/basic/orders_controller.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# Handles order creation. Pricing, validation, and persistence-shaped +# output all live in this action — extract them into a service object. +class OrdersController + PRICE_CENTS = 1000 + + def create(sku:, quantity:, paid:) + return { error: 'sku is required' } if sku.to_s.strip.empty? + return { error: 'quantity must be a positive integer' } unless quantity.is_a?(Integer) && quantity.positive? + return { error: 'payment required' } unless paid + + { + order_id: 1, + sku: sku, + quantity: quantity, + total_cents: quantity * PRICE_CENTS + } + end +end diff --git a/evals/skills/create-service-object/basic/orders_controller_test.rb b/evals/skills/create-service-object/basic/orders_controller_test.rb new file mode 100644 index 0000000..9a749e1 --- /dev/null +++ b/evals/skills/create-service-object/basic/orders_controller_test.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require_relative 'orders_controller' + +class OrdersControllerTest < Minitest::Test + def setup + @controller = OrdersController.new + end + + def test_create_charges_and_returns_order + result = @controller.create(sku: 'SKU-1', quantity: 2, paid: true) + + assert_equal 1, result[:order_id] + assert_equal 'SKU-1', result[:sku] + assert_equal 2, result[:quantity] + assert_equal 2000, result[:total_cents] + end + + def test_create_rejects_blank_sku + result = @controller.create(sku: ' ', quantity: 1, paid: true) + + assert_equal 'sku is required', result[:error] + end + + def test_create_rejects_non_positive_quantity + result = @controller.create(sku: 'SKU-1', quantity: 0, paid: true) + + assert_equal 'quantity must be a positive integer', result[:error] + end + + def test_create_rejects_unpaid + result = @controller.create(sku: 'SKU-1', quantity: 1, paid: false) + + assert_equal 'payment required', result[:error] + end +end diff --git a/evals/skills/create-service-object/basic/task.md b/evals/skills/create-service-object/basic/task.md index ef084c6..086f2dc 100644 --- a/evals/skills/create-service-object/basic/task.md +++ b/evals/skills/create-service-object/basic/task.md @@ -1,10 +1,27 @@ # Eval: create-service-object-basic +The sandbox starts with `orders_controller.rb` and `orders_controller_test.rb`. +`OrdersController#create` validates input, prices the order, and returns a result +hash inline. Extract that processing into a `ProcessOrder` service object. + ## Task -Extract the order processing logic from the controller into a service object following the PORO `.call` pattern. + +1. Add `process_order.rb` with a `ProcessOrder` PORO. +2. `ProcessOrder.call(sku:, quantity:, paid:)` must be the only public entry point + (`def self.call(...)` → `new(...).call`). +3. Success returns `{ success: true, response: { order_id:, sku:, quantity:, total_cents: } }`. +4. Failure returns `{ success: false, response: { error: { message: '...' } } }` using + the same messages the controller tests already expect (`sku is required`, + `quantity must be a positive integer`, `payment required`). +5. `OrdersController#create` stays the public API and delegates to `ProcessOrder`. + Map the service result back so `ruby orders_controller_test.rb` still passes. +6. Start `process_order.rb` with `# frozen_string_literal: true`. Document + `self.call` and `#call` with YARD `@param` / `@return`. ## Success Criteria -- A new service object exists with a `.call` class method. -- The controller delegates to the service object. -- The service object returns a standard { success:, response: } hash. -- All existing tests still pass. + +- `ProcessOrder` exists with `.call`. +- The controller no longer contains pricing or validation logic. +- `ruby orders_controller_test.rb` exits 0. +- The service uses the `{ success:, response: }` contract, not the controller's + public hash. diff --git a/skills/create-service-object/SKILL.md b/skills/create-service-object/SKILL.md new file mode 100644 index 0000000..a07e5a7 --- /dev/null +++ b/skills/create-service-object/SKILL.md @@ -0,0 +1,37 @@ +# Create Service Object + +Use when extracting or writing a Ruby service that callers invoke with `.call`. + +## Pattern + +```ruby +# frozen_string_literal: true + +class ProcessOrder + def self.call(sku:, quantity:, paid:) + new(sku: sku, quantity: quantity, paid: paid).call + end + + def initialize(sku:, quantity:, paid:) + @sku = sku + @quantity = quantity + @paid = paid + end + + def call + { success: true, response: { ... } } + rescue StandardError => e + { success: false, response: { error: { message: e.message } } } + end +end +``` + +## Hard rules + +1. Every `.rb` file begins with `# frozen_string_literal: true`. +2. Public entry point is `def self.call(...)` delegating to `new(...).call`. +3. Success: `{ success: true, response: { ... } }`. +4. Failure: `{ success: false, response: { error: { message: '...' } } }`. +5. Document `self.call` and `#call` with YARD `@param` and `@return`. +6. Controllers and other callers stay thin: they delegate and map the result. +7. Do not put HTTP, persistence models, or UI in the service response. diff --git a/test/evals/create_service_object_basic_test.rb b/test/evals/create_service_object_basic_test.rb new file mode 100644 index 0000000..cd23219 --- /dev/null +++ b/test/evals/create_service_object_basic_test.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'test_helper' +require 'open3' + +module SkillBench + class CreateServiceObjectBasicEvalTest < Minitest::Test + EVAL_DIR = File.expand_path('../../evals/skills/create-service-object/basic', __dir__) + + def test_eval_loads_and_names_the_fixture_files + evaluation = Models::Eval.load(EVAL_DIR) + + assert_includes evaluation.task, 'orders_controller.rb' + assert_includes evaluation.task, 'orders_controller_test.rb' + assert_includes evaluation.task, 'ProcessOrder' + end + + def test_eval_ships_a_fat_controller_without_the_extracted_service + assert_path_exists File.join(EVAL_DIR, 'orders_controller.rb') + assert_path_exists File.join(EVAL_DIR, 'orders_controller_test.rb') + refute_path_exists File.join(EVAL_DIR, 'process_order.rb'), + 'starting fixture must not already contain ProcessOrder' + end + + def test_starting_controller_tests_pass + stdout, stderr, status = Open3.capture3('ruby', 'orders_controller_test.rb', chdir: EVAL_DIR) + + assert status.success?, "fixture tests failed:\n#{stdout}\n#{stderr}" + assert_includes stdout, '0 failures' + end + end +end From 343a18b675fb7931ca5e17729171347b979c1b32 Mon Sep 17 00:00:00 2001 From: Ismael Marin Date: Sun, 13 Sep 2026 21:13:48 -0600 Subject: [PATCH 2/3] fix: use assert_predicate in create-service-object eval test RuboCop Minitest/AssertPredicate failed CI on both 3.3 and 3.4. --- test/evals/create_service_object_basic_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/evals/create_service_object_basic_test.rb b/test/evals/create_service_object_basic_test.rb index cd23219..c05468e 100644 --- a/test/evals/create_service_object_basic_test.rb +++ b/test/evals/create_service_object_basic_test.rb @@ -25,7 +25,7 @@ def test_eval_ships_a_fat_controller_without_the_extracted_service def test_starting_controller_tests_pass stdout, stderr, status = Open3.capture3('ruby', 'orders_controller_test.rb', chdir: EVAL_DIR) - assert status.success?, "fixture tests failed:\n#{stdout}\n#{stderr}" + assert_predicate status, :success?, "fixture tests failed:\n#{stdout}\n#{stderr}" assert_includes stdout, '0 failures' end end From fb5180b92c0c597bd15d6df8b28ccd22e66e58e9 Mon Sep 17 00:00:00 2001 From: Ismael Marin Date: Sun, 13 Sep 2026 21:24:29 -0600 Subject: [PATCH 3/3] docs: make ProcessOrder skill example valid Ruby with YARD Replace the invalid `{ ... }` response placeholder and document self.call / #call so a copied example parses and matches hard rule 5. --- skills/create-service-object/SKILL.md | 12 ++++++++++- .../evals/create_service_object_basic_test.rb | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/skills/create-service-object/SKILL.md b/skills/create-service-object/SKILL.md index a07e5a7..5faf60d 100644 --- a/skills/create-service-object/SKILL.md +++ b/skills/create-service-object/SKILL.md @@ -8,6 +8,12 @@ Use when extracting or writing a Ruby service that callers invoke with `.call`. # frozen_string_literal: true class ProcessOrder + # Process an order from sku, quantity, and payment flag. + # + # @param sku [String] product identifier + # @param quantity [Integer] units to purchase + # @param paid [Boolean] whether payment has been captured + # @return [Hash] `{ success: true, response: Hash }` or `{ success: false, response: { error: { message: String } } }` def self.call(sku:, quantity:, paid:) new(sku: sku, quantity: quantity, paid: paid).call end @@ -18,8 +24,12 @@ class ProcessOrder @paid = paid end + # @return [Hash] `{ success: true, response: Hash }` or `{ success: false, response: { error: { message: String } } }` def call - { success: true, response: { ... } } + { + success: true, + response: { order_id: 1, sku: @sku, quantity: @quantity, total_cents: @quantity * 1000 } + } rescue StandardError => e { success: false, response: { error: { message: e.message } } } end diff --git a/test/evals/create_service_object_basic_test.rb b/test/evals/create_service_object_basic_test.rb index c05468e..ac41ac6 100644 --- a/test/evals/create_service_object_basic_test.rb +++ b/test/evals/create_service_object_basic_test.rb @@ -2,6 +2,7 @@ require 'test_helper' require 'open3' +require 'tempfile' module SkillBench class CreateServiceObjectBasicEvalTest < Minitest::Test @@ -28,5 +29,25 @@ def test_starting_controller_tests_pass assert_predicate status, :success?, "fixture tests failed:\n#{stdout}\n#{stderr}" assert_includes stdout, '0 failures' end + + def test_skill_example_is_valid_ruby_with_yard_on_entry_points + skill = File.read(File.expand_path('../../skills/create-service-object/SKILL.md', __dir__)) + example = skill[/```ruby\n(.*?)```/m, 1] + + refute_nil example, 'SKILL.md must include a ruby example' + + %w[sku quantity paid].each do |name| + assert_includes example, "@param #{name}" + end + assert_equal 2, example.scan('@return').size, 'self.call and #call each need @return' + + Tempfile.create(['process_order', '.rb']) do |file| + file.write(example) + file.flush + _stdout, stderr, status = Open3.capture3('ruby', '-c', file.path) + + assert_predicate status, :success?, stderr + end + end end end