From 50ee6ab7bb51c44e662102e7db7ec4bd75e071d9 Mon Sep 17 00:00:00 2001 From: Ismael Marin Date: Sun, 13 Sep 2026 22:08:19 -0600 Subject: [PATCH] feat: fixture-backed refactor-process eval Ship OrderProcessor with duplicated standard/express paths and passing characterization tests. The agent extracts helpers without changing return values. Include a condensed skill and a bench test that the duplication is still present. --- CHANGELOG.md | 1 + .../refactor-process/basic/criteria.json | 29 +++-------- .../refactor-process/basic/order_processor.rb | 21 ++++++++ .../basic/order_processor_test.rb | 38 ++++++++++++++ evals/skills/refactor-process/basic/task.md | 23 ++++---- skills/refactor-process/SKILL.md | 46 ++++++++++++++++ test/evals/refactor_process_basic_test.rb | 52 +++++++++++++++++++ 7 files changed, 179 insertions(+), 31 deletions(-) create mode 100644 evals/skills/refactor-process/basic/order_processor.rb create mode 100644 evals/skills/refactor-process/basic/order_processor_test.rb create mode 100644 skills/refactor-process/SKILL.md create mode 100644 test/evals/refactor_process_basic_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 129a0b7..21305af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixture-backed `evals/skills/create-service-object/basic`: fat `OrdersController`, passing starting tests, and a condensed `skills/create-service-object/SKILL.md`. - Fixture-backed `evals/skills/write-yard-docs/basic`: undocumented `PriceCalculator`, passing starting tests, and a condensed `skills/write-yard-docs/SKILL.md`. - Fixture-backed `evals/skills/triage-bug/basic`: buggy `Discount.apply` (integer division), passing happy-path tests, and a condensed `skills/triage-bug/SKILL.md`. +- Fixture-backed `evals/skills/refactor-process/basic`: duplicated `OrderProcessor` methods, passing characterization tests, and a condensed `skills/refactor-process/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). diff --git a/evals/skills/refactor-process/basic/criteria.json b/evals/skills/refactor-process/basic/criteria.json index 323108d..7657a74 100644 --- a/evals/skills/refactor-process/basic/criteria.json +++ b/evals/skills/refactor-process/basic/criteria.json @@ -1,27 +1,12 @@ { - "context": "Evaluate ruby task", + "context": "Evaluate whether skill context helps extract duplicated OrderProcessor validation without changing characterization-test behavior", "dimensions": [ - { - "name": "correctness", - "max_score": 30 - }, - { - "name": "skill_adherence", - "max_score": 25 - }, - { - "name": "code_quality", - "max_score": 20 - }, - { - "name": "test_coverage", - "max_score": 15 - }, - { - "name": "documentation", - "max_score": 10 - } + { "name": "correctness", "max_score": 30 }, + { "name": "skill_adherence", "max_score": 25 }, + { "name": "code_quality", "max_score": 20 }, + { "name": "test_coverage", "max_score": 15 }, + { "name": "documentation", "max_score": 10 } ], "pass_threshold": 70, "minimum_delta": 10 -} \ No newline at end of file +} diff --git a/evals/skills/refactor-process/basic/order_processor.rb b/evals/skills/refactor-process/basic/order_processor.rb new file mode 100644 index 0000000..7c92855 --- /dev/null +++ b/evals/skills/refactor-process/basic/order_processor.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class OrderProcessor + UNIT_CENTS = 1000 + STANDARD_SHIPPING_CENTS = 500 + EXPRESS_SHIPPING_CENTS = 2000 + + def process_standard(sku:, quantity:) + return { error: 'sku required' } if sku.to_s.strip.empty? + return { error: 'quantity must be positive' } unless quantity.is_a?(Integer) && quantity.positive? + + { sku: sku, quantity: quantity, total_cents: quantity * UNIT_CENTS, shipping_cents: STANDARD_SHIPPING_CENTS } + end + + def process_express(sku:, quantity:) + return { error: 'sku required' } if sku.to_s.strip.empty? + return { error: 'quantity must be positive' } unless quantity.is_a?(Integer) && quantity.positive? + + { sku: sku, quantity: quantity, total_cents: quantity * UNIT_CENTS, shipping_cents: EXPRESS_SHIPPING_CENTS } + end +end diff --git a/evals/skills/refactor-process/basic/order_processor_test.rb b/evals/skills/refactor-process/basic/order_processor_test.rb new file mode 100644 index 0000000..a3f54f6 --- /dev/null +++ b/evals/skills/refactor-process/basic/order_processor_test.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require_relative 'order_processor' + +class OrderProcessorTest < Minitest::Test + def setup + @processor = OrderProcessor.new + end + + def test_standard_prices_units_and_shipping + result = @processor.process_standard(sku: 'SKU-1', quantity: 2) + + assert_equal 'SKU-1', result[:sku] + assert_equal 2, result[:quantity] + assert_equal 2000, result[:total_cents] + assert_equal 500, result[:shipping_cents] + end + + def test_express_uses_higher_shipping + result = @processor.process_express(sku: 'SKU-1', quantity: 2) + + assert_equal 2000, result[:total_cents] + assert_equal 2000, result[:shipping_cents] + end + + def test_standard_rejects_blank_sku + result = @processor.process_standard(sku: ' ', quantity: 1) + + assert_equal 'sku required', result[:error] + end + + def test_express_rejects_non_positive_quantity + result = @processor.process_express(sku: 'SKU-1', quantity: 0) + + assert_equal 'quantity must be positive', result[:error] + end +end diff --git a/evals/skills/refactor-process/basic/task.md b/evals/skills/refactor-process/basic/task.md index a9da1df..ccef4bf 100644 --- a/evals/skills/refactor-process/basic/task.md +++ b/evals/skills/refactor-process/basic/task.md @@ -1,14 +1,19 @@ # Eval: refactor-process-basic +The sandbox starts with `order_processor.rb` and `order_processor_test.rb`. +`process_standard` and `process_express` duplicate sku/quantity guards and unit pricing. +The tests already capture current behavior and pass. + ## Task -Refactor the provided `OrderProcessor` class to clean up duplication, extract methods, and improve code structure. -Ensure that: -1. You have a full set of characterization tests that pass (are Green) BEFORE making any changes. -2. You make only ONE atomic transformation at a time. -3. You run your tests after every single micro-change to ensure nothing breaks. -4. You do NOT change any behavior or return values. + +1. Run `ruby order_processor_test.rb` and confirm Green before any edit. +2. Extract the duplicated validation (and optionally pricing) into a private helper. One atomic transformation at a time. +3. Re-run the tests after each step. If Red, revert that step. +4. Do not change return hashes, error strings, or shipping amounts. +5. Do not fix bugs, add YARD, or extract a `ProcessOrder` service as the main change. ## Success Criteria -- The code structure of `OrderProcessor` is simplified and cleaner. -- No functional regressions are introduced. -- Tests are run and remain Green throughout the process. + +- Duplicated sku/quantity checks live in one place. +- `ruby order_processor_test.rb` exits 0. +- Public methods `process_standard` and `process_express` still exist with the same results. diff --git a/skills/refactor-process/SKILL.md b/skills/refactor-process/SKILL.md new file mode 100644 index 0000000..abf4b22 --- /dev/null +++ b/skills/refactor-process/SKILL.md @@ -0,0 +1,46 @@ +# Refactor Process + +Use when restructuring Ruby without changing behavior. + +## Pattern + +```ruby +# frozen_string_literal: true + +class OrderProcessor + def process_standard(sku:, quantity:) + error = validation_error(sku: sku, quantity: quantity) + return { error: error } if error + + priced(sku: sku, quantity: quantity, shipping_cents: 500) + end + + def process_express(sku:, quantity:) + error = validation_error(sku: sku, quantity: quantity) + return { error: error } if error + + priced(sku: sku, quantity: quantity, shipping_cents: 2000) + end + + private + + def validation_error(sku:, quantity:) + return 'sku required' if sku.to_s.strip.empty? + return 'quantity must be positive' unless quantity.is_a?(Integer) && quantity.positive? + + nil + end + + def priced(sku:, quantity:, shipping_cents:) + { sku: sku, quantity: quantity, total_cents: quantity * 1000, shipping_cents: shipping_cents } + end +end +``` + +## Hard rules + +1. Characterization tests must be Green before the first edit. +2. One atomic transformation per step (extract method, then re-run tests). +3. If tests go Red, revert that step. Do not debug in a broken tree. +4. Do not change return values, error strings, or add features in the same pass. +5. Do not mix this refactor with a bug fix or a new service object. diff --git a/test/evals/refactor_process_basic_test.rb b/test/evals/refactor_process_basic_test.rb new file mode 100644 index 0000000..a0b1960 --- /dev/null +++ b/test/evals/refactor_process_basic_test.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'test_helper' +require 'open3' +require 'tempfile' + +module SkillBench + class RefactorProcessBasicEvalTest < Minitest::Test + EVAL_DIR = File.expand_path('../../evals/skills/refactor-process/basic', __dir__) + SKILL_PATH = File.expand_path('../../skills/refactor-process/SKILL.md', __dir__) + + def test_eval_loads_and_names_the_fixture_files + evaluation = Models::Eval.load(EVAL_DIR) + + assert_includes evaluation.task, 'order_processor.rb' + assert_includes evaluation.task, 'order_processor_test.rb' + end + + def test_eval_ships_duplicated_processors_without_extracted_helpers + source = File.read(File.join(EVAL_DIR, 'order_processor.rb')) + + assert_path_exists File.join(EVAL_DIR, 'order_processor.rb') + assert_path_exists File.join(EVAL_DIR, 'order_processor_test.rb') + assert_equal 2, source.scan('sku required').size + assert_equal 2, source.scan('quantity must be positive').size + refute_includes source, 'def validate' + refute_includes source, 'def price' + end + + def test_starting_processor_tests_pass + stdout, stderr, status = Open3.capture3('ruby', 'order_processor_test.rb', chdir: EVAL_DIR) + + assert_predicate status, :success?, "fixture tests failed:\n#{stdout}\n#{stderr}" + assert_includes stdout, '0 failures' + end + + def test_skill_example_is_valid_ruby + skill = File.read(SKILL_PATH) + example = skill[/```ruby\n(.*?)```/m, 1] + + refute_nil example, 'SKILL.md must include a ruby example' + + Tempfile.create(['refactor_example', '.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