Skip to content

feat(AppHost): add WithSeedDataCommand for local dev seeding#263

Merged
mpaulosky merged 1 commit into
devfrom
squad/260-add-withseeddatacommand
May 8, 2026
Merged

feat(AppHost): add WithSeedDataCommand for local dev seeding#263
mpaulosky merged 1 commit into
devfrom
squad/260-add-withseeddatacommand

Conversation

@mpaulosky

Copy link
Copy Markdown
Owner

Closes #260

Working as Sam (Backend/.NET)

Changes

  • Added WithSeedDataCommand to MongoDbResourceBuilderExtensions
  • Command name: seed-myblog-data, display name: 🌱 Seed MyBlog Data
  • Icon: DatabaseArrowUp, no ConfirmationMessage, IsHighlighted = false
  • Inserts 3 seed BsonDocument blog posts (2 published, 1 draft) into blogposts
  • Shared _clearMutex semaphore prevents concurrent database operations
  • UpdateState gates on HealthStatus.HealthyEnabled, else Disabled
  • Unit tests: MongoDbSeedCommandTests (6 tests)
  • Integration tests: MongoSeedDataIntegrationTests (3 tests)
  • Infrastructure: MongoSeedIntegrationCollection (reuses ClearCommandAppFixture)

Gates

✅ Gate 2: Release build passed
✅ Gate 3: Unit/arch tests passed
✅ Gate 4: Integration tests passed

…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>
Copilot AI review requested due to automatic review settings May 8, 2026 16:45
@mpaulosky mpaulosky added the squad Squad triage inbox — Lead will assign to a member label May 8, 2026
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Test Results Summary

323 tests  +9   322 ✅ +9   19s ⏱️ ±0s
  6 suites ±0     1 💤 ±0 
  6 files   ±0     0 ❌ ±0 

Results for commit 202dd20. ± Comparison against base commit 976ec57.

@codecov

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.80531% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.56%. Comparing base (976ec57) to head (202dd20).

Files with missing lines Patch % Lines
src/AppHost/MongoDbResourceBuilderExtensions.cs 93.80% 13 Missing and 1 partial ⚠️
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              
Files with missing lines Coverage Δ
src/AppHost/MongoDbResourceBuilderExtensions.cs 93.80% <93.80%> (+0.41%) ⬆️
🚀 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.WithMongoDbDevCommands to also register a seed-myblog-data command that inserts 3 BsonDocument blog posts into blogposts.
  • 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.

Comment on lines +20 to +22
// 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)"
Comment on lines +254 to +262
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
});
Comment on lines +36 to +54
/// <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");
}
@mpaulosky

Copy link
Copy Markdown
Owner Author

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 — WithSeedDataCommand wired in WithMongoDbDevCommands; command name seed-myblog-data; IconName = DatabaseArrowUp; no ConfirmationMessage; IsHighlighted absent (defaults false); shared _clearMutex with WaitAsync(0); 3 documents (2 published, 1 draft); UpdateState gates on HealthStatus.Healthy.

Local tests: 9/9 passed (6 unit + 3 integration).

Copilot comments (4 — all non-blocking style/completeness suggestions):

  1. _clearMutex rename → style
  2. Markdown message format → enhancement
  3. Explicit IsHighlighted/ConfirmationMessage → style (tests already verify)
  4. Missing display-name assertion → test completeness

Proceeding with squash merge.

@mpaulosky
mpaulosky merged commit 924edfc into dev May 8, 2026
23 checks passed
@mpaulosky
mpaulosky deleted the squad/260-add-withseeddatacommand branch May 8, 2026 16:53
mpaulosky added a commit that referenced this pull request May 8, 2026
## 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

squad Squad triage inbox — Lead will assign to a member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add WithSeedDataCommand with unit and integration tests

2 participants