diff --git a/docs/reference/cli.md b/docs/reference/cli.md index f5f5322..6b188cc 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -184,6 +184,7 @@ The same option is available in `agent-docs.config.yml` as `options.urlPathPatte | -------------------------- | ------- | ------------------------------------------------------------------------------------ | | `--max-concurrency ` | `3` | Maximum concurrent HTTP requests | | `--request-delay ` | `200` | Delay between requests in milliseconds | +| `--request-timeout ` | `15000` | Timeout for individual HTTP requests in milliseconds | | `--canonical-origin ` | | The production base URL (origin, or origin plus a path prefix) your content links to | AFDocs enforces delays between requests and caps concurrent connections to avoid overloading your server. Adjust these if you need gentler or faster runs: @@ -196,6 +197,8 @@ afdocs check https://docs.example.com --request-delay 500 --max-concurrency 1 afdocs check https://docs.example.com --request-delay 50 --max-concurrency 10 ``` +Use `--request-timeout` when a slow server needs longer than the 15-second default to start or continue a response. A response that sends nothing for this long counts as stalled, so a very low value makes healthy pages look stalled. + Use `--canonical-origin` when your site's URLs in `sitemap.xml` and `llms.txt` don't match the base URL you're testing, such as preview deployments or localhost. It accepts either a bare origin or an origin plus a path prefix: - **Origin only** — rewrites every URL on that host, regardless of path. diff --git a/docs/reference/config-file.md b/docs/reference/config-file.md index c268225..d9b27f0 100644 --- a/docs/reference/config-file.md +++ b/docs/reference/config-file.md @@ -98,7 +98,7 @@ Override default runner options. All fields are optional: | `samplingStrategy` | `random` | `random`, `deterministic`, `curated`, or `none` | | `maxConcurrency` | `3` | Maximum concurrent HTTP requests | | `requestDelay` | `200` | Delay between requests in milliseconds | -| `requestTimeout` | `30000` | Timeout for individual HTTP requests in milliseconds | +| `requestTimeout` | `15000` | Timeout for individual HTTP requests in milliseconds (minimum 1) | | `preferredLocale` | auto-detect | Preferred locale for URL discovery (e.g. `en`, `fr`, `ja`, `zh-Hans`) | | `preferredVersion` | auto-detect | Preferred version for URL discovery (e.g. `v3`, `2.x`) | | `canonicalOrigin` | | The production base URL (origin, or origin plus a path prefix) your content links to | diff --git a/src/cli/commands/check.ts b/src/cli/commands/check.ts index c6f0c71..768fac9 100644 --- a/src/cli/commands/check.ts +++ b/src/cli/commands/check.ts @@ -31,6 +31,7 @@ export function registerCheckCommand(program: Command): void { .option('--skip-checks ', 'Comma-separated list of check IDs to skip') .option('--max-concurrency ', 'Maximum concurrent requests') .option('--request-delay ', 'Delay between requests in ms') + .option('--request-timeout ', 'Timeout for individual requests in ms (default 15000)') .option('--max-links ', 'Maximum links to test') .option( '--sampling ', @@ -199,6 +200,12 @@ export function registerCheckCommand(program: Command): void { String((opts.requestDelay as string | undefined) ?? config?.options?.requestDelay ?? 200), 10, ); + // Number, not parseInt: parseInt reads only the numeric prefix, so "1e4" + // would become a 1 ms timeout and "1.5" would slip past the integer check. + const requestTimeout = + opts.requestTimeout != null + ? Number(opts.requestTimeout) + : (config?.options?.requestTimeout ?? undefined); const maxLinksToTest = parseInt( String((opts.maxLinks as string | undefined) ?? config?.options?.maxLinksToTest ?? 50), 10, @@ -369,6 +376,7 @@ export function registerCheckCommand(program: Command): void { pass: transferPassThreshold, fail: transferFailThreshold, }, + ...(requestTimeout != null && { requestTimeout }), ...(urlPathPattern && { urlPathPattern: urlPathPattern as UrlPathPattern }), ...(preferredLocale && { preferredLocale }), ...(preferredVersion && { preferredVersion }), diff --git a/src/helpers/config.ts b/src/helpers/config.ts index 9f4a493..9adef33 100644 --- a/src/helpers/config.ts +++ b/src/helpers/config.ts @@ -67,7 +67,7 @@ function validateStringArray(value: unknown, field: string, source: string): voi const NUMERIC_OPTION_RULES: [string, { integer?: boolean; min?: number; max?: number }][] = [ ['maxConcurrency', { integer: true, min: 1, max: 100 }], ['requestDelay', { integer: true, min: 0 }], - ['requestTimeout', { integer: true, min: 0 }], + ['requestTimeout', { integer: true, min: 1 }], ['maxLinksToTest', { integer: true, min: 1 }], ['coveragePassThreshold', { integer: true, min: 0, max: 100 }], ['coverageWarnThreshold', { integer: true, min: 0, max: 100 }], diff --git a/src/validation.ts b/src/validation.ts index 55638cc..bc5641c 100644 --- a/src/validation.ts +++ b/src/validation.ts @@ -86,7 +86,7 @@ export function validateRunnerOptions(options: Partial): Validati validateNumber(options.maxConcurrency, 'maxConcurrency', { integer: true, min: 1, max: 100 }), ); pushError(validateNumber(options.requestDelay, 'requestDelay', { integer: true, min: 0 })); - pushError(validateNumber(options.requestTimeout, 'requestTimeout', { integer: true, min: 0 })); + pushError(validateNumber(options.requestTimeout, 'requestTimeout', { integer: true, min: 1 })); pushError(validateNumber(options.maxLinksToTest, 'maxLinksToTest', { integer: true, min: 1 })); if (options.thresholds) { diff --git a/test/unit/cli/check-command.test.ts b/test/unit/cli/check-command.test.ts index e9bd2e3..b9f4901 100644 --- a/test/unit/cli/check-command.test.ts +++ b/test/unit/cli/check-command.test.ts @@ -1149,6 +1149,114 @@ describe('check command config integration', () => { stdoutSpy.mockRestore(); }); + it('reads requestTimeout from config and lets --request-timeout override it', async () => { + server.use( + http.get('http://cmd-timeout.local/llms.txt', () => HttpResponse.text(VALID_LLMS_TXT)), + http.get( + 'http://cmd-timeout.local/docs/llms.txt', + () => new HttpResponse(null, { status: 404 }), + ), + ); + + const spy = vi.spyOn(validationMod, 'validateRunnerOptions'); + const stdoutSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true); + const { run } = await import('../../../src/cli/index.js'); + + // Unset, the CLI passes nothing so the runner applies DEFAULT_OPTIONS. + await run([ + 'node', + 'afdocs', + 'check', + 'http://cmd-timeout.local', + '--checks', + 'llms-txt-exists', + '--request-delay', + '0', + ]); + await new Promise((r) => setTimeout(r, 100)); + expect(spy.mock.calls.at(-1)?.[0]?.requestTimeout).toBeUndefined(); + + const configPath = resolve(CONFIG_TMP, 'agent-docs.config.yml'); + await mkdir(CONFIG_TMP, { recursive: true }); + await writeFile( + configPath, + [ + 'url: http://cmd-timeout.local', + 'checks:', + ' - llms-txt-exists', + 'options:', + ' requestDelay: 0', + ' requestTimeout: 4000', + '', + ].join('\n'), + ); + await run(['node', 'afdocs', 'check', '--config', configPath]); + await new Promise((r) => setTimeout(r, 100)); + expect(spy.mock.calls.at(-1)?.[0]?.requestTimeout).toBe(4000); + + await run(['node', 'afdocs', 'check', '--config', configPath, '--request-timeout', '7000']); + await new Promise((r) => setTimeout(r, 100)); + expect(spy.mock.calls.at(-1)?.[0]?.requestTimeout).toBe(7000); + + spy.mockRestore(); + stdoutSpy.mockRestore(); + }); + + it.each(['0', '1.5', '10s', ''])('rejects --request-timeout "%s"', async (value) => { + const stderrSpy = vi.spyOn(process.stderr, 'write').mockImplementation(() => true); + const { run } = await import('../../../src/cli/index.js'); + + await run([ + 'node', + 'afdocs', + 'check', + 'http://cmd-timeout-invalid.local', + '--checks', + 'llms-txt-exists', + '--request-timeout', + value, + ]); + await new Promise((r) => setTimeout(r, 100)); + + const errors = stderrSpy.mock.calls.map((c) => c[0]).join(''); + expect(errors).toContain('requestTimeout'); + expect(process.exitCode).toBe(1); + + stderrSpy.mockRestore(); + }); + + it('parses the whole --request-timeout value rather than its numeric prefix', async () => { + server.use( + http.get('http://cmd-timeout-exp.local/llms.txt', () => HttpResponse.text(VALID_LLMS_TXT)), + http.get( + 'http://cmd-timeout-exp.local/docs/llms.txt', + () => new HttpResponse(null, { status: 404 }), + ), + ); + + const spy = vi.spyOn(validationMod, 'validateRunnerOptions'); + const stdoutSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true); + const { run } = await import('../../../src/cli/index.js'); + + await run([ + 'node', + 'afdocs', + 'check', + 'http://cmd-timeout-exp.local', + '--checks', + 'llms-txt-exists', + '--request-delay', + '0', + '--request-timeout', + '1e4', + ]); + await new Promise((r) => setTimeout(r, 100)); + expect(spy.mock.calls.at(-1)?.[0]?.requestTimeout).toBe(10000); + + spy.mockRestore(); + stdoutSpy.mockRestore(); + }); + it('displays validation warnings on stderr', async () => { server.use( http.get('http://cmd-warn.local/llms.txt', () => HttpResponse.text(VALID_LLMS_TXT)), diff --git a/test/unit/validation.test.ts b/test/unit/validation.test.ts index d9b69f9..ed1d80e 100644 --- a/test/unit/validation.test.ts +++ b/test/unit/validation.test.ts @@ -117,6 +117,18 @@ describe('validateRunnerOptions', () => { }); }); + describe('numeric range: requestTimeout', () => { + it('accepts 1', () => { + expect(validateRunnerOptions({ requestTimeout: 1 }).valid).toBe(true); + }); + + it('rejects 0', () => { + const result = validateRunnerOptions({ requestTimeout: 0 }); + expect(result.valid).toBe(false); + expect(result.errors[0].field).toBe('requestTimeout'); + }); + }); + describe('numeric range: maxLinksToTest', () => { it('rejects 0', () => { const result = validateRunnerOptions({ maxLinksToTest: 0 });