Skip to content

Implement Mongo Transactions#4194

Closed
imnasnainaec wants to merge 28 commits intomasterfrom
mt2
Closed

Implement Mongo Transactions#4194
imnasnainaec wants to merge 28 commits intomasterfrom
mt2

Conversation

@imnasnainaec
Copy link
Copy Markdown
Collaborator

@imnasnainaec imnasnainaec commented Mar 6, 2026

This change is Reviewable

Summary by CodeRabbit

  • Bug Fixes

    • Undo-merge and word-restore now return empty success responses and surface Not Found when unsuccessful.
  • New Features

    • Bulk word import support.
    • Expanded frontier merge/replace/revert workflows and richer frontier update/restore/delete behaviors.
  • Chores

    • Added transactional DB execution for safer multi-step operations and updated test/mocks to align with new flows.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 6, 2026

⚠️ Commit Message Format Issues ⚠️
commit 095594aa0f:
1: T1 Title exceeds max length (78>72): "Add MongoDB transactions to WordRepository multi-collection operations (#4191)"

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5106f8bb-2387-46e9-a758-c937446be353

📥 Commits

Reviewing files that changed from the base of the PR and between 78917ae and d8e0f59.

📒 Files selected for processing (3)
  • Backend.Tests/Mocks/MongoDbContextMock.cs
  • Backend/Contexts/MongoDbContext.cs
  • Backend/Interfaces/IMongoDbContext.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • Backend/Interfaces/IMongoDbContext.cs

📝 Walkthrough

Walkthrough

Adds MongoDB transaction APIs and tests; refactors word repository toward frontier-focused, transactional operations; shifts many consumers from IWordRepository to IWordService; changes Restore/Undo endpoints to return Ok/NotFound (no boolean payload); updates services, controllers, tests, and frontend typings.

Changes

Cohort / File(s) Summary
MongoDB transaction infra
Backend/Interfaces/IMongoDbContext.cs, Backend/Contexts/MongoDbContext.cs, Backend.Tests/Mocks/MongoDbContextMock.cs
Introduce IMongoDbContext/IMongoTransaction, add Db, BeginTransaction, ExecuteInTransaction/ExecuteInTransactionAllowNull, implement transaction wrapper and test mock.
Word repository core
Backend/Interfaces/IWordRepository.cs, Backend/Repositories/WordRepository.cs, Backend.Tests/Mocks/WordRepositoryMock.cs
Replace older CRUD surface with frontier-centric APIs (Restore/Update/Replace/Revert/DeleteFrontier with modifier actions), add transactional/session helpers and complex session-bound operations; mock updated to match new signatures and behaviors.
Word service surface & logic
Backend/Interfaces/IWordService.cs, Backend/Services/WordService.cs, Backend.Tests/Services/WordServiceTests.cs
Add Import/MergeReplace/RevertMergeReplace methods, change RestoreFrontierWords→RestoreFrontierWord, centralize timestamp/history helpers, delegate frontier mutations to repository; tests updated and expanded.
Merge flow & API changes
Backend/Services/MergeService.cs, Backend/Controllers/MergeController.cs, src/api/api/merge-api.ts, Backend.Tests/Services/MergeServiceTests.cs, src/backend/index.ts
Merge/UndoMerge now call WordService merge/revert APIs; UndoMerge controller returns Ok()/NotFound (no bool); frontend typings and client wrappers updated to void return.
Word controller API
Backend/Controllers/WordController.cs, src/api/api/word-api.ts, src/backend/index.ts, Backend.Tests/Controllers/WordControllerTests.cs
RestoreWord now calls service restore directly and returns Ok/NotFound with no boolean payload; frontend types and tests adapted.
Lift import wiring
Backend/Interfaces/ILiftService.cs, Backend/Services/LiftService.cs, Backend/Controllers/LiftController.cs, Backend.Tests/Controllers/LiftControllerTests.cs
Change importer/merger APIs to accept IWordService instead of IWordRepository; update controller constructor, service wiring, and tests.
Repositories & transactional refactor
Backend/Repositories/WordRepository.cs
Add IMongoDbContext usage, ExecuteWithTransaction helpers and session-bound implementations (Create/Update/Restore/Replace/Revert) to ensure atomic frontier↔words moves.
Tests and mocks
Backend.Tests/..., Backend.Tests/Mocks/*
Many tests switched from IWordRepository to WordRepositoryMock, updated assertions/awaits; extensive new tests for import/merge/restore/delete/frontier behaviors; new MongoDbContextMock added.
Startup scope handling
Backend/Startup.cs
Resolve repositories from a created async startup scope and dispose the scope after use.
Frontend call changes
src/backend/index.ts, src/api/api/*.ts
Frontend wrappers and generated API typings updated to void return types for undoMerge and restoreWord and to stop returning response data.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Controller as Controller
    participant Service as WordService
    participant Repo as WordRepository
    participant DB as MongoDbContext

    rect rgba(200,230,255,0.5)
    Client->>Controller: HTTP restore/undo request
    Controller->>Service: call RestoreFrontierWord / RevertMergeReplaceFrontier
    end

    rect rgba(200,255,200,0.5)
    Service->>Repo: prepare actions (modify/update/replace)
    Repo->>DB: BeginTransaction / ExecuteInTransaction(operation)
    DB-->>Repo: session/transaction wrapper
    Repo->>DB: perform atomic operations across frontier & words
    DB-->>Repo: Commit or Abort
    Repo-->>Service: return result
    end

    Service-->>Controller: Ok / NotFound (no payload)
    Controller-->>Client: HTTP 200/404
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

🟥High

Suggested reviewers

  • jasonleenaylor

Poem

🐰 I hopped through sessions, neat and spry,
Frontiers shuffled under a watchful sky.
Bools went quiet, voids took the stage,
Mocks and services tuned the page.
A carrot cheer — commit, hop, and try!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 39.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Implement Mongo Transactions' directly and clearly describes the main objective of the changeset—adding transactional capabilities to MongoDB context.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mt2
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 98.80952% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 75.24%. Comparing base (c6afad4) to head (d8e0f59).

Files with missing lines Patch % Lines
Backend/Controllers/MergeController.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4194      +/-   ##
==========================================
+ Coverage   75.15%   75.24%   +0.09%     
==========================================
  Files         302      302              
  Lines       11099    11092       -7     
  Branches     1394     1386       -8     
==========================================
+ Hits         8341     8346       +5     
+ Misses       2357     2348       -9     
+ Partials      401      398       -3     
Flag Coverage Δ
backend 86.75% <98.80%> (+0.22%) ⬆️
frontend 66.34% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

coderabbitai[bot]

This comment was marked as outdated.

@imnasnainaec

This comment was marked as resolved.

This comment was marked as outdated.

@imnasnainaec
Copy link
Copy Markdown
Collaborator Author

@copilot In a new pr on this branch, set up integration testing for WordRepository.

  • The tests should spin up actual, minimal instances of a mongo database
  • Changes to Backend/ should be minimal and only if necessary
  • The integration testing should go in Backend.Tests/, but existing tests in Backend.Tests/ should be unchanged

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 9, 2026

@imnasnainaec I've opened a new pull request, #4196, to work on those changes. Once the pull request is ready, I'll request review from you.

coderabbitai[bot]

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as resolved.

@imnasnainaec imnasnainaec marked this pull request as draft March 13, 2026 19:28
@imnasnainaec
Copy link
Copy Markdown
Collaborator Author

Subsumed in #4198

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants