Skip to content

Conversation

@threepointone
Copy link
Contributor

Summary

  • Add comprehensive browser integration tests for AgentClient and useAgent React hook
  • Fix AgentClient.close() to immediately reject pending RPC calls instead of waiting for WebSocket close handshake timeout

Changes

New Browser Integration Tests (~50 tests)

Tests run in a real browser (Playwright/Chromium) against a miniflare worker:

AgentClient tests:

  • Connection lifecycle (identity, close, reconnect)
  • State synchronization (client→server, server→client broadcasts)
  • RPC calls (success, errors, streaming, timeouts)
  • agentFetch for HTTP requests
  • Multiple concurrent connections
  • Query parameters and basePath routing

useAgent hook tests:

Bug Fix

AgentClient.close() now immediately rejects pending RPC calls. Previously, pending calls would wait for the WebSocket close handshake to complete (~15 seconds in some environments).

Infrastructure

  • Test worker setup using wrangler unstable_dev
  • Separate tsconfig.json for browser tests
  • CORS enabled on test worker for browser requests

Test Plan

  • npm run check:test:react - 50 passed, 1 skipped
  • npm run check:test:workers - 418 passed, 6 skipped
  • No regressions in existing tests

Introduce a new React/browser integration test suite for AgentClient under packages/agents/src/react-tests. Adds comprehensive tests (connectivity, lifecycle, state sync, RPC, streaming, agentFetch, reconnection, query params, basePath routing, and multi-client scenarios). Add a global vitest setup that starts a Miniflare worker (setup.ts), test configuration helpers (test-config.ts), a tsconfig for the tests, and example useAgent tests. Update vitest config and agent test worker/wrangler settings to wire the suite up. Also add __screenshots__ to .gitignore to ignore Vitest browser screenshots.
Make AgentClient.close() immediately reject all pending RPC calls and clear pending state before closing the underlying socket. This provides immediate feedback on intentional disconnects (avoiding long WebSocket close-handshake timeouts). Also call stream.onError where applicable, add a changeset, and update the test to expect immediate rejection with the "Connection closed" error.
@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2026

🦋 Changeset detected

Latest commit: 9a6fffd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@claude

This comment was marked as resolved.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 3, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@834

commit: 9a6fffd

Extract repeated logic for rejecting and clearing pending RPC calls into a private _rejectPendingCalls(reason) method. Replace inline rejection code in the disconnect handler and close() to reduce duplication and ensure pending.stream?.onError is invoked with the provided reason (e.g., "Connection closed"). Adds a brief JSDoc for the new helper.
Add a note to AgentClient.close()'s documentation clarifying that any RPC calls made after close() will be rejected when the underlying WebSocket close event fires. This is a documentation-only change to make the rejection timing explicit and avoid confusion about calls made immediately after an intentional close.
@threepointone threepointone merged commit 2b4aecd into main Feb 3, 2026
5 checks passed
@threepointone threepointone deleted the e2e-tests branch February 3, 2026 19:09
@github-actions github-actions bot mentioned this pull request Feb 3, 2026
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