feat(AppHost): add WithSeedDataCommand for local dev seeding#263
Conversation
…sions (#260) - Add WithSeedDataCommand extension that inserts 3 hardcoded BsonDocument blog posts (2 published, 1 draft) into the blogposts collection - Command name: seed-myblog-data, icon: DatabaseArrowUp - No ConfirmationMessage (additive, not destructive), IsHighlighted = false - Shared _clearMutex semaphore prevents concurrent database operations - UpdateState gates on HealthStatus.Healthy → Enabled, else Disabled - Unit tests: MongoDbSeedCommandTests (6 tests) - Integration tests: MongoSeedDataIntegrationTests (3 tests) - Infrastructure: MongoSeedIntegrationCollection (reuses ClearCommandAppFixture) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #263 +/- ##
==========================================
+ Coverage 84.48% 85.56% +1.07%
==========================================
Files 44 44
Lines 851 956 +105
Branches 114 115 +1
==========================================
+ Hits 719 818 +99
- Misses 88 94 +6
Partials 44 44
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a new Aspire dashboard operator command for local development that seeds MongoDB with example blog post documents, alongside unit and integration coverage in AppHost.Tests.
Changes:
- Extended
MongoDbResourceBuilderExtensions.WithMongoDbDevCommandsto also register aseed-myblog-datacommand that inserts 3BsonDocumentblog posts intoblogposts. - Added model-level tests validating the seed command annotation behavior (icon, confirmation/highlight defaults, health-gated enablement).
- Added Docker-backed integration tests that execute the command against a real MongoDB container and assert inserted documents + concurrency behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/AppHost/MongoDbResourceBuilderExtensions.cs |
Registers the new seed operator command and implements the MongoDB insert behavior and command state gating. |
tests/AppHost.Tests/MongoDbSeedCommandTests.cs |
Adds unit tests for the seed command’s Aspire annotation contract and enabled/disabled state. |
tests/AppHost.Tests/MongoSeedDataIntegrationTests.cs |
Adds integration tests that run the seed command against a live MongoDB container and validate results/concurrency. |
tests/AppHost.Tests/Infrastructure/MongoSeedIntegrationCollection.cs |
Introduces an xUnit collection to share the Aspire fixture for the seed integration tests. |
| // Shared semaphore — one per process; all commands share the same mutex. | ||
| private static readonly SemaphoreSlim _clearMutex = new(1, 1); | ||
|
|
| return new ExecuteCommandResult | ||
| { | ||
| Success = true, | ||
| Message = $"blogposts: {seedDocuments.Length} inserted (2 published, 1 draft)" |
| new CommandOptions | ||
| { | ||
| Description = "Inserts seed blog posts into the myblog database. Local development only.", | ||
| IconName = "DatabaseArrowUp", | ||
| UpdateState = ctx => | ||
| ctx.ResourceSnapshot.HealthStatus == HealthStatus.Healthy | ||
| ? ResourceCommandState.Enabled | ||
| : ResourceCommandState.Disabled | ||
| }); |
| /// <summary> | ||
| /// Acceptance criterion #1: The mongodb resource exposes a "seed-myblog-data" operator action. | ||
| /// </summary> | ||
| [Fact] | ||
| public async Task MongoDb_Resource_Exposes_SeedMyBlogData_Command_Annotation() | ||
| { | ||
| // Arrange | ||
| var builder = await CreateBuilderAsync(); | ||
| var mongoResource = builder.Resources.Single(static r => r.Name == "mongodb"); | ||
|
|
||
| // Act | ||
| var annotation = mongoResource.Annotations | ||
| .OfType<ResourceCommandAnnotation>() | ||
| .SingleOrDefault(static a => a.Name == CommandName); | ||
|
|
||
| // Assert | ||
| annotation.Should().NotBeNull( | ||
| "the mongodb resource must expose a 'seed-myblog-data' operator action per issue #260"); | ||
| } |
|
✅ APPROVED — Aragorn (Lead/Architect) All gates passed. Merging. CI: 17/17 checks green (AppHost.Tests, CodeQL, Coverage, all test suites). Diff: All acceptance criteria verified — Local tests: 9/9 passed (6 unit + 3 integration). Copilot comments (4 — all non-blocking style/completeness suggestions):
Proceeding with squash merge. |
## 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 #260
Working as Sam (Backend/.NET)
Changes
WithSeedDataCommandtoMongoDbResourceBuilderExtensionsseed-myblog-data, display name:🌱 Seed MyBlog DataDatabaseArrowUp, noConfirmationMessage,IsHighlighted = falseBsonDocumentblog posts (2 published, 1 draft) intoblogposts_clearMutexsemaphore prevents concurrent database operationsUpdateStategates onHealthStatus.Healthy→Enabled, elseDisabledMongoDbSeedCommandTests(6 tests)MongoSeedDataIntegrationTests(3 tests)MongoSeedIntegrationCollection(reusesClearCommandAppFixture)Gates
✅ Gate 2: Release build passed
✅ Gate 3: Unit/arch tests passed
✅ Gate 4: Integration tests passed