Skip to content

Prevent duplicate inserts for canonical/reference rows#1054

Open
dgee2 wants to merge 2 commits intomainfrom
squad/978-prevent-duplicate-inserts-for-canonical-reference-rows
Open

Prevent duplicate inserts for canonical/reference rows#1054
dgee2 wants to merge 2 commits intomainfrom
squad/978-prevent-duplicate-inserts-for-canonical-reference-rows

Conversation

@dgee2
Copy link
Copy Markdown
Owner

@dgee2 dgee2 commented May 3, 2026

Summary

  • normalize ingredient unit-id payloads before canonical comparison
  • reuse an existing ingredient row when the same name resolves to the same effective unit set
  • block mismatched canonical redefinitions before insert and add unit/integration coverage for reuse behavior

Testing

  • dotnet test --project .\backend\MenuApi.Tests\MenuApi.Tests.csproj
  • dotnet test --project .\backend\MenuApi.Integration.Tests\MenuApi.Integration.Tests.csproj

Closes #978

Copilot AI review requested due to automatic review settings May 3, 2026 21:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 UnitIds at 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.

Comment thread backend/MenuApi/Repositories/IngredientRepository.cs
Comment thread backend/MenuApi/Repositories/IngredientRepository.cs
Comment thread backend/MenuApi/Repositories/IngredientRepository.cs
@dgee2
Copy link
Copy Markdown
Owner Author

dgee2 commented May 3, 2026

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.

@dgee2 dgee2 enabled auto-merge (squash) May 3, 2026 21:55
@dgee2
Copy link
Copy Markdown
Owner Author

dgee2 commented May 3, 2026

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.

dgee2 and others added 2 commits May 3, 2026 23:25
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 3, 2026 22:38
@dgee2 dgee2 force-pushed the squad/978-prevent-duplicate-inserts-for-canonical-reference-rows branch from d715b36 to f63fe3b Compare May 3, 2026 22:38
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 3, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

Prevent duplicate inserts for canonical/reference rows

2 participants