From d3a4ed5dde576af5aaa414b5b8ccdd848f880879 Mon Sep 17 00:00:00 2001 From: dacharyc Date: Sun, 29 Nov 2026 15:11:12 -0500 Subject: [PATCH 1/2] fix: honor options.requestTimeout in afdocs check (#169) The check command built its runner options field by field and never read requestTimeout from the config file, so the CLI always used the 15000 ms default while the vitest helpers honored the configured value. Forward the config value, add a --request-timeout flag that overrides it, and reject 0 in both validators, since a zero timeout aborts every request. Correct the documented default from 30000 to 15000. --- docs/reference/cli.md | 3 ++ docs/reference/config-file.md | 2 +- src/cli/commands/check.ts | 6 +++ src/helpers/config.ts | 2 +- src/validation.ts | 2 +- test/unit/cli/check-command.test.ts | 76 +++++++++++++++++++++++++++++ test/unit/validation.test.ts | 12 +++++ 7 files changed, 100 insertions(+), 3 deletions(-) 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..b474909 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,10 @@ export function registerCheckCommand(program: Command): void { String((opts.requestDelay as string | undefined) ?? config?.options?.requestDelay ?? 200), 10, ); + const requestTimeout = + opts.requestTimeout != null + ? parseInt(String(opts.requestTimeout), 10) + : (config?.options?.requestTimeout ?? undefined); const maxLinksToTest = parseInt( String((opts.maxLinks as string | undefined) ?? config?.options?.maxLinksToTest ?? 50), 10, @@ -369,6 +374,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..94ae8af 100644 --- a/test/unit/cli/check-command.test.ts +++ b/test/unit/cli/check-command.test.ts @@ -1149,6 +1149,82 @@ 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('rejects --request-timeout 0', async () => { + 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-zero.local', + '--checks', + 'llms-txt-exists', + '--request-timeout', + '0', + ]); + 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('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 }); From f8296f5dc280f9b64d36be80f7a9e42faf2a6dec Mon Sep 17 00:00:00 2001 From: dacharyc Date: Sun, 29 Nov 2026 15:21:16 -0500 Subject: [PATCH 2/2] fix: parse the whole --request-timeout value parseInt reads only the numeric prefix, so "1e4" became a 1 ms timeout and "1.5" passed the integer check. Convert with Number so the existing validator sees the real value and rejects anything that is not an integer. --- src/cli/commands/check.ts | 4 ++- test/unit/cli/check-command.test.ts | 38 ++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/cli/commands/check.ts b/src/cli/commands/check.ts index b474909..768fac9 100644 --- a/src/cli/commands/check.ts +++ b/src/cli/commands/check.ts @@ -200,9 +200,11 @@ 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 - ? parseInt(String(opts.requestTimeout), 10) + ? Number(opts.requestTimeout) : (config?.options?.requestTimeout ?? undefined); const maxLinksToTest = parseInt( String((opts.maxLinks as string | undefined) ?? config?.options?.maxLinksToTest ?? 50), diff --git a/test/unit/cli/check-command.test.ts b/test/unit/cli/check-command.test.ts index 94ae8af..b9f4901 100644 --- a/test/unit/cli/check-command.test.ts +++ b/test/unit/cli/check-command.test.ts @@ -1202,7 +1202,7 @@ describe('check command config integration', () => { stdoutSpy.mockRestore(); }); - it('rejects --request-timeout 0', async () => { + 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'); @@ -1210,11 +1210,11 @@ describe('check command config integration', () => { 'node', 'afdocs', 'check', - 'http://cmd-timeout-zero.local', + 'http://cmd-timeout-invalid.local', '--checks', 'llms-txt-exists', '--request-timeout', - '0', + value, ]); await new Promise((r) => setTimeout(r, 100)); @@ -1225,6 +1225,38 @@ describe('check command config integration', () => { 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)),