Skip to content

feat(cli): Add interactive review for prune plans#3421

Merged
c-r33d merged 1 commit into
mainfrom
prune-plan-review
May 1, 2026
Merged

feat(cli): Add interactive review for prune plans#3421
c-r33d merged 1 commit into
mainfrom
prune-plan-review

Conversation

@c-r33d

@c-r33d c-r33d commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Branch Summary

Branch: prune-plan-review

What Changed

  • Added interactive review support for prune plans.
  • Renamed migration interactive review files for clarity:
    • interactive_review.go -> migration_review.go
    • interactive_review_test.go -> migration_review_test.go
  • Added prune review flow in prune_review.go.
  • Added shared policy formatting helpers in policy_formatting.go.
  • Added prune plan item interfaces and helper methods in prune_plan.go.
  • Added TargetRef.String() and PruneStatusReason.String() formatting.
  • Updated prune planner behavior to use prune status reason messages consistently.
  • Moved shared formatting helpers out of summary.go:
    • appendDetails
    • strconvQuote

Interactive Prune Review Behavior

The prune review flow now prompts for unresolved prune items across:

  • actions
  • subject condition sets
  • subject mappings
  • registered resources
  • obligation triggers

For each unresolved item, the user can:

  • delete the source object
  • skip and leave it unresolved
  • abort the review

Choosing delete now clears the prune reason.

Formatting

Added reusable formatting for policy-related prompt details:

  • action name lists
  • registered resource values and action bindings
  • obligation labels
  • request contexts
  • target refs

Target refs now render as structured fields, including empty values:

id="target-1" (namespace="https://example.com")
id="" (namespace="")

Summary by CodeRabbit

Release Notes

  • New Features

    • Added interactive review functionality for namespace policy prune plans, enabling users to review, approve, skip, or abort individual migration items with detailed context and reasoning.
  • Refactor

    • Improved formatting and display of policy structures, including better human-readable summaries for actions, resources, and obligations.

@c-r33d
c-r33d requested a review from a team as a code owner April 30, 2026 16:25
@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 introduces an interactive review capability for prune plans, enabling users to safely manage the deletion of legacy policy objects following a migration. It establishes a robust planning mechanism to classify objects based on their usage and migration status, ensuring that only safe-to-delete objects are pruned while providing clear feedback for unresolved or blocked items.

Highlights

  • Interactive Prune Review: Added an interactive review flow for prune plans, allowing users to delete, skip, or abort the pruning of unresolved policy objects.
  • Prune Planning Logic: Implemented a new PrunePlanner that classifies legacy policy objects (actions, SCS, subject mappings, registered resources, and obligation triggers) as delete, blocked, or unresolved based on migration status.
  • Refactoring and Code Organization: Renamed interactive review files to 'migration_review' for clarity and moved shared formatting helpers to new utility files (plan_utils.go, policy_formatting.go) to support both migration and prune review flows.

🧠 New Feature in Public Preview: You can now enable Memory 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 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 counter productive. 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 code must fade away, To make the new path clear today. With prune and plan we check the state, And choose the objects to delete.

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 Apr 30, 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: 6eea5276-393c-46d5-b04b-0da0fd9b8bec

📥 Commits

Reviewing files that changed from the base of the PR and between 4ee1600 and d03082b.

📒 Files selected for processing (11)
  • otdfctl/migrations/namespacedpolicy/migration_review.go
  • otdfctl/migrations/namespacedpolicy/migration_review_test.go
  • otdfctl/migrations/namespacedpolicy/policy_formatting.go
  • otdfctl/migrations/namespacedpolicy/policy_formatting_test.go
  • otdfctl/migrations/namespacedpolicy/prune_plan.go
  • otdfctl/migrations/namespacedpolicy/prune_plan_test.go
  • otdfctl/migrations/namespacedpolicy/prune_planner.go
  • otdfctl/migrations/namespacedpolicy/prune_planner_test.go
  • otdfctl/migrations/namespacedpolicy/prune_review.go
  • otdfctl/migrations/namespacedpolicy/prune_review_test.go
  • otdfctl/migrations/namespacedpolicy/summary.go
💤 Files with no reviewable changes (2)
  • otdfctl/migrations/namespacedpolicy/summary.go
  • otdfctl/migrations/namespacedpolicy/prune_planner.go

📝 Walkthrough

Walkthrough

Refactors OpenTDF policy migration code by introducing new policy formatting utilities, adding interactive review functionality for prune plans, implementing String() methods for prune plan types, and relocating summary helper functions. The changes span formatting, review, and plan management across the namespacedpolicy package.

Changes

Cohort / File(s) Summary
Policy Formatting
otdfctl/migrations/namespacedpolicy/policy_formatting.go, otdfctl/migrations/namespacedpolicy/policy_formatting_test.go
New formatting helper functions (action names, registered resource values/bindings, obligation labels, request context client IDs) that deduplicate and quote display strings; comprehensive test suite validating exact string outputs across all formatting scenarios.
Prune Plan Infrastructure
otdfctl/migrations/namespacedpolicy/prune_plan.go, otdfctl/migrations/namespacedpolicy/prune_plan_test.go
Added String() methods for TargetRef and PruneStatusReason; new prunePlanItem interface; extended prune plan structs with pointer-receiver methods for source presence, status, and reason management; test coverage for TargetRef.String() formatting.
Interactive Prune Review
otdfctl/migrations/namespacedpolicy/prune_review.go, otdfctl/migrations/namespacedpolicy/prune_review_test.go
New ReviewPrunePlan function enabling item-by-item interactive review with delete/skip/abort actions; structured prompts including identifiers, attributes, and human-readable reasons; extensive test suite covering all item categories and decision paths.
Prune Planner Updates
otdfctl/migrations/namespacedpolicy/prune_planner.go, otdfctl/migrations/namespacedpolicy/prune_planner_test.go
Removed localized string constants for prune status reasons; updated test expectations to reflect new reason message format for registered-resource source mismatches.
Summary Refactoring
otdfctl/migrations/namespacedpolicy/summary.go
Deleted helper functions appendDetails and strconvQuote previously used for formatting metadata and quoting labels in summary output.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

The diff spans multiple new files with substantial logic (interactive review with ~224 LOC), refactored string formatting utilities, and cross-file reorganization of helper functions. While test-heavy and well-structured, the interactive review logic requires careful understanding of prune plan item handling, user interaction flow, and status transitions across multiple item types.

Possibly related PRs

Suggested labels

comp:policy, size/l

Suggested reviewers

  • elizabethhealy
  • alkalescent

Poem

🐰 A rabbit hops through code so neat,
New formatting makes reviews complete,
Interactive prompts now ask "delete or keep?"
String methods shine where prune plans creep,
Refactored helpers dance—no secrets to reap! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.55% 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 title accurately describes the main feature addition: interactive review functionality for prune plans, which is the primary focus across multiple files.
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 prune-plan-review

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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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 a pruning system for namespaced policies, enabling the identification and removal of legacy policy objects post-migration. It introduces the PrunePlanner, which categorizes objects as deleted, blocked, or unresolved, alongside an interactive review tool for manual decision-making. The PR also includes comprehensive testing for the pruning logic and refactors several utility functions for policy formatting and object identification into shared locations. Feedback identifies several redundant nil checks in the PrunePlanner implementation that should be removed to improve code clarity.

Comment thread otdfctl/migrations/namespacedpolicy/prune_planner.go
Comment thread otdfctl/migrations/namespacedpolicy/prune_planner.go
Comment thread otdfctl/migrations/namespacedpolicy/prune_planner.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 161.0893ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 423.718923ms
Throughput 236.01 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 42.155182712s
Average Latency 419.55225ms
Throughput 118.61 requests/second

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@otdfctl/migrations/namespacedpolicy/prune_plan.go`:
- Around line 38-42: The PruneStatusReason struct incorrectly embeds
fmt.Stringer causing an extra JSON field; remove the embedded fmt.Stringer from
the struct definition (PruneStatusReason) so its JSON shape no longer contains a
Stringer member, and if stringification is required implement a String() method
on PruneStatusReason (or provide a helper) instead of embedding the interface;
update any references expecting the embedded field to call the new String()
method or helper.

In `@otdfctl/migrations/namespacedpolicy/prune_planner.go`:
- Around line 183-186: Align nil-checking patterns between the loops over
sourceActions and planSubjectConditionSets by using the same guard form; update
the loop that populates planSubjectConditionSets to mirror the explicit check
used in planActions (i.e., check both source == nil || source.GetId() == "") so
both loops use the same nil-safe style; modify the loop that builds
planSubjectConditionSets (and any similar loops at lines 234-237) to reference
the same condition and keep the protobuf getter usage unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0637e001-5a7d-4d3b-9387-7a5866fd5067

📥 Commits

Reviewing files that changed from the base of the PR and between 3d2130d and 4ee1600.

📒 Files selected for processing (15)
  • otdfctl/migrations/namespacedpolicy/migration_review.go
  • otdfctl/migrations/namespacedpolicy/migration_review_test.go
  • otdfctl/migrations/namespacedpolicy/plan_utils.go
  • otdfctl/migrations/namespacedpolicy/planner.go
  • otdfctl/migrations/namespacedpolicy/policy_formatting.go
  • otdfctl/migrations/namespacedpolicy/policy_formatting_test.go
  • otdfctl/migrations/namespacedpolicy/prune_plan.go
  • otdfctl/migrations/namespacedpolicy/prune_plan_test.go
  • otdfctl/migrations/namespacedpolicy/prune_planner.go
  • otdfctl/migrations/namespacedpolicy/prune_planner_test.go
  • otdfctl/migrations/namespacedpolicy/prune_review.go
  • otdfctl/migrations/namespacedpolicy/prune_review_test.go
  • otdfctl/migrations/namespacedpolicy/resolved.go
  • otdfctl/migrations/namespacedpolicy/retrieve.go
  • otdfctl/migrations/namespacedpolicy/summary.go
💤 Files with no reviewable changes (2)
  • otdfctl/migrations/namespacedpolicy/retrieve.go
  • otdfctl/migrations/namespacedpolicy/summary.go

Comment thread otdfctl/migrations/namespacedpolicy/prune_plan.go
Comment thread otdfctl/migrations/namespacedpolicy/prune_planner.go
@github-actions

Copy link
Copy Markdown
Contributor

@c-r33d
c-r33d force-pushed the prune-plan-review branch from 4ee1600 to d03082b Compare May 1, 2026 17:54
@github-actions

github-actions Bot commented May 1, 2026

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 181.882662ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 398.194323ms
Throughput 251.13 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 42.817975202s
Average Latency 426.280254ms
Throughput 116.77 requests/second

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • tests-bdd

See the workflow run for details.

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

@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 1, 2026
Merged via the queue into main with commit c11680b May 1, 2026
40 checks passed
@c-r33d
c-r33d deleted the prune-plan-review branch May 1, 2026 20:14
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.

2 participants