-
Notifications
You must be signed in to change notification settings - Fork 107
feat(cli): improve evaluation reasoning output using existing fields #6417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1124d27
feat(cli): improve evaluation reasoning output using existing fields
sachin9058 3ec7c8c
refactor(cli): simplify evaluation details rendering and apply review…
sachin9058 51ace98
chore: tidy go modules
sachin9058 c84e306
chore: trigger CI rerun
sachin9058 32803af
refactor(cli): address review feedback and simplify details rendering
sachin9058 0d42254
test(cli): add golden tests for artifact get and enable test-friendly…
sachin9058 25edf52
feat(cli): add artifact get command tests and align with GetCLIClient…
sachin9058 2108f49
chore: trigger CI
sachin9058 f99a75f
test(cli): remove JSON golden tests for artifact get due to unstable …
sachin9058 9d29cb4
refactor(cli): address review feedback and stabilize CLI tests
sachin9058 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2026 The Minder Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package artifact | ||
|
|
||
| // JSON output is not tested because protojson formatting is not stable across environments. | ||
| // This can cause flaky tests due to spacing differences. | ||
| // See maintainer discussion in PR #6417. | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "go.uber.org/mock/gomock" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
|
|
||
| "github.com/mindersec/minder/internal/util/cli" | ||
| minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1" | ||
| mockv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1/mock" | ||
| ) | ||
|
|
||
| //nolint:paralleltest // Cannot run in parallel because it swaps global Viper/Stdout state | ||
| func TestArtifactGetCommand(t *testing.T) { | ||
| setupSuccess := func(t *testing.T, ctrl *gomock.Controller) context.Context { | ||
| t.Helper() | ||
|
|
||
| artifactClient := mockv1.NewMockArtifactServiceClient(ctrl) | ||
| profileClient := mockv1.NewMockProfileServiceClient(ctrl) | ||
|
|
||
| artifactResp := &minderv1.GetArtifactByIdResponse{} | ||
| cli.LoadFixture(t, "mock_artifact_get.json", artifactResp) | ||
|
|
||
| artifactClient.EXPECT(). | ||
| GetArtifactById(gomock.Any(), gomock.Any()). | ||
| Return(artifactResp, nil). | ||
| Times(1) | ||
|
|
||
| listProfilesResp := &minderv1.ListProfilesResponse{} | ||
| cli.LoadFixture(t, "mock_list_profiles.json", listProfilesResp) | ||
| profileClient.EXPECT(). | ||
| ListProfiles(gomock.Any(), gomock.Any()). | ||
| Return(listProfilesResp, nil). | ||
| Times(1) | ||
|
|
||
| statusResp := &minderv1.GetProfileStatusByNameResponse{} | ||
| cli.LoadFixture(t, "mock_profile_status.json", statusResp) | ||
| profileClient.EXPECT(). | ||
| GetProfileStatusByName(gomock.Any(), gomock.Any()). | ||
| Return(statusResp, nil). | ||
| Times(1) | ||
|
|
||
| ctx := cli.WithRPCClient[minderv1.ArtifactServiceClient](context.Background(), artifactClient) | ||
| ctx = cli.WithRPCClient[minderv1.ProfileServiceClient](ctx, profileClient) | ||
| return ctx | ||
| } | ||
|
|
||
| tests := []cli.CmdTestCase{ | ||
| { | ||
| Name: "get artifact - table output", | ||
| Args: []string{"artifact", "get", "-i", "111", "-o", "table"}, | ||
| MockSetup: setupSuccess, | ||
| GoldenFileName: "artifact_get.table", | ||
| }, | ||
| { | ||
| Name: "get artifact - yaml output", | ||
| Args: []string{"artifact", "get", "-i", "111", "-o", "yaml"}, | ||
| MockSetup: setupSuccess, | ||
| GoldenFileName: "artifact_get.yaml", | ||
| }, | ||
| { | ||
| Name: "server error handling", | ||
| Args: []string{"artifact", "get", "-i", "111"}, | ||
| MockSetup: func(t *testing.T, ctrl *gomock.Controller) context.Context { | ||
| t.Helper() | ||
| artifactClient := mockv1.NewMockArtifactServiceClient(ctrl) | ||
| profileClient := mockv1.NewMockProfileServiceClient(ctrl) | ||
|
|
||
| artifactClient.EXPECT(). | ||
| GetArtifactById(gomock.Any(), gomock.Any()). | ||
| Return(nil, status.Error(codes.NotFound, "artifact not found")). | ||
| Times(1) | ||
|
|
||
| ctx := cli.WithRPCClient[minderv1.ArtifactServiceClient](context.Background(), artifactClient) | ||
| ctx = cli.WithRPCClient[minderv1.ProfileServiceClient](ctx, profileClient) | ||
| return ctx | ||
| }, | ||
| ExpectedError: "artifact not found", | ||
| }, | ||
| } | ||
|
|
||
| cli.RunCmdTests(t, tests, ArtifactCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "artifact": { | ||
| "artifactPk": "111", | ||
| "name": "artifact-1", | ||
| "type": "image", | ||
| "owner": "owner-1", | ||
| "repository": "org/repo", | ||
| "visibility": "public", | ||
| "createdAt": "2024-01-02T15:04:05Z" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "profiles": [ | ||
| { | ||
| "name": "artifact-security-baseline" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "profile_status": { | ||
| "profile_id": "artifact-security-baseline", | ||
| "profile_name": "artifact-security-baseline", | ||
| "profile_status": "failure", | ||
| "last_updated": "2024-01-01T00:00:00Z" | ||
| }, | ||
| "rule_evaluation_status": [ | ||
| { | ||
| "profile_id": "artifact-security-baseline", | ||
| "rule_id": "artifact-attestation-slsa", | ||
| "entity": "artifact", | ||
| "status": "failure", | ||
| "last_updated": "2024-01-01T00:00:00Z", | ||
| "entity_info": { | ||
| "name": "owner-1/artifact-1" | ||
| }, | ||
| "details": "artifact attestation is disabled for this image", | ||
| "guidance": "enable artifact attestations before release", | ||
| "remediation_details": "rebuild the artifact with attestations enabled", | ||
| "remediation_url": "https://example.com/remediate/artifact-111", | ||
| "rule_type_name": "artifact_attestation_slsa", | ||
| "rule_description_name": "Require artifact attestation", | ||
| "alert": { | ||
| "status": "on", | ||
| "details": "artifact attestation alert is active", | ||
| "url": "https://example.com/alerts/artifact-111" | ||
| } | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| ID │ TYPE │ OWNER │ NAME │ REPOSITORY │ VISIBILITY │ CREATION DATE | ||
| ───────┼────────┼──────────┼──────────────┼──────────────┼──────────────┼─────────────────────────── | ||
| 111 │ image │ owner-1 │ artifact-1 │ org/repo │ public │ 2024-01-02T15:04:05Z | ||
| PROFILE │ RULE │ RESULT │ DETAILS | ||
| ────────────────────────────┼──────────────────────────────┼─────────┼────────────────────────────── | ||
| artifact-security-baseline │ Require artifact attestation │ failure │ Alert: artifact attestation | ||
| │ │ │ alert is active URL: | ||
| │ │ │ https://example.com/alerts/a | ||
| │ │ │ rtifact-111 Remediation: | ||
| │ │ │ rebuild the artifact with | ||
| │ │ │ attestations enabled URL: | ||
| │ │ │ https://example.com/remediat | ||
| │ │ │ e/artifact-111 Details: | ||
| │ │ │ artifact attestation is | ||
| │ │ │ disabled for this image | ||
| │ │ │ Guidance: enable artifact | ||
| │ │ │ attestations before release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| artifact: | ||
| artifactPk: "111" | ||
| createdAt: "2024-01-02T15:04:05Z" | ||
| name: artifact-1 | ||
| owner: owner-1 | ||
| repository: org/repo | ||
| type: image | ||
| visibility: public | ||
|
|
||
| - alert: | ||
| details: artifact attestation alert is active | ||
| status: "on" | ||
| url: https://example.com/alerts/artifact-111 | ||
| details: artifact attestation is disabled for this image | ||
| entity: artifact | ||
| entityInfo: | ||
| name: owner-1/artifact-1 | ||
| guidance: enable artifact attestations before release | ||
| lastUpdated: "2024-01-01T00:00:00Z" | ||
| profileId: artifact-security-baseline | ||
| remediationDetails: rebuild the artifact with attestations enabled | ||
| remediationUrl: https://example.com/remediate/artifact-111 | ||
| ruleDescriptionName: Require artifact attestation | ||
| ruleId: artifact-attestation-slsa | ||
| ruleTypeName: artifact_attestation_slsa | ||
| status: failure | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.