Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/model-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"branch": "main",
"src": "clients/ui",
"target": "upstream",
"commit": "f55b1d022bbb27784fc4f4d37c33bbe99bdf9d1f"
"commit": "222366a73be89f0401d8609ba10303e5b35bfd60"
},
"module-federation": {
"name": "modelRegistry",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,137 @@ var _ = Describe("CreateCatalogSourcePreviewHandler", func() {
Expect(actual.Data.Items).To(Equal(expected.Data.Items))

})

It("should filter by filterStatus=included", func() {
By("creating a source preview with filterStatus=included")
requestIdentity := kubernetes.RequestIdentity{
UserID: "[email protected]",
}

requestBody := struct {
Data models.CatalogSourcePreviewRequest `json:"data"`
}{
Data: models.CatalogSourcePreviewRequest{
Type: "yaml",
IncludedModels: []string{},
ExcludedModels: []string{},
Properties: map[string]interface{}{
"yaml": "models:\n - name: test-model",
},
},
}
bodyBytes, _ := json.Marshal(requestBody)

actual, rs, err := setupApiTest[CatalogSourcePreviewEnvelope](http.MethodPost, "/api/v1/settings/model_catalog/source_preview?namespace=kubeflow&filterStatus=included", bytes.NewReader(bodyBytes), kubernetesMockedStaticClientFactory, requestIdentity, "kubeflow")
Expect(err).NotTo(HaveOccurred())

By("should return only included models")
Expect(rs.StatusCode).To(Equal(http.StatusOK))
for _, item := range actual.Data.Items {
Expect(item.Included).To(BeTrue(), "All items should have Included=true when filterStatus=included")
}
})

It("should filter by filterStatus=excluded", func() {
By("creating a source preview with filterStatus=excluded")
requestIdentity := kubernetes.RequestIdentity{
UserID: "[email protected]",
}

requestBody := struct {
Data models.CatalogSourcePreviewRequest `json:"data"`
}{
Data: models.CatalogSourcePreviewRequest{
Type: "yaml",
IncludedModels: []string{},
ExcludedModels: []string{},
Properties: map[string]interface{}{
"yaml": "models:\n - name: test-model",
},
},
}
bodyBytes, _ := json.Marshal(requestBody)

actual, rs, err := setupApiTest[CatalogSourcePreviewEnvelope](http.MethodPost, "/api/v1/settings/model_catalog/source_preview?namespace=kubeflow&filterStatus=excluded", bytes.NewReader(bodyBytes), kubernetesMockedStaticClientFactory, requestIdentity, "kubeflow")
Expect(err).NotTo(HaveOccurred())

By("should return only excluded models")
Expect(rs.StatusCode).To(Equal(http.StatusOK))
for _, item := range actual.Data.Items {
Expect(item.Included).To(BeFalse(), "All items should have Included=false when filterStatus=excluded")
}
})

It("should paginate with pageSize and nextPageToken", func() {
By("creating a source preview with pageSize=5")
requestIdentity := kubernetes.RequestIdentity{
UserID: "[email protected]",
}

requestBody := struct {
Data models.CatalogSourcePreviewRequest `json:"data"`
}{
Data: models.CatalogSourcePreviewRequest{
Type: "yaml",
IncludedModels: []string{},
ExcludedModels: []string{},
Properties: map[string]interface{}{
"yaml": "models:\n - name: test-model",
},
},
}
bodyBytes, _ := json.Marshal(requestBody)

actual, rs, err := setupApiTest[CatalogSourcePreviewEnvelope](http.MethodPost, "/api/v1/settings/model_catalog/source_preview?namespace=kubeflow&pageSize=5", bytes.NewReader(bodyBytes), kubernetesMockedStaticClientFactory, requestIdentity, "kubeflow")
Expect(err).NotTo(HaveOccurred())

By("should return at most 5 items with a nextPageToken")
Expect(rs.StatusCode).To(Equal(http.StatusOK))
Expect(len(actual.Data.Items)).To(BeNumerically("<=", 5))
// If there are more items available, nextPageToken should be set
if actual.Data.Size > 5 {
Expect(actual.Data.NextPageToken).NotTo(BeEmpty(), "NextPageToken should be set when more items exist")
}
})

It("should return next page when using nextPageToken", func() {
By("creating a source preview with pageSize=5 to get first page")
requestIdentity := kubernetes.RequestIdentity{
UserID: "[email protected]",
}

requestBody := struct {
Data models.CatalogSourcePreviewRequest `json:"data"`
}{
Data: models.CatalogSourcePreviewRequest{
Type: "yaml",
IncludedModels: []string{},
ExcludedModels: []string{},
Properties: map[string]interface{}{
"yaml": "models:\n - name: test-model",
},
},
}
bodyBytes, _ := json.Marshal(requestBody)

firstPage, rs, err := setupApiTest[CatalogSourcePreviewEnvelope](http.MethodPost, "/api/v1/settings/model_catalog/source_preview?namespace=kubeflow&pageSize=5", bytes.NewReader(bodyBytes), kubernetesMockedStaticClientFactory, requestIdentity, "kubeflow")
Expect(err).NotTo(HaveOccurred())
Expect(rs.StatusCode).To(Equal(http.StatusOK))

// If there's a next page token, fetch the next page
if firstPage.Data.NextPageToken != "" {
By("fetching next page using nextPageToken")
bodyBytes2, _ := json.Marshal(requestBody)
secondPage, rs2, err2 := setupApiTest[CatalogSourcePreviewEnvelope](http.MethodPost, "/api/v1/settings/model_catalog/source_preview?namespace=kubeflow&pageSize=5&nextPageToken="+firstPage.Data.NextPageToken, bytes.NewReader(bodyBytes2), kubernetesMockedStaticClientFactory, requestIdentity, "kubeflow")
Expect(err2).NotTo(HaveOccurred())
Expect(rs2.StatusCode).To(Equal(http.StatusOK))

By("should return different items on second page")
// Verify that the items are different (not overlapping)
if len(firstPage.Data.Items) > 0 && len(secondPage.Data.Items) > 0 {
Expect(firstPage.Data.Items[0].Name).NotTo(Equal(secondPage.Data.Items[0].Name), "First item on second page should be different from first page")
}
}
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,19 @@ func (m *ModelCatalogClientMock) GetCatalogFilterOptions(client httpclient.HTTPC
}

func (m *ModelCatalogClientMock) CreateCatalogSourcePreview(client httpclient.HTTPClientInterface, sourcePreviewPayload models.CatalogSourcePreviewRequest, pageValues url.Values) (*models.CatalogSourcePreviewResult, error) {
catalogSourcePreview := CreateCatalogSourcePreviewMock()
filterStatus := pageValues.Get("filterStatus")
if filterStatus == "" {
filterStatus = "all"
}

pageSize := 20
if ps := pageValues.Get("pageSize"); ps != "" {
_, _ = fmt.Sscanf(ps, "%d", &pageSize)
}

nextPageToken := pageValues.Get("nextPageToken")

catalogSourcePreview := CreateCatalogSourcePreviewMockWithFilter(filterStatus, pageSize, nextPageToken)

return &catalogSourcePreview, nil
}
Loading
Loading