fix(artifact): abort delete when project selection fails - #1104
mantrapatel05 wants to merge 2 commits into
Conversation
…ve delete Signed-off-by: Mantra Patel <patelmantra551@gmail.com>
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="cmd/harbor/root/artifact/delete.go">
<violation number="1" location="cmd/harbor/root/artifact/delete.go:41">
P2: Custom agent: **Enforce Pragmatic Test Coverage**
Add a regression test for the interactive `GetProjectNameFromUser()` error path and assert that `RunE` returns the wrapped error without attempting artifact deletion. This changed failure behavior prevents a destructive API call and is not covered by the existing tests.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| projectName, err = prompt.GetProjectNameFromUser() | ||
| if err != nil { | ||
| log.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err)) | ||
| return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err)) |
There was a problem hiding this comment.
P2: Custom agent: Enforce Pragmatic Test Coverage
Add a regression test for the interactive GetProjectNameFromUser() error path and assert that RunE returns the wrapped error without attempting artifact deletion. This changed failure behavior prevents a destructive API call and is not covered by the existing tests.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At cmd/harbor/root/artifact/delete.go, line 41:
<comment>Add a regression test for the interactive `GetProjectNameFromUser()` error path and assert that `RunE` returns the wrapped error without attempting artifact deletion. This changed failure behavior prevents a destructive API call and is not covered by the existing tests.</comment>
<file context>
@@ -39,7 +38,7 @@ func DeleteArtifactCommand() *cobra.Command {
projectName, err = prompt.GetProjectNameFromUser()
if err != nil {
- log.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err))
+ return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err))
}
repoName = prompt.GetRepoNameFromUser(projectName)
</file context>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1104 +/- ##
=========================================
- Coverage 10.99% 9.83% -1.16%
=========================================
Files 173 326 +153
Lines 8671 16529 +7858
=========================================
+ Hits 953 1626 +673
- Misses 7612 14763 +7151
- Partials 106 140 +34 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: Mantra Patel <patelmantra551@gmail.com>
|
codecov/patch is at 100%. The codecov/project failure compares against a base report (60ad0bd) that's 223 commits behind main, so the drop looks inherited from main rather than from this PR. The branch is already rebased on current upstream/main. Happy to adjust if you'd like anything changed. |
Fixes #1102
In interactive mode,
harbor artifact deletepreviously logged errors fromGetProjectNameFromUser()and continued with an empty project name. This could lead to an API call with empty values and produce a confusing error.The command now returns the project selection error immediately, matching the behavior of
artifact label deleteandrepository delete. The unusedlogrusimport was also removed.Type of Change
Changes
logrusimport.Tested
go testroot.