(t *testing.T)
| 379 | } |
| 380 | |
| 381 | func TestCollectWorkflowRunDiagnostics(t *testing.T) { |
| 382 | // Given diagnostic commands that expose each Actions registration boundary |
| 383 | var actionsAPIArgs []string |
| 384 | exec := func(name string, args ...string) (string, string, error) { |
| 385 | switch { |
| 386 | case name == "git" && args[0] == "rev-parse": |
| 387 | return "abc123\n", "", nil |
| 388 | case name == "git" && args[0] == "remote": |
| 389 | return "https://github.com/example/repo.git\n", "", nil |
| 390 | case name == "git" && args[0] == "ls-remote": |
| 391 | return "abc123\trefs/heads/feature\n", "", nil |
| 392 | case name == "git" && args[0] == "ls-tree": |
| 393 | return ".github/workflows/workflow.yml\n", "", nil |
| 394 | case name == "gh" && args[0] == "run": |
| 395 | return `[{"databaseId":42,"headBranch":"other"}]`, "", nil |
| 396 | case name == "gh" && args[1] == "repos/{owner}/{repo}/commits/abc123/check-suites": |
| 397 | return `{"id":7,"app":"actions"}`, "", nil |
| 398 | case name == "gh" && args[1] == "repos/{owner}/{repo}/actions/runs": |
| 399 | actionsAPIArgs = append([]string(nil), args...) |
| 400 | return "x-github-request-id: REQUEST-ID\n", "", nil |
| 401 | default: |
| 402 | return "", "", fmt.Errorf("unexpected command: %s %s", name, strings.Join(args, " ")) |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | // When collecting diagnostics for a run that did not register |
| 407 | diagnostics := collectWorkflowRunDiagnostics(exec, []string{"--branch", "feature", "--event", "push"}) |
| 408 | |
| 409 | // Then the snapshot includes evidence from every boundary and the request ID |
| 410 | assert.Contains(t, diagnostics, "run filters: --branch feature --event push") |
| 411 | assert.Contains(t, diagnostics, "repository:\nhttps://github.com/example/repo.git") |
| 412 | assert.Contains(t, diagnostics, "local commit:\nabc123") |
| 413 | assert.Contains(t, diagnostics, "remote branch:\nabc123\trefs/heads/feature") |
| 414 | assert.Contains(t, diagnostics, "workflow files:\n.github/workflows/workflow.yml") |
| 415 | assert.Contains(t, diagnostics, "recent workflow runs:\n"+`[{"databaseId":42,"headBranch":"other"}]`) |
| 416 | assert.Contains(t, diagnostics, "commit check suites:\n"+`{"id":7,"app":"actions"}`) |
| 417 | assert.Contains(t, diagnostics, "Actions API response headers:\nx-github-request-id: REQUEST-ID") |
| 418 | assert.Equal(t, []string{ |
| 419 | "api", "repos/{owner}/{repo}/actions/runs", |
| 420 | "--method", "GET", |
| 421 | "-f", "per_page=1", |
| 422 | "--include", |
| 423 | "--silent", |
| 424 | "-f", "branch=feature", |
| 425 | "-f", "event=push", |
| 426 | "-f", "head_sha=abc123", |
| 427 | }, actionsAPIArgs) |
| 428 | } |
| 429 | |
| 430 | func TestCollectWorkflowRunDiagnosticsIncludesCommandFailures(t *testing.T) { |
| 431 | // Given diagnostic commands that fail while gathering supplementary evidence |
nothing calls this directly
no test coverage detected