refactor(apphost): extract WithClearDatabaseCommand into MongoDbResourceBuilderExtensions#262
Conversation
…rceBuilderExtensions
Moves the 120-line inline WithCommand clear-data block into a new
MongoDbResourceBuilderExtensions class. AppHost.cs is reduced to a
single mongo.WithMongoDbDevCommands("myblog") call.
- All 10 existing tests (5 unit + 5 integration) pass unchanged
- Command name 'clear-myblog-data' preserved exactly
- Semaphore, IsRunMode guard, and error handling preserved exactly
Closes #259
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🏗️ PR Added to Squad Triage QueueThis PR has been labeled with Next steps:
|
There was a problem hiding this comment.
Pull request overview
This pull request refactors the AppHost MongoDB “clear data” operator command by extracting the inline WithCommand logic from AppHost.cs into a dedicated MongoDbResourceBuilderExtensions extension, keeping the AppHost bootstrap minimal while preserving the existing operator command behavior.
Changes:
- Added
MongoDbResourceBuilderExtensionswithWithMongoDbDevCommands(databaseName)to register the MongoDB dev/operator commands in run mode. - Simplified
AppHost.csto a singlemongo.WithMongoDbDevCommands("myblog")call and removed inline command implementation/imports.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/AppHost/MongoDbResourceBuilderExtensions.cs | New extension class that encapsulates MongoDB dev/operator command registration and clear-data handler logic. |
| src/AppHost/AppHost.cs | Removes inline clear-data command block and replaces it with a single extension method call. |
| // Shared semaphore — one per process; all commands share the same mutex. | ||
| private static readonly SemaphoreSlim _clearMutex = new(1, 1); | ||
|
|
||
| public static IResourceBuilder<MongoDBServerResource> WithMongoDbDevCommands( | ||
| this IResourceBuilder<MongoDBServerResource> builder, | ||
| string databaseName) | ||
| { | ||
| if (!builder.ApplicationBuilder.ExecutionContext.IsRunMode) | ||
| return builder; | ||
|
|
||
| builder.WithClearDatabaseCommand(databaseName); | ||
| return builder; |
| "clear-myblog-data", | ||
| "⚠️ Clear MyBlog Data", | ||
| executeCommand: async context => | ||
| { | ||
| // AC2: Non-blocking acquire — return immediately if another clear is already in flight. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #262 +/- ##
==========================================
+ Coverage 83.01% 84.48% +1.47%
==========================================
Files 43 44 +1
Lines 730 851 +121
Branches 112 114 +2
==========================================
+ Hits 606 719 +113
- Misses 81 88 +7
- Partials 43 44 +1
🚀 New features to boost your workflow:
|
## Sprint 18 — AppHost MongoDB Dev Commands Refactor This release promotes all Sprint 18 work from `dev` to `main`. ### What's included #### Feature work - **#262** — `refactor(apphost): extract WithClearDatabaseCommand into MongoDbResourceBuilderExtensions` - **#263** — `feat(AppHost): add WithSeedDataCommand for local dev seeding` - **#264** — `feat(AppHost): add WithShowStatsCommand for local dev stats` - **#267** — `refactor: rename _clearMutex to _dbMutex in MongoDbResourceBuilderExtensions` #### CI fixes - **#270** — `fix(ci): Blog → README Sync — push to dev instead of main` - **#271** — `fix(ci): add pre-flight token validation and fix permissions block in squad-mark-released` ### CI status - ✅ **Squad CI** (`ci.yml`) — green on latest `dev` commit -⚠️ **Test Suite** — 1 flaky test failure: `SeedMyBlogData Concurrent Invocations Allow Only One Run` (timing-sensitive concurrency test; race condition in test harness, not production code). All other 47 tests pass. Squad CI gate is the authoritative pass/fail gate. ### Notes - Last release tag: `v1.5.0` - `dev` is 55 commits ahead of `main` - No open Sprint 18 issues, no open PRs - Merge strategy: squash merge per playbook --- ## Release Checklist - [ ] Latest `dev` Squad CI is green ✅ - [ ] Release scope reviewed (Sprint 18 milestone closed, all 4 issues merged) - [ ] Breaking changes documented (none — additive AppHost extension methods only) - [ ] Flaky test acknowledged (`SeedMyBlogData Concurrent` — timing race in test, not prod) - [ ] Release notes drafted (see sprint summary above) - [ ] Aragorn approval received - [ ] Boromir confirms branch state and workflow health - [ ] PR CI passes before merge - [ ] Merge to `main` with squash merge - [ ] Tag `main` with appropriate `vX.Y.Z` after merge + CI green Closes the Sprint 18 release gate. Working as Boromir (DevOps) --------- Co-authored-by: Boromir <boromir@squad.dev> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
#422) …rceBuilderExtensions (#262) ## Summary Extracts the inline `WithCommand` clear-data block from `AppHost.cs` into a new `MongoDbResourceBuilderExtensions` class. ## Changes - **New**: `src/AppHost/MongoDbResourceBuilderExtensions.cs` — contains `WithMongoDbDevCommands` public entry point and private `WithClearDatabaseCommand` - **Simplified**: `src/AppHost/AppHost.cs` — reduced from ~157 lines to ~30 lines; single `mongo.WithMongoDbDevCommands("myblog")` call ## Testing All 10 existing tests pass: - 5 unit tests in `MongoDbClearCommandTests` - 5 integration tests in `MongoClearDataIntegrationTests` Closes #259 Working as Sam (Backend/.NET) Co-authored-by: Boromir <boromir@squad.dev> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>## Summary <!-- Describe what this PR does and why. Link the issue it closes. --> Closes #<!-- issue number --> ## Type of Change <!-- Check all that apply --> - [ ] 🐛 Bug fix (non-breaking change that fixes an issue) - [ ] ✨ Feature (non-breaking change that adds functionality) - [ ] ♻️ Refactor (no behavior change, code cleanup/restructure) - [ ] 🧪 Tests (new or updated tests only) - [ ] 📝 Docs (README, XML docs, comments) - [ ] ⚙️ Infra/CI (GitHub Actions, Aspire, NuGet, deployment) - [ ] 🔒 Security (auth, permissions, secrets, headers) - [ ] 💥 Breaking change (existing behavior changes) ## Domain Affected <!-- Check all that apply — this determines which reviewers are required --> - [ ] 🏗️ Architecture / domain logic / CQRS → **Aragorn required** - [ ] 🔧 Backend (handlers, repositories, API endpoints, MediatR) → **Sam required** - [ ] ⚛️ Frontend (Blazor components, Razor pages, CSS, JS) → **Legolas required** - [ ] 🧪 Unit / bUnit / integration tests → **Gimli required** - [ ] 🧪 E2E / Playwright / Aspire integration tests → **Pippin required** - [ ] ⚙️ CI/CD / GitHub Actions / NuGet / Aspire AppHost → **Boromir required** - [ ] 🔒 Auth0 / authorization / security-relevant changes → **Gandalf required** - [ ] 📝 Docs / README / XML docs → **Frodo required** ## Self-Review Checklist <!-- Complete before requesting review — incomplete PRs will be returned --> ### Code Quality - [ ] I ran `dotnet build MyBlog.slnx --configuration Release` — 0 errors, 0 warnings - [ ] I ran `dotnet test MyBlog.slnx --configuration Release --no-build` — all pass - [ ] No TODO/FIXME left unless tracked in a follow-up issue (link it) - [ ] No secrets, API keys, or credentials committed ### Architecture - [ ] New handlers follow the `Command`/`Query`/`Handler`/`Validator` naming conventions - [ ] New handlers are `sealed` - [ ] Domain layer has no references to `Web` or `Persistence.*` projects - [ ] `Result<T>` / `ResultErrorCode` used for expected failures (no exception-driven control flow) - [ ] DTOs are records in `Domain.DTOs`; Models are in `Domain.Models` - [ ] No DTO types embedded in Model classes ### Tests - [ ] New code has corresponding unit tests - [ ] Integration tests use domain-specific collections (`[Collection("XxxIntegration")]`) - [ ] No test compares two `IssueDto.Empty` / `CommentDto.Empty` instances directly ### Security (check if security-relevant) - [ ] New endpoints have appropriate `RequireAuthorization` / policy applied - [ ] No `MarkupString` used with user-supplied content - [ ] No user input reflected in MongoDB queries without sanitization ### Merge Readiness - [ ] Branch is up to date with `main` (no merge conflicts) - [ ] CI checks are green (do not request review while checks are pending/failing) - [ ] PR description is complete — reviewers should not have to ask what this does ## Screenshots / Evidence <!-- For UI changes: before/after screenshots. For fixes: evidence the bug is resolved. --> ## Notes for Reviewers <!-- Anything you want reviewers to pay special attention to, or context they need. --> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Boromir <boromir@squad.dev> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: GitHub Copilot <copilot@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Boromir <lead-organizer@squad.local> Co-authored-by: mpaulosky <mpaulosky@users.noreply.github.com>
#427) …rceBuilderExtensions (#262) ## Summary Extracts the inline `WithCommand` clear-data block from `AppHost.cs` into a new `MongoDbResourceBuilderExtensions` class. ## Changes - **New**: `src/AppHost/MongoDbResourceBuilderExtensions.cs` — contains `WithMongoDbDevCommands` public entry point and private `WithClearDatabaseCommand` - **Simplified**: `src/AppHost/AppHost.cs` — reduced from ~157 lines to ~30 lines; single `mongo.WithMongoDbDevCommands("myblog")` call ## Testing All 10 existing tests pass: - 5 unit tests in `MongoDbClearCommandTests` - 5 integration tests in `MongoClearDataIntegrationTests` Closes #259 Working as Sam (Backend/.NET) Co-authored-by: Boromir <boromir@squad.dev> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>## Summary <!-- Describe what this PR does and why. Link the issue it closes. --> Closes #<!-- issue number --> ## Type of Change <!-- Check all that apply --> - [ ] 🐛 Bug fix (non-breaking change that fixes an issue) - [ ] ✨ Feature (non-breaking change that adds functionality) - [ ] ♻️ Refactor (no behavior change, code cleanup/restructure) - [ ] 🧪 Tests (new or updated tests only) - [ ] 📝 Docs (README, XML docs, comments) - [ ] ⚙️ Infra/CI (GitHub Actions, Aspire, NuGet, deployment) - [ ] 🔒 Security (auth, permissions, secrets, headers) - [ ] 💥 Breaking change (existing behavior changes) ## Domain Affected <!-- Check all that apply — this determines which reviewers are required --> - [ ] 🏗️ Architecture / domain logic / CQRS → **Aragorn required** - [ ] 🔧 Backend (handlers, repositories, API endpoints, MediatR) → **Sam required** - [ ] ⚛️ Frontend (Blazor components, Razor pages, CSS, JS) → **Legolas required** - [ ] 🧪 Unit / bUnit / integration tests → **Gimli required** - [ ] 🧪 E2E / Playwright / Aspire integration tests → **Pippin required** - [ ] ⚙️ CI/CD / GitHub Actions / NuGet / Aspire AppHost → **Boromir required** - [ ] 🔒 Auth0 / authorization / security-relevant changes → **Gandalf required** - [ ] 📝 Docs / README / XML docs → **Frodo required** ## Self-Review Checklist <!-- Complete before requesting review — incomplete PRs will be returned --> ### Code Quality - [ ] I ran `dotnet build MyBlog.slnx --configuration Release` — 0 errors, 0 warnings - [ ] I ran `dotnet test MyBlog.slnx --configuration Release --no-build` — all pass - [ ] No TODO/FIXME left unless tracked in a follow-up issue (link it) - [ ] No secrets, API keys, or credentials committed ### Architecture - [ ] New handlers follow the `Command`/`Query`/`Handler`/`Validator` naming conventions - [ ] New handlers are `sealed` - [ ] Domain layer has no references to `Web` or `Persistence.*` projects - [ ] `Result<T>` / `ResultErrorCode` used for expected failures (no exception-driven control flow) - [ ] DTOs are records in `Domain.DTOs`; Models are in `Domain.Models` - [ ] No DTO types embedded in Model classes ### Tests - [ ] New code has corresponding unit tests - [ ] Integration tests use domain-specific collections (`[Collection("XxxIntegration")]`) - [ ] No test compares two `IssueDto.Empty` / `CommentDto.Empty` instances directly ### Security (check if security-relevant) - [ ] New endpoints have appropriate `RequireAuthorization` / policy applied - [ ] No `MarkupString` used with user-supplied content - [ ] No user input reflected in MongoDB queries without sanitization ### Merge Readiness - [ ] Branch is up to date with `main` (no merge conflicts) - [ ] CI checks are green (do not request review while checks are pending/failing) - [ ] PR description is complete — reviewers should not have to ask what this does ## Screenshots / Evidence <!-- For UI changes: before/after screenshots. For fixes: evidence the bug is resolved. --> ## Notes for Reviewers <!-- Anything you want reviewers to pay special attention to, or context they need. --> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Boromir <boromir@squad.dev> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: GitHub Copilot <copilot@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Boromir <lead-organizer@squad.local> Co-authored-by: mpaulosky <mpaulosky@users.noreply.github.com>
Summary
Extracts the inline
WithCommandclear-data block fromAppHost.csinto a newMongoDbResourceBuilderExtensionsclass.Changes
src/AppHost/MongoDbResourceBuilderExtensions.cs— containsWithMongoDbDevCommandspublic entry point and privateWithClearDatabaseCommandsrc/AppHost/AppHost.cs— reduced from ~157 lines to ~30 lines; singlemongo.WithMongoDbDevCommands("myblog")callTesting
All 10 existing tests pass:
MongoDbClearCommandTestsMongoClearDataIntegrationTestsCloses #259
Working as Sam (Backend/.NET)