Skip to content

test(router): add dynamic agent test#1246

Merged
chimurai merged 1 commit into
masterfrom
test-router-dynamic-agent
May 24, 2026
Merged

test(router): add dynamic agent test#1246
chimurai merged 1 commit into
masterfrom
test-router-dynamic-agent

Conversation

@chimurai

@chimurai chimurai commented May 24, 2026

Copy link
Copy Markdown
Owner

closes: #1123

Summary by CodeRabbit

  • Tests
    • Expanded end-to-end test coverage for the proxy router to validate dynamic HTTPS agent selection per request and confirm requests are routed to the correct targets. These tests assert that each agent is used as expected, improving confidence in proxy routing and connection behavior.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b428e727-dd40-4688-825b-f1103aedf53f

📥 Commits

Reviewing files that changed from the base of the PR and between b452059 and c2d7367.

📒 Files selected for processing (1)
  • test/e2e/router.spec.ts

📝 Walkthrough

Walkthrough

Added Node.js agent imports and a new E2E test that verifies the router dynamically assigns different HTTPS agents per request; the test spies on each agent's createConnection, routes requests to separate targets based on URL, and asserts each agent was used exactly once.

Changes

Dynamic Agent Selection E2E Test

Layer / File(s) Summary
E2E test for per-request agent selection
test/e2e/router.spec.ts
Imports HttpAgent, HttpsAgent, and vitest vi. Adds a test that creates two HTTPS agents with spies on createConnection, configures the router to set options.agent conditionally by req.url (/api/a → agent A, otherwise agent B), and verifies proxied responses and that each agent's createConnection was called once.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ProxyRouter
  participant HttpsAgentA
  participant HttpsAgentB
  participant TargetA
  participant TargetB

  Client->>ProxyRouter: GET /api/a
  ProxyRouter->>HttpsAgentA: set options.agent = agentA
  ProxyRouter->>TargetA: proxy request (agentA)
  HttpsAgentA->>TargetA: createConnection()
  TargetA-->>Client: response A

  Client->>ProxyRouter: GET /api/b
  ProxyRouter->>HttpsAgentB: set options.agent = agentB
  ProxyRouter->>TargetB: proxy request (agentB)
  HttpsAgentB->>TargetB: createConnection()
  TargetB-->>Client: response B
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through agent gates,
Each request picks its destined fate,
Two agents wait, connections spy,
Targets answer as requests fly,
Hooray — per-request paths verified!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds a test for dynamic agent selection but does not implement the requested callback hook feature from issue #1123. Implement the callback hook mechanism in middleware options to allow dynamic adjustment of proxy options per request, as requested in issue #1123.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a test for dynamic agent behavior in the router.
Out of Scope Changes check ✅ Passed The changes are focused on E2E testing of dynamic agent selection and are within the scope of validating the router's capability.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test-router-dynamic-agent

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 and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented May 24, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/http-proxy-middleware@1246

commit: c2d7367

Comment thread test/e2e/router.spec.ts Fixed
Comment thread test/e2e/router.spec.ts Fixed
@coveralls

coveralls commented May 24, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 94.656%. remained the same — test-router-dynamic-agent into master

@chimurai chimurai force-pushed the test-router-dynamic-agent branch from b452059 to c2d7367 Compare May 24, 2026 16:51
@chimurai chimurai merged commit 3ab96d8 into master May 24, 2026
26 checks passed
@chimurai chimurai deleted the test-router-dynamic-agent branch May 24, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide possibility to influence proxy options during req processing

3 participants