Skip to content

fix: findings from a code audit - #15

Closed
dev-agentic-platform[bot] wants to merge 8 commits into
masterfrom
agent/6f7ce55a-96e3-4788-b279-b3bc93eb0fec/fix
Closed

dev-agentic-platform[bot] wants to merge 8 commits into
masterfrom
agent/6f7ce55a-96e3-4788-b279-b3bc93eb0fec/fix

Conversation

@dev-agentic-platform

Copy link
Copy Markdown

Fixes for findings a person selected after a code audit. Agents made these changes; the run was approved at a gate before this pull request was opened.

Review it as you would any change: agents can be wrong.

Decouple Quality from ItemKind; add Quality/ItemState tests

I could not build or run the tests here, so none of this has been compiled or run.

  • src/Core/ProposedCode/Domain/Quality.cs:24 (value-object-coupled-to-item-kind). Fixed: I removed FromItemKind, the Legendary constant and the allowLegendary constructor. Quality no longer references ItemKind.
    • It stays a clamped 0..50 value. The only addition is an internal static Quality Unclamped(int) factory. It uses a private constructor with a neutral clamp flag, so it knows nothing about item kinds.
    • ItemState now holds public const int LegendaryQuality = 80. ItemState.Create(ItemKind, int, int) keeps its signature. For ItemKind.Sulfuras it uses Quality.Unclamped(80). Other kinds use new Quality(quality), which clamps.
    • Sulfuras quality still reads 80, so ItemMaturationService output should not change.
    • Some bypass remains: the instructions asked for none in Quality, but also allowed a factory that is not kind-aware. Quality still has a non-clamping path, but only ItemState can reach it.
  • tests/Core.Tests/ProposedCode/Domain/QualityTests.cs:26 (missing-error-case-test). Fixed: I added Increase_WhenAmountIsNegative_Throws and Decrease_WhenAmountIsNegative_Throws. Both use act.Should().Throw<ArgumentOutOfRangeException>().
  • tests/Core.Tests/ProposedCode/Domain/QualityTests.cs:60 (missing-branch-test). Fixed: I removed the FromItemKind test and added tests/Core.Tests/ProposedCode/Domain/ItemStateTests.cs, in namespace GildedRoseKata.ProposedCode.Tests. It covers:
    • Sulfuras with an input of 12 or 80 gives 80.
    • A Standard item clamps 99 to 50 and -5 to 0, and leaves 20 as 20.
    • SellIn is passed through unchanged for 10, 0 and -3.

Centralize item names in ItemKind and extend its tests

I couldn't build or run the tests here, so the build and test run are unconfirmed.

  • src/Core/ProposedCode/Domain/ItemKind.cs:23 (hardcoded-item-names-and-duplicated-aliases)
    • Fixed: I added public constants for the canonical names: AgedBrieName, BackstageName, ConjuredName and SulfurasName.
    • The short aliases AgedBrieAlias, BackstageAlias and ConjuredAlias are now explicit constants under a comment saying they are accepted in addition to the canonical names.
    • FromName now matches on these constants with or patterns. The input-to-kind mapping is the same as before, and src/Core/OriginalCode is untouched.
  • tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs:13 (weak-test-coverage)
    • Fixed: I added a theory covering names that differ in case ("aged brie", "AGED BRIE", "backstage"), names with surrounding whitespace, "" and " ". All of them are expected to map to ItemKind.Standard.
    • I also added a fact checking that FromName(null) does not throw and returns Standard.
    • The file header and style are kept. I used ItemKind result = null; rather than ItemKind? because I found no Nullable setting in the repo.

Dedupe ItemMaturingPolicy and add boundary tests

I couldn't run the build or tests here (my tools only read and write files). I checked each expected value by hand against the code.

  • src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs:23 (duplicated-maturation-algorithm): Fixed: I replaced the four Mature* methods with one private Age(state, dailyChange, expiredChange) helper. The helper changes quality, advances the day, then applies the expired change if the new sellIn is expired. Each kind now declares only its two changes:
    • Standard: -1 / -1.
    • Aged Brie: +1 / +1.
    • Conjured: -2 / -2.
    • Backstage: BackstageDailyChange reads the sellIn before the day advances (+3 below 6, +2 below 11, otherwise +1), then Reset when expired.
    • The public Mature(ItemKind, ItemState) and the Sulfuras pass-through are unchanged, so behaviour is the same.
  • tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs:46 (missing-edge-case-test): Fixed: I added these cases, each checked against the code:
    • Backstage 50/0 → 0,-1.
    • Backstage 20/-1 → 0,-2.
    • Backstage 48/5 → 50,4.
    • Aged Brie 20/-1 → 22,-2.
    • Standard 10/-1 → 8,-2.
    • A new Sulfuras test using ItemState.Create(new ItemKind.Sulfuras(), 10, 5) that checks the state is unchanged and sellIn stays 5. Create sets Sulfuras quality to 80, so the test covers the nonzero sellIn rather than a quality other than 80.

Extend ItemMaturationService tests

I couldn't build or run the tests here, so none of the new tests have been run. I worked out the expected values by reading ItemMaturingPolicy, Quality and ItemKind.FromName. Only tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs changed.

  • tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs:14 (missing-edge-case-test, ee9c8340…ca078)

    • Fixed: I added new [InlineData] rows to the existing theory:
      • Sulfuras at quality 10 and sellIn 3 gives 80 and 3.
      • Backstage with sellIn -1 gives quality 0 and sellIn -2.
      • Standard with sellIn -1 gives quality 8 and sellIn -2.
      • Standard at quality 60 gives 49, and at quality -5 gives 0.
      • An empty name and a null name are both treated as Standard.
    • I also added four new tests:
      • Mature_PreservesName covers a standard name, Aged Brie, Sulfuras, a custom name, an empty name and a null name.
      • Mature_DoesNotMutateInputItem checks that Name, Quality and SellIn are unchanged and that the result is a different instance.
      • Mature_NullItem_ThrowsNullReferenceException pins the current behaviour with Should().Throw<NullReferenceException>().
    • The null-name theory parameters are string? and use name! to avoid nullable warnings. No src files were touched.
  • tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs:25 (missing-injection-test, 6ba0b0be…b6df)

    • Fixed: I added Mature_WithInjectedPolicy_PassesResolvedKindAndStateAndUsesReturnedState, which uses a private nested StubMaturingPolicy : IMaturingPolicy. The stub records the call count, the ItemKind and the ItemState it receives, and returns a fixed ItemState(Quality 33, SellIn 7).
    • The test asserts:
      • the policy is called once;
      • the kind is ItemKind.AgedBrie;
      • the received state has quality 10 and sellIn 2;
      • the result has Quality 33 and SellIn 7 from the stub, with the name preserved.

agentic-dev agent added 8 commits November 10, 2026 22:50
…020128c2f141d9cefeda1bc70516f2f96cce8af4958421b961, 74e8f98c131a7a40af033f63dc834b7117364b338222ddec706ba65bc9a8ca43)
…620c598a976be77df3fa7a2da069b127d7730b705f885968f34c10b5f738db3, 64f1f564596b5afb21d683c3adb0e43f36c9505a7d5ff8dd0e6f5acc361ad4a3)
Fingerprints: f2dc349dd3cff54bf10125220a357a1ad720a60f33221630b516ae662c7ceb4f, 6c83c72b422a54ac3beff62c9b7e8bcb92d1a657260a8f5fbbf1cb45b8d6e826, bb2c77653800c0a7baf402364e5c613c50c4a065d1fc2b1c94d6f85a32aab1fd
…04b45d8cd7fac22902c3f8b88912b23ca078, 6ba0b0bee2cfa27d661440cc999f697df0a553fbe5ba719041fe3a1cf9c2b6df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant