feat(AppHost): add WithShowStatsCommand for local dev stats#264
Conversation
- Add WithShowStatsCommand private method to MongoDbResourceBuilderExtensions - Command name: 'show-myblog-stats', display: '📊 Show MyBlog Stats' - Returns Markdown table of collection document counts via CommandResultData with Format = Markdown and DisplayImmediately = true - Empty DB returns '*(no collections found)*' row with Success = true - Shared _clearMutex prevents concurrent operations (non-blocking WaitAsync(0)) - Skips system.* collections consistent with clear command - UpdateState gates on HealthStatus.Healthy → Enabled, else Disabled - Wire builder.WithShowStatsCommand(databaseName) in WithMongoDbDevCommands - Unit tests: MongoDbStatsCommandTests (5 tests) - Collection definition: Infrastructure/MongoStatsIntegrationCollection - Integration tests: MongoShowStatsIntegrationTests (3 tests) - All 16 prior unit tests continue to pass Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a new Aspire dashboard operator command for local development to display MongoDB collection document counts (“show-myblog-stats”), along with unit and integration tests in AppHost.Tests.
Changes:
- Registers
WithShowStatsCommandinWithMongoDbDevCommandsand returns Markdown output viaCommandResultData(displayed immediately). - Implements non-blocking concurrency gating via the shared
_clearMutexand skipssystem.*collections. - Adds new unit and integration test coverage scaffolding for the stats command.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/AppHost/MongoDbResourceBuilderExtensions.cs |
Adds WithShowStatsCommand and wires it into the existing MongoDB dev commands pipeline. |
tests/AppHost.Tests/MongoDbStatsCommandTests.cs |
Adds model-level tests for stats command annotation/state behavior. |
tests/AppHost.Tests/MongoShowStatsIntegrationTests.cs |
Adds integration tests invoking the new command against a real Aspire+MongoDB container. |
tests/AppHost.Tests/Infrastructure/MongoStatsIntegrationCollection.cs |
Adds an xUnit collection definition for stats integration tests. |
| result.Success.Should().BeTrue("the handler must succeed when MongoDB is reachable"); | ||
| result.Message.Should().Contain("collection(s)", | ||
| "the success message must report the number of collections found"); | ||
| } |
| // Assert | ||
| result.Success.Should().BeTrue("an empty database must still return success — no collections is not an error"); | ||
| result.Message.Should().Contain("0 collection(s)", | ||
| "the message must indicate zero collections were found in the empty database"); |
|
|
||
| // Assert | ||
| annotation.Should().NotBeNull( | ||
| "the mongodb resource must expose a 'show-myblog-stats' operator action per issue #261"); |
| var client = new MongoClient(connectionString); | ||
| var database = client.GetDatabase(databaseName); | ||
|
|
||
| var namesCursor = await database.ListCollectionNamesAsync(cancellationToken: context.CancellationToken); |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #264 +/- ##
==========================================
+ Coverage 85.56% 86.57% +1.01%
==========================================
Files 44 44
Lines 956 1043 +87
Branches 115 116 +1
==========================================
+ Hits 818 903 +85
- Misses 94 96 +2
Partials 44 44
🚀 New features to boost your workflow:
|
❌ Aragorn Review — Changes Required (1 CI Failure)Failing test:
|
| Checklist item | Result |
|---|---|
File headers on all 3 new .cs files |
✅ |
No .squad/ files in diff |
✅ |
Command name "show-myblog-stats" hardcoded |
✅ |
CommandResultData { Format = Markdown, DisplayImmediately = true } |
✅ |
Empty DB → *(no collections found)* row |
✅ |
system.* collections filtered out |
✅ |
_clearMutex.WaitAsync(0) non-blocking guard reused |
✅ |
IsHighlighted = false (default; unit test verifies) |
✅ |
WithShowStatsCommand wired into WithMongoDbDevCommands |
✅ |
| xUnit collection definition follows existing pattern | ✅ |
[Collection("MongoStatsIntegration")] on integration test class |
✅ |
| Code style matches existing file | ✅ |
| Codecov patch ✅ project ✅ — no coverage decrease | ✅ |
| All other 16 CI checks (CodeQL, build, Web/Domain/Arch/Bunit/Integration) | ✅ |
One fix needed, then this is ready to squash-merge. 🎯
— Aragorn, Lead Developer
…ndow The empty-DB path completes in microseconds, so both concurrent invocations succeed before either releases the semaphore. Seeding 50 documents gives the first task real I/O work, ensuring the second task hits WaitAsync(0) while the semaphore is held. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
## 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>
Closes #261
Working as Sam (Backend/.NET)
Changes
WithShowStatsCommandtoMongoDbResourceBuilderExtensionsshow-myblog-stats, display:📊 Show MyBlog StatsCommandResultDatawithDisplayImmediately = true*(no collections found)*row withSuccess = true_clearMutexprevents concurrent operations (non-blockingWaitAsync(0))system.*collections consistent with clear commandUpdateStategates onHealthStatus.Healthy→Enabled, elseDisabledMongoDbStatsCommandTests(5 tests)Infrastructure/MongoStatsIntegrationCollectionMongoShowStatsIntegrationTests(3 tests)