The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(ci): add retry wrapper for markdown link checks
Steven Enamakel0785b882b6cf
diff --git a/scripts/__tests__/retry-markdown-links.test.mjs b/scripts/__tests__/retry-markdown-links.test.mjsnew file mode 100644index 0000000000..13a4afa6c4--- /dev/null+++ b/scripts/__tests__/retry-markdown-links.test.mjs@@ -0,0 +1,43 @@+import assert from 'node:assert/strict';+import test from 'node:test';+import { retryServiceUnavailable, serviceUnavailableUrls } from '../ci/retry-markdown-links.mjs';++const unavailable = '* [503] <https://example.test/docs#anchor> | Service Unavailable\n';+const missing = '* [404] <https://example.test/missing> | Not Found\n';++function checker(results) {+ const calls = [];+ return { calls, check: async (urls) => { calls.push(urls); return results[calls.length - 1]; } };+}++test('transient 503 recovers after more than one retry and preserves fragments', async () => {+ const { calls, check } = checker([{ status: 2, report: unavailable }, { status: 0, report: '' }]);+ const waits = [];+ assert.equal(await retryServiceUnavailable({ initialReport: unavailable, check, wait: async (ms) => waits.push(ms) }), 0);+ assert.deepEqual(calls, [['https://example.test/docs#anchor'], ['https://example.test/docs#anchor']]);+ assert.deepEqual(waits, [5000, 10000]);+});++test('persistent 503 remains a failure after bounded retries', async () => {+ const { calls, check } = checker(Array.from({ length: 3 }, () => ({ status: 2, report: unavailable })));+ assert.equal(await retryServiceUnavailable({ initialReport: unavailable, check, wait: async () => {} }), 2);+ assert.equal(calls.length, 3);+});++test('404 or mixed failures are not retried', async () => {+ for (const initialReport of [missing, unavailable + missing, '', '* [TIMEOUT] <https://example.test/> | Timeout\n']) {+ const { calls, check } = checker([]);+ assert.equal(await retryServiceUnavailable({ initialReport, check, wait: async () => {} }), 1);+ assert.equal(calls.length, 0);+ }+});++test('a permanent error discovered on retry remains a failure', async () => {+ const { calls, check } = checker([{ status: 2, report: missing }]);+ assert.equal(await retryServiceUnavailable({ initialReport: unavailable, check, wait: async () => {} }), 2);+ assert.equal(calls.length, 1);+});++test('retry inputs deduplicate repeated failures without dropping URL fragments', () => {+ assert.deepEqual(serviceUnavailableUrls(unavailable.repeat(3)), ['https://example.test/docs#anchor']);+});diff --git a/scripts/ci/retry-markdown-links.mjs b/scripts/ci/retry-markdown-links.mjsnew file mode 100644index 0000000000..fe0ae89521--- /dev/null+++ b/scripts/ci/retry-markdown-links.mjs@@ -0,0 +1,44 @@+import { readFileSync, writeFileSync } from 'node:fs';+import { dirname, join, resolve } from 'node:path';+import { spawnSync } from 'node:child_process';+import { setTimeout as delay } from 'node:timers/promises';+import { fileURLToPath } from 'node:url';++/** Extract URLs only when every reported link failure is an HTTP 503. */+export function serviceUnavailableUrls(report) {+ const failures = [...report.matchAll(/^\*\s+\[([^\]]+)\]\s+<([^>]+)>/gm)];+ if (!failures.length || failures.some(([, status]) => status !== '503')) return null;+ return [...new Set(failures.map(([, , url]) => url))];+}++/** Recheck a failed sweep without accepting unsuccessful HTTP responses. */+export async function retryServiceUnavailable({ initialReport, check, wait = delay }) {+ const urls = serviceUnavailableUrls(initialReport);+ if (!urls) return 1;+ await wait(5000);+ return (await check(urls)).status;+}++async function main(reportPath, binary) {+ const initialReport = readFileSync(reportPath, 'utf8');+ let attempt = 0;+ const status = await retryServiceUnavailable({+ initialReport,+ check(urls) {+ const input = join(dirname(reportPath), `retry-${++attempt}.md`);+ writeFileSync(input, urls.map((url) => `- <${url}>`).join('\n') + '\n');+ // These URLs passed the full sweep's inclusion/exclusion rules already.+ // Keep fragment checking on the retry, and require actual successful HTTP.+ const run = spawnSync(binary, [+ '--no-progress', '--max-concurrency', '4', '--include-fragments',+ '--format', 'markdown', '--output', reportPath, input,+ ], { stdio: 'inherit', timeout: 90000 });+ return { status: run.status ?? 1, report: readFileSync(reportPath, 'utf8') };+ },+ });+ process.exitCode = status;+}++if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {+ await main(process.argv[2], process.argv[3]);+}