Prevent duplicate inserts for canonical/reference rows#1054
Prevent duplicate inserts for canonical/reference rows#1054
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates ingredient creation so canonical ingredient rows are reused instead of duplicated when the same ingredient name resolves to an equivalent effective unit-id set, and it rejects attempts to redefine an existing canonical name with a different unit set.
Changes:
- Normalize/deduplicate
UnitIdsat the service boundary before repository calls. - Add repository lookup-before-insert logic to reuse equivalent existing ingredients (and throw on mismatched redefinitions).
- Add unit + integration test coverage for normalization and reuse behavior, plus squad documentation/decision records.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/MenuApi/Services/IngredientService.cs | Normalizes/deduplicates incoming UnitIds before calling the repository. |
| backend/MenuApi/Repositories/IngredientRepository.cs | Implements lookup-by-name, equivalent-unit-set reuse, and mismatched redefinition rejection; refactors mapping. |
| backend/MenuApi.Tests/Services/IngredientServiceTests.cs | Unit test ensuring service-level UnitIds deduping before repository call. |
| backend/MenuApi.Tests/Repositories/IngredientRepositoryTests.cs | Repository tests covering reuse of equivalent canonical rows and rejection of redefinitions. |
| backend/MenuApi.Integration.Tests/IngredientIntegrationTests.cs | Integration test ensuring repeated equivalent creates return the same canonical row (same ID). |
| .squad/skills/canonical-reference-row-reuse/SKILL.md | Documents the canonical/reference row reuse pattern (normalization + reuse + reject redefinition). |
| .squad/decisions/inbox/basher-issue-978.md | Records the decision for issue #978 and scope rationale for POST /api/ingredient. |
| .squad/agents/basher/history.md | Adds project/agent history notes including where coverage for canonical reuse lives. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Danny review: approve. This satisfies #978 cleanly: IngredientService normalizes UnitIds, IngredientRepository does lookup-before-insert on ingredient name, reuses an equivalent canonical row, and blocks mismatched redefinitions before another row can be written. CI is green, and I re-ran the backend unit + integration suites locally with 47/47 and 22/22 passing. GitHub would not let me submit a formal approval because the current auth identity is the PR author. |
|
Danny status check: the #978 logic remains approved on substance, but this branch is now blocked by a mechanical post-update compile break. I reproduced the failing checks locally: dotnet test --project .\backend\MenuApi.Integration.Tests\MenuApi.Integration.Tests.csproj --output Detailed --no-progress fails because �ackend/MenuApi.Integration.Tests/IngredientIntegrationTests.cs:90 still references ShortStringAutoData, while ShortStringAutoDataAttribute.cs no longer exists on main after #1051. This does not change my approval of the canonical-row behavior; align that test with the current AutoData/StringLength pattern, rerun checks, and the PR should be mergeable again. GitHub still will not let me submit a formal review because the current auth identity is the PR author. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d715b36 to
f63fe3b
Compare
|



Summary
Testing
Closes #978