From 7665673d7ee1ec3ba7f21d027cd22915764cfe20 Mon Sep 17 00:00:00 2001 From: agentic-dev agent Date: Sun, 29 Nov 2026 20:18:21 +0000 Subject: [PATCH 1/4] Add exact Mature Cheese classification Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Core/ProposedCode/Domain/ItemKind.cs | 5 ++++- tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs | 5 ++++- 2 files changed, 8 insertions(+), 2 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/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs b/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs index 040e12d..a8e83f8 100644 --- a/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs +++ b/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs @@ -18,6 +18,9 @@ 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("Mature Cheeses", typeof(ItemKind.Standard))] + [InlineData("mature Cheese", typeof(ItemKind.Standard))] [InlineData("Elixir of the Mongoose", typeof(ItemKind.Standard))] public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType) { @@ -25,4 +28,4 @@ public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType result.Should().BeOfType(expectedType); } -} \ No newline at end of file +} From 31445e254466cd14218bb904372295176cee6409 Mon Sep 17 00:00:00 2001 From: agentic-dev agent Date: Sun, 29 Nov 2026 20:18:29 +0000 Subject: [PATCH 2/4] Add Mature Cheese maturation policy and tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ProposedCode/Domain/ItemMaturingPolicy.cs | 10 ++++- .../Domain/ItemMaturingPolicyTests.cs | 42 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs b/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs index 0221621..fe016c6 100644 --- a/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs +++ b/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs @@ -15,6 +15,7 @@ public ItemState Mature(ItemKind kind, ItemState state) ItemKind.AgedBrie => this.MatureAgedBrie(state), ItemKind.Backstage => this.MatureBackstage(state), ItemKind.Conjured => this.MatureConjured(state), + ItemKind.MatureCheese => this.MatureMatureCheese(state), ItemKind.Sulfuras => state, _ => this.MatureStandard(state), }; @@ -77,4 +78,11 @@ private ItemState MatureConjured(ItemState state) return new(newQuality, newSellIn); } -} \ No newline at end of file + + private ItemState MatureMatureCheese(ItemState state) + { + var increase = state.SellIn.IsBelow(1) ? 2 : 1; + + return new(state.Quality.Increase(increase), state.SellIn.NextDay()); + } +} diff --git a/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs b/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs index 55d645c..1e14492 100644 --- a/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs +++ b/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs @@ -80,6 +80,46 @@ public void Mature_WhenKindIsConjured_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, 5, 1, 4)] + [InlineData(1, 0, 3, -1)] + [InlineData(49, 5, 50, 4)] + [InlineData(49, 0, 50, -1)] + [InlineData(50, 5, 50, 4)] + [InlineData(50, 0, 50, -1)] + [InlineData(-5, 5, 1, 4)] + [InlineData(-5, 0, 2, -1)] + [InlineData(80, 5, 50, 4)] + [InlineData(80, -3, 50, -4)] + 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); + } + + [Fact] + public void Mature_WhenMatureCheeseMaturesRepeatedly_CrossesSellByAndCapsAtFifty() + { + var state = new ItemState(new Quality(46), new SellIn(2)); + var expected = new[] { (47, 1), (48, 0), (50, -1), (50, -2) }; + + foreach (var (quality, sellIn) in expected) + { + state = this.policy.Mature(new ItemKind.MatureCheese(), state); + + state.Quality.Value.Should().Be(quality); + state.SellIn.Value.Should().Be(sellIn); + } + } + [Fact] public void Mature_WhenKindIsSulfuras_PreservesProvidedState() { @@ -89,4 +129,4 @@ public void Mature_WhenKindIsSulfuras_PreservesProvidedState() result.Should().Be(state); } -} \ No newline at end of file +} From 79df14136a6f1c3f4dbdf4bfa1067c5dca4f4f3e Mon Sep 17 00:00:00 2001 From: agentic-dev agent Date: Sun, 29 Nov 2026 20:19:14 +0000 Subject: [PATCH 3/4] Add Mature Cheese service coverage Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ItemMaturationServiceTests.cs | 99 ++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs b/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs index 4690ec6..5dfb621 100644 --- a/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs +++ b/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs @@ -35,4 +35,101 @@ public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int qualit result.Quality.Should().Be(expectedQuality); result.SellIn.Should().Be(expectedSellIn); } -} \ No newline at end of file + + [Theory] + [InlineData(5, 10, 11, 4)] + [InlineData(1, 10, 11, 0)] + [InlineData(0, 10, 12, -1)] + [InlineData(-1, 10, 12, -2)] + [InlineData(5, 49, 50, 4)] + [InlineData(0, 49, 50, -1)] + [InlineData(5, 50, 50, 4)] + [InlineData(0, 50, 50, -1)] + [InlineData(5, -5, 1, 4)] + [InlineData(5, 100, 50, 4)] + public void Mature_MatureCheese_UsesStartingSellInAndClampsQuality(int sellIn, int quality, int expectedQuality, int expectedSellIn) + { + var service = new ItemMaturationService(); + var item = new Item + { + Name = "Mature Cheese", + Quality = quality, + SellIn = sellIn, + }; + + var result = service.Mature(item); + + result.Quality.Should().Be(expectedQuality); + result.SellIn.Should().Be(expectedSellIn); + } + + [Fact] + public void Mature_MatureCheese_DoesNotMutateInputItem() + { + var service = new ItemMaturationService(); + var item = new Item + { + Name = "Mature Cheese", + Quality = 10, + SellIn = 5, + }; + + var result = service.Mature(item); + + result.Should().NotBeSameAs(item); + item.Quality.Should().Be(10); + item.SellIn.Should().Be(5); + result.Quality.Should().Be(11); + result.SellIn.Should().Be(4); + } + + [Fact] + public void Mature_HandlesMultipleMatureCheeseItemsInMixedInventory() + { + var service = new ItemMaturationService(); + var inventory = new[] + { + new Item { Name = "Mature Cheese", Quality = 10, SellIn = 5 }, + new Item { Name = "Aged Brie", Quality = 10, SellIn = 2 }, + new Item { Name = "Mature Cheese", Quality = 49, SellIn = 0 }, + new Item { Name = "Sulfuras, Hand of Ragnaros", Quality = 80, SellIn = 0 }, + }; + + var results = new[] + { + service.Mature(inventory[0]), + service.Mature(inventory[1]), + service.Mature(inventory[2]), + service.Mature(inventory[3]), + }; + + results.Should().BeEquivalentTo(new[] + { + new Item { Name = "Mature Cheese", Quality = 11, SellIn = 4 }, + new Item { Name = "Aged Brie", Quality = 11, SellIn = 1 }, + new Item { Name = "Mature Cheese", Quality = 50, SellIn = -1 }, + new Item { Name = "Sulfuras, Hand of Ragnaros", Quality = 80, SellIn = 0 }, + }, options => options.WithStrictOrdering()); + } + + [Theory] + [InlineData("Mature cheese")] + [InlineData("Mature Cheese ")] + [InlineData("Mature Cheese Extra")] + public void Mature_SimilarButNonExactNames_UseStandardRules(string name) + { + var service = new ItemMaturationService(); + var item = new Item + { + Name = name, + Quality = 10, + SellIn = 5, + }; + + var result = service.Mature(item); + + result.Name.Should().Be(name); + result.Quality.Should().Be(9); + result.SellIn.Should().Be(4); + } +} From a3e8b5bf0494f3269b756b030249dfcaddab59c7 Mon Sep 17 00:00:00 2001 From: agentic-dev agent Date: Sun, 29 Nov 2026 20:20:03 +0000 Subject: [PATCH 4/4] Add Spec Kit files for gilded_rose_new_product_business_rules.md --- .../add-a-new-product-to-gilded-rose/plan.md | 34 ++++++ .../add-a-new-product-to-gilded-rose/spec.md | 107 ++++++++++++++++++ .../add-a-new-product-to-gilded-rose/tasks.md | 6 + 3 files changed, 147 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..3fa8aa3 --- /dev/null +++ b/specs/add-a-new-product-to-gilded-rose/plan.md @@ -0,0 +1,34 @@ +# Implementation plan: Add Mature Cheese to Gilded Rose + +## Technical context + +The proposed implementation is C# on .NET 8. Product classification, quality bounds, and daily maturation are handled in `src/Core/ProposedCode`; unit tests use xUnit and FluentAssertions. CI restores, builds, and tests the solution with the .NET CLI. + +## Approach + +Add a distinct `MatureCheese` item kind, recognized only for the exact name `Mature Cheese`. Handle it in the proposed maturation policy using the starting `SellIn`: increase quality by 1 when it is positive, otherwise by 2, then decrement `SellIn`. Use the existing `Quality` value object to clamp imported values and increases to 0–50. Leave other product rules and all Original Code untouched. + +The service returns a new item rather than mutating the input, so test that values change only when the daily maturation operation is explicitly called. Do not add behavior for reading, displaying, or searching; this repository has no corresponding inventory APIs. + +## Files + +- `src/Core/ProposedCode/Domain/ItemKind.cs` — add the Mature Cheese kind and exact-name mapping. +- `src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs` — add the isolated rule and dispatch for the new kind. +- `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` — verify exact-name classification and similar-name fallback. +- `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` — cover sell-by boundaries, quality limits, imported out-of-range values, and repeated updates. +- `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` — verify end-to-end results, input non-mutation, and mixed product behavior. + +## Risks + +`ItemKind` and the maturation policy are public proposed-code types; adding a kind expands their supported set. Existing `Quality` construction already clamps values to 0–50, so the new rule should reuse it rather than introduce separate normalization. Keep changes confined to Proposed Code to preserve Original Code and existing product behavior. + +## Test plan + +Run `dotnet test tests/Core.Tests/GildedRoseKata.Core.Tests.csproj`. + +- **FR-001, FR-007:** `ItemKindTests` and service tests verify exact matching and similar-name fallback. +- **FR-002–FR-006:** Policy and service tests verify sell-in starts of 5, 1, 0, and -1; quality boundaries 0, 1, 49, and 50; out-of-range input clamping; and the 0–50 invariant. +- **FR-008–FR-009:** Regression tests for existing product kinds verify their behavior remains unchanged; review confirms no Original Code files are changed. +- **FR-010:** Service tests verify the input item is unchanged until maturation is called; no read, display, or search APIs exist in this repository. +- **FR-011–FR-013:** Tests cover consecutive updates, separate Mature Cheese items, mixed products, and deterministic expected results. +- **FR-014:** Mature Cheese tests verify only the specified quality and sell-in rules, with no age-based unsafe or value-loss behavior. \ 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..83f8796 --- /dev/null +++ b/specs/add-a-new-product-to-gilded-rose/spec.md @@ -0,0 +1,107 @@ +# Feature specification: Add Mature Cheese to Gilded Rose +UI work: no +gilded_rose_new_product_business_rules.md + +## User scenarios + +### Scenario 1: Mature Cheese before its sell-by date +As the inventory update process, I update Mature Cheese each day so its quality improves while it is within its sell-by period. +- **Given** a Mature Cheese item with `sellIn = 5` and `quality = 10`, **when** the inventory is updated, **then** it has `sellIn = 4` and `quality = 11`. + +### Scenario 2: Mature Cheese on or past its sell-by date +As the inventory update process, I improve Mature Cheese quality faster once its sell-by date has arrived. +- **Given** a Mature Cheese item with `sellIn = 0` and `quality = 10`, **when** the inventory is updated, **then** it has `sellIn = -1` and `quality = 12`. + +### Scenario 3: Quality boundaries and imported data +As the inventory update process, I keep Mature Cheese quality within its valid range, including when existing inventory data is out of range. +- **Given** a Mature Cheese item at a quality boundary or with out-of-range quality data, **when** the inventory is updated, **then** its quality is within 0–50. + +### Scenario 4: Existing inventory and other operations +As an inventory user, I rely on existing product rules and on reading or searching inventory not changing item values. +- **Given** an inventory containing Mature Cheese and other product types, **when** it is updated or items are read, displayed, or searched, **then** only the daily update changes Mature Cheese values and existing product behavior remains unchanged. + +## Requirements + +FR-001 The system shall recognize `Mature Cheese` as the exact product name for the new behavior. [NEEDS CLARIFICATION: Is the official product name `Mature Cheese`, or should it be another exact name?] + +FR-002 The system shall increase Mature Cheese quality by 1 when its `sellIn` value at the start of the update is greater than 0. [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?] + +FR-003 The system shall increase Mature Cheese quality by 2 when its `sellIn` value at the start of the update is 0 or less. [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?] + +FR-004 The system shall decrease Mature Cheese `sellIn` by 1 during each daily inventory update, after evaluating the sell-by condition using its starting value. + +FR-005 The system shall cap Mature Cheese quality at 50 after each update. [NEEDS CLARIFICATION: Is 50 the correct maximum quality?] + +FR-006 The system shall keep Mature Cheese quality within 0–50, applying the existing proposed-code policy for out-of-range quality data. + +FR-007 The system shall apply the Mature Cheese behavior only to the exact product name, leaving similar but non-matching names to their existing product rules. + +FR-008 The system shall add this behavior only to Proposed Code and shall not change Original Code. + +FR-009 The system shall preserve existing behavior for Aged Brie, Backstage passes, Sulfuras, Conjured items, and other existing product types. + +FR-010 The system shall limit changes to Mature Cheese quality and `sellIn` to the daily inventory update; creating, reading, displaying, or searching for an item shall not change either value. + +FR-011 The system shall apply the Mature Cheese rules independently to each matching item in inventories containing multiple Mature Cheese items or mixed product types. + +FR-012 The system shall produce the same result for the same starting item and daily update operation. + +FR-013 The system shall keep the new rules isolated from existing product rules and verifiable through automated unit tests. + +FR-014 The system shall not add age-based unsafe or value-loss behavior beyond the stated rules unless that behavior is confirmed. [NEEDS CLARIFICATION: Should Mature Cheese have special behavior such as becoming unsafe or losing value after a maximum age?] + +## Success criteria + +SC-001 A daily update produces the specified results for starting `sellIn` values of 5, 1, 0, and -1 with quality 10: respectively `(4, 11)`, `(0, 11)`, `(-1, 12)`, and `(-2, 12)`. + +SC-002 Tests at qualities 0, 1, 49, and 50 and with out-of-range imported values confirm that updated Mature Cheese quality is always within 0–50. + +SC-003 Tests covering consecutive updates, multiple Mature Cheese items, mixed inventories, and similar but non-exact product names confirm the stated behavior. + +SC-004 Regression tests confirm existing product behavior is unchanged and Original Code is untouched. + +SC-005 Tests confirm that creating, reading, displaying, or searching for Mature Cheese does not change its quality or `sellIn`. + +## Acceptance criteria + +AC-001 When an item named exactly `Mature Cheese` is updated, the system shall apply the new product behavior. Checks FR-001. + +AC-002 When Mature Cheese has `sellIn = 5` and `quality = 10` at update start, the system shall produce `sellIn = 4` and `quality = 11`. Checks FR-002. + +AC-003 When Mature Cheese has `sellIn = 0` and `quality = 10` at update start, the system shall produce `sellIn = -1` and `quality = 12`; when it starts at `sellIn = -1` and `quality = 10`, it shall produce `sellIn = -2` and `quality = 12`. Checks FR-003. + +AC-004 When a Mature Cheese item is updated, the system shall decrease `sellIn` by 1, using its value before the update to determine the quality increase. Checks FR-004. + +AC-005 When a quality increase would exceed 50, the system shall store 50; an item starting at `quality = 49` shall end at 50 for both `sellIn = 5` and `sellIn = 0`, and an item starting at 50 shall remain at 50. Checks FR-005. + +AC-006 When Mature Cheese is updated with a valid or out-of-range quality value, the system shall follow the existing proposed-code data policy and leave quality within 0–50. Checks FR-006. + +AC-007 When an item has a name similar to but not exactly `Mature Cheese`, the system shall not apply the new behavior to it. Checks FR-007. + +AC-008 When this feature is implemented, the system shall leave Original Code unchanged. Checks FR-008. + +AC-009 When an existing product is updated, the system shall preserve its previous behavior, including for Aged Brie, Backstage passes, Sulfuras, and Conjured items. Checks FR-009. + +AC-010 When a Mature Cheese item is created, read, displayed, or searched, the system shall leave its quality and `sellIn` unchanged; changes shall occur only during the daily inventory update. Checks FR-010. + +AC-011 When an inventory update includes multiple Mature Cheese items or a mix of Mature Cheese and existing products, the system shall apply each product’s rules independently. Checks FR-011. + +AC-012 When the same starting item receives the same update operation, the system shall produce the same result. Checks FR-012. + +AC-013 When the new behavior is verified, the system shall have automated unit tests covering its rules without requiring changes to existing product behavior. Checks FR-013. + +AC-014 When Mature Cheese is updated, the system shall not apply age-based unsafe or value-loss behavior unless that behavior is confirmed. Checks FR-014. + +## Out of scope + +- Changes to Original Code. +- User interface work. +- Unrelated refactoring or changes to existing product behavior. +- Additional aging behavior beyond the stated rules unless confirmed. + +## 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..d9ae86e --- /dev/null +++ b/specs/add-a-new-product-to-gilded-rose/tasks.md @@ -0,0 +1,6 @@ +# Tasks: Add Mature Cheese to Gilded Rose +- [ ] T001 [P] Add exact-name and similar-name classification tests for Mature Cheese in `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` (FR-001, FR-007; AC-001, AC-007) +- [ ] T002 [P] Add policy tests for sell-by boundaries, quality limits, imported values, and consecutive updates in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-002, FR-003, FR-004, FR-005, FR-006, FR-012, FR-013, FR-014; AC-002, AC-003, AC-004, AC-005, AC-006, AC-012, AC-013, AC-014) +- [ ] T003 [P] Add service tests for Mature Cheese results, input non-mutation, multiple and mixed items, and existing-product regressions in `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` (FR-001, FR-007, FR-008, FR-009, FR-010, FR-011, FR-012, FR-013, FR-014; AC-001, AC-007, AC-008, AC-009, AC-010, AC-011, AC-012, AC-013, AC-014) +- [ ] T004 Add the Mature Cheese kind and exact-name mapping in `src/Core/ProposedCode/Domain/ItemKind.cs` after T001 (FR-001, FR-007, FR-008; AC-001, AC-007, AC-008) +- [ ] T005 Add isolated Mature Cheese maturation and dispatch using the starting `SellIn` and existing `Quality` bounds in `src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs` after T002 and T004 (FR-002, FR-003, FR-004, FR-005, FR-006, FR-008, FR-009, FR-011, FR-012, FR-014; AC-002, AC-003, AC-004, AC-005, AC-006, AC-008, AC-009, AC-011, AC-012, AC-014) \ No newline at end of file