Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
29 changes: 7 additions & 22 deletions evals/skills/refactor-process/basic/criteria.json
Original file line number Diff line number Diff line change
@@ -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
}
}
21 changes: 21 additions & 0 deletions evals/skills/refactor-process/basic/order_processor.rb
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions evals/skills/refactor-process/basic/order_processor_test.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 14 additions & 9 deletions evals/skills/refactor-process/basic/task.md
Original file line number Diff line number Diff line change
@@ -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.
46 changes: 46 additions & 0 deletions skills/refactor-process/SKILL.md
Original file line number Diff line number Diff line change
@@ -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.
52 changes: 52 additions & 0 deletions test/evals/refactor_process_basic_test.rb
Original file line number Diff line number Diff line change
@@ -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
Loading