Skip to content

feat(policy): add sort support to listobligations api#3300

Draft
dsm20 wants to merge 11 commits intomainfrom
add-sort-support-listobligations-api
Draft

feat(policy): add sort support to listobligations api#3300
dsm20 wants to merge 11 commits intomainfrom
add-sort-support-listobligations-api

Conversation

@dsm20
Copy link
Copy Markdown
Contributor

@dsm20 dsm20 commented Apr 13, 2026

Proposed Changes

Resolves DSPX-2690

Changes

Protoservice/policy/obligations/obligations.proto

  • SortObligationsType enum (UNSPECIFIED, NAME, FQN, CREATED_AT, UPDATED_AT)
  • ObligationsSort message (field + direction)
  • repeated ObligationsSort sort = 11 on ListObligationsRequest with max_items = 1 constraint
  • Regenerated protos and docs

SQLservice/policy/db/queries/obligations.sql

  • CASE WHEN sort blocks in listObligations query for 4 fields (8 blocks total)
  • FQN sort uses constructed expression fqns.fqn || '/obl/' || LOWER(od.name) since obligation FQNs aren't stored in attribute_fqns
  • Fallback od.created_at DESC

Goservice/policy/db/utils.go + service/policy/db/obligations.go

  • GetObligationsSortParams(): maps enum to SQL-compatible field/direction strings
  • ListObligations handler wired to call mapper and pass params to sqlc query
  • Added sortFieldName and sortFieldFQN constants in utils.go (same pattern as sortFieldCreatedAt/sortFieldUpdatedAt from feat(policy): add sort ListSubjectMappings API #3255)

Tests

  • 12 unit tests for the enum mapper helper (nil, empty, unspecified, each field + direction)
  • 9 integration tests (name ASC/DESC, fqn ASC/DESC, created_at ASC/DESC, updated_at ASC/DESC, unspecified fallback) using createSortTestObligations and createNamedSortTestObligations suite helpers
  • Protovalidate sort constraint test (Test_ListObligationsRequest_Sort)

Notes

Checklist

  • I have added or updated unit tests
  • I have added or updated integration tests (if appropriate)
  • I have added or updated documentation

Testing Instructions

Summary by CodeRabbit

  • New Features

    • Added sorting support for the obligations list API with multiple sort options: name, FQN, created date, and last modified date
    • Users can sort in ascending or descending order
    • Default ordering by creation date (descending) when no sort is specified
  • Tests

    • Added comprehensive integration and unit test coverage for sorting functionality
  • Documentation

    • Updated API documentation to reflect sorting capabilities

dsm20 added 11 commits April 10, 2026 14:00
has buf.validate as per usual and comments for docs. regen protos as
well
api-level tests for no items, 1 item, and 2 items sort (pass pass fail)
fqn and name in utils
in listObligations query, remove ORDER BY replace with CASE WHEN block.
FQN is assembled here. also regenerated sqlc
this is getting saved for a later PR since its inconsistent across
listAPIs
12 unit tests, full coverage) in utils_test.go
wire sort params into the go DB function in /db/obligations.go
full coverage (created_at, updated_at, name, fqn. two helpers for time
based and name based sorting. uses assertIDsInOrder helper across each
integration test
@dsm20 dsm20 requested review from a team as code owners April 13, 2026 19:17
@dsm20 dsm20 marked this pull request as draft April 13, 2026 19:18
@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 sorting capabilities to the ListObligations API, enabling clients to request ordered data based on specific fields. The changes involve updating the protocol definitions, database query logic, and service layer to handle sort parameters, while maintaining backward compatibility with existing default ordering.

Highlights

  • API Enhancement: Added strongly-typed sort support to the ListObligations RPC, allowing results to be ordered by name, FQN, created_at, or updated_at.
  • Database Updates: Updated the SQL query for listing obligations to support dynamic sorting using CASE statements, ensuring efficient ordering.
  • Testing: Implemented comprehensive unit and integration tests to verify sorting functionality, including edge cases and validation constraints.

🧠 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.

Ignored Files
  • Ignored by pattern: docs/openapi/**/* (1)
    • docs/openapi/policy/obligations/obligations.openapi.yaml
  • Ignored by pattern: protocol/**/* (1)
    • protocol/go/policy/obligations/obligations.pb.go
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 obligations list is long, To sort them right, not wrong. With fields defined and SQL set, The best results you'll surely get.

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.

@github-actions github-actions bot added comp:db DB component comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) docs Documentation labels Apr 13, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 13, 2026

📝 Walkthrough

Walkthrough

This PR adds sorting functionality to the ListObligations API by introducing new proto message types, OpenAPI schemas, and SQL query logic. Changes span proto definitions, database layer modifications, documentation updates, and comprehensive test coverage for sort behavior across multiple fields and directions.

Changes

Cohort / File(s) Summary
Proto Definitions
service/policy/obligations/obligations.proto
Added SortObligationsType enum with sort field options (NAME, FQN, CREATED_AT, UPDATED_AT) and ObligationsSort message; extended ListObligationsRequest with optional sort field (max 1 item).
OpenAPI Schema
docs/openapi/policy/obligations/obligations.openapi.yaml, docs/grpc/index.html
Added schemas for policy.SortDirection, policy.obligations.SortObligationsType, and policy.obligations.ObligationsSort; updated ListObligationsRequest to include optional sort array property with max items constraint; removed stale Definitions description from GetObligationRequest.
Database Layer - Query
service/policy/db/queries/obligations.sql
Modified listObligations query to support dynamic ORDER BY using conditional CASE WHEN expressions based on sort field and direction parameters, with fallback to default created_at DESC ordering.
Database Layer - Go
service/policy/db/obligations.go, service/policy/db/obligations.sql.go
Updated ListObligations handler to extract and pass sort parameters; extended listObligationsParams struct with SortField and SortDirection fields; adjusted pagination parameter indices.
Database Utilities
service/policy/db/utils.go, service/policy/db/utils_test.go
Added GetObligationsSortParams helper function to map proto sort enum/direction to SQL-compatible strings; includes unit tests covering nil/empty/UNSPECIFIED cases and all sort field combinations.
Proto Validation Tests
service/policy/obligations/obligations_test.go
Added Test_ListObligationsRequest_Sort to validate sort field constraint (max 1 item); ensures single sort entry passes, multiple entries fail validation.
Integration Tests
service/integration/obligations_test.go
Added comprehensive test helpers and cases for sorting: ascending/descending by name, fqn, created_at, and updated_at; includes UNSPECIFIED fallback behavior and deterministic obligation ordering fixtures.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

comp:db, comp:policy, size/m, docs

Suggested reviewers

  • c-r33d
  • alkalescent

Poem

🐰 Obligations sorted, oh what a delight!
By name, by fqn, or time of creation bright,
The database hops with a CASE WHEN so neat,
Making list queries orderly and fleet! 📋✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: adding sort support to the ListObligations API, which is the central focus of the entire changeset.

✏️ 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 add-sort-support-listobligations-api

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.

@dsm20 dsm20 changed the title Add sort support listobligations api policy(feat): add sort support to listobligations api Apr 13, 2026
@dsm20 dsm20 changed the title policy(feat): add sort support to listobligations api feat(policy): add sort support to listobligations api Apr 13, 2026
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 introduces sorting capabilities for the ListObligations endpoint, allowing results to be ordered by name, FQN, creation date, or update date. The implementation includes updates to the protobuf definitions, service logic to parse sort parameters, and SQL queries utilizing CASE statements for dynamic ordering. Comprehensive integration and unit tests have been added to verify the new functionality. Feedback highlights that the SQL implementation lacks the 'id ASC' tie-breaker mentioned in the documentation, which is necessary to ensure deterministic pagination when multiple records share the same timestamp.

CASE WHEN @sort_field::text = 'created_at' AND @sort_direction::text = 'DESC' THEN od.created_at END DESC,
CASE WHEN @sort_field::text = 'updated_at' AND @sort_direction::text = 'ASC' THEN od.updated_at END ASC,
CASE WHEN @sort_field::text = 'updated_at' AND @sort_direction::text = 'DESC' THEN od.updated_at END DESC,
od.created_at DESC
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.

medium

The ORDER BY clause is missing the id ASC tie-breaker. The documentation in the proto file (and the generated gRPC docs) explicitly states that the default ordering includes id ASC as a tie-breaker. Without a unique tie-breaker, pagination results can be non-deterministic if multiple records share the same created_at timestamp. Adding od.id ASC here will ensure stable sorting for both the default case and as a final tie-breaker for other sort fields.

    od.created_at DESC,
    od.id ASC

@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

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

See the workflow run for details.

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

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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.818251ms
Throughput 242.83 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 44.019836434s
Average Latency 438.558577ms
Throughput 113.59 requests/second

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: 6

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

Inline comments:
In `@docs/grpc/index.html`:
- Line 13206: Restore a non-empty description for the GetObligationRequest entry
in the generated docs by replacing the empty paragraph at the
GetObligationRequest section with a short summary (e.g., "Request message to
retrieve obligation details by ID and optional filters") so the documentation
regains context; locate the GetObligationRequest heading in the generated HTML
and update the empty <p>...</p> into a concise one-line description matching the
request purpose.
- Around line 13573-13580: The docs claim a tie-breaker "id ASC (tie-breaker)"
for ListObligationsRequest.sort/ObligationsSort which is not implemented; update
the HTML table cell describing the sort field in docs/grpc/index.html to remove
or neutralize the specific tie-breaker language and instead state the concrete
default ordering that matches the service (e.g., "created_at DESC" and leave
tie-breaking as implementation-defined or deferred), ensuring the text for the
sort field (the <td> describing ObligationsSort) matches actual endpoint
behavior.

In `@docs/openapi/policy/obligations/obligations.openapi.yaml`:
- Around line 1787-1790: The docs for ListObligationsRequest.sort currently
assert a tie-breaker "then id ASC (tie-breaker)" which is not implemented;
update the description for the ListObligationsRequest.sort field by removing the
tie-breaker clause and any wording that implies a stable secondary ordering,
leaving only the documented default ordering that matches current endpoint
behavior (e.g., "created_at DESC" or the existing default phrasing) so the
OpenAPI text no longer guarantees id ASC as a tie-breaker.
- Around line 547-553: Update the policy.SortDirection schema to document how
SORT_DIRECTION_UNSPECIFIED should be treated: add an endpoint-neutral
description stating that SORT_DIRECTION_UNSPECIFIED maps to ascending order
(UNSPECIFIED => ASC) and note that concrete per-endpoint default ordering should
still be documented in each request's docs; reference the enum value
SORT_DIRECTION_UNSPECIFIED and the schema name policy.SortDirection so the
change is applied to the central enum definition rather than individual
endpoints.

In `@service/integration/obligations_test.go`:
- Around line 1990-2000: The helper createNamedSortTestObligations currently
always uses nsExampleCom so it creates all obligations in one namespace and
masks FQN-based sorting bugs; modify createNamedSortTestObligations to create
obligations across multiple namespaces (e.g., alternate between nsExampleCom and
another test namespace obtained via s.getNamespaceData or accept a namespace
list) by fetching distinct namespaceIDs with s.getNamespaceData (or use existing
namespace fixtures) and using those namespaceIDs when calling
s.createObligation; update the related fixtures/tests (including the similar
code around lines 2036-2064) so the generated obligations span at least two
namespaces to properly exercise full FQN sorting.

In `@service/policy/db/queries/obligations.sql`:
- Around line 190-199: The ORDER BY lacks a final unique tie-breaker, causing
nondeterministic pagination; update the ORDER BY in obligations.sql (the CASE
expressions and final default) to always append od.id ASC as the ultimate
deterministic tie-breaker (so the current tail "od.created_at DESC" becomes
"od.created_at DESC, od.id ASC" and ensure id ASC is applied after any
CASE-driven sort to satisfy the contract "created_at DESC, then id ASC").
🪄 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: a2eecd90-c407-411a-a178-4b5469d1885b

📥 Commits

Reviewing files that changed from the base of the PR and between 888a4f0 and cb39c35.

⛔ Files ignored due to path filters (1)
  • protocol/go/policy/obligations/obligations.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (10)
  • docs/grpc/index.html
  • docs/openapi/policy/obligations/obligations.openapi.yaml
  • service/integration/obligations_test.go
  • service/policy/db/obligations.go
  • service/policy/db/obligations.sql.go
  • service/policy/db/queries/obligations.sql
  • service/policy/db/utils.go
  • service/policy/db/utils_test.go
  • service/policy/obligations/obligations.proto
  • service/policy/obligations/obligations_test.go


<h3 id="policy.obligations.GetObligationRequest">GetObligationRequest</h3>
<p>Definitions</p>
<p></p>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Restore a non-empty description for GetObligationRequest.

Line 13206 is now empty, which drops useful context from the docs. Please keep at least a short request summary.

Suggested doc fix
-        <p></p>
+        <p>Retrieve an obligation by ID or FQN.</p>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<p></p>
<p>Retrieve an obligation by ID or FQN.</p>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/grpc/index.html` at line 13206, Restore a non-empty description for the
GetObligationRequest entry in the generated docs by replacing the empty
paragraph at the GetObligationRequest section with a short summary (e.g.,
"Request message to retrieve obligation details by ID and optional filters") so
the documentation regains context; locate the GetObligationRequest heading in
the generated HTML and update the empty <p>...</p> into a concise one-line
description matching the request purpose.

Comment on lines +13573 to +13580
<tr>
<td>sort</td>
<td><a href="#policy.obligations.ObligationsSort">ObligationsSort</a></td>
<td>repeated</td>
<td><p>Optional - CONSTRAINT: max 1 item
Default ordering when omitted or when the first entry&#39;s field is UNSPECIFIED:
created_at DESC, then id ASC (tie-breaker). </p></td>
</tr>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

ListObligationsRequest.sort documents an unimplemented tie-breaker.

Line 13579 states id ASC (tie-breaker), but this PR explicitly defers tie-breaker behavior. This creates a docs/API behavior mismatch.

Suggested doc fix
-                  <td><p>Optional - CONSTRAINT: max 1 item
-Default ordering when omitted or when the first entry&#39;s field is UNSPECIFIED:
-created_at DESC, then id ASC (tie-breaker). </p></td>
+                  <td><p>Optional - CONSTRAINT: max 1 item
+Default ordering when omitted or when the first entry&#39;s field is UNSPECIFIED:
+created_at DESC. </p></td>

Based on learnings: document concrete defaults on the specific List* request field, but keep them aligned with actual endpoint behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/grpc/index.html` around lines 13573 - 13580, The docs claim a
tie-breaker "id ASC (tie-breaker)" for
ListObligationsRequest.sort/ObligationsSort which is not implemented; update the
HTML table cell describing the sort field in docs/grpc/index.html to remove or
neutralize the specific tie-breaker language and instead state the concrete
default ordering that matches the service (e.g., "created_at DESC" and leave
tie-breaking as implementation-defined or deferred), ensuring the text for the
sort field (the <td> describing ObligationsSort) matches actual endpoint
behavior.

Comment on lines +547 to +553
policy.SortDirection:
type: string
title: SortDirection
enum:
- SORT_DIRECTION_UNSPECIFIED
- SORT_DIRECTION_ASC
- SORT_DIRECTION_DESC
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Document SORT_DIRECTION_UNSPECIFIED behavior on policy.SortDirection.

Line 551 introduces SORT_DIRECTION_UNSPECIFIED, but this schema currently does not define how it is interpreted. Add an endpoint-neutral description here (UNSPECIFIED => ASC) and keep endpoint-specific defaults in request docs.

Suggested doc patch
     policy.SortDirection:
       type: string
       title: SortDirection
+      description: |-
+        Endpoint-neutral sort direction.
+        SORT_DIRECTION_UNSPECIFIED is treated as ascending.
+        For default ordering when `sort` is omitted or `field` is UNSPECIFIED,
+        see the specific List* request schema.
       enum:
         - SORT_DIRECTION_UNSPECIFIED
         - SORT_DIRECTION_ASC
         - SORT_DIRECTION_DESC

Based on learnings: keep SortDirection endpoint-neutral and document UNSPECIFIED=>ASC, while directing concrete default ordering to per-request docs.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
policy.SortDirection:
type: string
title: SortDirection
enum:
- SORT_DIRECTION_UNSPECIFIED
- SORT_DIRECTION_ASC
- SORT_DIRECTION_DESC
policy.SortDirection:
type: string
title: SortDirection
description: |-
Endpoint-neutral sort direction.
SORT_DIRECTION_UNSPECIFIED is treated as ascending.
For default ordering when `sort` is omitted or `field` is UNSPECIFIED,
see the specific List* request schema.
enum:
- SORT_DIRECTION_UNSPECIFIED
- SORT_DIRECTION_ASC
- SORT_DIRECTION_DESC
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/openapi/policy/obligations/obligations.openapi.yaml` around lines 547 -
553, Update the policy.SortDirection schema to document how
SORT_DIRECTION_UNSPECIFIED should be treated: add an endpoint-neutral
description stating that SORT_DIRECTION_UNSPECIFIED maps to ascending order
(UNSPECIFIED => ASC) and note that concrete per-endpoint default ordering should
still be documented in each request's docs; reference the enum value
SORT_DIRECTION_UNSPECIFIED and the schema name policy.SortDirection so the
change is applied to the central enum definition rather than individual
endpoints.

Comment on lines +1787 to +1790
description: |-
Optional - CONSTRAINT: max 1 item
Default ordering when omitted or when the first entry's field is UNSPECIFIED:
created_at DESC, then id ASC (tie-breaker).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Remove the unimplemented tie-breaker guarantee from ListObligationsRequest.sort docs.

Line 1790 documents then id ASC (tie-breaker), but this PR explicitly defers tie-breaker behavior. Keeping this line overstates current guarantees and can mislead clients relying on stable ordering.

Suggested doc patch
         sort:
           type: array
           items:
             $ref: '#/components/schemas/policy.obligations.ObligationsSort'
           title: sort
           maxItems: 1
           description: |-
             Optional - CONSTRAINT: max 1 item
             Default ordering when omitted or when the first entry's field is UNSPECIFIED:
-            created_at DESC, then id ASC (tie-breaker).
+            created_at DESC.

Based on learnings: concrete defaults should be documented at the request level, and those defaults must match current endpoint behavior.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
description: |-
Optional - CONSTRAINT: max 1 item
Default ordering when omitted or when the first entry's field is UNSPECIFIED:
created_at DESC, then id ASC (tie-breaker).
description: |-
Optional - CONSTRAINT: max 1 item
Default ordering when omitted or when the first entry's field is UNSPECIFIED:
created_at DESC.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/openapi/policy/obligations/obligations.openapi.yaml` around lines 1787 -
1790, The docs for ListObligationsRequest.sort currently assert a tie-breaker
"then id ASC (tie-breaker)" which is not implemented; update the description for
the ListObligationsRequest.sort field by removing the tie-breaker clause and any
wording that implies a stable secondary ordering, leaving only the documented
default ordering that matches current endpoint behavior (e.g., "created_at DESC"
or the existing default phrasing) so the OpenAPI text no longer guarantees id
ASC as a tie-breaker.

Comment on lines +1990 to +2000
func (s *ObligationsSuite) createNamedSortTestObligations(prefixes []string) []string {
namespaceID, _, _ := s.getNamespaceData(nsExampleCom)
suffix := time.Now().UnixNano()
ids := make([]string, len(prefixes))
for i, prefix := range prefixes {
name := fmt.Sprintf("%s-%d", prefix, suffix)
obl := s.createObligation(namespaceID, name, nil)
ids[i] = obl.GetId()
}
return ids
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Make the FQN sort fixtures span multiple namespaces.

This helper always creates obligations under example.com, so the FQN sort tests below collapse into name-sort tests. A regression that orders by od.name instead of the full fqns.fqn || '/obl/' || lower(od.name) expression would still pass.

As per coding guidelines, "Run go test ./... or make test and ensure all existing tests pass; add tests for new functionality".

Also applies to: 2036-2064

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@service/integration/obligations_test.go` around lines 1990 - 2000, The helper
createNamedSortTestObligations currently always uses nsExampleCom so it creates
all obligations in one namespace and masks FQN-based sorting bugs; modify
createNamedSortTestObligations to create obligations across multiple namespaces
(e.g., alternate between nsExampleCom and another test namespace obtained via
s.getNamespaceData or accept a namespace list) by fetching distinct namespaceIDs
with s.getNamespaceData (or use existing namespace fixtures) and using those
namespaceIDs when calling s.createObligation; update the related fixtures/tests
(including the similar code around lines 2036-2064) so the generated obligations
span at least two namespaces to properly exercise full FQN sorting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:db DB component comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) docs Documentation size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant