scorecard: restore comment, rename uploadSARIFResult, add error path tests#816
scorecard: restore comment, rename uploadSARIFResult, add error path tests#816jeffmendoza merged 2 commits intomainfrom
Conversation
0e624ed to
80dfb96
Compare
- Rename uploadSARIFResult back to uploadSARIF — the old function no longer exists, so the "Result" suffix is redundant - Add TestCheckUnknownCheckSkipped: verifies that unknown checks are filtered out and remaining valid checks still execute - Add TestCheckPerCheckErrorSkipped: verifies that checks with CheckResult.Error are skipped while other checks still produce results Addresses review feedback from #807. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Stephen Augustus <foo@auggie.dev>
80dfb96 to
551eaf4
Compare
There was a problem hiding this comment.
Pull request overview
Follow-up to the Scorecard check-execution consolidation, restoring rationale around per-check error skipping, simplifying the SARIF upload helper name, and extending tests + OpenSpec documentation to reflect the new control flow.
Changes:
- Restores the explanatory comment for skipping per-check Scorecard errors (continue vs abort).
- Renames
uploadSARIFResultback touploadSARIFand updates call sites/tests accordingly. - Adds two new tests for “unknown check” and “per-check error” skip paths; archives the related OpenSpec change set with updated status.
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/policies/scorecard/scorecard_test.go | Adds new tests for unknown-check and per-check-error skip behavior. |
| pkg/policies/scorecard/scorecard.go | Restores comment explaining why per-check errors are logged + skipped; updates SARIF upload call to renamed helper. |
| pkg/policies/scorecard/sarif_test.go | Renames SARIF upload tests to match uploadSARIF and updates invocations. |
| pkg/policies/scorecard/sarif.go | Renames uploadSARIFResult to uploadSARIF and updates the doc comment. |
| openspec/changes/archive/2026-04-14-consolidate-check-execution/tasks.md | Updates archived task checklist/status to match final implementation and follow-up PR. |
| openspec/changes/archive/2026-04-14-consolidate-check-execution/proposal.md | Adds archived proposal describing the consolidation rationale and behavioral changes. |
| openspec/changes/archive/2026-04-14-consolidate-check-execution/design.md | Adds archived design notes for validation, batching, and error-handling changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| s := NewScorecard() | ||
| res, err := s.Check(context.Background(), github.NewClient(nil), "", "") | ||
| if err != nil { | ||
| t.Fatalf("Unexpected error: %v", err) | ||
| } | ||
| if !res.Pass { | ||
| t.Error("Expected pass — unknown check should be skipped, valid check should still run") | ||
| } |
There was a problem hiding this comment.
This test doesn’t actually prove the valid check ran after encountering an unknown check. If the implementation regresses to break (so no checks run), pass will still default to true and the assertion will still pass. To make this cover the intended behavior, assert an observable effect from the valid check (e.g., have the valid check return a failing score below the threshold and expect res.Pass == false, or explicitly assert that scRun was called / called with only the valid check).
| func TestCheckUnknownCheckSkipped(t *testing.T) { | ||
| configFetchConfig = func(_ context.Context, _ *github.Client, _, _, _ string, | ||
| ol config.ConfigLevel, out interface{}, | ||
| ) error { | ||
| if ol == config.OrgLevel { | ||
| oc := out.(*OrgConfig) | ||
| *oc = OrgConfig{ | ||
| Checks: []string{"nonexistent-check", "test"}, | ||
| Threshold: 8, | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
| configIsEnabled = func(_ context.Context, _ config.OrgOptConfig, _, | ||
| _ config.RepoOptConfig, _ *github.Client, _, _ string, | ||
| ) (bool, error) { | ||
| return true, nil | ||
| } | ||
| scorecardGet = func(_ context.Context, _ string, _ bool, | ||
| _ http.RoundTripper, | ||
| ) (*scorecard.ScClient, error) { | ||
| return &scorecard.ScClient{}, nil | ||
| } | ||
| checksAllChecks = checker.CheckNameToFnMap{"test": {}} | ||
| scRun = func(_ context.Context, _ clients.Repo, _ ...sc.Option) (sc.Result, error) { | ||
| return sc.Result{ | ||
| Checks: []checker.CheckResult{{Name: "test", Score: 10}}, | ||
| }, nil | ||
| } |
There was a problem hiding this comment.
This test mutates package-level function vars (configFetchConfig/configIsEnabled/scorecardGet/checksAllChecks/scRun) without restoring them, which can leak state into other tests and make failures order-dependent. Consider capturing the original values at the start of the test and restoring them with t.Cleanup (as done in sarif_test.go).
| s := NewScorecard() | ||
| res, err := s.Check(context.Background(), github.NewClient(nil), "", "") | ||
| if err != nil { | ||
| t.Fatalf("Unexpected error: %v", err) | ||
| } | ||
| if !res.Pass { | ||
| t.Error("Expected pass — errored check should be skipped, passing check should still count") | ||
| } |
There was a problem hiding this comment.
This test also doesn’t validate the intended “skip errored check but still let other checks affect pass/notify” behavior. If the code regresses to break on the errored check, the passing check would be skipped but pass would remain true, so this assertion would still pass. Make the non-errored check produce a failing score below threshold (and expect res.Pass == false), or otherwise assert that later check results were processed.
| func TestCheckPerCheckErrorSkipped(t *testing.T) { | ||
| configFetchConfig = func(_ context.Context, _ *github.Client, _, _, _ string, | ||
| ol config.ConfigLevel, out interface{}, | ||
| ) error { | ||
| if ol == config.OrgLevel { | ||
| oc := out.(*OrgConfig) | ||
| *oc = OrgConfig{ | ||
| Checks: []string{"erroring", "passing"}, | ||
| Threshold: 8, | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
| configIsEnabled = func(_ context.Context, _ config.OrgOptConfig, _, | ||
| _ config.RepoOptConfig, _ *github.Client, _, _ string, | ||
| ) (bool, error) { | ||
| return true, nil | ||
| } | ||
| scorecardGet = func(_ context.Context, _ string, _ bool, | ||
| _ http.RoundTripper, | ||
| ) (*scorecard.ScClient, error) { | ||
| return &scorecard.ScClient{}, nil | ||
| } | ||
| checksAllChecks = checker.CheckNameToFnMap{"erroring": {}, "passing": {}} | ||
| scRun = func(_ context.Context, _ clients.Repo, _ ...sc.Option) (sc.Result, error) { | ||
| return sc.Result{ | ||
| Checks: []checker.CheckResult{ | ||
| {Name: "erroring", Error: fmt.Errorf("unsupported check")}, | ||
| {Name: "passing", Score: 10}, | ||
| }, | ||
| }, nil | ||
| } |
There was a problem hiding this comment.
Like the previous test, this one overrides package-level function variables without restoring them. Please use t.Cleanup to restore the original values so test behavior doesn’t depend on execution order and future tests aren’t affected.
|
@copilot — Address the review comments you've left in this PR. |
Agent-Logs-Url: https://github.com/ossf/allstar/sessions/db2b87bf-95ff-4444-8743-d64b627d1244 Co-authored-by: justaugustus <567897+justaugustus@users.noreply.github.com>
Done in c01fcff. Fixed both new tests:
|
Summary
Follow-up to #807. Addresses remaining review feedback:
Restore error handling comment — the original comment explaining why per-check errors are skipped (rather than aborting) was lost during the consolidation refactor. Restored to
scorecard.go.Rename
uploadSARIFResultback touploadSARIF— the old function no longer exists after the consolidation, so the "Result" suffix is redundant.Add tests for new error handling paths — the consolidation changed error handling from break-on-error to skip-and-continue, but the new paths were untested:
TestCheckUnknownCheckSkipped: verifies unknown checks are filtered out and remaining valid checks still execute and produce resultsTestCheckPerCheckErrorSkipped: verifies checks withCheckResult.Errorare skipped while other checks still affect pass/notifyArchive OpenSpec proposal — move
openspec/changes/consolidate-check-execution/toopenspec/changes/archive/2026-04-14-consolidate-check-execution/with updated task completion status.Test plan
go vetcleango buildclean🤖 Generated with Claude Code