uts: add ProxyManager and ProxySession for integration tests#1210
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughAdds sandbox and proxy test helpers, a polling utility, and a proxy-driven integration test for re-authentication. The build gains Ktor test dependencies and proxy path wiring. Translation guidance in ChangesProxy Integration Test Infrastructure
Sequence Diagram(s)sequenceDiagram
participant AuthReauthTest
participant ProxySession
participant RealtimeClient
participant AuthCallback
AuthReauthTest->>ProxySession: create()
AuthReauthTest->>RealtimeClient: connectThroughProxy(session)
AuthReauthTest->>RealtimeClient: set authCallback
AuthReauthTest->>RealtimeClient: connect()
RealtimeClient->>AuthCallback: token request
AuthCallback-->>RealtimeClient: signed TokenRequest
AuthReauthTest->>ProxySession: triggerAction(action=17)
ProxySession->>RealtimeClient: inject_to_client
RealtimeClient->>AuthCallback: re-auth
AuthReauthTest->>AuthReauthTest: pollUntil(callbackCount++)
AuthReauthTest->>ProxySession: getLog()
AuthReauthTest->>AuthReauthTest: assert connected, same connId, auth frame present
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
ProxyManager and ProxySession for integration test proxy…ProxyManager and ProxySession for integration tests
ce07a09 to
9322674
Compare
… lifecycle management - Introduced `ProxyManager` to manage the `uts-proxy` binary lifecycle, including downloading, verification, and process control. - Added `ProxySession` for managing proxy sessions with rules, actions, event logging, and cleanup. - Included KDoc documentation for clear usage guidelines in integration tests.
04f8bce to
eded262
Compare
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 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 @.claude/skills/uts-to-kotlin/SKILL.md:
- Line 531: The documentation example in the SKILL.md file shows AblyRest being
initialized with app.apiKey, but the actual SandboxApp object only exposes the
defaultKey property, not apiKey. Update the parameter in the AblyRest
constructor call at line 531 from app.apiKey to app.defaultKey to match both the
actual test implementation (AuthReauthTest) and the correct API exposed by the
SandboxApp object.
- Around line 573-581: Update the documentation statement for the getLog()
method to correctly state that it returns List<Event> instead of
List<Map<String, Any>>. Find and modify only the type description in the
documentation; the code example is already correct using dot notation and should
not be changed. Remove the note about Gson deserialization and .toInt() casting
since the Event data class has properly typed fields.
In
`@uts/src/test/kotlin/io/ably/lib/realtime/integration/proxy/AuthReauthTest.kt`:
- Around line 125-128: The session cleanup is not guaranteed because
session.close() is called after awaitState(...) which may throw an exception if
the wait times out. Wrap the awaitState(client, ConnectionState.closed,
10.seconds) call in its own try-catch or try-finally block to ensure that
session.close() is always invoked regardless of whether awaitState succeeds or
times out, guaranteeing the proxy session is properly cleaned up.
In `@uts/src/test/kotlin/io/ably/lib/test/helper/ProxySession.kt`:
- Line 18: The HttpClient initialization in ProxySession.kt at the client
variable declaration is missing explicit timeout configurations for request,
connect, and socket operations. Modify the HttpClient(CIO) instantiation to
include an engine configuration block that sets these three timeouts
(requestTimeoutMillis, connectTimeoutMillis, and socketTimeoutMillis) to
appropriate values to prevent indefinite hangs when the local proxy or control
endpoint becomes stalled during test execution.
In `@uts/src/test/kotlin/io/ably/lib/test/helper/SandboxApp.kt`:
- Around line 16-25: The HttpRequestRetry configuration is applying retry logic
to all HTTP methods including POST requests for app creation, which will cause
duplicate sandbox apps if a timeout occurs after the server successfully creates
the app. Modify the retryIf lambda in the install(HttpRequestRetry) block to
check the HTTP request method and only retry for idempotent requests (such as
GET, HEAD, OPTIONS). Exclude POST requests from being retried by adding a method
check that returns false when the request method is POST, ensuring that the POST
/apps endpoint is not retried on failure.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 67c0dd6c-8aad-455e-9007-71034d5268b6
📒 Files selected for processing (7)
.claude/skills/uts-to-kotlin/SKILL.mduts/build.gradle.ktsuts/src/test/kotlin/io/ably/lib/Utils.ktuts/src/test/kotlin/io/ably/lib/realtime/integration/proxy/AuthReauthTest.ktuts/src/test/kotlin/io/ably/lib/test/helper/ProxyManager.ktuts/src/test/kotlin/io/ably/lib/test/helper/ProxySession.ktuts/src/test/kotlin/io/ably/lib/test/helper/SandboxApp.kt
There was a problem hiding this comment.
Pull request overview
Adds programmable-proxy infrastructure to the UTS Kotlin integration tests, enabling tests to drive real Ably Sandbox traffic through uts-proxy with session-scoped fault injection and event logging.
Changes:
- Introduces
ProxyManagerto download/verify/cache and start a shareduts-proxyprocess for test suites. - Adds
ProxySession+ rule factory helpers + client wiring (connectThroughProxy) for session-based proxy control and log inspection. - Adds sandbox app provisioning/teardown helper (
SandboxApp) and a first proxy-based integration test (AuthReauthTest), plus a polling utility for real-time waits.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
uts/src/test/kotlin/io/ably/lib/Utils.kt |
Adds pollUntil utility for wall-clock polling in integration tests. |
uts/src/test/kotlin/io/ably/lib/test/helper/SandboxApp.kt |
Adds helper to provision/delete Ably sandbox apps for proxy suites. |
uts/src/test/kotlin/io/ably/lib/test/helper/ProxySession.kt |
Adds session API, rule factories, typed log events, and client proxy wiring. |
uts/src/test/kotlin/io/ably/lib/test/helper/ProxyManager.kt |
Adds proxy binary lifecycle management (download/verify/extract/start/health). |
uts/src/test/kotlin/io/ably/lib/realtime/integration/proxy/AuthReauthTest.kt |
Adds proxy integration test for server-initiated reauth (RTN22/RTC8a). |
uts/build.gradle.kts |
Adds Ktor client dependencies needed by the new test helpers. |
.claude/skills/uts-to-kotlin/SKILL.md |
Updates translation guidance to include proxy integration test flow and helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- ProxyManager: fix binary cache check (a present+executable binary is a hit; the prior check compared the extracted binary's hash to the *archive* checksum and never matched, re-downloading every run); add JVM shutdown hook + real stopProxy() so the child process is reaped; read-and-discard TAR entries instead of skip() (skip may return 0 before EOF); add HTTP timeouts. - ProxySession: add HTTP timeouts; accept any 2xx on control calls and surface a failed DELETE; remove unused JsonElement import; fix Event.message KDoc. - SandboxApp: retry only idempotent GETs (avoid duplicate app provisioning on a post-write timeout); add HTTP timeouts; remove unused self-import. - AuthReauthTest: drop useBinaryProtocol override (proxy inspects JSON frames); restore RTC8a auth-details assertion; close session/tokenSigner in a nested finally; add RTC8a @uts tag. - SKILL.md: app.apiKey -> app.defaultKey, deafultKey typo, getLog List<Event>. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ction state tests - Added support for using locally built `uts-proxy` binaries or distributives via system property or environment variable. - Improved `AuthReauthTest` by simplifying connection state listener and reauth verification logic. - Updated Gradle test task to propagate local proxy paths.
de0feb2 to
18f4a68
Compare
ProxyManagerto manage theuts-proxybinary lifecycle, including downloading, verification, and process control.ProxySessionfor managing proxy sessions with rules, actions, event logging, and cleanup.Summary by CodeRabbit
Release Notes
New Features
Tests
pollUntilfor real-time, wall-clock polling assertions.uts.proxy.localPathfor forked test JVMs.Documentation