From 73d09d040ad34701fbf5cb4214e17181a1516aaf Mon Sep 17 00:00:00 2001 From: agentic-dev agent Date: Sun, 22 Nov 2026 19:36:22 +0000 Subject: [PATCH 1/2] Add Mature Cheese classification and maturation policy Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Core/ProposedCode/Domain/ItemKind.cs | 5 +- .../ProposedCode/Domain/ItemMaturingPolicy.cs | 12 +++- .../ProposedCode/Domain/ItemKindTests.cs | 14 +++- .../Domain/ItemMaturingPolicyTests.cs | 52 ++++++++++++++- .../ItemMaturationServiceTests.cs | 64 ++++++++++++++++++- 5 files changed, 142 insertions(+), 5 deletions(-) diff --git a/src/Core/ProposedCode/Domain/ItemKind.cs b/src/Core/ProposedCode/Domain/ItemKind.cs index 199f351..cb7f8a6 100644 --- a/src/Core/ProposedCode/Domain/ItemKind.cs +++ b/src/Core/ProposedCode/Domain/ItemKind.cs @@ -18,6 +18,8 @@ public sealed record Conjured : ItemKind; public sealed record Sulfuras : ItemKind; + public sealed record MatureCheese : ItemKind; + public static ItemKind FromName(string itemName) { return itemName switch @@ -29,7 +31,8 @@ public static ItemKind FromName(string itemName) "Conjured Mana Cake" => new Conjured(), "Conjured" => new Conjured(), "Sulfuras, Hand of Ragnaros" => new Sulfuras(), + "Mature Cheese" => new MatureCheese(), _ => new Standard(), }; } -} \ No newline at end of file +} diff --git a/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs b/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs index 0221621..21730aa 100644 --- a/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs +++ b/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs @@ -16,6 +16,7 @@ public ItemState Mature(ItemKind kind, ItemState state) ItemKind.Backstage => this.MatureBackstage(state), ItemKind.Conjured => this.MatureConjured(state), ItemKind.Sulfuras => state, + ItemKind.MatureCheese => this.MatureMatureCheese(state), _ => this.MatureStandard(state), }; } @@ -77,4 +78,13 @@ private ItemState MatureConjured(ItemState state) return new(newQuality, newSellIn); } -} \ No newline at end of file + + private ItemState MatureMatureCheese(ItemState state) + { + var increase = state.SellIn.Value > 0 ? 1 : 2; + var newQuality = state.Quality.Increase(increase); + var newSellIn = state.SellIn.NextDay(); + + return new(newQuality, newSellIn); + } +} diff --git a/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs b/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs index 040e12d..ce583aa 100644 --- a/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs +++ b/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs @@ -18,6 +18,7 @@ public class ItemKindTests [InlineData("Conjured Mana Cake", typeof(ItemKind.Conjured))] [InlineData("Conjured", typeof(ItemKind.Conjured))] [InlineData("Sulfuras, Hand of Ragnaros", typeof(ItemKind.Sulfuras))] + [InlineData("Mature Cheese", typeof(ItemKind.MatureCheese))] [InlineData("Elixir of the Mongoose", typeof(ItemKind.Standard))] public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType) { @@ -25,4 +26,15 @@ public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType result.Should().BeOfType(expectedType); } -} \ No newline at end of file + + [Theory] + [InlineData("mature cheese")] + [InlineData("Mature Cheese ")] + [InlineData("Mature Cheeses")] + public void FromName_MapsSimilarMatureCheeseNamesToStandard(string itemName) + { + var result = ItemKind.FromName(itemName); + + result.Should().BeOfType(); + } +} diff --git a/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs b/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs index 55d645c..fe472c7 100644 --- a/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs +++ b/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs @@ -27,6 +27,56 @@ public void Mature_WhenKindIsStandard_FollowsExpectedRules(int quality, int sell result.SellIn.Value.Should().Be(expectedSellIn); } + [Theory] + [InlineData(10, 5, 11, 4)] + [InlineData(10, 1, 11, 0)] + [InlineData(10, 0, 12, -1)] + [InlineData(10, -1, 12, -2)] + [InlineData(0, 0, 2, -1)] + [InlineData(49, 5, 50, 4)] + [InlineData(49, 0, 50, -1)] + [InlineData(50, 5, 50, 4)] + [InlineData(50, 0, 50, -1)] + public void Mature_WhenKindIsMatureCheese_FollowsExpectedRules(int quality, int sellIn, int expectedQuality, int expectedSellIn) + { + var state = new ItemState(new Quality(quality), new SellIn(sellIn)); + + var result = this.policy.Mature(new ItemKind.MatureCheese(), state); + + result.Quality.Value.Should().Be(expectedQuality); + result.SellIn.Value.Should().Be(expectedSellIn); + result.Quality.Value.Should().BeInRange(Quality.Minimum, Quality.Maximum); + } + + [Theory] + [InlineData(-5, 0, 2)] + [InlineData(55, 5, 50)] + public void Mature_WhenKindIsMatureCheese_NormalizesInvalidImportedQuality(int importedQuality, int sellIn, int expectedQuality) + { + var state = ItemState.Create(new ItemKind.MatureCheese(), importedQuality, sellIn); + + var result = this.policy.Mature(new ItemKind.MatureCheese(), state); + + result.Quality.Value.Should().Be(expectedQuality); + result.Quality.Value.Should().BeInRange(Quality.Minimum, Quality.Maximum); + } + + [Fact] + public void Mature_WhenKindIsMatureCheese_AppliesRulesOnRepeatedUpdates() + { + var state = ItemState.Create(new ItemKind.MatureCheese(), 10, 2); + + var firstDay = this.policy.Mature(new ItemKind.MatureCheese(), state); + var secondDay = this.policy.Mature(new ItemKind.MatureCheese(), firstDay); + var thirdDay = this.policy.Mature(new ItemKind.MatureCheese(), secondDay); + var fourthDay = this.policy.Mature(new ItemKind.MatureCheese(), thirdDay); + + firstDay.Should().Be(new ItemState(new Quality(11), new SellIn(1))); + secondDay.Should().Be(new ItemState(new Quality(12), new SellIn(0))); + thirdDay.Should().Be(new ItemState(new Quality(14), new SellIn(-1))); + fourthDay.Should().Be(new ItemState(new Quality(16), new SellIn(-2))); + } + [Theory] [InlineData(20, 4, 21, 3)] [InlineData(20, 0, 22, -1)] @@ -89,4 +139,4 @@ public void Mature_WhenKindIsSulfuras_PreservesProvidedState() result.Should().Be(state); } -} \ No newline at end of file +} diff --git a/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs b/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs index 4690ec6..f2caa3e 100644 --- a/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs +++ b/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs @@ -8,6 +8,7 @@ namespace GildedRoseKata.ProposedCode.Tests; using FluentAssertions; using GildedRoseKata.OriginalCode; +using System.Linq; public class ItemMaturationServiceTests { @@ -20,6 +21,13 @@ public class ItemMaturationServiceTests [InlineData("Conjured Mana Cake", 10, 5, 8, 4)] [InlineData("Conjured", 10, 0, 6, -1)] [InlineData("Sulfuras, Hand of Ragnaros", 80, 0, 80, 0)] + [InlineData("Mature Cheese", 10, 5, 11, 4)] + [InlineData("Mature Cheese", 10, 1, 11, 0)] + [InlineData("Mature Cheese", 10, 0, 12, -1)] + [InlineData("Mature Cheese", 10, -1, 12, -2)] + [InlineData("Mature Cheese", 49, 5, 50, 4)] + [InlineData("Mature Cheese", 49, 0, 50, -1)] + [InlineData("Mature Cheese", 50, 5, 50, 4)] public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int quality, int sellIn, int expectedQuality, int expectedSellIn) { var service = new ItemMaturationService(); @@ -35,4 +43,58 @@ public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int qualit result.Quality.Should().Be(expectedQuality); result.SellIn.Should().Be(expectedSellIn); } -} \ No newline at end of file + + [Fact] + public void Mature_ReturnsMaturedItemWithoutChangingInput() + { + var service = new ItemMaturationService(); + var item = new Item + { + Name = "Mature Cheese", + Quality = 10, + SellIn = 5, + }; + + var result = service.Mature(item); + + result.Should().NotBeSameAs(item); + result.Quality.Should().Be(11); + result.SellIn.Should().Be(4); + item.Quality.Should().Be(10); + item.SellIn.Should().Be(5); + } + + [Fact] + public void Mature_UpdatesMultipleItemsAcrossConsecutiveMixedInventoryDays() + { + var service = new ItemMaturationService(); + var inventory = new[] + { + new Item { Name = "Mature Cheese", Quality = 10, SellIn = 1 }, + new Item { Name = "Elixir of the Mongoose", Quality = 10, SellIn = 5 }, + new Item { Name = "Mature Cheese", Quality = 49, SellIn = 0 }, + }; + + var firstDay = inventory.Select(service.Mature).ToArray(); + var secondDay = firstDay.Select(service.Mature).ToArray(); + + firstDay[0].Quality.Should().Be(11); + firstDay[0].SellIn.Should().Be(0); + firstDay[1].Quality.Should().Be(9); + firstDay[1].SellIn.Should().Be(4); + firstDay[2].Quality.Should().Be(50); + firstDay[2].SellIn.Should().Be(-1); + + secondDay[0].Quality.Should().Be(13); + secondDay[0].SellIn.Should().Be(-1); + secondDay[1].Quality.Should().Be(8); + secondDay[1].SellIn.Should().Be(3); + secondDay[2].Quality.Should().Be(50); + secondDay[2].SellIn.Should().Be(-2); + + inventory[0].Quality.Should().Be(10); + inventory[0].SellIn.Should().Be(1); + inventory[2].Quality.Should().Be(49); + inventory[2].SellIn.Should().Be(0); + } +} From 094daf3375d564456fa36878377dfefcb82b1e5e Mon Sep 17 00:00:00 2001 From: agentic-dev agent Date: Sun, 22 Nov 2026 19:37:18 +0000 Subject: [PATCH 2/2] Add Spec Kit files for gilded_rose_new_product_business_rules.md --- .../add-a-new-product-to-gilded-rose/plan.md | 35 +++++ .../add-a-new-product-to-gilded-rose/spec.md | 120 ++++++++++++++++++ .../add-a-new-product-to-gilded-rose/tasks.md | 7 + 3 files changed, 162 insertions(+) create mode 100644 specs/add-a-new-product-to-gilded-rose/plan.md create mode 100644 specs/add-a-new-product-to-gilded-rose/spec.md create mode 100644 specs/add-a-new-product-to-gilded-rose/tasks.md diff --git a/specs/add-a-new-product-to-gilded-rose/plan.md b/specs/add-a-new-product-to-gilded-rose/plan.md new file mode 100644 index 0000000..9e3f13a --- /dev/null +++ b/specs/add-a-new-product-to-gilded-rose/plan.md @@ -0,0 +1,35 @@ +# Implementation plan: Add Mature Cheese + +## Technical context + +The proposed implementation is C# on .NET 8, using xUnit and FluentAssertions. Product classification and maturation rules live in the Proposed Code domain; `Quality` already clamps values to 0–50. CI runs `dotnet test`. + +## Approach + +Add a `MatureCheese` item kind for the exact name `Mature Cheese`. Handle it in a dedicated policy method: choose a quality increase of 1 when the starting `sellIn` is positive, otherwise 2; let the existing `Quality` value object enforce the 0–50 range; then decrement `sellIn` once. Keep other policy branches unchanged. The service already returns updated item values without mutating the input item. + +Use the defined name, increases, and cap as the implementation defaults. Add no behavior beyond the stated post-sell-by increase because no additional maximum-age rule is specified. Do not modify Original Code. + +## Files + +- `src/Core/ProposedCode/Domain/ItemKind.cs` — add exact-name classification for Mature Cheese. +- `src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs` — add the isolated Mature Cheese update rule. +- `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` — test exact classification and similar non-matching names. +- `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` — test before, on, and past sell-by behavior; sellIn countdown; quality boundaries and invalid imported values. +- `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` — test the returned updated values, multiple and consecutive updates in mixed inventories, unchanged input items, and existing product regressions. + +## Risks + +- The item kind and policy are shared dispatch points; an incorrect switch branch could alter existing product behavior. Preserve all existing branches and cover their current behavior with regression tests (FR-010). +- `Quality` clamps on state creation as well as when increased. Verify out-of-range values through the service path so tests reflect the application’s normalization policy (FR-008). +- The spec leaves additional maximum-age behavior undecided. Implement only the explicit rule for `sellIn <= 0`; do not add a separate age threshold (FR-014). +- Limit source changes to Proposed Code to preserve Original Code (FR-017). + +## Test plan + +Run `dotnet test` (the CI test command). + +- `ItemKindTests`: verify exact-name classification and near-match exclusion (FR-001, FR-009). +- `ItemMaturingPolicyTests`: verify +1 for positive starting `sellIn`, +2 for zero or negative starting `sellIn`, decrement by one using the starting value, cap at 50, floor at 0, and repeated deterministic updates (FR-002–FR-008, FR-014–FR-016). +- `ItemMaturationServiceTests`: verify returned quality and `sellIn`, multiple matching items and consecutive updates in mixed inventories, and that the input item remains unchanged outside the update result (FR-011–FR-013, FR-015). +- Existing product cases in policy and service tests, plus the full test suite: verify established product behavior remains unchanged and Original Code is untouched (FR-010, FR-017–FR-019). \ No newline at end of file diff --git a/specs/add-a-new-product-to-gilded-rose/spec.md b/specs/add-a-new-product-to-gilded-rose/spec.md new file mode 100644 index 0000000..92a3cc0 --- /dev/null +++ b/specs/add-a-new-product-to-gilded-rose/spec.md @@ -0,0 +1,120 @@ +# Feature specification: Add a New Product to Gilded Rose +UI work: no +spec.md + +## User scenarios + +**Mature Cheese before its sell-by date** +Given a Mature Cheese item with `sellIn` greater than 0, when the inventory is updated, then its quality increases by 1 and its `sellIn` decreases by 1. + +**Mature Cheese at or past its sell-by date** +Given a Mature Cheese item with `sellIn` equal to or less than 0 at the start of an update, when the inventory is updated, then its quality increases by 2 and its `sellIn` decreases by 1. + +**Quality boundaries and legacy data** +Given Mature Cheese quality at a boundary or outside the valid range, when the inventory is updated, then its quality remains within 0–50. + +**Mixed inventory and ordinary access** +Given an inventory containing Mature Cheese and other products, when a daily update runs, then only the exact Mature Cheese product follows these rules, and creating, reading, displaying, or searching for an item does not change it. + +## Requirements + +FR-001: The system shall recognize the exact product name `Mature Cheese` as an aging food product. [NEEDS CLARIFICATION: Is the official product name `Mature Cheese`, or should it be another exact name?] + +FR-002: The system shall support Mature Cheese quality values from 0 through 50, inclusive. + +FR-003: When Mature Cheese has `sellIn` greater than 0 at the start of an update, the system shall increase its quality by 1. [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?] + +FR-004: When Mature Cheese has `sellIn` equal to or less than 0 at the start of an update, the system shall increase its quality by 2. [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?] + +FR-005: At the end of each inventory update, the system shall decrease Mature Cheese `sellIn` by 1. + +FR-006: The system shall determine the quality increase using `sellIn` before it is decreased. + +FR-007: The system shall cap Mature Cheese quality at 50 after an increase. [NEEDS CLARIFICATION: Is 50 the correct maximum quality?] + +FR-008: The system shall keep Mature Cheese quality between 0 and 50, inclusive, including when imported quality is outside that range; invalid values shall follow the proposed code’s existing quality normalization policy. + +FR-009: The system shall apply Mature Cheese behavior only to the exact product name; similar but non-exact names shall not receive this behavior. + +FR-010: The system shall leave the existing behavior of Aged Brie, Backstage passes, Sulfuras, Conjured items, and other products unchanged. + +FR-011: The system shall change a Mature Cheese item’s quality or `sellIn` only during the daily inventory update, not during creation, reading, displaying, or searching. + +FR-012: The system shall persist both updated quality and `sellIn` values after each daily inventory update. + +FR-013: The system shall apply the rules consistently to multiple Mature Cheese items and across consecutive updates, including in mixed inventories. + +FR-014: The system shall follow the approved policy for any additional behavior after a maximum age. [NEEDS CLARIFICATION: Should Mature Cheese have special behavior such as becoming unsafe or losing value after a maximum age?] + +FR-015: The system shall produce the same result for the same starting item and update operation. + +FR-016: The system shall keep the Mature Cheese behavior isolated and independently testable. + +FR-017: The change shall modify only Proposed Code and shall not change Original Code. + +FR-018: Automated unit tests shall cover the business rules and regression tests shall confirm existing product behavior is unchanged. Suggested test names are `increases_quality_by_one_before_sell_by`, `increases_quality_by_two_on_sell_by_date`, `increases_quality_by_two_after_sell_by`, `does_not_increase_quality_above_fifty`, `keeps_quality_at_fifty`, `decreases_sell_in_by_one_each_day`, and `does_not_change_existing_product_behaviour`. + +FR-019: The change shall avoid unrelated refactoring or changes to unrelated product behavior. + +## Success criteria + +SC-001: One update produces `sellIn = 4`, `quality = 11` from `sellIn = 5`, `quality = 10`, and `sellIn = 0`, `quality = 11` from `sellIn = 1`, `quality = 10`. + +SC-002: One update produces `sellIn = -1`, `quality = 12` from `sellIn = 0`, `quality = 10`, and `sellIn = -2`, `quality = 12` from `sellIn = -1`, `quality = 10`. + +SC-003: Quality is 50 after an increase from 49, and remains 50 when it starts at 50; no update leaves quality outside 0–50. + +SC-004: Existing product behavior and outputs remain unchanged, and accessing an item outside the daily update does not change its quality or `sellIn`. + +## Acceptance criteria + +AC-001 — When an item named exactly `Mature Cheese` is classified, the system shall recognize it as the new aging food product (FR-001). + +AC-002 — When Mature Cheese is created or its quality is normalized, the system shall keep its quality within 0–50, inclusive (FR-002). + +AC-003 — When one update starts with `sellIn = 5`, `quality = 10`, or `sellIn = 1`, `quality = 10`, the system shall increase quality by 1 (FR-003). + +AC-004 — When one update starts with `sellIn = 0`, `quality = 10`, or `sellIn = -1`, `quality = 10`, the system shall increase quality by 2 (FR-004). + +AC-005 — When a Mature Cheese item is updated once, the system shall decrease its `sellIn` by exactly 1 (FR-005). + +AC-006 — When an update starts with `sellIn = 1`, the system shall apply the before-sell-by increase and end with `sellIn = 0` (FR-006). + +AC-007 — When an increase would take quality above 50, the system shall store quality as 50 (FR-007). + +AC-008 — When an update receives Mature Cheese quality below 0 or above 50, the system shall leave the updated quality within 0–50 (FR-008). + +AC-009 — When an item’s name is similar to but not exactly `Mature Cheese`, the system shall not apply the Mature Cheese behavior (FR-009). + +AC-010 — When existing products are updated, the system shall retain their previous behavior and outputs (FR-010). + +AC-011 — When a Mature Cheese item is created, read, displayed, or searched for without a daily update, the system shall leave its quality and `sellIn` unchanged (FR-011). + +AC-012 — When a daily update completes for Mature Cheese, the system shall provide the updated quality and `sellIn` values (FR-012). + +AC-013 — When consecutive updates run on multiple Mature Cheese items in a mixed inventory, the system shall apply the Mature Cheese rules to each matching item on each update (FR-013). + +AC-014 — When Mature Cheese reaches an age beyond its sell-by date, the system shall apply the approved maximum-age behavior (FR-014). + +AC-015 — When the same starting item and update operation are repeated, the system shall produce the same result each time (FR-015). + +AC-016 — When Mature Cheese rules are tested independently, the system shall allow those rules to be verified without changing other product behavior (FR-016). + +AC-017 — When the feature is delivered, the system shall have changes only in Proposed Code, with Original Code unchanged (FR-017). + +AC-018 — When automated tests run, the system shall have unit coverage for the business rules and regression coverage for existing products, using the suggested test names where applicable (FR-018). + +AC-019 — When the feature is delivered, the system shall contain no unrelated refactoring or unrelated product behavior changes (FR-019). + +## Out of scope + +- Changing Original Code. +- Adding user-interface behavior. +- Introducing product behavior beyond the approved Mature Cheese rules. + +## Open questions + +- [NEEDS CLARIFICATION: Is the official product name `Mature Cheese`, or should it be another exact name?] +- [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?] +- [NEEDS CLARIFICATION: Is 50 the correct maximum quality?] +- [NEEDS CLARIFICATION: Should Mature Cheese have special behavior such as becoming unsafe or losing value after a maximum age?] \ No newline at end of file diff --git a/specs/add-a-new-product-to-gilded-rose/tasks.md b/specs/add-a-new-product-to-gilded-rose/tasks.md new file mode 100644 index 0000000..e58e290 --- /dev/null +++ b/specs/add-a-new-product-to-gilded-rose/tasks.md @@ -0,0 +1,7 @@ +# Tasks: Add Mature Cheese + +- [ ] T001 [P] Test exact `Mature Cheese` classification and similar-name exclusion in `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` (FR-001, FR-009, AC-001, AC-009) +- [ ] T002 [P] Test Mature Cheese policy behavior for positive, zero, and negative `sellIn`, countdown, quality boundaries, invalid imported values, and repeated updates in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-002–FR-008, FR-014–FR-016, AC-002–AC-008, AC-014–AC-016) +- [ ] T003 [P] Test returned values, unchanged input items, multiple and consecutive updates in mixed inventories, and existing-product regressions in `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` (FR-010–FR-013, FR-015, FR-018, AC-010–AC-013, AC-015, AC-018) +- [ ] T004 [P] Add exact-name Mature Cheese classification in `src/Core/ProposedCode/Domain/ItemKind.cs` (FR-001, FR-009, FR-017, FR-019, AC-001, AC-009, AC-017, AC-019) +- [ ] T005 Add the isolated Mature Cheese maturation rule, using the starting `sellIn` and existing quality normalization, in `src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs` after T004 (FR-002–FR-008, FR-010, FR-012–FR-017, FR-019, AC-002–AC-008, AC-010, AC-012–AC-017, AC-019) \ No newline at end of file