-
Notifications
You must be signed in to change notification settings - Fork 219
Add retry logic for transient GitHub API errors in live integration test #14799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
351b81b
aa795d3
b097c7d
546aba9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,27 @@ | ||
| // @ts-check | ||
| import { describe, it, expect, beforeAll } from "vitest"; | ||
| import { describe, it, expect, beforeAll, vi } from "vitest"; | ||
| const path = require("path"); | ||
| const fs = require("fs"); | ||
| const { computeFrontmatterHash, createGitHubFileReader } = require("./frontmatter_hash_pure.cjs"); | ||
| const { withRetry, isTransientError } = require("./error_recovery.cjs"); | ||
|
|
||
| // Retry configuration for live API tests | ||
| const LIVE_API_RETRY_CONFIG = { | ||
| maxRetries: 3, | ||
| initialDelayMs: 1000, | ||
| shouldRetry: isTransientError, | ||
| }; | ||
|
|
||
| /** | ||
| * Wraps a file reader function with retry logic for transient GitHub API errors | ||
| * @param {Function} fileReader - The original file reader function | ||
| * @returns {Function} File reader with retry logic | ||
| */ | ||
| function createRetryableFileReader(fileReader) { | ||
| return async function (filePath) { | ||
| return withRetry(async () => fileReader(filePath), LIVE_API_RETRY_CONFIG, `fetch file ${filePath}`); | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Tests for frontmatter hash computation using GitHub's API to fetch real workflows. | ||
|
|
@@ -13,6 +32,14 @@ describe("frontmatter_hash with GitHub API", () => { | |
| let mockGitHub; | ||
|
|
||
| beforeAll(() => { | ||
| // Mock @actions/core for retry logging in test environment | ||
| global.core = { | ||
| info: vi.fn((...args) => console.log(...args)), | ||
| warning: vi.fn((...args) => console.warn(...args)), | ||
|
Comment on lines
34
to
+38
|
||
| error: vi.fn((...args) => console.error(...args)), | ||
| debug: vi.fn((...args) => console.log(...args)), | ||
| }; | ||
|
|
||
| // Create a mock GitHub API client for testing | ||
| // In real scenarios, this would be replaced with @actions/github | ||
| mockGitHub = { | ||
|
|
@@ -354,7 +381,10 @@ describe("frontmatter_hash with GitHub API", () => { | |
| const ref = "main"; | ||
|
|
||
| // Create file reader with real GitHub API | ||
| const fileReader = createGitHubFileReader(octokit, owner, repo, ref); | ||
| const baseFileReader = createGitHubFileReader(octokit, owner, repo, ref); | ||
|
|
||
| // Wrap with retry logic to handle transient GitHub API errors | ||
| const fileReader = createRetryableFileReader(baseFileReader); | ||
|
|
||
| // Test with a real public agentic workflow | ||
| const workflowPath = ".github/workflows/audit-workflows.md"; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LIVE_API_RETRY_CONFIG.initialDelayMsis likely not the actual delay before the first retry with the currentwithRetryimplementation:withRetrymultipliesdelayat the end of the first failure, so the first retry sleepsinitialDelayMs * backoffMultiplier(default 2). If the intent is a 1s first backoff, either passbackoffMultiplier: 1/ adjustinitialDelayMs, or changewithRetryto increase the delay after sleeping soinitialDelayMsis honored for the first retry.