Skip to content

Report actual outcome of database/container creation - #263

Merged
Mike Krüger (mkrueger) merged 5 commits into
mainfrom
dev/mkrueger/fix/261-creation-outcome
Oct 29, 2026
Merged

Mike Krüger (mkrueger) merged 5 commits into
mainfrom
dev/mkrueger/fix/261-creation-outcome

Conversation

@mkrueger

Copy link
Copy Markdown
Collaborator

Fixes #261.

Problem

mkdb, mkcon, create database, and create container always returned created: true, even when an existing resource was reused. Automation could not distinguish a new resource from an adopted one, so replays overcounted creations and audit trails described mutations that never happened.

The data-plane backend already received the distinguishing status from CreateDatabaseIfNotExistsAsync / CreateContainerIfNotExistsAsync (201 Created vs. 200 OK), but the resource-operations abstraction returned only the resource ID, and the commands hard-coded created = true.

Fix

Carry an explicit ResourceCreationResult (ID plus nullable Created) through ICosmosResourceOperations, the facade, and both backends.

Backend result created outcome Human-readable
Data plane, HTTP 201 true created Created database/container X
Data plane, HTTP 200 (reused) false existing Using existing database/container X
ARM create-or-update null createdOrUpdated Created or updated database/container X
  • Data plane: the outcome comes from the SDK response status itself, not a preflight existence check, so a concurrent creator cannot cause a misreport.
  • ARM: the create-or-update API returns 200/202 for both new and existing resources, so the shell reports an explicit unknown outcome instead of guessing. ARM request behavior is unchanged.
  • Existing partition-key mismatch errors and existing-resource throughput validation are unchanged.

Breaking change

On Entra ID (ARM) connections, created changes from true to null. Scripts that treat created as a boolean should check outcome instead. This is listed under Breaking changes in the changelog.

Tests

  • Offline (ResourceCreationResultTests): all four command forms × created/existing/ARM × user/JSON output. Checks that structured and human-readable results agree, and that the ARM path never reports a boolean or performs a preflight existence lookup, for both 200 and 202 responses.
  • Emulator (ResourceCreationTests):
    • First creation reports true; a replay reports false.
    • A container created through the SDK (partition-key version 2, TTL, unique keys) is adopted with false.
    • Container properties are byte-identical after the replay, and items are retained.
    • A mismatched partition key still fails and leaves the container unchanged.
  • Existing serverless/throughput tests updated for the new return type.

Validation: both projects build with 0 warnings; offline suite 4,914 passed / 5 skipped; emulator management and creation tests 14/14 passed. Also manually verified the CLI messages and JSON against the local emulator. ARM behavior is covered by mocks, not a live Azure account.

Localization: four new en.ftl keys with the regenerated l10n/CosmosDBShell.json. Docs: management result semantics in docs/commands.md and an MCP note in docs/mcp.md.

mkdb, mkcon, create database, and create container always reported created: true, even when an existing resource was reused. Carry an explicit creation outcome through the resource-operations abstraction: the data plane uses the SDK response status (201 created, 200 existing), and ARM reports created: null with outcome createdOrUpdated because its create-or-update API cannot distinguish the two. Human-readable messages match the structured result.

Fixes #261

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the resource-creation outcome changes.

No open issues 🎉

What changed in this PR

Fixes #261 by carrying creation outcomes from the resource backends through the shell’s database and container commands, allowing automation to distinguish new resources from reused ones.

Changes:

  • Reports data-plane creation from the SDK response status and ARM create-or-update as created: null with outcome: "createdOrUpdated".
  • Aligns structured results, localized messages, and documentation, including the ARM breaking change.
  • Adds offline outcome tests and emulator coverage for replay, resource preservation, and partition-key mismatch errors.
File Description
l10n/​CosmosDBShell.json Adds generated creation-outcome messages.
docs/​mcp.md Explains creation outcomes for MCP consumers.
docs/​commands.md Documents backend-specific result semantics.
CosmosDBShell/​lang/​en.ftl Adds existing and created-or-updated messages.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​ResourceCreationResult.cs Defines the shared creation-result model.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​ICosmosResourceOperations.cs Changes creation methods to return outcomes.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​DataPlaneCosmosResourceOperations.cs Derives creation status from SDK responses.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​CosmosResourceFacade.cs Propagates creation results to commands.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​ArmCosmosResourceOperations.cs Returns an explicit unknown creation status.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Commands/​MakeDbCommand.cs Reports database outcomes in results and messages.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Commands/​MakeContainerCommand.cs Reports container outcomes in results and messages.
CosmosDBShell.Tests/​Integration/​ResourceCreationTests.cs Tests replay outcomes and resource preservation.
CosmosDBShell.Tests/​CommandTests/​ServerlessCreationThroughputTests.cs Updates assertions for the new result type.
CosmosDBShell.Tests/​CommandTests/​ResourceCreationResultTests.cs Tests command output and ARM outcome semantics.
CHANGELOG.md Records the reporting fix and ARM breaking change.

Review effort: Balanced

Address CodeQL constant-condition findings on PR #263. The null arm is reachable (ARM create-or-update), so keep all three outcomes and centralize selection in ResourceCreationResult.Select.
Copilot AI balanced review requested due to automatic review settings October 28, 2026 09:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the resource-creation outcome reporting changes.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 28, 2026 09:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are identified for the resource-creation outcome reporting changes.

No open issues 🎉

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage/dotnet

main 86efb3c dev/mkrueger/fix/261... a172e7e +/-
72% 72% 0%
View coverage of the 5 most impacted files.
File main 86efb3c dev/mkrueger/fix/261... a172e7e +/-
D:\a\CosmosDBSh...akeDbCommand.cs 92% 91% -1%
D:\a\CosmosDBSh...ceOperations.cs 51% 51% 0%
D:\a\CosmosDBSh...ceOperations.cs 1% 5% +4%
D:\a\CosmosDBSh...ainerCommand.cs 85% 89% +4%
D:\a\CosmosDBSh...eationResult.cs 0% 89% +89%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 28, 2026 09:58 UTC

Replace the nullable Created flag with ResourceCreationOutcome (Created, Existing, CreatedOrUpdated) so the unknown ARM outcome is explicit rather than encoded as null. The structured result keeps its created/outcome fields; outcome is derived from the enum name in camelCase.
Copilot AI balanced review requested due to automatic review settings October 28, 2026 09:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the resource-creation outcome reporting changes.

No open issues 🎉

Review effort: Balanced

@mkrueger
Mike Krüger (mkrueger) merged commit 437e8b4 into main Oct 29, 2026
13 checks passed
@mkrueger
Mike Krüger (mkrueger) deleted the dev/mkrueger/fix/261-creation-outcome branch October 29, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Idempotent database/container creation incorrectly reports created: true for existing resources

3 participants