fix(welcome): include bearer token in core RPC test-connection probe#1301
Conversation
Welcome.tsx's "Test Connection" button was firing a raw fetch with no Authorization header, so the embedded core's auth middleware rejected every probe with 401 — surfaced to the user as a misleading "Connection failed" even when the URL was correct. Resolve the per-process bearer token via the existing `getCoreRpcToken` helper (now exported from coreRpcClient) and attach `Authorization: Bearer <token>` to the ping. Behavior matches every other core RPC caller in the app.
|
Caution Review failedFailed to post review comments 📝 WalkthroughWalkthroughAdded exported function ChangesToken-Based RPC Connection Test
Sequence Diagram(s)sequenceDiagram
participant Welcome as Welcome (UI)
participant Service as coreRpcClient.testCoreRpcConnection
participant Token as getCoreRpcToken
participant Core as Core RPC Server
Welcome->>Service: testCoreRpcConnection(normalizedURL)
Service->>Token: getCoreRpcToken()
Token-->>Service: token or null
Service->>Core: POST JSON-RPC openhuman.ping (Authorization: Bearer <token>?)
Core-->>Service: HTTP Response
Service-->>Welcome: Response returned
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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. Comment |
There was a problem hiding this comment.
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 `@app/src/pages/Welcome.tsx`:
- Around line 68-80: The component is assembling auth headers and performing a
raw RPC POST (using getCoreRpcToken, headers, fetch to normalized with method
'openhuman.ping'), which belongs in the coreRpcClient service; move this logic
into a new method on app/src/services/coreRpcClient (e.g., pingCore or
probeCore) that: (1) obtains the token via getCoreRpcToken, (2) builds the
headers including Authorization when present, (3) performs the JSON-RPC POST to
the provided URL (the normalized value), and (4) returns a normalized
success/failure result; then replace the direct fetch call in Welcome.tsx with a
call to that new coreRpcClient method.
🪄 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: 0ad7a13e-d559-482f-a1c8-67f7e1b4b077
📒 Files selected for processing (2)
app/src/pages/Welcome.tsxapp/src/services/coreRpcClient.ts
CodeRabbit feedback (tinyhumansai#1301): the inline bearer-token + JSON-RPC envelope assembly in `Welcome.tsx`'s `handleTestConnection` violates the project guideline that RPC client calls live in `services/coreRpcClient`, not in components. Move the probe behind a new `testCoreRpcConnection(url)` helper and revert the public export of `getCoreRpcToken` (now only the new helper needs it).
Adds 4 unit tests against `testCoreRpcConnection` in `coreRpcClient.test.ts` so the diff-coverage gate (≥ 80%) is satisfied for the new helper: - POSTs an `openhuman.ping` JSON-RPC envelope to the supplied URL - omits `Authorization` header when no bearer token is available (non-Tauri environment / Vitest) - attaches `Authorization: Bearer <token>` when the Tauri bearer token resolves - returns the raw `Response` so callers can inspect status/ok (Welcome.tsx checks `response.ok || response.status === 405`) Pattern follows the existing `callCoreRpc` tests in the same file — mocks `@tauri-apps/api/core` for `invoke` / `isTauri` and stubs `globalThis.fetch`.
|
@coderabbitai full review Refactor commit Test commit Both fixes are landed; could you re-review and update the review state? Currently still showing CHANGES_REQUESTED from the original review which is stale. |
|
Tip For best results, initiate chat on the files or code changes.
I'll kick off a fresh full review now to clear the stale [full_review] |
|
@coderabbitai review The earlier |
✅ Actions performedFull review triggered. |
The 14:46 review state is sticky despite all original concerns being addressed (refactor in b3fbc2e, tests in a9eb239, both confirmed inline by CodeRabbit at 14:55). The earlier @coderabbitai full review ping promised a fresh review but didn't produce one — likely because the initial "Review failed" comment at 14:41 left the review pipeline in a transient bad state. This empty commit forces a fresh incremental review on the current HEAD so CodeRabbit re-evaluates the PR end-to-end and updates the review decision.
Status note for maintainerThis PR is code-complete and fully green — only the formal review state is stuck:
What happenedThe original review at 14:46 was preceded by a CodeRabbit "Review failed" auto-comment at 14:41 — that left their review pipeline in a transient bad state. Both inline concerns from the 14:46 review have since been addressed:
I've pinged Recommended actionIf CodeRabbit doesn't auto-resolve in the next pass, dismiss the 14:46 review ("Dismiss review" → reason: "All concerns addressed in b3fbc2e + a9eb239, confirmed inline by reviewer"). Compare to #1302 where CodeRabbit naturally upgraded their review to APPROVED after the fix was confirmed — that path didn't fire here. |
|
Tip For best results, initiate chat on the files or code changes.
I'm triggering a fresh full review now. This will submit a new formal review submission against the current HEAD ( [full_review] |
Summary
Authorization: Bearer <token>, so it stops being rejected with 401 when the URL is correct.getCoreRpcTokenfromcoreRpcClient.tsso other call sites can attach the bearer header without going throughcallCoreRpc.Problem
Clicking Test Connection in the welcome page's "Configure RPC URL (Advanced)" section fired a raw
fetch()with onlyContent-Type— noAuthorizationheader. The embedded core's auth middleware rejected every probe with 401, regardless of whether the URL was actually correct, surfacing to the user as a misleading "Connection failed". Every other core RPC caller in the app already attaches the bearer; this one path was the outlier.Solution
Resolve the per-process bearer token via the existing
getCoreRpcTokenhelper (now exported) and attachAuthorization: Bearer <token>to the ping. Behavior matches every other core RPC caller in the app.Submission Checklist
Impact
Related
dev:app:winWindows dev-environment plumbingSummary by CodeRabbit
New Features
Tests