Skip to content

feat(cli) add --ensure-cosmos-containers post-deploy smoke-test#57

Merged
jkeeley2073 merged 1 commit into
mainfrom
Dev-EnsureCosmosContainersFlag
May 3, 2026
Merged

feat(cli) add --ensure-cosmos-containers post-deploy smoke-test#57
jkeeley2073 merged 1 commit into
mainfrom
Dev-EnsureCosmosContainersFlag

Conversation

@jkeeley2073
Copy link
Copy Markdown
Contributor

Summary

Adds a CLI flag that runs CosmosBootstrapper.EnsureCreatedAsync against the configured Cosmos account — creates the pinwiz database + the configured containers if missing, asserts existing partition-key paths match (drift throws). Idempotent. Returns exit code 2 with a clear remediation message when Cosmos isn't configured (the bootstrapper is only DI-registered when AddCosmosPersistence was wired).

Why this exists: before this flag, the closest "is Cosmos working?" smoke-test was --status, but --status reads only the local file catalog and does NOT exercise Cosmos at all. A Cosmos misconfig would surface only on first --source opdb attempt (which requires an OPDB API token to even reach the Cosmos write path).

Also: CosmosOptions.Containers default flips from [] to the canonical Phase 1 list per ADR 0011 — machines (PK /manufacturer) and ingestion_sources (PK /partitionKey). Matches the container names the existing MachineRepository / IngestionSourceRepository registrations already reference; previously the bootstrapper would no-op without an explicit appsettings.json Cosmos:Containers entry.

.gitignore gains infra/*.json to prevent future accidental commits of az bicep build artifacts (caught one in this branch and removed it before push).

Test Plan

  • dotnet build PinballWizard.slnx -> 7 / 7 projects, 0 warnings, 0 errors
  • dotnet test PinballWizard.slnx -> 501 / 501 passing (was 496 — +5 in CosmosOptionsTests pinning the canonical defaults)
  • Live smoke-test post-PR-merge: pwsh ./infra/scripts/Deploy-SharedResources.ps1 -Environment dev then $env:Cosmos__AccountEndpoint = "<endpoint>" ; dotnet run --project src/PinballWizard.Cli -- --ensure-cosmos-containers -> expects "Cosmos database + containers ensured." and the pinwiz database + 2 containers visible in the Azure portal

Out of Scope

  • Removing the duplication between CosmosOptions.Containers defaults and the hardcoded "machines" / "ingestion_sources" strings in Persistence/Cosmos/ServiceCollectionExtensions.cs. Future small PR — pull the names into constants on CosmosOptions so the repository registrations reference them too.
  • Calling EnsureCreatedAsync automatically at startup. Considered; rejected in favor of an explicit flag so --scrape-only --source jjp doesn't fail at startup if Cosmos is mis-configured (and so the smoke-test is a deliberate operator action, not a side effect of every CLI run).

Checklist

  • CI is green
  • PR title follows the Conventional Commits format
  • If user-visible behavior changes, README.md is updated -> --ensure-cosmos-containers row added to the CLI Flags table; the session-handoff playbook Step 7 updated to use the new flag instead of --status for the post-deploy smoke-test
  • No TODO / FIXME / commented-out code committed

Pre-push self-audit

Step 0 — /local-review (qualitative)

  • Skipped with justification — single-flag addition with the dispatch mirroring the existing --install-playwright early-exit pattern; the new CosmosOptions defaults are pinned by 5 behavior tests; no architectural surface added.

Step 1 — Mechanical checklist

  • Every new *Options property has at least one real getter call in src/CosmosOptions.Containers is read by CosmosBootstrapper.EnsureCreatedAsync (lines 52-55)
  • Sibling-diffed against the closest existing implementation — dispatch mirrors --install-playwright early-exit pattern (Program.cs:103); error path matches --source opdb exit-code-2 pattern (Program.cs:130-134)
  • No bare catch { } — N/A (no catch added)
  • New ISourceScraper? — N/A (the flag is a host-resolved bootstrap call, not a scraper)
  • Tests assert behavior, not just structure — 5 new tests pin every default field in CosmosOptions against ADR 0011
  • Build is zero-warning
  • git log -1 --format='%an <%ae>' shows personal noreply, not work email

Adds a CLI flag that resolves CosmosBootstrapper from DI and runs
EnsureCreatedAsync: creates the configured database + every container
in CosmosOptions.Containers if missing, asserts existing partition-key
paths match. Idempotent.

Useful as the canonical post-deploy smoke-test that the configured
Cosmos endpoint + Managed Identity / Aspire connection string actually
work end-to-end. Before this flag, --status was the closest available
smoke-test in the playbook, but --status reads only the local file
catalog and does NOT exercise Cosmos at all — so a Cosmos misconfig
would surface only at first --source opdb attempt (which requires an
OPDB API token).

Returns exit code 2 with a clear remediation message when Cosmos
is not configured (CosmosBootstrapper is only DI-registered when
AddCosmosPersistence was wired).

Also: CosmosOptions.Containers default flips from [] to the canonical
Phase 1 list per ADR 0011 — machines (PK /manufacturer) and
ingestion_sources (PK /partitionKey). Matches the container names the
existing MachineRepository and IngestionSourceRepository registrations
already reference; previously the bootstrapper would no-op without an
appsettings.json Cosmos:Containers entry. +5 tests in
CosmosOptionsTests pinning the defaults so a future drift between
the options list and the repository hardcoded names trips a test.

Tests: 496 -> 501. Build clean, zero warnings.

README + session-handoff Step 7 updated to use the new flag for the
post-deploy smoke-test.

Pre-push self-audit: 7-item mechanical (all pass). /local-review
skipped — single-flag addition with the dispatch mirroring the
existing --install-playwright early-exit pattern; the new
CosmosOptions defaults are pinned by behavior tests.
@jkeeley2073 jkeeley2073 added the claude-code Generated with Claude Code label May 3, 2026
@jkeeley2073 jkeeley2073 merged commit 89a9e47 into main May 3, 2026
5 checks passed
@jkeeley2073 jkeeley2073 deleted the Dev-EnsureCosmosContainersFlag branch May 3, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-code Generated with Claude Code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant