Fix checkLink failures by adding User-Agent headers and timeout#413
Fix checkLink failures by adding User-Agent headers and timeout#413
Conversation
WalkthroughChanges extend .gitignore to ignore PNG test artifacts and enhance error handling in checkLink.js by introducing request configuration with timeout and redirect limits, plus improved error messages that differentiate between HTTP response errors and unresolvable URLs. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…or messages Co-authored-by: hawkeyexl <5209367+hawkeyexl@users.noreply.github.com>
Co-authored-by: hawkeyexl <5209367+hawkeyexl@users.noreply.github.com>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/tests/checkLink.js (1)
55-64: Consider consistent quote style.The
requestConfigobject uses single quotes for string values, while the rest of the file consistently uses double quotes (see lines 36, 42, 82, etc.). For consistency, consider updating to double quotes.🔎 Proposed fix for quote consistency
- const requestConfig = { - headers: { - 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', - 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', - 'Accept-Language': 'en-US,en;q=0.9' - }, - timeout: 10000, // 10 second timeout - maxRedirects: 5 - }; + const requestConfig = { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.9" + }, + timeout: 10000, // 10 second timeout + maxRedirects: 5 + };
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.gitignoresrc/tests/checkLink.js
🧰 Additional context used
📓 Path-based instructions (2)
src/tests/*.js
📄 CodeRabbit inference engine (AGENTS.md)
src/tests/*.js: Create new step type handlers as async functions exported fromsrc/tests/[actionName].js
Step handlers must return object with{ status: "PASS"|"FAIL"|"WARNING", description: string, outputs: {} }
Validate step schema before resolving to object and setting defaults in new step handlers
Always handle driver cleanup in try/finally blocks in browser automation code
Set step variables viastep.variables = { MY_VAR: "$$response.body.token" }to store data as environment variables
UsesetViewportSize()to calculate inner dimensions rather than directly setting window size in browser automation
Mark unsafe steps withstep.unsafe = trueand requireconfig.allowUnsafeSteps = trueto execute
Files:
src/tests/checkLink.js
src/**/*.js
📄 CodeRabbit inference engine (AGENTS.md)
src/**/*.js: Uselog(config, level, message)for all logging, where level = "debug"|"info"|"warning"|"error"
UsegetAvailableApps()to detect installed browsers instead of hardcoding browser paths
Files:
src/tests/checkLink.js
🧠 Learnings (2)
📚 Learning: 2025-12-03T00:21:10.834Z
Learnt from: CR
Repo: doc-detective/core PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T00:21:10.834Z
Learning: Applies to src/tests/httpRequest.js : Extract request/response examples from OpenAPI spec and use AJV for schema validation in HTTP request handling
Applied to files:
src/tests/checkLink.js
📚 Learning: 2025-12-03T00:21:10.834Z
Learnt from: CR
Repo: doc-detective/core PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T00:21:10.834Z
Learning: Applies to src/tests/*.js : Step handlers must return object with `{ status: "PASS"|"FAIL"|"WARNING", description: string, outputs: {} }`
Applied to files:
src/tests/checkLink.js
🧬 Code graph analysis (1)
src/tests/checkLink.js (3)
src/utils.js (1)
axios(4-4)src/tests/httpRequest.js (3)
axios(2-2)step(680-708)result(12-12)src/tests.js (1)
axios(5-5)
🔇 Additional comments (4)
.gitignore (1)
115-115: LGTM!The addition of
test/artifacts/*.pngis appropriate for preventing test artifacts from being committed while remaining consistent with existing artifact patterns.src/tests/checkLink.js (3)
66-73: LGTM!The axios request correctly applies the
requestConfigwith headers, timeout, and redirect limits. The implementation properly handles both success and error cases, returning a normalized response structure.
76-84: Excellent improvement in error handling.The enhanced error messages now differentiate between HTTP response errors (e.g., 403, 401) and network/resolution failures (e.g., ENOTFOUND, timeouts), providing much clearer feedback for debugging. The logic correctly accesses the axios error structure and is consistent with the existing status code comparison pattern.
55-67: The axios configuration is correct. Axios 1.13.2 fully supportsheaders,timeout, andmaxRedirectsoptions as implemented.
|
📝 Documentation updates detected! New suggestion: Document checkLink HTTP status code errors in troubleshooting |
|
📝 Documentation updates detected! Updated existing suggestion: Document checkLink HTTP status code errors in troubleshooting |
Investigated 80 checkLink test failures from user report. Root cause: modern websites (Wikipedia, JFrog, etc.) reject HTTP requests without User-Agent headers, returning 400/403 errors.
Changes
Added browser-like headers to axios requests:
Added timeout protection: 10s timeout, 5 max redirects
Improved error messages: Show actual HTTP status codes (401, 403) instead of generic "Invalid or unresolvable URL"
Updated .gitignore: Exclude PNG test artifacts
Before/After
Before:
After:
Impact
No breaking changes. Fully backward compatible.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Summary by CodeRabbit
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.