From 010f836df56ff678682c389cf8edd718553ea9be Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Fri, 13 Mar 2026 11:02:09 +0100 Subject: [PATCH] Improve the task logic. --- cmd/pm/tasks/issueReviewCleanup.go | 52 +++++++++++------------------- internal/utils/check/expect.go | 7 ++-- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/cmd/pm/tasks/issueReviewCleanup.go b/cmd/pm/tasks/issueReviewCleanup.go index 79aa453..c12027b 100644 --- a/cmd/pm/tasks/issueReviewCleanup.go +++ b/cmd/pm/tasks/issueReviewCleanup.go @@ -2,7 +2,6 @@ package tasks import ( "context" - "fmt" "github.com/LazyBachelor/LazyPM/internal/models" "github.com/LazyBachelor/LazyPM/internal/utils/check" @@ -103,47 +102,32 @@ func (t *IssueReviewCleanupTask) Validate(ctx context.Context) ValidationFeedbac issues, err := FetchIssues(ctx, t.app, t.setupIssue) if err != nil { - return expect.Fail("Could not fetch issues: " + err.Error()).Complete() + return expect.Fatal("Could not fetch issues") } - // Step 1 cannot be verified (opening/viewing leaves no trace) — not shown in results - - // Step 2: Add comment to 2 issues - var issueIDs []string + // Count the amount of comments on each issue + commentCount := map[string]int{} for _, issue := range issues { - issueIDs = append(issueIDs, issue.ID) + comments, _ := t.app.Issues.GetIssueComments(ctx, issue.ID) + commentCount[issue.ID] = len(comments) } - issuesWithComments := 0 - if len(issueIDs) > 0 { - counts, err := t.app.Issues.GetCommentCounts(ctx, issueIDs) - if err != nil { - expect.Fail("Step 2: Could not verify comments: " + err.Error()) - } else { - for _, count := range counts { - if count >= 1 { - issuesWithComments++ - } - } - if issuesWithComments >= 2 { - expect.Pass(fmt.Sprintf("Step 2: Added comments to at least 2 issues (%d issues have comments)", issuesWithComments)) - } else { - expect.Fail(fmt.Sprintf("Step 2: Add comments to at least 2 issues (found %d with comments)", issuesWithComments)) - } + + // Add a count if there are comment on a issue + commentsInIssues := 0 + for _, count := range commentCount { + if count > 0 { + commentsInIssues++ } - } else { - expect.Fail("Step 2: Add comments to at least 2 issues (no issues to check)") } - // Step 3: Delete the cleanup task issue — we verify it's gone (Step 4 is same outcome; we can't verify they "looked") - setupStillExists, _ := t.app.Issues.GetIssue(ctx, t.setupIssue.ID) - deletedCleanupIssue := setupStillExists == nil + expect.Equal(commentsInIssues, 2, "Comments on issues") - if len(issues) == 5 && deletedCleanupIssue { - expect.Pass("Step 3: Deleted the cleanup task issue — it no longer appears in the list") - } else if len(issues) < 5 { - expect.Fail(fmt.Sprintf("Step 3: Delete only the cleanup task issue — you deleted a project issue (expected 5, got %d)", len(issues))) - } else if !deletedCleanupIssue { - expect.Fail("Step 3: Delete the cleanup task issue (\"Issue Review and Cleanup Task\") from the list") + // Fetching the setup issue as as FetchIssues only updates the setup issue if it exists, + // we can check if it was deleted by seeing if it can be fetched again + if t.setupIssue, err = t.app.Issues.GetIssue(ctx, t.setupIssue.ID); t.setupIssue != nil { + expect.Fail("Setup issue still exists") + } else { + expect.Pass("Setup issue deleted") } return expect.Complete() diff --git a/internal/utils/check/expect.go b/internal/utils/check/expect.go index dbeaa29..256c6e6 100644 --- a/internal/utils/check/expect.go +++ b/internal/utils/check/expect.go @@ -90,9 +90,10 @@ func (e *Expector) Equal(val, expected any, message string) *Expector { } func (e *Expector) Assert(condition bool, message string) *Expector { - check := NewCheck(message, condition) - e.Checks = append(e.Checks, check) - return e + if !condition { + return e.Fail(message) + } + return e.Pass(message + " is correct") } func (e *Expector) Nil(value any, message string) *Expector {