From 31b1da383a2f8c861e7c45ebc9cd8e25e809d492 Mon Sep 17 00:00:00 2001 From: Ismael Marin Date: Sun, 13 Sep 2026 21:39:29 -0600 Subject: [PATCH 1/2] feat: fixture-backed write-yard-docs eval Ship an undocumented PriceCalculator and passing starting tests so the agent adds YARD instead of inventing a class. Include a condensed skill and a bench test that the fixture stays undocumented and green. --- CHANGELOG.md | 1 + .../write-yard-docs/basic/criteria.json | 2 +- .../write-yard-docs/basic/price_calculator.rb | 19 +++++++ .../basic/price_calculator_test.rb | 22 ++++++++ evals/skills/write-yard-docs/basic/task.md | 24 +++++++-- skills/write-yard-docs/SKILL.md | 47 ++++++++++++++++ test/evals/write_yard_docs_basic_test.rb | 54 +++++++++++++++++++ 7 files changed, 163 insertions(+), 6 deletions(-) create mode 100644 evals/skills/write-yard-docs/basic/price_calculator.rb create mode 100644 evals/skills/write-yard-docs/basic/price_calculator_test.rb create mode 100644 skills/write-yard-docs/SKILL.md create mode 100644 test/evals/write_yard_docs_basic_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index bebcb17..38d3e34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - 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`. ### 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/write-yard-docs/basic/criteria.json b/evals/skills/write-yard-docs/basic/criteria.json index fb4eaca..98bbbcf 100644 --- a/evals/skills/write-yard-docs/basic/criteria.json +++ b/evals/skills/write-yard-docs/basic/criteria.json @@ -1,5 +1,5 @@ { - "context": "Evaluate ruby task", + "context": "Evaluate whether skill context helps add complete YARD (@param, @return, @raise) to PriceCalculator public methods without changing behavior", "dimensions": [ { "name": "correctness", "max_score": 30 }, { "name": "skill_adherence", "max_score": 25 }, diff --git a/evals/skills/write-yard-docs/basic/price_calculator.rb b/evals/skills/write-yard-docs/basic/price_calculator.rb new file mode 100644 index 0000000..7cbc726 --- /dev/null +++ b/evals/skills/write-yard-docs/basic/price_calculator.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class PriceCalculator + def self.call(cents:, quantity:) + new(cents: cents, quantity: quantity).call + end + + def initialize(cents:, quantity:) + @cents = cents + @quantity = quantity + end + + def call + raise ArgumentError, 'cents must be non-negative' if @cents.negative? + raise ArgumentError, 'quantity must be positive' unless @quantity.positive? + + @cents * @quantity + end +end diff --git a/evals/skills/write-yard-docs/basic/price_calculator_test.rb b/evals/skills/write-yard-docs/basic/price_calculator_test.rb new file mode 100644 index 0000000..a728dd9 --- /dev/null +++ b/evals/skills/write-yard-docs/basic/price_calculator_test.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require_relative 'price_calculator' + +class PriceCalculatorTest < Minitest::Test + def test_call_multiplies_cents_by_quantity + assert_equal 2000, PriceCalculator.call(cents: 1000, quantity: 2) + end + + def test_call_rejects_negative_cents + error = assert_raises(ArgumentError) { PriceCalculator.call(cents: -1, quantity: 1) } + + assert_equal 'cents must be non-negative', error.message + end + + def test_call_rejects_non_positive_quantity + error = assert_raises(ArgumentError) { PriceCalculator.call(cents: 1000, quantity: 0) } + + assert_equal 'quantity must be positive', error.message + end +end diff --git a/evals/skills/write-yard-docs/basic/task.md b/evals/skills/write-yard-docs/basic/task.md index e5c0ce4..8b90d54 100644 --- a/evals/skills/write-yard-docs/basic/task.md +++ b/evals/skills/write-yard-docs/basic/task.md @@ -1,10 +1,24 @@ # Eval: write-yard-docs-basic +The sandbox starts with `price_calculator.rb` and `price_calculator_test.rb`. +`PriceCalculator` already works. Public methods have no YARD. + ## Task -Add YARD documentation to the provided Ruby class with public methods. For each public method write @param, @return, and @raise tags where appropriate. + +Add YARD to `PriceCalculator` without changing behavior. + +1. Class: one-line summary of responsibility. +2. `self.call` and `#call` each get their own docs. Do not document only one of them. +3. Every public method gets `@param`, `@return`, and `@raise` where they apply. +4. `@param` for `cents` and `quantity` on `self.call` (and on `initialize` if you treat it as public). +5. `@return` states the type (`Integer` total cents, or the Hash/result shape if you change nothing else). +6. One `@raise [ArgumentError]` tag per raising method, with the actual messages (`cents must be non-negative`, `quantity must be positive`). Do not group exceptions on one tag. +7. Leave `ruby price_calculator_test.rb` passing. Do not add `process_order.rb` or extract a new service. ## Success Criteria -- All public methods have YARD documentation. -- @param tags are accurate and complete. -- @return tags specify the return type and structure. -- @raise tags document exceptions where applicable. + +- All public methods have YARD. +- `@param` tags match `cents:` and `quantity:`. +- `@return` names the return type. +- `@raise` documents `ArgumentError` on methods that raise. +- `ruby price_calculator_test.rb` exits 0. diff --git a/skills/write-yard-docs/SKILL.md b/skills/write-yard-docs/SKILL.md new file mode 100644 index 0000000..870a5ea --- /dev/null +++ b/skills/write-yard-docs/SKILL.md @@ -0,0 +1,47 @@ +# Write YARD Docs + +Use when documenting Ruby public APIs with YARD. + +## Pattern + +```ruby +# frozen_string_literal: true + +# Multiplies unit price in cents by quantity. +class PriceCalculator + # Multiply unit cents by quantity. + # + # @param cents [Integer] non-negative unit price in cents + # @param quantity [Integer] positive unit count + # @return [Integer] total price in cents + # @raise [ArgumentError] when cents is negative or quantity is not positive + def self.call(cents:, quantity:) + new(cents: cents, quantity: quantity).call + end + + def initialize(cents:, quantity:) + @cents = cents + @quantity = quantity + end + + # Multiply unit cents by quantity. + # + # @return [Integer] total price in cents + # @raise [ArgumentError] when cents is negative or quantity is not positive + def call + raise ArgumentError, 'cents must be non-negative' if @cents.negative? + raise ArgumentError, 'quantity must be positive' unless @quantity.positive? + + @cents * @quantity + end +end +``` + +## Hard rules + +1. Every public method gets YARD. Document `self.call` separately from `#call`. +2. `@param` for each argument. `@return` names the type (and Hash keys when the result is a Hash). +3. One `@raise` tag per exception class that can escape. Never group two exceptions on one tag. +4. Class gets a one-line summary. +5. YARD text is English unless the user asked otherwise. +6. Do not change runtime behavior to make the docs easier. diff --git a/test/evals/write_yard_docs_basic_test.rb b/test/evals/write_yard_docs_basic_test.rb new file mode 100644 index 0000000..c4d0fa1 --- /dev/null +++ b/test/evals/write_yard_docs_basic_test.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'test_helper' +require 'open3' +require 'tempfile' + +module SkillBench + class WriteYardDocsBasicEvalTest < Minitest::Test + EVAL_DIR = File.expand_path('../../evals/skills/write-yard-docs/basic', __dir__) + SKILL_PATH = File.expand_path('../../skills/write-yard-docs/SKILL.md', __dir__) + + def test_eval_loads_and_names_the_fixture_files + evaluation = Models::Eval.load(EVAL_DIR) + + assert_includes evaluation.task, 'price_calculator.rb' + assert_includes evaluation.task, 'price_calculator_test.rb' + end + + def test_eval_ships_undocumented_public_methods + source = File.read(File.join(EVAL_DIR, 'price_calculator.rb')) + + assert_path_exists File.join(EVAL_DIR, 'price_calculator.rb') + assert_path_exists File.join(EVAL_DIR, 'price_calculator_test.rb') + refute_includes source, '@param' + refute_includes source, '@return' + refute_includes source, '@raise' + end + + def test_starting_calculator_tests_pass + stdout, stderr, status = Open3.capture3('ruby', 'price_calculator_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_with_yard_tags + skill = File.read(SKILL_PATH) + example = skill[/```ruby\n(.*?)```/m, 1] + + refute_nil example, 'SKILL.md must include a ruby example' + assert_includes example, '@param' + assert_includes example, '@return' + assert_includes example, '@raise' + + Tempfile.create(['yard_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 From 6ff32ecbeb2509baba2b60f083b33e91d3b76b85 Mon Sep 17 00:00:00 2001 From: Ismael Marin Date: Sun, 13 Sep 2026 21:47:31 -0600 Subject: [PATCH 2/2] fix: stop resolver tests assuming write-yard-docs is not local Shipping skills/write-yard-docs made the fallback tests resolve to the repo skill instead of the tmpdir skill_sources fixture. --- test/evaluator/source_path_resolver_test.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/evaluator/source_path_resolver_test.rb b/test/evaluator/source_path_resolver_test.rb index aa3a476..63933bd 100644 --- a/test/evaluator/source_path_resolver_test.rb +++ b/test/evaluator/source_path_resolver_test.rb @@ -81,16 +81,16 @@ def test_local_skills_resolve_first_with_empty_sources def test_falls_back_to_skill_sources_when_local_not_found Dir.mktmpdir do |tmpdir| source_path = File.join(tmpdir, 'code-quality') - skill_dir = File.join(source_path, 'write-yard-docs') + skill_dir = File.join(source_path, 'unshipped-skill') FileUtils.mkdir_p(skill_dir) - File.write(File.join(skill_dir, 'SKILL.md'), '# Write YARD Docs') + File.write(File.join(skill_dir, 'SKILL.md'), '# Unshipped Skill') resolved = Execution::SourcePathResolver.call( - eval_folder_path: 'tmp/evals/skills/write-yard-docs/basic', + eval_folder_path: 'tmp/evals/skills/unshipped-skill/basic', skill_sources: { 'core' => tmpdir } ) - assert_equal File.join(source_path, 'write-yard-docs'), resolved + assert_equal File.join(source_path, 'unshipped-skill'), resolved end end @@ -98,21 +98,21 @@ def test_first_matching_source_wins Dir.mktmpdir do |tmpdir_a| Dir.mktmpdir do |tmpdir_b| source_a = File.join(tmpdir_a, 'code-quality') - skill_a = File.join(source_a, 'write-yard-docs') + skill_a = File.join(source_a, 'unshipped-skill') FileUtils.mkdir_p(skill_a) File.write(File.join(skill_a, 'SKILL.md'), '# A') source_b = File.join(tmpdir_b, 'patterns') - skill_b = File.join(source_b, 'write-yard-docs') + skill_b = File.join(source_b, 'unshipped-skill') FileUtils.mkdir_p(skill_b) File.write(File.join(skill_b, 'SKILL.md'), '# B') resolved = Execution::SourcePathResolver.call( - eval_folder_path: 'custom/evals/skills/write-yard-docs/basic', + eval_folder_path: 'custom/evals/skills/unshipped-skill/basic', skill_sources: { 'first' => tmpdir_a, 'second' => tmpdir_b } ) - assert_equal File.join(source_a, 'write-yard-docs'), resolved + assert_equal File.join(source_a, 'unshipped-skill'), resolved end end end