Skip to content

feat: add mock-upstream mode for fetch/http/nextjs e2e suites#125

Merged
jy-tan merged 4 commits intomainfrom
e2e-mock-server
Feb 26, 2026
Merged

feat: add mock-upstream mode for fetch/http/nextjs e2e suites#125
jy-tan merged 4 commits intomainfrom
e2e-mock-server

Conversation

@jy-tan
Copy link
Contributor

@jy-tan jy-tan commented Feb 26, 2026

Summary

Introduce a deterministic mock-upstream path for Node SDK HTTP-style e2e suites, and refactor fetch/http/nextjs e2e apps to route external calls through shared helpers with env-based override support.

Changes

  • Add shared e2e HTTP helper at src/instrumentation/libraries/e2e-common/external-http.cjs to centralize USE_MOCK_EXTERNALS and MOCK_SERVER_BASE_URL URL rewriting, external request timeout defaults, and shared Node http/https request helpers used by HTTP tests
  • Add local mock service at src/instrumentation/libraries/e2e-common/mock-upstream/mock-server.js with deterministic endpoints used by current fetch/http e2e flows.
  • Wire mock-upstream into fetch/http e2e compose configs (CJS + ESM), including env defaults:
    • USE_MOCK_EXTERNALS=${USE_MOCK_EXTERNALS:-1}
    • MOCK_SERVER_BASE_URL=${MOCK_SERVER_BASE_URL:-http://mock-upstream:8081}
    • EXTERNAL_HTTP_TIMEOUT_MS=${EXTERNAL_HTTP_TIMEOUT_MS:-3000}
  • Update fetch, http, nextjs e2e servers (CJS + ESM) to use shared upstream URL + timeout helpers for all outbound fetch calls.
  • Keep override behavior explicit so real-upstream testing remains easy by setting USE_MOCK_EXTERNALS=0.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 10 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/instrumentation/libraries/fetch/e2e-tests/cjs-fetch/src/index.ts">

<violation number="1" location="src/instrumentation/libraries/fetch/e2e-tests/cjs-fetch/src/index.ts:17">
P2: `withExternalTimeout()` depends on `AbortSignal.timeout`, which only exists starting in Node 16.14+. Since the project supports node >=16.0.0, these new fetch calls can crash on Node 16.0–16.13. Add a fallback when `AbortSignal.timeout` is unavailable or guard for older Node versions.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 5 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/instrumentation/libraries/nextjs/e2e-tests/esm-nextjs/src/app/api/weather/route.ts">

<violation number="1" location="src/instrumentation/libraries/nextjs/e2e-tests/esm-nextjs/src/app/api/weather/route.ts:51">
P2: The GET error handler now returns a 200 response with fallback data, which hides upstream failures from clients. Preserve the error status so callers can detect failures.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@jy-tan jy-tan changed the title feat: add mock-upstream mode for fetch/http e2e suites feat: add mock-upstream mode for fetch/http/nextjs e2e suites Feb 26, 2026
@jy-tan jy-tan merged commit cae3367 into main Feb 26, 2026
15 checks passed
@jy-tan jy-tan deleted the e2e-mock-server branch February 26, 2026 18:51
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.

1 participant