Skip to content

feat(cli): Confirm and execute pruning of legacy objects#3458

Merged
c-r33d merged 2 commits into
mainfrom
confirm-interactive-prune
May 12, 2026
Merged

feat(cli): Confirm and execute pruning of legacy objects#3458
c-r33d merged 2 commits into
mainfrom
confirm-interactive-prune

Conversation

@c-r33d

@c-r33d c-r33d commented May 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds execution support for migrate prune namespaced-policy so commit mode can delete legacy/global policy objects after prune planning and optional interactive review.

Changes

  • Wires migrate prune namespaced-policy into the prune planner, interactive review, commit confirmation, executor, and summary rendering.
  • Adds prune-specific backup confirmation copy for destructive delete commits.
  • Extends the namespaced policy executor handler with delete operations.
  • Adds Executor.ExecutePrune with single-scope dispatch for:
    • actions
    • subject condition sets
    • subject mappings
    • registered resources
    • obligation triggers
  • Ensures prune execution only processes the one scope declared by the PrunePlan.
  • Records prune execution results in-place for summary output.
  • Deletes registered resources through the parent delete API only, relying on existing cascade behavior for values.
  • Adds per-prune-item sourceID() helpers for source ID validation.
  • Adds unit coverage for prune execution, prune backup confirmation, and prune source ID handling.

Summary by CodeRabbit

  • New Features

    • Added a hidden prune command allowing scoped pruning with interactive plan review, optional commit execution, and rendered summary output.
    • Added an interactive backup confirmation step before executing prune commits.
  • Behavior Changes

    • Prune execution now validates plans, dispatches scoped deletions, records per-item results, and reports failures or aborted runs.
  • Tests

    • Added extensive tests covering prune execution, scope validation, failure handling, and interactive prompts.

Review Change Stack

@c-r33d
c-r33d requested a review from a team as a code owner May 11, 2026 16:48
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enables the 'migrate prune namespaced-policy' command to execute deletions of legacy policy objects. It introduces a robust execution pipeline that integrates with the existing prune planner, provides interactive safety checks, and ensures that destructive operations are confirmed by the user. The changes include new execution handlers, improved source ID validation, and detailed summary rendering for prune operations.

Highlights

  • Pruning Execution Support: Implemented the execution logic for pruning legacy namespaced policy objects, including support for actions, subject condition sets, subject mappings, registered resources, and obligation triggers.
  • Interactive Review and Confirmation: Integrated interactive review and backup confirmation steps into the prune workflow to ensure safe, destructive deletions of legacy policy objects.
  • Executor Handler Expansion: Extended the ExecutorHandler interface with specific delete operations for all supported policy object types.
  • Unit Testing: Added comprehensive unit tests for prune execution, source ID handling, and interactive backup confirmation.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.


The legacy objects must fade away, To clear the path for a brighter day. With plans in place and caution shown, The pruned policy is finally sown.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a1ee6cc9-f355-4b25-8598-a6cc63f03c13

📥 Commits

Reviewing files that changed from the base of the PR and between deb0659 and a485989.

📒 Files selected for processing (2)
  • otdfctl/cmd/migrate/namespaced_policy.go
  • otdfctl/cmd/migrate/prune/namespaced_policy.go

📝 Walkthrough

Walkthrough

Implements namespaced-policy pruning end-to-end: extends prune plan items with source/execution methods, expands the executor handler with Delete* methods and a missing-source error, implements ExecutePrune with scope dispatch and failure recording, adds interactive backup confirmation, and wires a hidden CLI prune command with summary output.

Changes

Namespaced Policy Prune Workflow

Layer / File(s) Summary
Prune Plan Model
otdfctl/migrations/namespacedpolicy/prune_plan.go, otdfctl/migrations/namespacedpolicy/prune_plan_test.go
Adds sourceID() and setExecution() to the internal prunePlanItem interface and implements them for all plan item types; unit test verifies sourceID() behavior.
Handler Interface & Mocks
otdfctl/migrations/namespacedpolicy/execute.go, otdfctl/migrations/namespacedpolicy/execute_test_helpers_test.go
Adds ErrMissingPruneSourceID and six Delete* methods to ExecutorHandler; extends mockExecutorHandler with delete call tracking, per-ID error maps, and delete method implementations.
Plan Execution
otdfctl/migrations/namespacedpolicy/prune_execute.go, otdfctl/migrations/namespacedpolicy/prune_execute_test.go
Implements Executor.ExecutePrune with plan validation, single-scope dispatch, scope-specific handlers, and a generic executePruneItems loop that validates source IDs, invokes handler deletes, records failures, and marks successful executions; tests cover scope dispatch, failure recording/stop-on-error, and scope validation.
Interactive Confirmation
otdfctl/migrations/namespacedpolicy/interactive_commit.go, otdfctl/migrations/namespacedpolicy/interactive_commit_test.go
Introduces ConfirmNamespacedPolicyPruneBackup and refactors shared confirmation helper to accept prune-specific prompt constants; adds tests for prompt content and abort-to-error mapping.
CLI Orchestration
otdfctl/cmd/migrate/prune/namespaced_policy.go, otdfctl/cmd/migrate/prune/namespacedPolicy.go
Adds hidden migrate prune namespaced-policy command reading --scope and inherited --commit/--interactive, builds planner and plan, supports interactive review and backup confirmation on commit, executes prune when committed, and writes rendered prune summary to stdout. Includes commit execution and summary helper functions.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as Command
  participant Planner as Planner
  participant Reviewer as InteractiveReview
  participant Prompter as BackupPrompter
  participant Executor as Executor
  participant Out as SummaryOutput

  CLI->>Planner: BuildPrunePlan(scope)
  Planner-->>CLI: PrunePlan
  alt interactive review
    CLI->>Reviewer: Review(PrunePlan)
    Reviewer-->>CLI: continue|abort
    opt abort
      CLI->>Out: WritePruneSummary(aborted)
    end
  end
  alt commit
    CLI->>Prompter: ConfirmNamespacedPolicyPruneBackup
    Prompter-->>CLI: confirmed|abort
    CLI->>Executor: ExecutePrune(PrunePlan)
    Executor-->>CLI: result|error
  end
  CLI->>Out: WritePruneSummary(result)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • opentdf/platform#3456: Implements prune plan execution results and RenderNamespacedPolicyPruneSummary that this PR wires into the CLI summary output.
  • opentdf/platform#3411: Introduces the prune planner consumed by ExecutePrune in this PR.
  • opentdf/platform#3421: Related prune workflow changes modifying plan types and interactive prune behavior used across both PRs.

Suggested labels

size/l

Suggested reviewers

  • elizabethhealy
  • alkalescent

"A rabbit hops through code so grand,
Prunes and prompts all close at hand,
Plans inspected, deletes applied,
Summary printed with joyful pride,
🐰✨"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly aligns with the primary objective: implementing confirmation and execution for pruning legacy/global policy objects in the migrate prune namespaced-policy workflow.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch confirm-interactive-prune

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request implements the migrate prune namespaced-policy command, providing the logic for planning, interactive review, and execution of policy pruning. It extends the Executor with an ExecutePrune method and adds corresponding deletion capabilities to the ExecutorHandler interface. The review feedback recommends using cmd.OutOrStdout() instead of os.Stdout to improve testability and adhere to CLI standards. There is also a suggestion to consider continuing the prune process after an error occurs to provide a more comprehensive report of failures rather than stopping immediately.

Comment thread otdfctl/cmd/migrate/prune/namespacedPolicy.go Outdated
Comment thread otdfctl/cmd/migrate/prune/namespacedPolicy.go Outdated
Comment thread otdfctl/migrations/namespacedpolicy/prune_execute.go
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 171.036614ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 88.948539ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 430.547471ms
Throughput 232.26 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 41.801758723s
Average Latency 415.417822ms
Throughput 119.61 requests/second

@c-r33d

c-r33d commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 167.233491ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 93.208944ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 435.551503ms
Throughput 229.59 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 42.517169795s
Average Latency 423.145639ms
Throughput 117.60 requests/second

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • examples
  • otdfctl
  • sdk
  • service
  • lib/fixtures
  • tests-bdd

See the workflow run for details.

Comment thread otdfctl/cmd/migrate/prune/namespaced_policy.go
Comment thread otdfctl/migrations/namespacedpolicy/interactive_commit.go

@alkalescent alkalescent 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.

lgtm

@c-r33d
c-r33d added this pull request to the merge queue May 12, 2026
Merged via the queue into main with commit 24c09dd May 12, 2026
40 checks passed
@c-r33d
c-r33d deleted the confirm-interactive-prune branch May 12, 2026 18:01
JBCongdon pushed a commit to JBCongdon/platform that referenced this pull request May 24, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.32.0](opentdf/platform@otdfctl/v0.31.0...otdfctl/v0.32.0)
(2026-05-19)


### Features

* **cli:** Add better unit testing.
([opentdf#3378](opentdf#3378))
([3ad33dc](opentdf@3ad33dc))
* **cli:** Add interactive review for prune plans
([opentdf#3421](opentdf#3421))
([c11680b](opentdf@c11680b))
* **cli:** Add prune confirmation.
([opentdf#3469](opentdf#3469))
([c6d47ec](opentdf@c6d47ec))
* **cli:** Add prune planner.
([opentdf#3411](opentdf#3411))
([3e294e6](opentdf@3e294e6))
* **cli:** Add prune summary information
([opentdf#3456](opentdf#3456))
([c900c53](opentdf@c900c53))
* **cli:** add sensitive flag annotation to DocFlag
([opentdf#3457](opentdf#3457))
([98f48d2](opentdf@98f48d2))
* **cli:** Confirm and execute pruning of legacy objects
([opentdf#3458](opentdf#3458))
([24c09dd](opentdf@24c09dd))
* **cli:** Print report on failure
([opentdf#3365](opentdf#3365))
([05a4473](opentdf@05a4473))
* **cli:** Sort parameters.
([opentdf#3478](opentdf#3478))
([73ad878](opentdf@73ad878))
* **policy:** Add FQN to RegisteredResourceValues
([opentdf#3446](opentdf#3446))
([3199583](opentdf@3199583))
* **policy:** Add resource mapping group FQNs
([opentdf#3447](opentdf#3447))
([6a0b3c6](opentdf@6a0b3c6))


### Bug Fixes

* **cli:** Prune was not classifying multi-namespaced RRs properly.
([opentdf#3488](opentdf#3488))
([eae8645](opentdf@eae8645))
* **cli:** support json profile output
([opentdf#3448](opentdf#3448))
([61f194c](opentdf@61f194c))
* **deps:** bump github.com/opentdf/platform/lib/identifier from 0.3.0
to 0.4.0 in /otdfctl
([opentdf#3367](opentdf#3367))
([aa23179](opentdf@aa23179))
* **deps:** bump github.com/opentdf/platform/protocol/go from 0.27.0 to
0.28.0 in /otdfctl
([opentdf#3419](opentdf#3419))
([c80374f](opentdf@c80374f))
* **deps:** bump github.com/opentdf/platform/sdk from 0.16.0 to 0.17.0
in /otdfctl ([opentdf#3397](opentdf#3397))
([bb9fcd6](opentdf@bb9fcd6))
* **deps:** bump go.opentelemetry.io/otel from 1.40.0 to 1.41.0 in
/otdfctl ([opentdf#3400](opentdf#3400))
([5631c37](opentdf@5631c37))
* **deps:** bump module protocol/go to v0.30.0 throughout
([opentdf#3459](opentdf#3459))
([8eaa502](opentdf@8eaa502))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: opentdf-automation[bot] <149537512+opentdf-automation[bot]@users.noreply.github.com>
Co-authored-by: Chris Reed <87077975+c-r33d@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants