Skip to content

chore(cli): Namespaced-Policy bats prune tests and docs updates #3482

Merged
c-r33d merged 3 commits into
mainfrom
prune-e2e-tests
May 18, 2026
Merged

chore(cli): Namespaced-Policy bats prune tests and docs updates #3482
c-r33d merged 3 commits into
mainfrom
prune-e2e-tests

Conversation

@c-r33d
Copy link
Copy Markdown
Contributor

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

Summary

Adds end-to-end coverage for otdfctl migrate prune namespaced-policy --commit in otdfctl/e2e/migrate-namespaced-policy.bats.

The new tests cover:

  • prune validation for --scope
  • rejects empty scope
  • rejects invalid scope
  • rejects CSV input with multiple scopes
  • confirms invalid requests do not delete otherwise-prunable source fixtures or disturb migrated targets
  • prune behavior for each supported single scope
  • actions
  • subject-condition-sets
  • subject-mappings
  • registered-resources
  • obligation-triggers
  • mixed-state prune scenarios in each scope
  • deletes legacy source objects only when a labeled migrated target exists and prune is safe
  • retains source objects that are still referenced
  • retains source objects that were not migrated
  • retains source objects when the matching target is unlabeled
  • retains registered resources whose source values span multiple namespaces
  • idempotency and state safety
  • reruns each prune scope a second time to confirm no further changes
  • uses namespace delta checks to ensure prune does not create or mutate unexpected namespaced targets

Verification

Ran against a live local platform stack:

bats --tap e2e/migrate-namespaced-policy.bats --filter 'prune namespaced-policy'

All prune tests passed.

Summary by CodeRabbit

  • Documentation

    • Clarified that migrate namespaced-policy is non-destructive; cleanup is performed via migrate prune namespaced-policy.
    • Expanded prune docs with prerequisites, delete-safety outcomes, best practices, single-scope --scope usage, --commit/--interactive behavior, and updated examples.
  • Tests

    • Added comprehensive end-to-end prune tests covering scope validation, per-scope pruning behavior, retention cases, namespace deltas, and idempotency; includes new test helpers and assertions to validate prune outcomes.

Review Change Stack

@c-r33d c-r33d requested a review from a team as a code owner May 18, 2026 15:13
@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 implements and verifies the prune workflow for namespaced policy migration. It ensures that legacy objects can be safely removed after migration by validating scopes, verifying dependency safety, and confirming idempotency. The changes include significant updates to the documentation and the addition of a comprehensive suite of end-to-end tests to ensure the reliability of the prune command.

Highlights

  • End-to-End Test Coverage: Added comprehensive E2E tests for the otdfctl migrate prune namespaced-policy command, covering validation, scope-specific behavior, and mixed-state scenarios.
  • Documentation Updates: Updated documentation for migrate prune namespaced-policy to clarify command usage, delete safety mechanisms, and best practices.
  • Test Infrastructure: Enhanced the migrate-namespaced-policy.bats test suite with new helper functions for ID tracking and assertions to support robust prune verification.
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 fade from view, As namespaced targets start anew. With prune in hand, the path is clear, Removing all the ghosts of yesteryear.

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
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

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: 331f0f89-626e-472c-ae64-03d65035253d

📥 Commits

Reviewing files that changed from the base of the PR and between e8daf70 and 473c15f.

📒 Files selected for processing (3)
  • otdfctl/docs/man/migrate/prune/_index.md
  • otdfctl/docs/man/migrate/prune/namespaced-policy.md
  • otdfctl/e2e/migrate-namespaced-policy.bats

📝 Walkthrough

Walkthrough

Adds single-scope namespaced-policy prune docs (scope validation, safety outcomes, examples, best practices) and extends the migrate namespaced-policy E2E BATS suite with teardown untracking, namespaced fixture helpers, prune-specific assertions, a prune-run helper, and per-scope prune tests validating deletion/retention and idempotency.

Changes

Namespaced-policy prune documentation and E2E test coverage

Layer / File(s) Summary
Migration non-destructiveness clarification
otdfctl/docs/man/migrate/namespaced-policy.md, otdfctl/docs/man/migrate/prune/_index.md
Clarifies migrate namespaced-policy commit mode must not delete legacy objects and documents the parent migrate flags (--interactive, --commit) and that cleanup uses migrate prune namespaced-policy.
Comprehensive prune command documentation
otdfctl/docs/man/migrate/prune/namespaced-policy.md
Reworks prune guide to require a single --scope=... value, adds prerequisites, delete-safety outcomes (delete/blocked/unresolved), best practices, updated examples (--commit/--interactive), and detailed behavior for actions and subject-condition-sets.
E2E test helpers for prune validation
otdfctl/e2e/migrate-namespaced-policy.bats
Adds remove_tracked_id and untrack_* helpers, namespaced fixture creators (create_namespaced_action, create_namespaced_registered_resource), prune assertion helpers (assert_legacy_*_pruned, assert_*_target_still_exists, unlabeled-target checks), and run_namespaced_policy_prune_commit.
Prune test suite with scope validation and per-type coverage
otdfctl/e2e/migrate-namespaced-policy.bats
New prune section: scope validation (empty/invalid/multi-scope CSV) and per-scope suites for actions, SCS, subject-mappings, registered-resources, obligation-triggers. Tests assert legacy deletions vs retained cases, migrated target existence, namespace deltas, untracking of deleted IDs, and idempotency on re-run.

Sequence Diagram

sequenceDiagram
  participant otdfctl as otdfctl CLI
  participant PrunePlanner as PrunePlanner
  participant ServerAPI as Server API
  participant DB as Database
  otdfctl->>PrunePlanner: request prune plan (--scope, --commit/--interactive)
  PrunePlanner->>ServerAPI: request candidate legacy/target info
  ServerAPI->>DB: query legacy objects and migrated targets
  DB-->>ServerAPI: returns objects + labels (migrated_from, unlabeled)
  ServerAPI-->>PrunePlanner: candidate classification (delete/blocked/unresolved)
  PrunePlanner-->>otdfctl: plan summary and interactive confirmations
  alt commit
    otdfctl->>ServerAPI: delete confirmed legacy objects
    ServerAPI->>DB: perform deletes
    DB-->>ServerAPI: ack deletions
    ServerAPI-->>otdfctl: prune results
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • opentdf/platform#3458: Implements prune executor and single-scope --scope behavior exercised by these E2E tests and docs.
  • opentdf/platform#3324: Earlier namespaced migration tests in the same BATS file; this PR extends that suite with prune coverage.
  • opentdf/platform#3469: Related interactive deletion/confirmation behavior and typed prune summary results that align with the documented and tested interactive flow.

Suggested labels

comp:policy, size/xl

Suggested reviewers

  • alkalescent
  • elizabethhealy
  • jhaage-virtru

"I hopped through docs and tests with glee,
Pruned old roots so new branches run free,
Helpers and assertions — tidy and neat,
Idempotent runs make the garden complete,
A rabbit's small cheer for a job grown sweet!"

🚥 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 title accurately summarizes the main changes: adding BATS prune tests and updating documentation for the namespaced-policy migrate command.
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-e2e-tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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 documentation and comprehensive end-to-end tests for the migrate prune namespaced-policy command. The documentation updates include detailed sections on prerequisites, delete safety, and best practices for pruning legacy policy objects. The E2E test suite is expanded with new helpers for untracking IDs, assertion functions for verifying pruned resources, and test cases covering various pruning scenarios across all policy scopes. Review feedback identified a bug in the untrack_* bash helpers where command substitution strips required newlines, noted potential global variable leakage in tests due to missing local declarations, and recommended replacing hardcoded connection strings with existing environment variables for better maintainability.

Comment thread otdfctl/e2e/migrate-namespaced-policy.bats
Comment thread otdfctl/e2e/migrate-namespaced-policy.bats
Comment thread otdfctl/e2e/migrate-namespaced-policy.bats
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@otdfctl/docs/man/migrate/prune/namespaced-policy.md`:
- Around line 60-61: The example showing "otdfctl migrate prune
namespaced-policy --scope=obligation-triggers --interactive --commit" is
inconsistent with the documented shared apply flag (--commit only); either
remove "--interactive" from the example or explicitly document that the prune
subcommand supports an interactive mode. Update the namespaced-policy prune
examples to match the actual behavior of the prune command (edit the example to
use only "otdfctl migrate prune namespaced-policy --scope=obligation-triggers
--commit" if interactive is unsupported), or add a note in the prune
documentation and the shared flags section describing the "--interactive" flag
and how it interacts with "--commit" if interactive is supported.

In `@otdfctl/e2e/migrate-namespaced-policy.bats`:
- Around line 2228-2231: The test currently calls
untrack_action_id("$delete_a_id") and untrack_action_id("$delete_b_id") before
verifying prune success, which can leak fixtures if the prune assertions fail;
change the order so that assert_legacy_custom_action_pruned "$delete_a_id" and
assert_legacy_custom_action_pruned "$delete_b_id" run first and only
untrack_action_id for each ID after its corresponding prune assertion passes,
and apply the same reorder pattern for the other similar blocks (the ones
referencing untrack_action_id and assert_legacy_custom_action_pruned in the
file).
🪄 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: c0c6a324-91b5-4d29-9b58-2a7e1940f065

📥 Commits

Reviewing files that changed from the base of the PR and between 6e79af6 and e8daf70.

📒 Files selected for processing (4)
  • otdfctl/docs/man/migrate/namespaced-policy.md
  • otdfctl/docs/man/migrate/prune/_index.md
  • otdfctl/docs/man/migrate/prune/namespaced-policy.md
  • otdfctl/e2e/migrate-namespaced-policy.bats
💤 Files with no reviewable changes (1)
  • otdfctl/docs/man/migrate/prune/_index.md

Comment thread otdfctl/docs/man/migrate/prune/namespaced-policy.md
Comment thread otdfctl/e2e/migrate-namespaced-policy.bats Outdated
@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 183.590628ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 415.243496ms
Throughput 240.82 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 44.152489394s
Average Latency 439.890815ms
Throughput 113.24 requests/second

@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 150.204958ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 411.382559ms
Throughput 243.08 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 42.384779361s
Average Latency 421.28453ms
Throughput 117.97 requests/second

Comment thread otdfctl/e2e/migrate-namespaced-policy.bats
Comment thread otdfctl/e2e/migrate-namespaced-policy.bats
Comment thread otdfctl/e2e/migrate-namespaced-policy.bats Outdated
Comment thread otdfctl/docs/man/migrate/prune/namespaced-policy.md Outdated
elizabethhealy
elizabethhealy previously approved these changes May 18, 2026
@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.68587ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 431.278614ms
Throughput 231.87 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 43.644278294s
Average Latency 434.618645ms
Throughput 114.56 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.

@c-r33d c-r33d added this pull request to the merge queue May 18, 2026
Merged via the queue into main with commit bc7f8cd May 18, 2026
40 checks passed
@c-r33d c-r33d deleted the prune-e2e-tests branch May 18, 2026 19:56
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