Skip to content

fix: accept both proxyAgent shapes and correct proxy docs - #233

Open
seantomburke wants to merge 1 commit into
masterfrom
seantomburke/issue-186-documentation-out-date
Open

seantomburke wants to merge 1 commit into
masterfrom
seantomburke/issue-186-documentation-out-date

Conversation

@seantomburke

@seantomburke seantomburke commented Jul 30, 2026 •

Copy link
Copy Markdown
Owner

Fixes #186

The problem

The README, JSDoc, and TypeScript definitions all documented passing a bare hpagent instance:

proxyAgent: new HttpsProxyAgent({ proxy: 'http://localhost:8080' })

But got v13 expects its agent option to be an object keyed by protocol ({ http, https, http2 }). Its setter iterates the value's keys and rejects anything unrecognized, so a bare agent throws on the enumerable properties it inherits from EventEmitter:

RequestError: Unexpected agent option: _events

This happens before any request is sent — the documented proxy example could never have worked. Verified against got v13:

BARE AGENT -> RequestError: Unexpected agent option: _events
WRAPPED    -> RequestError: Bad response: 407   # reaches the proxy

The fix

The issue thread suggested docs-only, on the grounds that changing the interface would be breaking. Both are addressed here, and the code change is not breaking: the only shape that would "break" is the bare agent, which is currently 100% non-functional, so no working caller exists to break.

normalizeProxyAgent() in the constructor:

  • { http, https } / http2 objects pass through untouched
  • a bare agent is wrapped under the key matching its protocol
  • omitted stays {}, as before

Protocol detection inspects the instance (defaultPort / protocol) rather than using instanceof. hpagent is only a devDependency, so importing it at runtime would break installs for the majority of users who don't use a proxy.

Docs

README example and options table, JSDoc, and sitemapper.d.ts now show got's { http, https } form as the documented shape, with the bare agent still accepted and typed.

Testing

  • 4 new unit tests covering both shapes, the pass-through case, and the default
  • type-check.ts exercises both the wrapped and bare forms
  • Full suite green: 75 passing, plus tsc, ESLint, Prettier, CSpell
  • Manually confirmed a normalized agent reaches an actual connection attempt where a bare agent still dies in raw got, and that no-proxy fetching is unaffected (36 sites)

🤖 Generated with Claude Code

Made with Orca 🐋

Summary by CodeRabbit

  • New Features

    • Added support for configuring proxy agents separately by protocol, including HTTP and HTTPS.
    • Existing single-agent proxy configurations remain supported.
    • Updated TypeScript definitions to reflect the expanded proxy configuration options.
  • Documentation

    • Updated the Advanced Proxy example and configuration reference with the new object-based format.

The README and type definitions documented passing a bare hpagent
instance as `proxyAgent`, but got v13 expects an object keyed by
protocol. Passing a bare agent made got throw
`Unexpected agent option: _events` before any request was sent, so the
documented proxy example could never work.

Normalize `proxyAgent` in the constructor: an `{ http, https }` object
passes through untouched, and a bare agent is wrapped under the key
matching its protocol. Protocol detection inspects the instance rather
than using `instanceof`, since hpagent is only a devDependency and
importing it would break installs that don't use a proxy.

Existing usage keeps working either way, so this is not a breaking
change. Updates the README example and options table, the JSDoc, and
the TypeScript definitions, and adds tests for both shapes.

Fixes #186

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Sitemapper now supports protocol-keyed proxy agent objects and normalizes bare HTTP or HTTPS hpagent instances before passing them to got. Type declarations, documentation, runtime logic, and tests were updated accordingly.

Changes

Proxy agent support

Layer / File(s) Summary
Proxy agent contract and documentation
sitemapper.d.ts, src/assets/sitemapper.js, README.md
Proxy configuration types and documentation now describe direct hpagent instances and { http, https } objects.
Proxy agent normalization
src/assets/sitemapper.js
The constructor converts missing, keyed, and bare proxy agent inputs into the shape expected by got.
Normalization and type-check coverage
src/tests/coverage.test.ts, src/tests/type-check.ts
Tests cover default handling, HTTP/HTTPS wrapping, keyed-agent pass-through, and TypeScript usage.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Sitemapper
  participant normalizeProxyAgent
  participant hpagent
  participant got
  Sitemapper->>normalizeProxyAgent: pass proxyAgent option
  normalizeProxyAgent->>hpagent: inspect bare agent protocol
  normalizeProxyAgent-->>Sitemapper: return keyed agent object
  Sitemapper->>got: provide normalized request agent
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the proxyAgent shape support and documentation updates.
Linked Issues check ✅ Passed The PR updates docs and code to support protocol-keyed proxy agents, matching issue #186.
Out of Scope Changes check ✅ Passed The changes are limited to proxyAgent behavior, docs, types, and tests, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sitemapper.d.ts`:
- Around line 53-57: Update the proxyAgent type in sitemapper.d.ts to use false
| http2-wrapper.Agent.AgentLike instead of unknown for http2. In
src/assets/sitemapper.js and README.md, update the matching JSDoc/documentation
to describe the supported shape as { http, https? [, http2] }, preserving the
existing http and https entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c9334739-2864-4fc0-8203-0f0e470f7a2f

📥 Commits

Reviewing files that changed from the base of the PR and between 76eac0b and 127d7f0.

📒 Files selected for processing (5)
  • README.md
  • sitemapper.d.ts
  • src/assets/sitemapper.js
  • src/tests/coverage.test.ts
  • src/tests/type-check.ts

Comment thread sitemapper.d.ts
Comment on lines +53 to +57
| {
http?: HttpProxyAgent;
https?: HttpsProxyAgent;
http2?: unknown;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

For got v13, what TypeScript type is accepted for the agent.http2option, and does it use thehttp2-wrapper Agent type?

💡 Result:

In Got v13, the agent.http2 option accepts a value of type unknown | false within the TypeScript Agents type definition [1][2]. While the type is defined as unknown in the source code [1][2], the official documentation explicitly requires that the HTTP/2 agent must be an instance of http2wrapper.Agent [3][4]. It is not compatible with the standard Node.js http.Agent [5][6]. Got uses the http2-wrapper library to provide HTTP/2 support, and consequently, the agent.http2 property is specifically intended to hold an http2wrapper.Agent instance [3][1][7].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Tracked files matching sitemapper/package/readme:"
git ls-files | rg '(^|/)(sitemapper\.d\.ts|package\.json|README\.md)$|src/assets/sitemapper\.js$' || true

echo
echo "sitemapper.d.ts around proxyAgent:"
sed -n '40,70p' sitemapper.d.ts 2>/dev/null || true

echo
echo "src/assets/sitemapper.js around normalize function and usages:"
rg -n "normalize.*proxyAgent|proxyAgent|http2|httpProxy|httpsProxy|agent:" src/assets/sitemapper.js 2>/dev/null || true

echo
echo "README proxy doc:"
sed -n '200,225p' README.md 2>/dev/null || true

echo
echo "package got/http2-wrapper versions:"
node - <<'JS'
const fs = require('fs');
for (const file of ['package.json']) {
  if (!fs.existsSync(file)) continue;
  const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
  console.log(file, JSON.stringify({dependencies: pkg.dependencies, devDependencies: pkg.devDependencies}, null, 2));
}
JS

Repository: seantomburke/sitemapper

Length of output: 4117


Specify the http2 proxy-agent contract.

proxyAgent.http2?: unknown lets invalid keys/values pass through to Got. Use false | http2-wrapper.Agent.AgentLike (or an equivalent typed definition) and update the matching JSDoc/README text to cover { http, https? [, http2] }.

📍 Affects 3 files
  • sitemapper.d.ts#L53-L57 (this comment)
  • src/assets/sitemapper.js#L56-L66
  • README.md#L214-L216
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sitemapper.d.ts` around lines 53 - 57, Update the proxyAgent type in
sitemapper.d.ts to use false | http2-wrapper.Agent.AgentLike instead of unknown
for http2. In src/assets/sitemapper.js and README.md, update the matching
JSDoc/documentation to describe the supported shape as { http, https? [, http2]
}, preserving the existing http and https entries.

Source: Coding guidelines

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Note

Unit test generation is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

🤖 Coding Agent task started for unit test generation.

coderabbitai Bot added a commit that referenced this pull request Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation is out of date / incorrect.

1 participant