Skip to content

fix(audit): misleading "failed with 0 error(s)" message and wrong workflow_name for pre-activation failures#21692

Merged
pelikhan merged 3 commits intomainfrom
copilot/cli-tools-test-fix-audit-messages
Mar 19, 2026
Merged

fix(audit): misleading "failed with 0 error(s)" message and wrong workflow_name for pre-activation failures#21692
pelikhan merged 3 commits intomainfrom
copilot/cli-tools-test-fix-audit-messages

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

For runs that fail before agent activation (cancelled, infrastructure-level failures, no downloadable artifacts), the audit tool produced two user-facing bugs: a logically contradictory "Workflow failed with 0 error(s)" finding, and workflow_name showing the file path (.github/workflows/daily-cli-tools-tester.lock.yml) instead of the display name (Daily CLI Tools Exploratory Tester).

Changes

Fix 1 — Contradictory failure message (audit_report_analysis.go)

When ErrorCount == 0 and no error objects are available (i.e. no logs to analyze), the description now reads:

"Workflow 'X' failed before agent activation — no error logs were available to analyze"

The existing "failed with N error(s)" format is kept when error data is present.

Fix 2 — Wrong workflow_name in overview (audit.go)

The GitHub REST API sporadically returns the workflow file path as .name for quickly-cancelled runs. Added resolveWorkflowDisplayName, called in fetchWorkflowRunMetadata when WorkflowName starts with .github/:

  1. Uses findGitRoot() to resolve the repo-relative workflow path to an absolute path, then reads and parses the local YAML file using goccy/go-yaml — works correctly from any subdirectory within the repository.
  2. Falls back to GET /actions/workflows/{filename} for remote-repo (--repo) usage.

A companion extractWorkflowNameFromYAML helper unmarshals the YAML into a typed struct using goccy/go-yaml, correctly handling inline comments, quoted scalars, and all valid YAML forms.

Fix 3 — Non-existent run ID error message (audit.go)

Broadened the 404 detection heuristics to cover more gh CLI version variants: adds "not found", "Could not resolve", and err.Error() checks alongside the existing "Not Found" / "404" string matches, so users get "workflow run N not found" instead of the opaque "failed to fetch run metadata".

Tests added

  • TestGenerateFindings/failed_workflow_with_zero_errors_and_no_error_details_uses_pre-activation_message — verifies the new message and that "0 error(s)" is never emitted for zero-error failures
  • TestExtractWorkflowNameFromYAML — 8 cases (quoted names, inline comments, indented keys, empty content)
  • TestResolveWorkflowDisplayNameFromLocalFile — validates YAML name extraction directly

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

…e for pre-activation failures

- Fix contradictory "failed with 0 error(s)" message: when ErrorCount==0 and no
  errors are available, emit "failed before agent activation — no error logs were
  available to analyze" instead
- Fix wrong workflow_name: when the GitHub API returns the file path as the run
  name, resolve the actual display name by reading the local workflow YAML file
  first, then falling back to the GitHub API /actions/workflows/{filename}
- Improve 404 detection in fetchWorkflowRunMetadata to handle more error variants
  (adds "not found", "Could not resolve", err.Error() checks)
- Add tests: pre-activation failure message, extractWorkflowNameFromYAML (7 cases),
  and resolveWorkflowDisplayNameFromLocalFile

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] [cli-tools-test] Fix misleading audit messages and workflow name format fix(audit): misleading "failed with 0 error(s)" message and wrong workflow_name for pre-activation failures Mar 19, 2026
Copilot AI requested a review from pelikhan March 19, 2026 01:49
@pelikhan pelikhan marked this pull request as ready for review March 19, 2026 02:19
Copilot AI review requested due to automatic review settings March 19, 2026 02:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes two user-facing issues in the audit command when a workflow run fails before agent activation: an incorrect “failed with 0 error(s)” finding and workflow names showing as workflow file paths instead of display names.

Changes:

  • Update failure finding text to explicitly indicate pre-activation failures when no logs/errors are available.
  • Resolve workflow display name when GitHub returns a workflow file path as the run name (local YAML read first, then GitHub API fallback).
  • Improve 404 detection to emit a clearer “workflow run N not found” error across more gh CLI variants.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/cli/audit.go Improves run-not-found messaging and adds workflow display-name resolution logic.
pkg/cli/audit_report_analysis.go Adjusts failure finding description to avoid contradictory “0 error(s)” message when no logs exist.
pkg/cli/audit_report_test.go Adds coverage for the new pre-activation failure finding message.
pkg/cli/audit_test.go Adds unit tests for YAML workflow name extraction and local-file display-name resolution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

pkg/cli/audit.go Outdated
Comment on lines +696 to +701
// Try local file first (works when audit is run from inside a cloned repository).
if content, err := os.ReadFile(workflowPath); err == nil {
if name := extractWorkflowNameFromYAML(string(content)); name != "" {
return name
}
}
pkg/cli/audit.go Outdated
Comment on lines +727 to +744
// extractWorkflowNameFromYAML scans the top-level YAML content for a 'name:' key and
// returns its value. Only the first occurrence at the root level is considered.
// This intentionally avoids importing a full YAML parser to keep the dependency
// footprint minimal.
func extractWorkflowNameFromYAML(content string) string {
for line := range strings.SplitSeq(content, "\n") {
trimmed := strings.TrimSpace(line)
// Skip blank lines and YAML comments.
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
continue
}
// A top-level key starts at column 0 (no leading whitespace).
if !strings.HasPrefix(line, " ") && !strings.HasPrefix(line, "\t") {
if after, ok := strings.CutPrefix(trimmed, "name:"); ok {
name := strings.TrimSpace(after)
// Strip optional surrounding quotes (single or double).
name = strings.Trim(name, "\"'")
return name
@pelikhan
Copy link
Contributor

@copilot review comments.

Use helpers to resolve workflow file from workflow name

… resolution

Address review feedback:
- resolveWorkflowDisplayName now uses findGitRoot() so the repo-relative
  workflowPath is resolved to an absolute path, working from any subdirectory
- extractWorkflowNameFromYAML replaced manual string scanning with goccy/go-yaml
  struct unmarshaling, correctly handling inline comments and all YAML scalar forms
- Tests updated to use []byte signature and add inline-comment case

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 19, 2026

@copilot review comments.

Use helpers to resolve workflow file from workflow name

Done in ab3397d. The changes address both reviewer suggestions:

  1. resolveWorkflowDisplayName now calls findGitRoot() to resolve the repo-relative workflowPath (e.g. .github/workflows/foo.lock.yml) to an absolute path before attempting local file read — works correctly from any subdirectory within the repo.

  2. extractWorkflowNameFromYAML now uses goccy/go-yaml struct unmarshaling (struct { Name string \yaml:"name"` }`) instead of manual string scanning, correctly handling inline comments, quoted scalars, and all valid YAML forms.

@pelikhan pelikhan merged commit 56547c3 into main Mar 19, 2026
82 checks passed
@pelikhan pelikhan deleted the copilot/cli-tools-test-fix-audit-messages branch March 19, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cli-tools-test] audit: misleading "failed with 0 error(s)" and wrong workflow_name for runs that fail before agent activation

3 participants