Skip to content

[ci-coach] fix: mock GitHub API in TestHealthConfigValidation to prevent pkg/cli test timeout - #55411

Merged
pelikhan merged 3 commits into
mainfrom
gh-aw/pre-created/32732743065-1
Aug 24, 2026
Merged

[ci-coach] fix: mock GitHub API in TestHealthConfigValidation to prevent pkg/cli test timeout#55411
pelikhan merged 3 commits into
mainfrom
gh-aw/pre-created/32732743065-1

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

TestHealthConfigValidation in pkg/cli/health_command_test.go previously fell through to a real GitHub API call (healthListWorkflowRuns) for its "valid days" test cases, which could take tens of seconds or hang in sandboxed/offline CI environments and caused pkg/cli test timeouts. The fix stubs this call with a mock that returns an empty result, since the test only validates the days parameter and run-listing behavior is covered elsewhere.

Change Classification

  • Type: test
  • Scope: pkg/cli
  • Breaking: No

Key Changes

File Change Impact
pkg/cli/health_command_test.go Stubs healthListWorkflowRuns with a mock returning (nil, 0, nil), restored via t.Cleanup, before running TestHealthConfigValidation cases Medium — removes real network dependency from a config-validation test, preventing CI timeouts/hangs

Impact Assessment

  • No production code or public API changes; the fix is confined to test setup.
  • Improves pkg/cli test suite reliability and speed in sandboxed/offline environments by eliminating unintended network calls.
  • Run-listing behavior itself remains covered by other dedicated tests, so test coverage is preserved.

Commits

b732a9209 fix(test): mock GitHub API in TestHealthConfigValidation to avoid CI timeout
9a1ba4b41 Initialize pull request for CI Optimization Coach
128438965 Initialize pull request for CI Optimization Coach

Generated by PR Description Updater for #55411 · copilot · auto · 43.5 AIC · ⌖ 5.26 AIC · ⊞ 7.7K ·

github-actions Bot and others added 3 commits August 24, 2026 13:27
…timeout

TestHealthConfigValidation's 'valid days' subtests called RunHealth without
mocking healthListWorkflowRuns, so each fell through to real GitHub API
pagination (up to MaxIterations batches). This took 46-48s per subtest
(141s total) in CI, pushing the whole pkg/cli unit test binary (which has
a 3m timeout in the ci-coach validation step) over budget and causing
'panic: test timed out after 3m0s'.

Stub healthListWorkflowRuns to return no runs immediately, since this test
only exercises the Days validation branch in RunHealth, not GitHub API
pagination (which is already covered by TestFetchWorkflowRunsPaginatesPastFilteredBatches
and friends).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot changed the title [WIP] [ci-coach] CI Optimization Coach: work in progress [ci-coach] fix: mock GitHub API in TestHealthConfigValidation to prevent pkg/cli test timeout Aug 24, 2026
@pelikhan
pelikhan marked this pull request as ready for review August 24, 2026 16:05
Copilot AI balanced review requested due to automatic review settings August 24, 2026 16:05
@pelikhan
pelikhan merged commit 5720175 into main Aug 24, 2026
2 checks passed
@pelikhan
pelikhan deleted the gh-aw/pre-created/32732743065-1 branch August 24, 2026 16:05
@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Ponytail Reviewer failed. Please review the logs for details.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Generated by Ponytail Reviewer for #55411

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the implementation label and has only 10 new lines of code in business logic directories (threshold is 100).

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Prevents health validation tests from making real GitHub API requests.

Changes:

  • Stubs workflow-run listing during TestHealthConfigValidation.
  • Restores the original implementation through test cleanup.
Show a summary per file
File Description
pkg/cli/health_command_test.go Adds deterministic API mocking for validation tests.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /diagnosing-bugs — approving. The fix is minimal, correctly targeted, and follows the established mocking pattern in the package.

📋 Summary

Positive Highlights

  • ✅ Root cause properly addressed: valid-days subtests no longer hit the real GitHub API
  • t.Cleanup ensures the stub is torn down even if a subtest panics — good hygiene
  • ✅ Stub is placed before the for loop, covering all subtests consistently
  • ✅ Comment clearly explains the scope boundary (days validation only; run listing covered elsewhere)
  • ✅ Pattern mirrors existing healthListWorkflowRuns usage in neighboring tests

No regression risk: error/validation subtests return before reaching the stub, so the mock is harmless there.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet46 · 13.7 AIC · ⌖ 9.72 AIC · ⊞ 7.6K
Comment /matt to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed with Impeccable audit mode (tests-only change).

The mock is correctly scoped: t.Cleanup restores the original after all sub-tests run, and the stub returns nil, 0, nil so valid-days cases do not fall through to real network access. No issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · copilot · sonnet46 · 15.2 AIC · ⌖ 8.96 AIC · ⊞ 6.2K

@github-actions

Copy link
Copy Markdown
Contributor Author

Comment Memory

reviewed_at: 2026-08-24T00:00:00Z
review_event: COMMENT
top_themes:
  - test-scoped stub avoids slow network-dependent validation path
  - no blocking correctness or maintainability regressions found in changed lines
files_reviewed:
  - pkg/cli/health_command_test.go
comment_count: 0

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · pi · gpt54 · 3.74 AIC · ⌖ 6.79 AIC · ⊞ 4.6K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verdict

Non-blocking change; this correctly removes an accidental network dependency from a unit test without introducing an obvious regression in the touched lines.

Notes

I only reviewed pkg/cli/health_command_test.go. The new package-level stub is restored with t.Cleanup, keeps the test focused on days validation, and matches the existing test seam already used elsewhere in this package. I did not find a changed-line issue that warrants blocking merge.

🔎 Code quality review by PR Code Quality Reviewer · pi · gpt54 · 3.74 AIC · ⌖ 6.79 AIC · ⊞ 4.6K
Comment /review to run again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants