Skip to content
34 changes: 34 additions & 0 deletions specs/add-a-new-product-to-gilded-rose/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Implementation plan: Add Mature Cheese to Gilded Rose

## Technical context

The proposed implementation is C# on .NET 8, with nullable reference types and the latest C# language version. Product rules use `ItemKind`, `ItemState`, and `Quality` value types, applied through `ItemMaturingPolicy` and `ItemMaturationService`. Tests use xUnit and FluentAssertions; CI runs `dotnet test`.

## Approach

Add a `MatureCheese` item kind and recognize only the exact name `Mature Cheese`. Route that kind to an isolated policy method that decides the quality increase from the starting `SellIn`, clamps quality using the existing `Quality` behavior, and decrements `SellIn` once. Preserve all existing policy branches and leave Original Code untouched.

Extend the proposed-code tests for exact-name recognition, before/on/after sell-by behavior, quality boundaries and invalid imported values, countdown, input immutability, mixed items, and regression behavior. Proceed with the values specified in the feature requirements: increases of 1 and 2, maximum quality 50, and no maximum-age penalty.

## 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 update rule without changing existing product rules.
- `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` — cover exact recognition and similar-but-not-exact names.
- `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` — cover quality increase based on pre-decrement sell-by value, decrement, and quality bounds.
- `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` — cover service-level normalization, unchanged input, multiple items, and existing-product behavior.

## Risks

`ItemKind` and `ItemMaturingPolicy` are shared by existing products; changes there could affect their behavior, so retain existing mappings and branches and run the full proposed-code test suite. `Quality` already clamps to 0–50 for ordinary items, while Sulfuras has special handling; use that existing policy rather than changing the shared quality type. No public interface changes or migrations are expected. Original Code must remain unchanged.

## Test plan

Run `dotnet test tests/Core.Tests/GildedRoseKata.Core.Tests.csproj`.

- **FR-001, FR-007:** Item-kind tests verify exact `Mature Cheese` recognition and reject similar names.
- **FR-002–FR-005:** Policy tests verify decrement, +1 when starting `sellIn > 0`, +2 when starting `sellIn <= 0`, and the 50 ceiling.
- **FR-006:** Service tests verify qualities below 0 and above 50 are normalized and remain in range after update; boundary cases cover 0, 1, 49, and 50.
- **FR-008, FR-012, FR-013:** Existing product tests and mixed-item cases verify existing behavior remains unchanged; keep production edits confined to Proposed Code.
- **FR-009:** Service tests verify processing an item does not mutate the input item; no update operation means no value changes.
- **FR-010–FR-011:** Policy tests verify no added maximum-age behavior and deterministic results for repeated identical starting states.
101 changes: 101 additions & 0 deletions specs/add-a-new-product-to-gilded-rose/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Feature specification: Add Mature Cheese to Gilded Rose
spec.md

UI work: no

## User scenarios

**Daily inventory update:** As the inventory update process, I want Mature Cheese quality and sell-by values updated each day so that its quality improves according to its age.

- Given a Mature Cheese item with `sellIn` above zero, when the inventory is updated, then quality increases by 1 and `sellIn` decreases by 1.
- Given a Mature Cheese item with `sellIn` equal to or below zero, when the inventory is updated, then quality increases by 2 and `sellIn` decreases by 1; the increase is based on `sellIn` before it is decremented.

**Protect quality values:** As the inventory system, I want Mature Cheese quality kept within valid bounds so that invalid quality values are not stored after an update.

- Given Mature Cheese at or near either quality boundary, when the inventory is updated, then its quality remains between 0 and 50 inclusive.

**Preserve other inventory behavior:** As the inventory manager, I want the new product rule limited to the exact product name and proposed code so that existing product behavior is preserved.

- Given a mixed inventory, when it is updated, then only the exact Mature Cheese product receives the new rule, and existing product behavior remains unchanged.

## Requirements

FR-001 The system shall recognize `Mature Cheese` as an aging food product with an initial quality in the range 0–50 and a sell-by value measured in days remaining. [NEEDS CLARIFICATION: Is the official product name `Mature Cheese`, or should it be another exact name?]

FR-002 At each daily inventory update, the system shall decrease Mature Cheese `sellIn` by 1.

FR-003 When Mature Cheese `sellIn` is 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 `sellIn` is 0 or less 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 The system shall cap Mature Cheese quality at 50 after an update. [NEEDS CLARIFICATION: Is 50 the correct maximum quality?]

FR-006 The system shall keep Mature Cheese quality between 0 and 50 inclusive after an update, including when imported quality is outside that range; invalid imported values shall follow the existing policy of normalizing to the range.

FR-007 The system shall apply the new behavior only to the exact product name `Mature Cheese`. [NEEDS CLARIFICATION: Is the official product name `Mature Cheese`, or should it be another exact name?]

FR-008 The system shall preserve existing behavior for other product types, including Aged Brie, Backstage passes, Sulfuras, and Conjured items.

FR-009 Creating, reading, displaying, or searching for a Mature Cheese item shall not change its quality or `sellIn`; these values shall change only during the daily inventory update.

FR-010 The system shall not add behavior that makes Mature Cheese unsafe or reduces its value after a maximum age unless that behavior is confirmed. [NEEDS CLARIFICATION: Should Mature Cheese have special behavior such as becoming unsafe or losing value after a maximum age?]

FR-011 The system shall produce the same result for the same starting item and daily update operation.

FR-012 The new rule shall be isolated and covered by automated unit tests, including the suggested cases `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-013 The change shall be limited to Proposed Code and shall not change Original Code.

## Success criteria

SC-001 A Mature Cheese item with `sellIn = 5` and `quality = 10` updates to `sellIn = 4` and `quality = 11`.

SC-002 A Mature Cheese item with `sellIn = 1` and `quality = 10` updates to `sellIn = 0` and `quality = 11`; with `sellIn = 0` and `quality = 10`, it updates to `sellIn = -1` and `quality = 12`; with `sellIn = -1` and `quality = 10`, it updates to `sellIn = -2` and `quality = 12`.

SC-003 Updates keep quality within 0–50 for starting qualities 0, 1, 49, and 50, including multiple consecutive updates and invalid imported values.

SC-004 Multiple Mature Cheese items update correctly in the same inventory, and similar-but-not-exact product names and other product types retain their existing behavior.

SC-005 Existing product behavior and outputs remain unchanged, and Original Code remains unchanged.

## Acceptance criteria

AC-001 When a Mature Cheese item is created and updated, the system shall recognize the specified product and valid initial quality and treat `sellIn` as days remaining (FR-001).

AC-002 When a Mature Cheese item undergoes a daily update, the system shall decrease `sellIn` by exactly 1 (FR-002).

AC-003 When an update starts with Mature Cheese `sellIn` greater than 0, the system shall increase quality by exactly 1 (FR-003).

AC-004 When an update starts with Mature Cheese `sellIn` equal to or below 0, the system shall increase quality by exactly 2 using the pre-decrement `sellIn` value (FR-004).

AC-005 When a quality increase would put Mature Cheese above 50, the system shall store quality as 50 (FR-005).

AC-006 When an update processes Mature Cheese with quality below 0 or above 50, the system shall leave its updated quality within 0–50, applying the existing normalization policy to invalid imported values (FR-006).

AC-007 When an item name is exactly `Mature Cheese`, the system shall apply the new rule, and when its name differs, the system shall not apply that rule (FR-007).

AC-008 When an inventory containing existing product types is updated, the system shall preserve their previous behavior, including the named special products (FR-008).

AC-009 When a Mature Cheese item is created, read, displayed, or searched without a daily update, the system shall leave its quality and `sellIn` unchanged (FR-009).

AC-010 When Mature Cheese is updated at any age, the system shall apply no unconfirmed unsafe-product or maximum-age value-loss behavior (FR-010).

AC-011 When the same starting item is processed by the same daily update operation, the system shall produce the same updated values (FR-011).

AC-012 When the Mature Cheese behavior is covered by automated unit tests, the system shall include tests for the listed before-sell-by, on-sell-by, after-sell-by, quality-boundary, sell-by countdown, and existing-product behavior cases (FR-012).

AC-013 When the Mature Cheese change is made, the system shall leave Original Code unchanged and limit the implementation change to Proposed Code (FR-013).

## Out of scope

- User-interface changes.
- Changes to existing product rules or unrelated refactoring.
- Changes to Original Code.
- Additional Mature Cheese behavior beyond the proposed rules, pending clarification about maximum-age behavior.

## 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?]
16 changes: 16 additions & 0 deletions specs/add-a-new-product-to-gilded-rose/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Tasks: Add Mature Cheese to Gilded Rose
- [ ] T001 Add `AC001_RecognizesMatureCheeseWithValidQuality` in `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` (FR-001, AC-001)
- [ ] T002 Add `AC002_DecreasesSellInByOneEachDay` in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-002, AC-002)
- [ ] T003 Add `AC003_IncreasesQualityByOneBeforeSellBy` in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-003, AC-003)
- [ ] T004 Add `AC004_IncreasesQualityByTwoAtOrAfterSellByUsingStartingSellIn` in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-004, AC-004)
- [ ] T005 Add `AC005_CapsQualityAtFifty` in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-005, AC-005)
- [ ] T006 Add `AC006_NormalizesInvalidImportedQuality` in `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` (FR-006, AC-006)
- [ ] T007 Add `AC007_RejectsSimilarButNotExactProductNames` in `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` (FR-007, AC-007)
- [ ] T008 Add `AC008_PreservesExistingProductBehaviorInMixedInventory` in `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` (FR-008, AC-008)
- [ ] T009 Add `AC009_LeavesInputUnchangedOutsideDailyUpdate` in `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` (FR-009, AC-009)
- [ ] T010 Add `AC010_AppliesNoMaximumAgePenalty` in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-010, AC-010)
- [ ] T011 Add `AC011_ProducesDeterministicResults` in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-011, AC-011)
- [ ] T012 Add `AC012_CoversRequiredMatureCheeseScenarios` for the specified sell-by, quality-boundary, countdown, and existing-product cases in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-012, AC-012)
- [ ] T013 Add `AC013_PreservesOriginalCodeBehavior` regression coverage in `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` (FR-013, AC-013)
- [ ] T014 [P] Add the Mature Cheese kind and exact-name mapping in `src/Core/ProposedCode/Domain/ItemKind.cs` after T013 (FR-001, FR-007, FR-013, AC-001, AC-007, AC-013)
- [ ] T015 [P] Add the isolated Mature Cheese update rule using starting `SellIn` and bounded quality in `src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs` after T014 (FR-002, FR-003, FR-004, FR-005, FR-006, FR-008, FR-010, FR-011, FR-013, AC-002, AC-003, AC-004, AC-005, AC-006, AC-008, AC-010, AC-011, AC-013)
5 changes: 4 additions & 1 deletion src/Core/ProposedCode/Domain/ItemKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
};
}
}
}
12 changes: 11 additions & 1 deletion src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.MatureCheese(state),
_ => this.MatureStandard(state),
};
}
Expand Down Expand Up @@ -77,4 +78,13 @@ private ItemState MatureConjured(ItemState state)

return new(newQuality, newSellIn);
}
}

private ItemState MatureCheese(ItemState state)
{
var qualityIncrease = state.SellIn.Value > 0 ? 1 : 2;
var newQuality = state.Quality.Increase(qualityIncrease);
var newSellIn = state.SellIn.NextDay();

return new(newQuality, newSellIn);
}
}
21 changes: 20 additions & 1 deletion tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,23 @@ public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType

result.Should().BeOfType(expectedType);
}
}

[Fact]
public void AC001_RecognizesMatureCheeseWithValidQuality()
{
var result = ItemKind.FromName("Mature Cheese");

result.Should().BeOfType<ItemKind.MatureCheese>();
}

[Theory]
[InlineData("Mature cheese")]
[InlineData("Mature Cheeses")]
[InlineData("Mature Cheese ")]
public void AC007_RejectsSimilarButNotExactProductNames(string itemName)
{
var result = ItemKind.FromName(itemName);

result.Should().BeOfType<ItemKind.Standard>();
}
}
Loading
Loading