Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ The same option is available in `agent-docs.config.yml` as `options.urlPathPatte
| -------------------------- | ------- | ------------------------------------------------------------------------------------ |
| `--max-concurrency <n>` | `3` | Maximum concurrent HTTP requests |
| `--request-delay <ms>` | `200` | Delay between requests in milliseconds |
| `--request-timeout <ms>` | `15000` | Timeout for individual HTTP requests in milliseconds |
| `--canonical-origin <url>` | | 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:
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
8 changes: 8 additions & 0 deletions src/cli/commands/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function registerCheckCommand(program: Command): void {
.option('--skip-checks <checks>', 'Comma-separated list of check IDs to skip')
.option('--max-concurrency <n>', 'Maximum concurrent requests')
.option('--request-delay <ms>', 'Delay between requests in ms')
.option('--request-timeout <ms>', 'Timeout for individual requests in ms (default 15000)')
.option('--max-links <n>', 'Maximum links to test')
.option(
'--sampling <strategy>',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 }),
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }],
Expand Down
2 changes: 1 addition & 1 deletion src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function validateRunnerOptions(options: Partial<RunnerOptions>): 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) {
Expand Down
108 changes: 108 additions & 0 deletions test/unit/cli/check-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
12 changes: 12 additions & 0 deletions test/unit/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down