Repository navigation
feat: paginate the organization unpriced AI models endpoint - #32170
Conversation
3496ae0 to
985e9b4
Compare
985e9b4 to
6c56899
Compare
6c56899 to
177604e
Compare
177604e to
7c23f24
Compare
7c23f24 to
158c358
Compare
158c358 to
a633cc3
Compare
a633cc3 to
b33ae60
Compare
b33ae60 to
64005e8
Compare
64005e8 to
62994d7
Compare
62994d7 to
a7b4c56
Compare
pawbana
left a comment
There was a problem hiding this comment.
LGTM, one small non important nit.
| }, got) | ||
| }) | ||
|
|
||
| t.Run("Pagination", func(t *testing.T) { |
There was a problem hiding this comment.
nit+: This is tested in querier so I don't think it must be tested here but on API layer I think there is no test that shows limit working. Here there only 2 models with offset 1, non working limit in theory could still pass as there is no 3rd model that could be potentially returned.
Another test without offset and limit 1 would cover it.
| Models: slice.List(rows, db2sdk.UnpricedAIModel), | ||
| } | ||
| if len(rows) > 0 { | ||
| resp.Count = rows[0].Count |
There was a problem hiding this comment.
When offset >= number of rows no rows are returned and Count will not be set.
Running the query agains with limit:1 offset: 0 would get this count.
There was a problem hiding this comment.
Good point. I had it like that at first, but removed it because other paginated endpoints (users, members, groups) return a count of 0 for a page past the end. However, some AI spend endpoints already keep the count on every page, so I added it back to stay consistent with them.
| }, got) | ||
| }) | ||
|
|
||
| t.Run("Validation", func(t *testing.T) { |
There was a problem hiding this comment.
nit: test case for invalid limit value could be added, I think limit <= 0 / limit > 100
There was a problem hiding this comment.
I have a draft PR that adds tests for the shared pagination helper: #32168. That way, the limit validation is tested once there, and the endpoints don't need duplicate tests. Will update it to include this endpoint once this is merged.
mollymaefraser
left a comment
There was a problem hiding this comment.
Few nits and one Q/suggestion 👍
| { | ||
| name: "UnknownParameter", | ||
| params: map[string]string{"limit": "10"}, | ||
| params: map[string]string{"model": "model-without-price"}, |
There was a problem hiding this comment.
Nit: now that the endpoint accepts limit and offset, could we add a case for a limit that's out of range, e.g. {"limit": "101"} (or "0"), expecting Query parameters have invalid values.?
parseOrganizationAISpendPage is shared and tested elsewhere, so this is a cheap guard. If the endpoint is later wired to a different parser or loses its maximum, this test would catch it. (Same idea as @pawbana's nit above, so one change covers both.)
There was a problem hiding this comment.
I have a draft PR that adds tests for the shared pagination helper: #32168. That way the limit validation is tested once there, and the endpoints don't need duplicate tests. Will update it to include this endpoint once this is merged.
mollymaefraser
left a comment
There was a problem hiding this comment.
LGTM!! Thanks for addressing the comments 🚀
Description
Paginates the experimental
GET /api/experimental/organizations/{organization}/ai/model-prices/unpricedendpoint from #31753. The list is keyed by the requested model, which clients set, so it has no upper bound.Changes
GetUnpricedAIModelstakeslimit_optandoffset_opt, and each row carries thecountof every model. A zero limit returns every model, so the unpriced models notification is unchanged.limitandoffsetwithparseOrganizationAISpendPage(default 10, maximum 100), as the other AI spend endpoints do.countis now the number of models over every page.ExperimentalClient.OrganizationUnpricedAIModelstakes anOrganizationAISpendPage.Related to AIGOV-730
Note
Generated by Coder Agents on behalf of @ssncferreira.