Repository navigation
fix(cli): seed redirect probe and cache Vary key use the custom User-Agent header #2316 - #2361
Merged
Merged
Conversation
…Agent header #2316 Signed-off-by: longshore-nc9[bot] <360568931+longshore-nc9[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2316.
What changed and why
When an audit sets a custom
User-Agentheader (-H "user-agent: ..."or[crawler] headers) and[crawler] user_agentis also set, page requests send the header (applyBrowserHeaderskeeps a header the request already has). Two places still used[crawler] user_agent:resolveAuditStart(apps/cli/src/cli/start-redirect.ts) takes a newcustomHeadersinput and sendscustomUserAgent(customHeaders) || userAgent. Only the agent is read from those headers; no other custom header is passed toresolveStartRedirect. The CLI audit command passes[crawler] headersmerged with-H. The MCPaudit_websitetool now passes[crawler] user_agentand the merged headers too (it passed no agent before, so the probe sent the fallback agent).buildCacheRequestContextinpackages/crawler/src/core/crawler.tsnow takes the custom headers that page's request carries (customHeadersFor(url), so none off the header scope) and keysuser-agenton theirUser-Agentwhen present, elseconfig.userAgent. Both the lookup and the stored page'srequestHeadersuse it.Docs: the
-Hparagraph indocs/configuration/crawler.mdxnow names the start-URL redirect probe among the requests that use the custom agent, and says it wins overuser_agent.Tests
apps/cli/tests/cli/audit-seed-probe-custom-user-agent-2316.test.ts(new, e2e): the real CLI in a subprocess,[crawler] user_agentset plus a secret custom header in TOML,-H "<User-Agent|user-agent|USER-AGENT>: custom". A local server is the subprocess's HTTP proxy, 403s every other agent and redirectsexample.comtowww.example.com. Asserts exit 0, the first request is the apex probe with the custom agent and no secret header, the base URL iswww.example.com,/aboutwas crawled, and crawl requests do carry the secret. Without the fix: exit 3 on all three casings.apps/cli/tests/cli/start-redirect.test.ts(new case):resolveAuditStarthands the resolver the custom agent overuserAgentin every casing, the configured agent without one, and never the other header value. Fails without the fix.apps/cli/tests/mcp/audit-website-start-redirect.test.ts(new case): MCPaudit_websiteprobe sends the custom agent over[crawler] user_agent, no other custom header. Fails without the fix.packages/crawler/tests/cache-vary-custom-user-agent-2316.test.ts(new): crawl with an injected cache store and fetcher; the lookup context and the saved page'srequestHeadershold the agent the request actually put on the wire (computed with the realapplyBrowserHeaders), for all three casings; without a custom agent, the configured one.fetchis spied to refuse any network call. The first case fails without the fix.Expected values come from the agent the request actually sent (recorded by the server or by
applyBrowserHeaders), not from the code's own selection helper.Commands run
bun run scripts/test-suites.ts --run crawler: 1188 pass, 0 failbun run scripts/test-suites.ts --run cli: 4673 pass, 14 skip, 0 failbun run scripts/test-suites.ts --check: OKapps/cli:bun run format:check,bun run lint,bun run typecheck: cleanpackages/crawler:bun run typecheckclean;oxfmt --checkandoxlinton the changed files (the only lint findings incrawler.tsare pre-existingno-loop-funcon untouched lines)bun run docs:check: passbun scripts/changelog.ts check: OKNot in scope, noted for review: the reachability check before the crawl and the crawl's own
config.userAgent(robots and other probes without custom headers) still prefer[crawler] user_agentover a custom header (user_agent || customUserAgent(headers)incontrollers/audit.tsandcontrollers/crawl.ts). The e2e audit succeeds regardless, since a 403 there does not stop the audit.Docs: docs/configuration/crawler.mdx. Skill: none.