Skip to content

Add partition-key scoping and ETag support to rm - #230

Merged
Mike Krüger (mkrueger) merged 5 commits into
mainfrom
dev/mkrueger/rm-partition-key-etag
Sep 30, 2026
Merged

Mike Krüger (mkrueger) merged 5 commits into
mainfrom
dev/mkrueger/rm-partition-key-etag

Conversation

@mkrueger

Copy link
Copy Markdown
Collaborator

Fixes #229

Adds two optional arguments to rm:

  • --partition-key / --pk restricts both the dry run and the deletion to one complete logical partition key. It uses the same typed and hierarchical parsing as patch and batch. Incomplete hierarchical keys are rejected, and piped items outside the partition are skipped.
  • --etag deletes a single item only if its current ETag matches, enforced server-side through IfMatchEtag. A mismatch is reported as a failed precondition and is not retried.

For rm <id> --key=id --partition-key=<pk>, the command uses a point read (dry run) or point delete against (id, partitionKey) instead of scanning the container. The exact-item dry run keeps count and adds id, partitionKey, and etag.

--etag is rejected before any deletion for wildcard patterns, piped input, missing --key=id, empty values, or a missing --partition-key. MCP confirmation shows the partition key and ETag in the command presented for approval. Behavior is unchanged when the new options are omitted.

Help text, MCP tool schemas, docs/commands.md, docs/mcp.md, and the README are updated, with unit, MCP, and emulator integration tests.

Adds --partition-key/--pk to restrict rm previews and deletions to one complete logical partition, uses point read/delete for exact ids, and adds --etag enforced via IfMatchEtag for single-item deletes.

Fixes #229

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟡 Changes recommended

Numeric partition keys at the 64-bit upper boundary can be corrupted in result serialization.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds partition-key scoping and conditional ETag deletion to rm.

Changes:

  • Adds scoped point reads/deletes and ETag validation.
  • Updates help, localization, and documentation.
  • Adds unit, MCP, and emulator coverage.
File Description
README.md Documents safe deletion.
l10n/​CosmosDBShell.json Updates localization catalog.
docs/​mcp.md Documents MCP workflow.
docs/​commands.md Documents new options.
CosmosDBShell/​lang/​en.ftl Adds localized messages.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Commands/​RmCommand.cs Implements scoped and conditional deletion.
CosmosDBShell.Tests/​ToolOperationsTests.cs Tests MCP schema.
CosmosDBShell.Tests/​ToolOperationsCallToolTests.cs Tests confirmation rendering.
CosmosDBShell.Tests/​Integration/​RmPartitionKeyETagTests.cs Tests emulator behavior.
CosmosDBShell.Tests/​CommandTests/​RmCommandTests.cs Tests parsing and validation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-code-quality

github-code-quality Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall line coverage in commit a1fa6c5 in the dev/mkrueger/rm-part... branch remains at 64%, unchanged from commit e172863 in the main branch.

Show a line coverage summary of the most impacted files.
File main e172863 dev/mkrueger/rm-part... a1fa6c5 +/-
D:\a\CosmosDBSh...olOperations.cs 93% 95% +2%
D:\a\CosmosDBSh...osmosCommand.cs 37% 40% +3%
D:\a\CosmosDBSh...ds\RmCommand.cs 17% 30% +13%

Updated September 30, 2026 13:34 UTC

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 30, 2026 11:41
The Linux emulator does not distinguish numeric and string partition key values, so the typed-key distinction stays covered by unit tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟡 Changes recommended

The explicit safety guarantee for mixed-partition piped input lacks regression coverage.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (1)
Copilot AI balanced review requested due to automatic review settings September 30, 2026 11:45

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.

Copilot review overview

🟡 Changes recommended

MCP can bind an explicit null ETag as omitted and perform an unconditional deletion after confirmation.

Review effort: Balanced
Findings: 1 High severity · 1 Low severity

Open (2)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 30, 2026 12:30

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.

Copilot review overview

🟢 Approval recommended

The implementation satisfies the safety requirements and includes comprehensive documentation, localization, unit, MCP, and emulator coverage.

Review effort: Balanced
Findings: None

Resolved since last review (2)

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.

Copilot review overview

🟢 Approval recommended

The implementation matches the stated safety requirements and includes focused unit, MCP, and integration coverage.

Review effort: Balanced
Findings: None

@mkrueger
Mike Krüger (mkrueger) merged commit 5773b0a into main Sep 30, 2026
12 checks passed
@mkrueger
Mike Krüger (mkrueger) deleted the dev/mkrueger/rm-partition-key-etag branch September 30, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants